001    // This file is part of AceWiki.
002    // Copyright 2008-2012, AceWiki developers.
003    // 
004    // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU
005    // Lesser General Public License as published by the Free Software Foundation, either version 3 of
006    // the License, or (at your option) any later version.
007    // 
008    // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009    // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
010    // Lesser General Public License for more details.
011    // 
012    // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If
013    // not, see http://www.gnu.org/licenses/.
014    
015    package ch.uzh.ifi.attempto.acewiki.core;
016    
017    import ch.uzh.ifi.attempto.base.TextContainer;
018    import ch.uzh.ifi.attempto.base.TextElement;
019    import ch.uzh.ifi.attempto.base.TextOperator;
020    
021    /**
022     * This class is a partial implementation of a sentence.
023     * 
024     * @author Tobias Kuhn
025     */
026    public abstract class AbstractSentence extends AbstractStatement implements Sentence {
027            
028            private boolean integrated = false;
029            
030            public boolean isIntegrated() {
031                    return integrated;
032            }
033            
034            public void setIntegrated(boolean integrated) {
035                    this.integrated = integrated;
036            }
037            
038            public boolean isImmutable() {
039                    return getArticle() == null;
040            }
041            
042            /**
043             * Returns a text container with the text of this sentence in the given language.
044             * 
045             * @param language The language.
046             * @return The text container.
047             */
048            protected abstract TextContainer getTextContainer(String language);
049            
050            public String getText(String language) {
051                    String t = "";
052                    TextElement prev = null;
053                    TextOperator textOperator = getTextOperator(language);
054                    for (TextElement te : getTextContainer(language).getTextElements()) {
055                            String glue = "";
056                            if (prev != null) {
057                                    glue = textOperator.getGlue(prev, te);
058                            }
059                            if (te instanceof OntologyTextElement) {
060                                    t += glue + ((OntologyTextElement) te).getUnderscoredText();
061                            } else {
062                                    t += glue + te.getText();
063                            }
064                            prev = te;
065                    }
066                    return t;
067            }
068    
069    }