List of usage examples for javax.xml.stream XMLStreamConstants NOTATION_DECLARATION
int NOTATION_DECLARATION
To view the source code for javax.xml.stream XMLStreamConstants NOTATION_DECLARATION.
Click Source Link
From source file:com.widowcrawler.exo.parse.Parser.java
private static String getEventTypeString(int eventType) { switch (eventType) { case XMLStreamConstants.START_ELEMENT: return "START_ELEMENT"; case XMLStreamConstants.END_ELEMENT: return "END_ELEMENT"; case XMLStreamConstants.PROCESSING_INSTRUCTION: return "PROCESSING_INSTRUCTION"; case XMLStreamConstants.CHARACTERS: return "CHARACTERS"; case XMLStreamConstants.COMMENT: return "COMMENT"; case XMLStreamConstants.START_DOCUMENT: return "START_DOCUMENT"; case XMLStreamConstants.END_DOCUMENT: return "END_DOCUMENT"; case XMLStreamConstants.ENTITY_REFERENCE: return "ENTITY_REFERENCE"; case XMLStreamConstants.ATTRIBUTE: return "ATTRIBUTE"; case XMLStreamConstants.DTD: return "DTD"; case XMLStreamConstants.CDATA: return "CDATA"; case XMLStreamConstants.SPACE: return "SPACE"; case XMLStreamConstants.ENTITY_DECLARATION: return "ENTITY_DECLARATION"; case XMLStreamConstants.NAMESPACE: return "NAMESPACE"; case XMLStreamConstants.NOTATION_DECLARATION: return "NOTATION_DECLARATION"; }/*from w ww . ja v a 2s.co m*/ return "UNKNOWN_EVENT_TYPE: " + eventType; }
From source file:org.javelin.sws.ext.bind.internal.model.ComplexTypePattern.java
@Override public T consumeValue(XMLEventReader eventReader, UnmarshallingContext context) throws XMLStreamException { // first create an object to be filled (using PropertyAccessors - direct or bean) according to the content model T object = BeanUtils.instantiate(this.getJavaType()); // the order is dictated by incoming events, not by the mode // TODO: create a property to enable strict unmarshalling - dictated by content model // only this (ContentModel) pattern iterates over XML Events XMLEvent event = null;/*from ww w . j a va 2s .c o m*/ PropertyMetadataValue<T, ?> pmv = null; // this loop will only handle first level of start elements and only single end element // deeper levels will be handled by nested patterns while (true) { boolean end = false; event = eventReader.peek(); pmv = null; switch (event.getEventType()) { case XMLStreamConstants.ATTRIBUTE: pmv = this.consumeNestedAttribute(eventReader, context); break; case XMLStreamConstants.CDATA: case XMLStreamConstants.CHARACTERS: // TODO: XMLEvent.ENTITY_REFERENCE? if (this.simpleContent != null) { pmv = this.consumeSimpleContent(eventReader, context); break; } case XMLStreamConstants.COMMENT: case XMLStreamConstants.DTD: case XMLStreamConstants.SPACE: case XMLStreamConstants.ENTITY_DECLARATION: case XMLStreamConstants.NOTATION_DECLARATION: case XMLStreamConstants.PROCESSING_INSTRUCTION: eventReader.nextEvent(); break; case XMLStreamConstants.ENTITY_REFERENCE: // TODO: XMLEvent.ENTITY_REFERENCE? eventReader.nextEvent(); break; case XMLStreamConstants.START_DOCUMENT: // strange break; case XMLStreamConstants.START_ELEMENT: pmv = this.consumeNestedElement(eventReader, context); break; case XMLStreamConstants.END_ELEMENT: // TODO: in mixed content there will be more than one end element it this content model's level case XMLStreamConstants.END_DOCUMENT: end = true; break; } if (end) break; if (pmv != null) pmv.getMetadata().setValue(object, pmv.getValue()); } return (T) object; }
From source file:ca.uhn.fhir.parser.XmlParser.java
private void encodeXhtml(XhtmlDt theDt, XMLStreamWriter theEventWriter) throws XMLStreamException { if (theDt == null || theDt.getValue() == null) { return;// ww w.j a v a 2 s. c o m } boolean firstElement = true; for (XMLEvent event : theDt.getValue()) { switch (event.getEventType()) { case XMLStreamConstants.ATTRIBUTE: Attribute attr = (Attribute) event; if (isBlank(attr.getName().getPrefix())) { if (isBlank(attr.getName().getNamespaceURI())) { theEventWriter.writeAttribute(attr.getName().getLocalPart(), attr.getValue()); } else { theEventWriter.writeAttribute(attr.getName().getNamespaceURI(), attr.getName().getLocalPart(), attr.getValue()); } } else { theEventWriter.writeAttribute(attr.getName().getPrefix(), attr.getName().getNamespaceURI(), attr.getName().getLocalPart(), attr.getValue()); } break; case XMLStreamConstants.CDATA: theEventWriter.writeCData(((Characters) event).getData()); break; case XMLStreamConstants.CHARACTERS: case XMLStreamConstants.SPACE: String data = ((Characters) event).getData(); theEventWriter.writeCharacters(data); break; case XMLStreamConstants.COMMENT: theEventWriter.writeComment(((Comment) event).getText()); break; case XMLStreamConstants.END_ELEMENT: theEventWriter.writeEndElement(); break; case XMLStreamConstants.ENTITY_REFERENCE: EntityReference er = (EntityReference) event; theEventWriter.writeEntityRef(er.getName()); break; case XMLStreamConstants.NAMESPACE: Namespace ns = (Namespace) event; theEventWriter.writeNamespace(ns.getPrefix(), ns.getNamespaceURI()); break; case XMLStreamConstants.START_ELEMENT: StartElement se = event.asStartElement(); if (firstElement) { if (StringUtils.isBlank(se.getName().getPrefix())) { String namespaceURI = se.getName().getNamespaceURI(); if (StringUtils.isBlank(namespaceURI)) { namespaceURI = "http://www.w3.org/1999/xhtml"; } theEventWriter.writeStartElement(se.getName().getLocalPart()); theEventWriter.writeDefaultNamespace(namespaceURI); } else { String prefix = se.getName().getPrefix(); String namespaceURI = se.getName().getNamespaceURI(); theEventWriter.writeStartElement(prefix, se.getName().getLocalPart(), namespaceURI); theEventWriter.writeNamespace(prefix, namespaceURI); } firstElement = false; } else { if (isBlank(se.getName().getPrefix())) { if (isBlank(se.getName().getNamespaceURI())) { theEventWriter.writeStartElement(se.getName().getLocalPart()); } else { if (StringUtils.isBlank(se.getName().getPrefix())) { theEventWriter.writeStartElement(se.getName().getLocalPart()); // theEventWriter.writeDefaultNamespace(se.getName().getNamespaceURI()); } else { theEventWriter.writeStartElement(se.getName().getNamespaceURI(), se.getName().getLocalPart()); } } } else { theEventWriter.writeStartElement(se.getName().getPrefix(), se.getName().getLocalPart(), se.getName().getNamespaceURI()); } for (Iterator<?> attrIter = se.getAttributes(); attrIter.hasNext();) { Attribute next = (Attribute) attrIter.next(); theEventWriter.writeAttribute(next.getName().getLocalPart(), next.getValue()); } } break; case XMLStreamConstants.DTD: case XMLStreamConstants.END_DOCUMENT: case XMLStreamConstants.ENTITY_DECLARATION: case XMLStreamConstants.NOTATION_DECLARATION: case XMLStreamConstants.PROCESSING_INSTRUCTION: case XMLStreamConstants.START_DOCUMENT: break; } } }
From source file:org.pentaho.di.trans.steps.webservices.WebService.java
private void compatibleProcessRows(InputStream anXml, Object[] rowData, RowMetaInterface rowMeta, boolean ignoreNamespacePrefix, String encoding) throws KettleException { // First we should get the complete string // The problem is that the string can contain XML or any other format such as HTML saying the service is no longer // available. // We're talking about a WEB service here. // As such, to keep the original parsing scheme, we first read the content. // Then we create an input stream from the content again. // It's elaborate, but that way we can report on the failure more correctly. ////from w ww . ja v a2s . com String response = readStringFromInputStream(anXml, encoding); // Create a new reader to feed into the XML Input Factory below... // StringReader stringReader = new StringReader(response.toString()); // TODO Very empirical : see if we can do something better here try { XMLInputFactory vFactory = XMLInputFactory.newInstance(); XMLStreamReader vReader = vFactory.createXMLStreamReader(stringReader); Object[] outputRowData = RowDataUtil.allocateRowData(data.outputRowMeta.size()); int outputIndex = 0; boolean processing = false; boolean oneValueRowProcessing = false; for (int event = vReader.next(); vReader.hasNext(); event = vReader.next()) { switch (event) { case XMLStreamConstants.START_ELEMENT: // Start new code // START_ELEMENT= 1 // if (log.isRowLevel()) { logRowlevel("START_ELEMENT / " + vReader.getAttributeCount() + " / " + vReader.getNamespaceCount()); } // If we start the xml element named like the return type, // we start a new row // if (log.isRowLevel()) { logRowlevel("vReader.getLocalName = " + vReader.getLocalName()); } if (Const.isEmpty(meta.getOutFieldArgumentName())) { // getOutFieldArgumentName() == null if (oneValueRowProcessing) { WebServiceField field = meta.getFieldOutFromWsName(vReader.getLocalName(), ignoreNamespacePrefix); if (field != null) { outputRowData[outputIndex++] = getValue(vReader.getElementText(), field); putRow(data.outputRowMeta, outputRowData); oneValueRowProcessing = false; } else { if (meta.getOutFieldContainerName().equals(vReader.getLocalName())) { // meta.getOutFieldContainerName() = vReader.getLocalName() if (log.isRowLevel()) { logRowlevel("OutFieldContainerName = " + meta.getOutFieldContainerName()); } oneValueRowProcessing = true; } } } } else { // getOutFieldArgumentName() != null if (log.isRowLevel()) { logRowlevel("OutFieldArgumentName = " + meta.getOutFieldArgumentName()); } if (meta.getOutFieldArgumentName().equals(vReader.getLocalName())) { if (log.isRowLevel()) { logRowlevel("vReader.getLocalName = " + vReader.getLocalName()); } if (log.isRowLevel()) { logRowlevel("OutFieldArgumentName = "); } if (processing) { WebServiceField field = meta.getFieldOutFromWsName(vReader.getLocalName(), ignoreNamespacePrefix); if (field != null) { int index = data.outputRowMeta.indexOfValue(field.getName()); if (index >= 0) { outputRowData[index] = getValue(vReader.getElementText(), field); } } processing = false; } else { WebServiceField field = meta.getFieldOutFromWsName(vReader.getLocalName(), ignoreNamespacePrefix); if (meta.getFieldsOut().size() == 1 && field != null) { // This can be either a simple return element, or a complex type... // try { if (meta.isPassingInputData()) { for (int i = 0; i < rowMeta.getValueMetaList().size(); i++) { ValueMetaInterface valueMeta = getInputRowMeta().getValueMeta(i); outputRowData[outputIndex++] = valueMeta.cloneValueData(rowData[i]); } } outputRowData[outputIndex++] = getValue(vReader.getElementText(), field); putRow(data.outputRowMeta, outputRowData); } catch (WstxParsingException e) { throw new KettleStepException("Unable to get value for field [" + field.getName() + "]. Verify that this is not a complex data type by looking at the response XML.", e); } } else { for (WebServiceField curField : meta.getFieldsOut()) { if (!Const.isEmpty(curField.getName())) { outputRowData[outputIndex++] = getValue(vReader.getElementText(), curField); } } processing = true; } } } else { if (log.isRowLevel()) { logRowlevel("vReader.getLocalName = " + vReader.getLocalName()); } if (log.isRowLevel()) { logRowlevel("OutFieldArgumentName = " + meta.getOutFieldArgumentName()); } } } break; case XMLStreamConstants.END_ELEMENT: // END_ELEMENT= 2 if (log.isRowLevel()) { logRowlevel("END_ELEMENT"); } // If we end the xml element named as the return type, we // finish a row if ((meta.getOutFieldArgumentName() == null && meta.getOperationName().equals(vReader.getLocalName()))) { oneValueRowProcessing = false; } else if (meta.getOutFieldArgumentName() != null && meta.getOutFieldArgumentName().equals(vReader.getLocalName())) { putRow(data.outputRowMeta, outputRowData); processing = false; } break; case XMLStreamConstants.PROCESSING_INSTRUCTION: // PROCESSING_INSTRUCTION= 3 if (log.isRowLevel()) { logRowlevel("PROCESSING_INSTRUCTION"); } break; case XMLStreamConstants.CHARACTERS: // CHARACTERS= 4 if (log.isRowLevel()) { logRowlevel("CHARACTERS"); } break; case XMLStreamConstants.COMMENT: // COMMENT= 5 if (log.isRowLevel()) { logRowlevel("COMMENT"); } break; case XMLStreamConstants.SPACE: // PROCESSING_INSTRUCTION= 6 if (log.isRowLevel()) { logRowlevel("PROCESSING_INSTRUCTION"); } break; case XMLStreamConstants.START_DOCUMENT: // START_DOCUMENT= 7 if (log.isRowLevel()) { logRowlevel("START_DOCUMENT"); } if (log.isRowLevel()) { logRowlevel(vReader.getText()); } break; case XMLStreamConstants.END_DOCUMENT: // END_DOCUMENT= 8 if (log.isRowLevel()) { logRowlevel("END_DOCUMENT"); } break; case XMLStreamConstants.ENTITY_REFERENCE: // ENTITY_REFERENCE= 9 if (log.isRowLevel()) { logRowlevel("ENTITY_REFERENCE"); } break; case XMLStreamConstants.ATTRIBUTE: // ATTRIBUTE= 10 if (log.isRowLevel()) { logRowlevel("ATTRIBUTE"); } break; case XMLStreamConstants.DTD: // DTD= 11 if (log.isRowLevel()) { logRowlevel("DTD"); } break; case XMLStreamConstants.CDATA: // CDATA= 12 if (log.isRowLevel()) { logRowlevel("CDATA"); } break; case XMLStreamConstants.NAMESPACE: // NAMESPACE= 13 if (log.isRowLevel()) { logRowlevel("NAMESPACE"); } break; case XMLStreamConstants.NOTATION_DECLARATION: // NOTATION_DECLARATION= 14 if (log.isRowLevel()) { logRowlevel("NOTATION_DECLARATION"); } break; case XMLStreamConstants.ENTITY_DECLARATION: // ENTITY_DECLARATION= 15 if (log.isRowLevel()) { logRowlevel("ENTITY_DECLARATION"); } break; default: break; } } } catch (Exception e) { throw new KettleStepException( BaseMessages.getString(PKG, "WebServices.ERROR0010.OutputParsingError", response.toString()), e); } }
From source file:org.rhq.plugins.hadoop.HadoopServerConfigurationDelegate.java
private static void updateFile(File configFile, Map<String, PropertySimple> allProps) throws IOException, InterruptedException, XMLStreamException { InputStream in = null;// w w w .ja va 2s . c om XMLStreamReader rdr = null; OutputStream out = null; XMLStreamWriter outWrt = null; try { Set<String> processedPropertyNames = new HashSet<String>(); in = new BufferedInputStream(new FileInputStream(configFile)); rdr = XML_INPUT_FACTORY.createXMLStreamReader(in); File tmpFile = File.createTempFile("hadoop-plugin", null); out = new FileOutputStream(tmpFile); outWrt = XML_OUTPUT_FACTORY.createXMLStreamWriter(out); ByteArrayOutputStream stash = new ByteArrayOutputStream(); XMLStreamWriter stashWrt = XML_OUTPUT_FACTORY.createXMLStreamWriter(stash); boolean outputActive = true; outWrt.writeStartDocument(); while (rdr.hasNext()) { int event = rdr.next(); XMLStreamWriter wrt = outputActive ? outWrt : stashWrt; switch (event) { case XMLStreamConstants.ATTRIBUTE: break; case XMLStreamConstants.CDATA: wrt.writeCData(rdr.getText()); break; case XMLStreamConstants.CHARACTERS: wrt.writeCharacters(rdr.getText()); break; case XMLStreamConstants.COMMENT: wrt.writeComment(rdr.getText()); break; case XMLStreamConstants.DTD: wrt.writeDTD(rdr.getText()); break; case XMLStreamConstants.END_DOCUMENT: wrt.writeEndDocument(); break; case XMLStreamConstants.END_ELEMENT: if (PROPERTY_TAG_NAME.equals(rdr.getName().getLocalPart())) { String encoding = rdr.getEncoding(); if (encoding == null) { encoding = "UTF-8"; } String propertyTagSoFar = Charset.forName(encoding) .decode(ByteBuffer.wrap(stash.toByteArray())).toString(); DetectedPropertyNameAndUpdatedTag propAndTag = updateProperty(propertyTagSoFar, allProps); //yes, we're intentionally circumventing the xml stream writer, because we already have the XML data we want to write. outWrt.flush(); out.write(propAndTag.updatedTag.getBytes("UTF-8")); processedPropertyNames.add(propAndTag.propertyName); //reset stuff stash.reset(); wrt = outWrt; outputActive = true; } else if (CONFIGURATION_TAG_NAME.equals(rdr.getName().getLocalPart())) { //now add the new props for (String prop : processedPropertyNames) { allProps.remove(prop); } for (Map.Entry<String, PropertySimple> e : allProps.entrySet()) { outWrt.writeStartElement(PROPERTY_TAG_NAME); outWrt.writeStartElement(NAME_TAG_NAME); outWrt.writeCharacters(e.getKey()); outWrt.writeEndElement(); outWrt.writeStartElement(VALUE_TAG_NAME); outWrt.writeCharacters(e.getValue().getStringValue()); outWrt.writeEndElement(); outWrt.writeEndElement(); } } wrt.writeEndElement(); break; case XMLStreamConstants.ENTITY_DECLARATION: //XXX could not find what to do with this break; case XMLStreamConstants.ENTITY_REFERENCE: wrt.writeEntityRef(rdr.getText()); break; case XMLStreamConstants.NAMESPACE: for (int i = 0; i < rdr.getNamespaceCount(); ++i) { wrt.writeNamespace(rdr.getNamespacePrefix(i), rdr.getNamespaceURI(i)); } break; case XMLStreamConstants.NOTATION_DECLARATION: //XXX could not find what to do with this break; case XMLStreamConstants.PROCESSING_INSTRUCTION: wrt.writeProcessingInstruction(rdr.getPITarget(), rdr.getPIData()); break; case XMLStreamConstants.SPACE: wrt.writeCharacters(rdr.getText()); break; case XMLStreamConstants.START_DOCUMENT: //this seems to be never called for some strange reason //wrt.writeStartDocument(); break; case XMLStreamConstants.START_ELEMENT: wrt.writeStartElement(rdr.getName().getPrefix(), rdr.getName().getLocalPart(), rdr.getName().getNamespaceURI()); for (int i = 0; i < rdr.getAttributeCount(); ++i) { wrt.writeAttribute(rdr.getAttributePrefix(i), rdr.getAttributeNamespace(i), rdr.getAttributeLocalName(i), rdr.getAttributeValue(i)); } if (PROPERTY_TAG_NAME.equals(rdr.getName().getLocalPart())) { wrt.writeCharacters(""); outputActive = false; } break; } } outWrt.flush(); out.flush(); out.close(); in.close(); //now copy the temp file in the place of the original one FileUtil.copyFile(tmpFile, configFile); } finally { rdr.close(); outWrt.flush(); outWrt.close(); try { in.close(); } finally { out.flush(); out.close(); } } }