List of usage examples for javax.xml.stream XMLStreamException XMLStreamException
public XMLStreamException(Throwable th)
From source file:org.apache.axiom.util.stax.AbstractXMLStreamWriter.java
private String internalGetPrefix(String namespaceURI) throws XMLStreamException { String prefix = namespaceContext.getPrefix(namespaceURI); if (prefix == null) { throw new XMLStreamException("Unbound namespace URI '" + namespaceURI + "'"); } else {//from ww w . ja v a 2 s . co m return prefix; } }
From source file:org.apache.axiom.util.stax.debug.XMLStreamReaderValidator.java
/** * Report a mismatched end element.//from w ww . j a v a 2s.com * @param expectedQName * @param delegateQName * @throws XMLStreamException */ private void reportMismatchedEndElement(QName expectedQName, QName delegateQName) throws XMLStreamException { String text = null; if (expectedQName == null) { text = "An END_ELEMENT event for " + delegateQName + " was encountered, but the START_ELEMENT stack is empty."; } else { text = "An END_ELEMENT event for " + delegateQName + " was encountered, but this doesn't match the corresponding START_ELEMENT " + expectedQName + " event."; } if (IS_DEBUG_ENABLED) { log.debug(text); } if (throwExceptions) { throw new XMLStreamException(text); } }
From source file:org.apache.axiom.util.stax.dialect.SecureXMLResolver.java
public Object resolveEntity(String arg0, String arg1, String arg2, String arg3) throws XMLStreamException { // Do not expose the name of the entity that was attempted to be // read as this will reveal secure information to the client. if (log.isDebugEnabled()) { log.debug("resolveEntity is disabled because this is a secure XMLStreamReader(" + arg0 + ") (" + arg1 + ") (" + arg2 + ") (" + arg3 + ")"); }//www . ja va 2s . c om throw new XMLStreamException("Reading external entities is disabled"); }
From source file:org.apache.axiom.util.stax.XMLStreamReaderUtils.java
/** * Get a {@link DataHandler} for the binary data encoded in an element. The method supports * base64 encoded character data as well as optimized binary data through the * {@link DataHandlerReader} extension.// ww w . ja v a 2s . c o m * <p> * <em>Precondition</em>: the reader is on a {@link XMLStreamConstants#START_ELEMENT} * <p> * <em>Postcondition</em>: the reader is on the corresponding * {@link XMLStreamConstants#END_ELEMENT} * * @param reader the stream to read the data from * @return the binary data from the element */ public static DataHandler getDataHandlerFromElement(XMLStreamReader reader) throws XMLStreamException { int event = reader.next(); if (event == XMLStreamConstants.END_ELEMENT) { // This means that the element is actually empty -> return empty DataHandler return new DataHandler(new EmptyDataSource("application/octet-stream")); } else if (event != XMLStreamConstants.CHARACTERS) { throw new XMLStreamException("Expected a CHARACTER event"); } DataHandlerReader dhr = getDataHandlerReader(reader); if (dhr != null && dhr.isBinary()) { DataHandler dh = dhr.getDataHandler(); reader.next(); return dh; } else { WritableBlob blob = new MemoryBlob(); Writer out = new Base64DecodingOutputStreamWriter(blob.getOutputStream()); try { writeTextTo(reader, out); // Take into account that in non coalescing mode, there may be additional // CHARACTERS events loop: while (true) { switch (reader.next()) { case XMLStreamConstants.CHARACTERS: writeTextTo(reader, out); break; case XMLStreamConstants.END_ELEMENT: break loop; default: throw new XMLStreamException("Expected a CHARACTER event"); } } out.close(); } catch (IOException ex) { throw new XMLStreamException("Error during base64 decoding", ex); } return new DataHandler(new BlobDataSource(blob, "application/octet-string")); } }
From source file:org.apache.axiom.util.stax.xop.XOPDecodingStreamReader.java
/** * Process an <tt>xop:Include</tt> event and return the content ID. * <p>/*from w w w . j a v a2 s . co m*/ * Precondition: The parent reader is on the START_ELEMENT event for the <tt>xop:Include</tt> * element. Note that the method doesn't check this condition. * <p> * Postcondition: The parent reader is on the event following the END_ELEMENT event for the * <tt>xop:Include</tt> element, i.e. the parent reader is on the END_ELEMENT event of the * element enclosing the <tt>xop:Include</tt> element. * * @return the content ID the <tt>xop:Include</tt> refers to * * @throws XMLStreamException */ private String processXopInclude() throws XMLStreamException { if (super.getAttributeCount() != 1 || !super.getAttributeLocalName(0).equals(XOPConstants.HREF)) { throw new XMLStreamException( "Expected xop:Include element information item with " + "a (single) href attribute"); } String href = super.getAttributeValue(0); if (log.isDebugEnabled()) { log.debug("processXopInclude - found href : " + href); } if (!href.startsWith("cid:")) { throw new XMLStreamException("Expected href attribute containing a URL in the " + "cid scheme"); } String contentID; try { // URIs should always be decoded using UTF-8. On the other hand, since non ASCII // characters are not allowed in content IDs, we can simply decode using ASCII // (which is a subset of UTF-8) contentID = URLDecoder.decode(href.substring(4), "ascii"); if (log.isDebugEnabled()) { log.debug("processXopInclude - decoded contentID : " + contentID); } } catch (UnsupportedEncodingException ex) { // We should never get here throw new XMLStreamException(ex); } if (super.next() != END_ELEMENT) { throw new XMLStreamException("Expected xop:Include element information item to be empty"); } // Also consume the END_ELEMENT event of the xop:Include element. There are // two reasons for this: // - It allows us to validate that the message conforms to the XOP specs. // - It makes it easier to implement the getNamespaceContext method. if (super.next() != END_ELEMENT) { throw new XMLStreamException(SOLE_CHILD_MSG); } if (log.isDebugEnabled()) { log.debug("Encountered xop:Include for content ID '" + contentID + "'"); } return contentID; }
From source file:org.apache.axiom.util.stax.xop.XOPDecodingStreamReader.java
public int next() throws XMLStreamException { boolean wasStartElement; int event;/*from w w w . j a v a2 s. co m*/ if (dh != null) { resetDataHandler(); // We already advanced to the next event after the xop:Include (see below), so there // is no call to parent.next() here event = END_ELEMENT; wasStartElement = false; } else { wasStartElement = super.getEventType() == START_ELEMENT; event = super.next(); } if (event == START_ELEMENT && super.getLocalName().equals(XOPConstants.INCLUDE) && super.getNamespaceURI().equals(XOPConstants.NAMESPACE_URI)) { if (!wasStartElement) { throw new XMLStreamException(SOLE_CHILD_MSG); } dh = new DataHandlerProviderImpl(mimePartProvider, processXopInclude()); return CHARACTERS; } else { return event; } }
From source file:org.apache.axiom.util.stax.xop.XOPDecodingStreamReader.java
public String getElementText() throws XMLStreamException { if (super.getEventType() != START_ELEMENT) { throw new XMLStreamException("The current event is not a START_ELEMENT event"); }//from w ww .j a v a 2 s . co m int event = super.next(); // Note that an xop:Include must be the first child of the element if (event == START_ELEMENT && super.getLocalName().equals(XOPConstants.INCLUDE) && super.getNamespaceURI().equals(XOPConstants.NAMESPACE_URI)) { String contentID = processXopInclude(); try { return toBase64(mimePartProvider.getDataHandler(contentID)); } catch (IOException ex) { throw new XMLStreamException("Failed to load MIME part '" + contentID + "'", ex); } } else { String text = null; StringBuffer buffer = null; while (event != END_ELEMENT) { switch (event) { case CHARACTERS: case CDATA: case SPACE: case ENTITY_REFERENCE: if (text == null && buffer == null) { text = super.getText(); } else { String thisText = super.getText(); if (buffer == null) { buffer = new StringBuffer(text.length() + thisText.length()); buffer.append(text); } buffer.append(thisText); } break; case PROCESSING_INSTRUCTION: case COMMENT: // Skip this event break; default: throw new XMLStreamException("Unexpected event " + XMLEventUtils.getEventTypeString(event) + " while reading element text"); } event = super.next(); } if (buffer != null) { return buffer.toString(); } else if (text != null) { return text; } else { return ""; } } }
From source file:org.apache.axiom.util.stax.xop.XOPDecodingStreamReader.java
public void require(int type, String namespaceURI, String localName) throws XMLStreamException { if (dh != null) { if (type != CHARACTERS) { throw new XMLStreamException("Expected CHARACTERS event"); }/* ww w .ja v a 2s. com*/ } else { super.require(type, namespaceURI, localName); } }
From source file:org.apache.axiom.util.stax.xop.XOPDecodingStreamReader.java
public DataHandler getDataHandler() throws XMLStreamException { try {//from w w w . j a va 2 s .c om return dh.getDataHandler(); } catch (IOException ex) { throw new XMLStreamException("Failed to load MIME part '" + dh.getContentID() + "'"); } }
From source file:org.apache.axis2.builder.BuilderUtil.java
public static StAXBuilder getAttachmentsBuilder(MessageContext msgContext, InputStream inStream, String contentTypeString, boolean isSOAP) throws OMException, XMLStreamException, FactoryConfigurationError { StAXBuilder builder = null;/* w w w .j a v a2s.co m*/ XMLStreamReader streamReader; Attachments attachments = createAttachmentsMap(msgContext, inStream, contentTypeString); String charSetEncoding = getCharSetEncoding(attachments.getSOAPPartContentType()); if ((charSetEncoding == null) || "null".equalsIgnoreCase(charSetEncoding)) { charSetEncoding = MessageContext.UTF_8; } msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEncoding); try { PushbackInputStream pis = getPushbackInputStream(attachments.getSOAPPartInputStream()); String actualCharSetEncoding = getCharSetEncoding(pis, charSetEncoding); streamReader = StAXUtils.createXMLStreamReader(pis, actualCharSetEncoding); } catch (IOException e) { throw new XMLStreamException(e); } // Put a reference to Attachments Map in to the message context For // backword compatibility with Axis2 1.0 msgContext.setProperty(MTOMConstants.ATTACHMENTS, attachments); // Setting the Attachments map to new SwA API msgContext.setAttachmentMap(attachments); String soapEnvelopeNamespaceURI = getEnvelopeNamespace(contentTypeString); return MessageProcessorSelector.getAttachmentBuilder(msgContext, attachments, streamReader, soapEnvelopeNamespaceURI, isSOAP); }