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.owl;
016    
017    import java.io.IOException;
018    
019    import org.coode.owlapi.owlxml.renderer.OWLXMLRenderer;
020    import org.semanticweb.owlapi.io.OWLRendererException;
021    import org.semanticweb.owlapi.model.OWLOntology;
022    
023    import ch.uzh.ifi.attempto.acewiki.core.OntologyExporter;
024    
025    /**
026     * This exporter generates an OWL/XML representation of the ontology.
027     * 
028     * @author Tobias Kuhn
029     */
030    public class OWLXMLExporter extends OntologyExporter {
031            
032            private final boolean consistent;
033    
034            /**
035             * Creates a new OWL/XML exporter.
036             * 
037             * @param consistent Defines if only the consistent part of the ontology should be considered.
038             */
039            public OWLXMLExporter(boolean consistent) {
040                    this.consistent = consistent;
041            }
042            
043            protected void writeContent() throws IOException {
044                    AceWikiOWLReasoner owlReasoner = (AceWikiOWLReasoner) getOntology()
045                                    .getReasoner().getWrappedReasoner();
046                    OWLOntology owlOntology = owlReasoner.exportOWLOntology(consistent);
047            try {
048                OWLXMLRenderer renderer = new OWLXMLRenderer(owlReasoner.getOWLOntologyManager());
049                renderer.render(owlOntology, getOutputStream());
050            } catch (OWLRendererException ex) {
051                ex.printStackTrace();
052            }
053            }
054            
055            public String getName() {
056                    return "OWL Ontology, " + (consistent ? "consistent" : "full");
057            }
058            
059            public boolean isApplicable() {
060                    return getOntology().getReasoner().getWrappedReasoner() instanceof AceWikiOWLReasoner;
061            }
062            
063            public String getFileSuffix() {
064                    return ".owl";
065            }
066            
067            public String getContentType() {
068                    return "application/owl+xml";
069            }
070    
071    }