List of usage examples for javax.xml.stream XMLStreamException XMLStreamException
public XMLStreamException(Throwable th)
From source file:org.apache.axis2.json.gson.GsonXMLStreamWriter.java
/** * Writes an end tag to the output relying on the internal * state of the writer to determine the prefix and local name * of the event.// www . j a v a 2s . co m * * @throws javax.xml.stream.XMLStreamException */ public void writeEndElement() throws XMLStreamException { if (!isProcessed) { try { process(); } catch (IOException e) { throw new XMLStreamException("Error occours while write first begin object "); } } JsonObject stackObj = null; try { //If the suspected element is empty if (potentialEmpty) { emptyObjectExists = true; } if (flushObject != null) { if (topNestedArrayObj != null && flushObject.getType() == JSONType.NESTED_ARRAY && flushObject.equals(topNestedArrayObj.getName())) { topNestedArrayObj = null; processedJsonObjects.clear(); } popStack(); writeEndJson(flushObject); flushObject = null; writeEndElement(); } else { if (stack.peek().getType() == JSONType.ARRAY) { flushObject = stack.peek(); } else if (stack.peek().getType() == JSONType.NESTED_ARRAY) { flushObject = stack.peek(); jsonWriter.endObject(); } else { stackObj = popStack(); writeEndJson(stackObj); } } } catch (IOException e) { throw new XMLStreamException("Json writer throw an exception"); } }
From source file:org.apache.axis2.json.gson.GsonXMLStreamWriter.java
/** * Closes any start tags and writes corresponding end tags. * * @throws javax.xml.stream.XMLStreamException *///from w w w . j a va 2 s . c o m public void writeEndDocument() throws XMLStreamException { if (!isProcessed) { try { process(); } catch (IOException e) { throw new XMLStreamException("Error occours while write first begin object "); } } //Since empty objects presents with the stream if (emptyObjectExists) { queue.clear(); } if (queue.isEmpty() && stack.isEmpty()) { try { if (flushObject != null) { writeEndJson(flushObject); } jsonWriter.endObject(); jsonWriter.flush(); jsonWriter.close(); } catch (IOException e) { throw new XMLStreamException("JsonWriter threw an exception", e); } } else { throw new XMLStreamException("Invalid xml element"); } }
From source file:org.apache.axis2.json.gson.GsonXMLStreamWriter.java
/** * Write the XML Declaration. Defaults the XML version to 1.0, and the encoding to utf-8 * * @throws javax.xml.stream.XMLStreamException */// w ww. java 2 s. com public void writeStartDocument() throws XMLStreamException { if (!isProcessed) { try { process(); } catch (IOException e) { throw new XMLStreamException("Error occur while write first begin object "); } } }
From source file:org.apache.axis2.json.gson.GsonXMLStreamWriter.java
/** * Write text to the output//from w w w .j ava 2s. c o m * * @param text the value to write * @throws javax.xml.stream.XMLStreamException */ public void writeCharacters(String text) throws XMLStreamException { if (!isProcessed) { try { process(); } catch (IOException e) { throw new XMLStreamException("Error occur while trying to write first begin object "); } } try { JsonObject peek = stack.peek(); String valueType = peek.getValueType(); if (valueType.equals("string")) { jsonWriter.value(text); } else if (valueType.equals("int") || valueType.equals("integer")) { Number num = new Integer(text); jsonWriter.value(num); } else if (valueType.equals("long")) { jsonWriter.value(Long.valueOf(text)); } else if (valueType.equals("double")) { jsonWriter.value(Double.valueOf(text)); } else if (valueType.equals("boolean")) { jsonWriter.value(Boolean.valueOf(text)); } else { jsonWriter.value(text); } } catch (IOException e) { throw new XMLStreamException("JsonWriter throw an exception"); } }
From source file:org.apache.synapse.util.WrappedTextNodeStreamReader.java
public int next() throws XMLStreamException { // Determine next event type based on current event type. If current event type // is START_ELEMENT or CHARACTERS, pull new data from the reader. switch (eventType) { case -1:/*from www .ja v a 2 s . c o m*/ eventType = START_DOCUMENT; break; case START_DOCUMENT: eventType = START_ELEMENT; break; case START_ELEMENT: charData = new char[chunkSize]; // No break here! case CHARACTERS: try { charDataLength = reader.read(charData); } catch (IOException ex) { throw new XMLStreamException(ex); } if (charDataLength == -1) { charData = null; eventType = END_ELEMENT; } else { eventType = CHARACTERS; } break; case END_ELEMENT: eventType = END_DOCUMENT; break; default: throw new IllegalStateException(); } return eventType; }
From source file:org.apache.xml.security.stax.impl.transformer.TransformBase64Decode.java
@Override public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException { int eventType = xmlSecEvent.getEventType(); switch (eventType) { case XMLStreamConstants.CHARACTERS: if (getOutputStream() != null) { //we have an output stream //encoding shouldn't matter here, because the data is Base64 encoded and is therefore in the ASCII range. try { getOutputStream().write(xmlSecEvent.asCharacters().getData().getBytes()); } catch (IOException e) { throw new XMLStreamException(e); }// www . j a v a 2s. co m } else { //we have a child transformer if (childOutputMethod == null) { final XMLSecurityConstants.TransformMethod preferredChildTransformMethod = getTransformer() .getPreferredTransformMethod(XMLSecurityConstants.TransformMethod.XMLSecEvent); switch (preferredChildTransformMethod) { case XMLSecEvent: { childOutputMethod = new ChildOutputMethod() { private UnsynchronizedByteArrayOutputStream byteArrayOutputStream; private Base64OutputStream base64OutputStream; @Override public void transform(Object object) throws XMLStreamException { if (base64OutputStream == null) { byteArrayOutputStream = new UnsynchronizedByteArrayOutputStream(); base64OutputStream = new Base64OutputStream(byteArrayOutputStream, false); } try { base64OutputStream.write(((byte[]) object)); } catch (IOException e) { throw new XMLStreamException(e); } } @Override public void doFinal() throws XMLStreamException { try { base64OutputStream.close(); } catch (IOException e) { throw new XMLStreamException(e); } XMLEventReaderInputProcessor xmlEventReaderInputProcessor = new XMLEventReaderInputProcessor( null, getXmlInputFactory() .createXMLStreamReader(new UnsynchronizedByteArrayInputStream( byteArrayOutputStream.toByteArray()))); try { XMLSecEvent xmlSecEvent; do { xmlSecEvent = xmlEventReaderInputProcessor.processNextEvent(null); getTransformer().transform(xmlSecEvent); } while (xmlSecEvent.getEventType() != XMLStreamConstants.END_DOCUMENT); } catch (XMLSecurityException e) { throw new XMLStreamException(e); } getTransformer().doFinal(); } }; break; } case InputStream: { childOutputMethod = new ChildOutputMethod() { private UnsynchronizedByteArrayOutputStream byteArrayOutputStream; private Base64OutputStream base64OutputStream; @Override public void transform(Object object) throws XMLStreamException { if (base64OutputStream == null) { byteArrayOutputStream = new UnsynchronizedByteArrayOutputStream(); base64OutputStream = new Base64OutputStream(byteArrayOutputStream, false); } try { base64OutputStream.write(((byte[]) object)); } catch (IOException e) { throw new XMLStreamException(e); } } @Override public void doFinal() throws XMLStreamException { try { base64OutputStream.close(); } catch (IOException e) { throw new XMLStreamException(e); } getTransformer().transform(new UnsynchronizedByteArrayInputStream( byteArrayOutputStream.toByteArray())); getTransformer().doFinal(); } }; break; } } } childOutputMethod.transform(xmlSecEvent.asCharacters().getData().getBytes()); } break; } }
From source file:org.apache.xml.security.stax.impl.transformer.TransformBase64Decode.java
@Override public void doFinal() throws XMLStreamException { if (getOutputStream() != null) { try {// w w w . java2s . c o m getOutputStream().close(); } catch (IOException e) { throw new XMLStreamException(e); } } if (childOutputMethod != null) { childOutputMethod.doFinal(); } else if (getTransformer() != null) { getTransformer().doFinal(); } }
From source file:org.betaconceptframework.astroboa.model.jaxb.writer.JSONXmlStreamWriter.java
@Override public void close() throws XMLStreamException { try {/*w w w . j a v a 2s. com*/ generator.close(); } catch (IOException e) { throw new XMLStreamException(e); } }
From source file:org.betaconceptframework.astroboa.model.jaxb.writer.JSONXmlStreamWriter.java
@Override public void flush() throws XMLStreamException { try {/*from www. ja va 2s . c o m*/ generator.flush(); } catch (IOException e) { throw new XMLStreamException(e); } }
From source file:org.betaconceptframework.astroboa.model.jaxb.writer.JSONXmlStreamWriter.java
@Override public void writeAttribute(String localName, String value) throws XMLStreamException { try {//from w w w .j av a 2 s .c om if (!objectQueue.isEmpty()) { if (StringUtils.equals(CmsConstants.EXPORT_AS_AN_ARRAY_INSTRUCTION, localName)) { objectQueue.peek().exportAsAnArray = BooleanUtils.isTrue(BooleanUtils.toBoolean(value)); } else { objectQueue.peek().addAttribute(localName, value); } } } catch (Exception e) { throw new XMLStreamException(e); } }