@Test public void parseErrorResponse() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\"?>\n") .append("<operation type=\"submit\">\n") .append(" <error code=\"1001\" message=\"This is a test message\" />\n") .append("</operation>\n") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); SxmpParser parser = new SxmpParser(); Operation operation = parser.parse(is); Assert.assertEquals(Operation.Type.SUBMIT, operation.getType()); Assert.assertEquals(true, operation.isResponse()); ErrorResponse errorResponse = (ErrorResponse)operation; Assert.assertEquals(new Integer(1001), errorResponse.getErrorCode()); Assert.assertEquals("This is a test message", errorResponse.getErrorMessage()); }
public Operation parse(InputStream in) throws SxmpParsingException, IOException, SAXException, ParserConfigurationException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: Handler handler = new Handler(); XMLReader reader = parser.getXMLReader(); reader.setContentHandler(handler); reader.setErrorHandler(handler); reader.setEntityResolver(handler); try { parser.parse(new InputSource(in), handler); } catch (com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException e) { throw new SxmpParsingException(SxmpErrorCode.INVALID_XML, "XML encoding mismatch", null); } if (handler.error != null) { throw handler.error; } if (handler.getOperation() == null) { throw new SxmpParsingException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "The operation type [" + handler.operationType.getValue() + "] requires a request element", new PartialOperation(handler.operationType)); } try { handler.getOperation().validate(); } catch (SxmpErrorException e) { throw new SxmpParsingException(e.getErrorCode(), e.getErrorMessage(), handler.getOperation()); } return handler.getOperation(); }
SxmpParser { public Operation parse(InputStream in) throws SxmpParsingException, IOException, SAXException, ParserConfigurationException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: Handler handler = new Handler(); XMLReader reader = parser.getXMLReader(); reader.setContentHandler(handler); reader.setErrorHandler(handler); reader.setEntityResolver(handler); try { parser.parse(new InputSource(in), handler); } catch (com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException e) { throw new SxmpParsingException(SxmpErrorCode.INVALID_XML, "XML encoding mismatch", null); } if (handler.error != null) { throw handler.error; } if (handler.getOperation() == null) { throw new SxmpParsingException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "The operation type [" + handler.operationType.getValue() + "] requires a request element", new PartialOperation(handler.operationType)); } try { handler.getOperation().validate(); } catch (SxmpErrorException e) { throw new SxmpParsingException(e.getErrorCode(), e.getErrorMessage(), handler.getOperation()); } return handler.getOperation(); } }
SxmpParser { public Operation parse(InputStream in) throws SxmpParsingException, IOException, SAXException, ParserConfigurationException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: Handler handler = new Handler(); XMLReader reader = parser.getXMLReader(); reader.setContentHandler(handler); reader.setErrorHandler(handler); reader.setEntityResolver(handler); try { parser.parse(new InputSource(in), handler); } catch (com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException e) { throw new SxmpParsingException(SxmpErrorCode.INVALID_XML, "XML encoding mismatch", null); } if (handler.error != null) { throw handler.error; } if (handler.getOperation() == null) { throw new SxmpParsingException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "The operation type [" + handler.operationType.getValue() + "] requires a request element", new PartialOperation(handler.operationType)); } try { handler.getOperation().validate(); } catch (SxmpErrorException e) { throw new SxmpParsingException(e.getErrorCode(), e.getErrorMessage(), handler.getOperation()); } return handler.getOperation(); } SxmpParser();  SxmpParser(final String version); }
SxmpParser { public Operation parse(InputStream in) throws SxmpParsingException, IOException, SAXException, ParserConfigurationException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: Handler handler = new Handler(); XMLReader reader = parser.getXMLReader(); reader.setContentHandler(handler); reader.setErrorHandler(handler); reader.setEntityResolver(handler); try { parser.parse(new InputSource(in), handler); } catch (com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException e) { throw new SxmpParsingException(SxmpErrorCode.INVALID_XML, "XML encoding mismatch", null); } if (handler.error != null) { throw handler.error; } if (handler.getOperation() == null) { throw new SxmpParsingException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "The operation type [" + handler.operationType.getValue() + "] requires a request element", new PartialOperation(handler.operationType)); } try { handler.getOperation().validate(); } catch (SxmpErrorException e) { throw new SxmpParsingException(e.getErrorCode(), e.getErrorMessage(), handler.getOperation()); } return handler.getOperation(); } SxmpParser();  SxmpParser(final String version); Operation parse(InputStream in); }
SxmpParser { public Operation parse(InputStream in) throws SxmpParsingException, IOException, SAXException, ParserConfigurationException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: Handler handler = new Handler(); XMLReader reader = parser.getXMLReader(); reader.setContentHandler(handler); reader.setErrorHandler(handler); reader.setEntityResolver(handler); try { parser.parse(new InputSource(in), handler); } catch (com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException e) { throw new SxmpParsingException(SxmpErrorCode.INVALID_XML, "XML encoding mismatch", null); } if (handler.error != null) { throw handler.error; } if (handler.getOperation() == null) { throw new SxmpParsingException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "The operation type [" + handler.operationType.getValue() + "] requires a request element", new PartialOperation(handler.operationType)); } try { handler.getOperation().validate(); } catch (SxmpErrorException e) { throw new SxmpParsingException(e.getErrorCode(), e.getErrorMessage(), handler.getOperation()); } return handler.getOperation(); } SxmpParser();  SxmpParser(final String version); Operation parse(InputStream in); static final String VERSION_1_0; static final String VERSION_1_1; static final String VERSION_1_2; }