001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.wiki.engines.antlrwiki.translator.internal;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.parsers.creole.ast.BoldTextNode;
019    import com.liferay.portal.parsers.creole.ast.FormattedTextNode;
020    import com.liferay.portal.parsers.creole.ast.ItalicTextNode;
021    import com.liferay.portal.parsers.creole.ast.NoWikiSectionNode;
022    import com.liferay.portal.parsers.creole.ast.UnformattedTextNode;
023    import com.liferay.portal.parsers.creole.ast.link.LinkNode;
024    import com.liferay.portal.parsers.creole.visitor.impl.BaseASTVisitor;
025    
026    /**
027     * @author Miguel Pastor
028     */
029    public abstract class UnformattedTextVisitor extends BaseASTVisitor {
030    
031            public String getText() {
032                    return _sb.toString();
033            }
034    
035            @Override
036            public void visit(BoldTextNode boldTextNode) {
037                    if (boldTextNode.getContent() != null) {
038                            write(boldTextNode.getContent());
039                    }
040                    else {
041                            super.visit(boldTextNode);
042                    }
043            }
044    
045            @Override
046            public void visit(FormattedTextNode formattedTextNode) {
047                    if (formattedTextNode.getContent() != null) {
048                            write(formattedTextNode.getContent());
049                    }
050                    else {
051                            super.visit(formattedTextNode);
052                    }
053            }
054    
055            @Override
056            public void visit(ItalicTextNode italicTextNode) {
057                    if (italicTextNode.getContent() != null) {
058                            write(italicTextNode.getContent());
059                    }
060                    else {
061                            super.visit(italicTextNode);
062                    }
063            }
064    
065            @Override
066            public void visit(LinkNode linkNode) {
067                    String link = linkNode.getLink();
068    
069                    if (link != null) {
070                            write(link);
071                    }
072    
073                    super.visit(linkNode);
074            }
075    
076            @Override
077            public void visit(NoWikiSectionNode noWikiSectionNode) {
078                    write(noWikiSectionNode.getContent());
079            }
080    
081            @Override
082            public void visit(UnformattedTextNode unformattedTextNode) {
083                    if (unformattedTextNode.hasContent()) {
084                            write(unformattedTextNode.getContent());
085                    }
086                    else {
087                            super.visit(unformattedTextNode);
088                    }
089            }
090    
091            protected void write(String text) {
092                    _sb.append(text);
093            }
094    
095            private StringBundler _sb = new StringBundler();
096    
097    }