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.TextOperator;
018
019 /**
020 * This class represents a statement that can be either an ACE sentence or a comment. A
021 * statement can either be part of an article or it can be an independent statement that has no
022 * article.
023 *
024 * @author Tobias Kuhn
025 */
026 public abstract class AbstractStatement implements Statement {
027
028 private Ontology ontology;
029 private Article article;
030
031 /**
032 * Initializes a new independent statement.
033 */
034 protected AbstractStatement() {
035 }
036
037 public void init(Ontology ontology, Article article) {
038 this.ontology = ontology;
039 this.article = article;
040 }
041
042 public Ontology getOntology() {
043 return ontology;
044 }
045
046 public Article getArticle() {
047 return article;
048 }
049
050 public String toString() {
051 return getText(getDefaultLanguage());
052 }
053
054 /**
055 * Returns the AceWiki engine.
056 *
057 * @return The engine.
058 */
059 protected AceWikiEngine getEngine() {
060 return getOntology().getEngine();
061 }
062
063 /**
064 * Returns the default language.
065 *
066 * @return The default language.
067 */
068 protected String getDefaultLanguage() {
069 return getEngine().getLanguages()[0];
070 }
071
072 /**
073 * Returns the language handler for the given language.
074 *
075 * @param language The language.
076 * @return The language handler.
077 */
078 protected LanguageHandler getLanguageHandler(String language) {
079 return getEngine().getLanguageHandler(language);
080 }
081
082 /**
083 * Returns the text operator for the given language.
084 *
085 * @param language The language.
086 * @return The text operator.
087 */
088 protected TextOperator getTextOperator(String language) {
089 return getLanguageHandler(language).getTextOperator();
090 }
091
092 }