001 // This file is part of the Attempto Java Packages. 002 // Copyright 2008-2009, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch). 003 // 004 // The Attempto Java Packages is free software: you can redistribute it and/or modify it under the 005 // terms of the GNU Lesser General Public License as published by the Free Software Foundation, 006 // either version 3 of the License, or (at your option) any later version. 007 // 008 // The Attempto Java Packages is distributed in the hope that it will be useful, but WITHOUT ANY 009 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 010 // PURPOSE. See the GNU Lesser General Public License for more details. 011 // 012 // You should have received a copy of the GNU Lesser General Public License along with the Attempto 013 // Java Packages. If not, see http://www.gnu.org/licenses/. 014 015 package ch.uzh.ifi.attempto.ape; 016 017 import java.io.StringReader; 018 019 import org.jdom.Document; 020 import org.jdom.Element; 021 import org.jdom.input.SAXBuilder; 022 023 /** 024 * This class represents the output that is returned by the ACEParser class. 025 * 026 * @author Tobias Kuhn 027 */ 028 public class ACEParserResult { 029 030 private Element result; 031 private MessageContainer messageContainer = new MessageContainer(); 032 033 034 ACEParserResult(String xmlString) { 035 try { 036 SAXBuilder sb = new SAXBuilder(); 037 sb.setValidation(false); 038 Document xml = sb.build(new StringReader(xmlString)); 039 result = xml.getRootElement(); 040 messageContainer = new MessageContainer(result.getChild("messages")); 041 } catch (Exception ex) { 042 ex.printStackTrace(); 043 } 044 } 045 046 /** 047 * Returns the specified output as a string. If the requested output is not available (because 048 * it has not been requested) then null is returned. 049 * 050 * @param outputType The output to be returned. 051 * @return The output as a string. 052 */ 053 public String get(OutputType outputType) { 054 try { 055 Element element = result.getChild(outputType.toString().toLowerCase()); 056 return element.getText(); 057 } catch (Exception ex) { 058 return null; 059 } 060 } 061 062 /** 063 * Returns the message container that contains the error and warning messages of the parsing 064 * procedure. 065 * 066 * @return The message container. 067 */ 068 public MessageContainer getMessageContainer() { 069 return messageContainer; 070 } 071 072 }