javax.xml.stream.XMLEventWriter Java Examples
The following examples show how to use
javax.xml.stream.XMLEventWriter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnimalRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException { XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); XMLEvent tab = eventFactory.createDTD("\t"); // Create Start node StartElement sElement = eventFactory.createStartElement("", "", name); eventWriter.add(tab); eventWriter.add(sElement); // Create Content Characters characters = eventFactory.createCharacters(value); eventWriter.add(characters); // Create End node EndElement eElement = eventFactory.createEndElement("", "", name); eventWriter.add(eElement); eventWriter.add(end); }
Example #2
Source File: AnimalRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException { XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); XMLEvent tab = eventFactory.createDTD("\t"); // Create start node StartElement sElement = eventFactory.createStartElement("", "", name); eventWriter.add(tab); eventWriter.add(sElement); // Create content Characters characters = eventFactory.createCharacters(value); eventWriter.add(characters); // Create end node EndElement eElement = eventFactory.createEndElement("", "", name); eventWriter.add(eElement); eventWriter.add(end); }
Example #3
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException { XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); XMLEvent tab = eventFactory.createDTD("\t"); // Create Start node StartElement sElement = eventFactory.createStartElement("", "", name); eventWriter.add(tab); eventWriter.add(sElement); // Create Content Characters characters = eventFactory.createCharacters(value); eventWriter.add(characters); // Create End node EndElement eElement = eventFactory.createEndElement("", "", name); eventWriter.add(eElement); eventWriter.add(end); }
Example #4
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 6 votes |
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException { XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); XMLEvent tab = eventFactory.createDTD("\t"); // Create Start node StartElement sElement = eventFactory.createStartElement("", "", name); eventWriter.add(tab); eventWriter.add(sElement); // Create Content Characters characters = eventFactory.createCharacters(value); eventWriter.add(characters); // Create End node EndElement eElement = eventFactory.createEndElement("", "", name); eventWriter.add(eElement); eventWriter.add(end); }
Example #5
Source File: Employee.java From JavaMainRepo with Apache License 2.0 | 5 votes |
/** * @param eventWriter * Text to encode. * @throws XMLStreamException * . */ public void encodeToXml(final XMLEventWriter eventWriter) throws XMLStreamException { createNode(eventWriter, "name", String.valueOf(this.name)); createNode(eventWriter, "isDead", String.valueOf(this.isDead)); createNode(eventWriter, "ID", String.valueOf(this.id)); createNode(eventWriter, "Salary", String.valueOf(this.salary)); }
Example #6
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public void save(ArrayList<T> entities) throws FileNotFoundException, XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(this.xmlFilename)); XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); StartDocument startDocument = eventFactory.createStartDocument(); eventWriter.add(startDocument); StartElement configStartElement = eventFactory.createStartElement("", "", "content"); eventWriter.add(configStartElement); eventWriter.add(end); for (XML_Parsable entity : entities) { StartElement sElement = eventFactory.createStartElement("", "", this.entityTag); eventWriter.add(sElement); eventWriter.add(end); entity.encodeToXml(eventWriter); EndElement eElement = eventFactory.createEndElement("", "", this.entityTag); eventWriter.add(eElement); eventWriter.add(end); } eventWriter.add(eventFactory.createEndElement("", "", "content")); eventWriter.add(eventFactory.createEndDocument()); eventWriter.close(); }
Example #7
Source File: EntityRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public void save(ArrayList<T> entities) throws FileNotFoundException, XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(this.xmlFilename)); XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); StartDocument startDocument = eventFactory.createStartDocument(); eventWriter.add(startDocument); StartElement configStartElement = eventFactory.createStartElement("", "", "content"); eventWriter.add(configStartElement); eventWriter.add(end); for (XML_Parsable entity : entities) { StartElement sElement = eventFactory.createStartElement("", "", this.entityTag); eventWriter.add(sElement); eventWriter.add(end); entity.encodeToXml(eventWriter); EndElement eElement = eventFactory.createEndElement("", "", this.entityTag); eventWriter.add(eElement); eventWriter.add(end); } eventWriter.add(eventFactory.createEndElement("", "", "content")); eventWriter.add(eventFactory.createEndDocument()); eventWriter.close(); }
Example #8
Source File: XStreamMarshallerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void marshalStaxResultXMLEventWriter() throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); StringWriter writer = new StringWriter(); XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(writer); Result result = StaxUtils.createStaxResult(eventWriter); marshaller.marshal(flight, result); assertXMLEqual("Marshaller writes invalid StreamResult", EXPECTED_STRING, writer.toString()); }
Example #9
Source File: Animal.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public void encodeToXml(XMLEventWriter eventWriter) throws XMLStreamException { createNode(eventWriter, "nrOfLegs", String.valueOf(this.nrOfLegs)); createNode(eventWriter, "name", String.valueOf(this.name)); createNode(eventWriter, "maintenanceCost", String.valueOf(this.maintenanceCost)); createNode(eventWriter, "dangerPerc", String.valueOf(this.dangerPerc)); createNode(eventWriter, "takenCareOf", String.valueOf(this.takenCareOf)); }
Example #10
Source File: AnimalRepository.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public void save(ArrayList<Animal> animals) throws FileNotFoundException, XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(XML_FILENAME)); XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); StartDocument startDocument = eventFactory.createStartDocument(); eventWriter.add(startDocument); StartElement configStartElement = eventFactory.createStartElement("", "", "content"); eventWriter.add(configStartElement); eventWriter.add(end); for (XML_Parsable animal : animals) { StartElement sElement = eventFactory.createStartElement("", "", Constants.XML_TAGS.ANIMAL); eventWriter.add(sElement); eventWriter.add(end); animal.encodeToXml(eventWriter); EndElement eElement = eventFactory.createEndElement("", "", Constants.XML_TAGS.ANIMAL); eventWriter.add(eElement); eventWriter.add(end); } eventWriter.add(eventFactory.createEndElement("", "", "content")); eventWriter.add(eventFactory.createEndDocument()); eventWriter.close(); }
Example #11
Source File: PathAndType2LowerCaseTransformer.java From recheck with GNU Affero General Public License v3.0 | 5 votes |
@Override public void convert( final XMLEvent event, final XMLEventWriter eventWriter ) throws XMLStreamException { // <attribute xsi:type="pathAttribute" key="path">Window/JRootPane_0/JPane_1</attribute> if ( isStartElementNamed( event, tagname ) && hasAttribute( event, "key", "path" ) ) { isInPath = true; } if ( isInPath && event.isCharacters() ) { path += event.asCharacters().getData().trim(); return; } if ( isInPath && isEndElementNamed( event, tagname ) ) { eventWriter.add( characters( path.toLowerCase() ) ); isInPath = false; path = ""; } if ( isStartElementNamed( event, tagname ) && hasAttribute( event, "key", "type" ) ) { isInType = true; } if ( isInType && event.isCharacters() ) { type += event.asCharacters().getData().trim(); return; } if ( isInType && isEndElementNamed( event, tagname ) ) { eventWriter.add( characters( type.toLowerCase() ) ); isInType = false; type = ""; } eventWriter.add( event ); }
Example #12
Source File: StaxResult.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Construct a new instance of the {@code StaxResult} with the specified {@code XMLEventWriter}. * @param eventWriter the {@code XMLEventWriter} to write to */ public StaxResult(XMLEventWriter eventWriter) { StaxEventHandler handler = new StaxEventHandler(eventWriter); super.setHandler(handler); super.setLexicalHandler(handler); this.eventWriter = eventWriter; }
Example #13
Source File: Caretaker.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public void encodeToXml(XMLEventWriter eventWriter) throws XMLStreamException { super.encodeToXml(eventWriter); createNode(eventWriter, "workingHours", String.valueOf(getWorkingHours())); super.encodeToXml(eventWriter); createNode(eventWriter, Constants.XML_TAGS.DISCRIMINANT, Constants.EmployeesType.Caretakers); }
Example #14
Source File: XMLUtilities.java From olingo-odata4 with Apache License 2.0 | 5 votes |
public InputStream addAtomInlinecount(final InputStream feed, final int count) throws Exception { final XMLEventReader reader = getEventReader(feed); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final XMLEventWriter writer = getEventWriter(bos); try { final XMLElement feedElement = extractElement(reader, writer, Collections.<String> singletonList("feed"), 0, 1, 1).getValue(); writer.add(feedElement.getStart()); addAtomElement(IOUtils.toInputStream(String.format("<m:count>%d</m:count>", count), Constants.ENCODING), writer); writer.add(feedElement.getContentReader()); writer.add(feedElement.getEnd()); while (reader.hasNext()) { writer.add(reader.nextEvent()); } } finally { writer.flush(); writer.close(); reader.close(); IOUtils.closeQuietly(feed); } return new ByteArrayInputStream(bos.toByteArray()); }
Example #15
Source File: AbstractDOMDocumentParser.java From jettison with Apache License 2.0 | 5 votes |
public Document parse(InputStream input) throws IOException { try { XMLStreamReader streamReader = inputFactory.createXMLStreamReader(input); XMLInputFactory readerFactory = XMLInputFactory.newInstance(); XMLEventReader eventReader = readerFactory.createXMLEventReader(streamReader); // Can not create a STaX writer for a DOMResult in woodstox-3.1.1 /*XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); Document nsDom = getDocumentBuilder().newDocument(); DOMResult result = new DOMResult(nsDom); XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(result);*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(baos); eventWriter.add(eventReader); eventWriter.close(); // This parsing step should not be necessary, if we could output to a DOMResult ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); return getDocumentBuilder().parse(bais); //return nsDom; } catch (Exception ex) { IOException ioex = new IOException("Cannot parse input stream"); ioex.initCause(ex); throw ioex; } }
Example #16
Source File: Animal.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public void encodeToXml(XMLEventWriter eventWriter)throws XMLStreamException{ createNode(eventWriter, "nrOfLegs", String.valueOf(this.nrOfLegs)); createNode(eventWriter, "name", String.valueOf(this.name)); createNode(eventWriter, "maintenanceCost", String.valueOf(this.maintenanceCost)); createNode(eventWriter, "dangerPerc", String.valueOf(this.dangerPerc)); createNode(eventWriter, "takenCareOf", String.valueOf(this.takenCareOf)); }
Example #17
Source File: Animal.java From JavaMainRepo with Apache License 2.0 | 5 votes |
public void encodeToXml(XMLEventWriter eventWriter) throws XMLStreamException { createNode(eventWriter, "nrOfLegs", String.valueOf(this.nrOfLegs)); createNode(eventWriter, "name", String.valueOf(this.name)); createNode(eventWriter, "maintenanceCost", String.valueOf(this.maintenanceCost)); createNode(eventWriter, "dangerPerc", String.valueOf(this.dangerPerc)); createNode(eventWriter, "takenCareOf", String.valueOf(this.takeCareOf)); }
Example #18
Source File: StaxResult.java From spring-analysis-note with MIT License | 5 votes |
/** * Construct a new instance of the {@code StaxResult} with the specified {@code XMLEventWriter}. * @param eventWriter the {@code XMLEventWriter} to write to */ public StaxResult(XMLEventWriter eventWriter) { StaxEventHandler handler = new StaxEventHandler(eventWriter); super.setHandler(handler); super.setLexicalHandler(handler); this.eventWriter = eventWriter; }
Example #19
Source File: XMLUtilities.java From olingo-odata4 with Apache License 2.0 | 5 votes |
protected static XMLEventWriter getEventWriter(final OutputStream os) throws XMLStreamException { if (ofactory == null) { ofactory = XMLOutputFactory.newInstance(); } return ofactory.createXMLEventWriter(os, "UTF-8"); }
Example #20
Source File: ArtifactsXmlAbsoluteUrlRemover.java From nexus-repository-p2 with Eclipse Public License 1.0 | 5 votes |
private void streamXmlToWriterAndRemoveAbsoluteUrls( final XMLEventReader reader, final XMLEventWriter writer) throws XMLStreamException { final XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent previous = null; // We need to buffer events so that we can also update properties size when removing the mirrorsUrl property List<XMLEvent> buffer = new ArrayList<>(); while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); // If xml tag is "properties" then start buffering. If started buffering then keep buffering until the buffer // is cleared if (!buffer.isEmpty() || isStartTagWithName(event, "properties")) { //Exclude the mirrorsURL property if (!(isMirrorsUrlProperty(event) || isMirrorsUrlProperty(previous))) { buffer.add(event); } } if (buffer.isEmpty()) { writer.add(event); } // When reached end of <properties> section, update count and flush buffer to writer. if (isEndTagWithName(event, "properties")) { for (XMLEvent xmlEvent : buffer) { if (isStartTagWithName(xmlEvent, "properties")) { xmlEvent = updateSize(xmlEvent.asStartElement(), countPropertyTags(buffer), eventFactory); } writer.add(xmlEvent); } buffer.clear(); } previous = event; } }
Example #21
Source File: Cockroach.java From JavaMainRepo with Apache License 2.0 | 4 votes |
public void encodeToXml(XMLEventWriter eventWriter) throws XMLStreamException { super.encodeToXml(eventWriter); createNode(eventWriter, Constants.XML_TAGS.DISCRIMINANT, Constants.Animals.Insects.Cockroach); }
Example #22
Source File: Sardine.java From JavaMainRepo with Apache License 2.0 | 4 votes |
public void encodeToXml(XMLEventWriter eventWriter) throws XMLStreamException { super.encodeToXml(eventWriter); createNode(eventWriter, Constants.XML_TAGS.DISCRIMINANT, Constants.Animals.Aquatics.Sardine); }
Example #23
Source File: Reptile.java From JavaMainRepo with Apache License 2.0 | 4 votes |
public void encodeToXML(XMLEventWriter eventWriter) throws XMLStreamException { super.encodeToXML(eventWriter); createNode(eventWriter, "laysEggs", String.valueOf(this.getLaysEggs())); }
Example #24
Source File: Albatross.java From JavaMainRepo with Apache License 2.0 | 4 votes |
public void encodeToXml(XMLEventWriter eventWriter) throws XMLStreamException { super.encodeToXml(eventWriter); createNode(eventWriter, Constants.XML_TAGS.DISCRIMINANT, Constants.Animals.Birds.Albatross); }
Example #25
Source File: SeaTurtle.java From JavaMainRepo with Apache License 2.0 | 4 votes |
public void encodeToXml(XMLEventWriter eventWriter) throws XMLStreamException { super.encodeToXml(eventWriter); createNode(eventWriter, Constants.XML_TAGS.DISCRIMINANT, Constants.Animals.Aquatics.SeaTurtle); }
Example #26
Source File: MarshallerImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Override public void marshal(Object obj, XMLEventWriter writer) throws JAXBException { write(obj, new XMLEventWriterOutput(writer), new StAXPostInitAction(writer,serializer)); }
Example #27
Source File: Butterfly.java From JavaMainRepo with Apache License 2.0 | 4 votes |
public void encodeToXml(XMLEventWriter eventWriter) throws XMLStreamException { super.encodeToXml(eventWriter); createNode(eventWriter, Constants.XML_TAGS.DISCRIMINANT, Constants.Animals.Insects.Butterfly); }
Example #28
Source File: Spider.java From JavaMainRepo with Apache License 2.0 | 4 votes |
public void encodeToXml(XMLEventWriter eventWriter) throws XMLStreamException { super.encodeToXml(eventWriter); createNode(eventWriter, Constants.XML_TAGS.DISCRIMINANT, Constants.Animals.Insects.Spider); }
Example #29
Source File: ArtifactsXmlAbsoluteUrlRemover.java From nexus-repository-p2 with Eclipse Public License 1.0 | 4 votes |
private TempBlob transformXmlMetadata(final TempBlob artifact, final Repository repository, final String file, final String extension, final XmlStreamTransformer transformer) throws IOException { Path tempFile = createTempFile("", ".xml"); // This is required in the case that the input stream is a jar to allow us to extract a single file Path artifactsTempFile = createTempFile("", ".xml"); try { try (InputStream xmlIn = xmlInputStream(artifact, file + "." + "xml", extension, artifactsTempFile); OutputStream xmlOut = xmlOutputStream(file + "." + "xml", extension, tempFile)) { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setProperty(SUPPORT_DTD, false); inputFactory.setProperty(IS_SUPPORTING_EXTERNAL_ENTITIES, false); XMLOutputFactory outputFactory = XMLOutputFactory.newFactory(); XMLEventReader reader = null; XMLEventWriter writer = null; //try-with-resources will be better here, but XMLEventReader and XMLEventWriter are not AutoCloseable try { reader = inputFactory.createXMLEventReader(xmlIn); writer = outputFactory.createXMLEventWriter(xmlOut); transformer.transform(reader, writer); writer.flush(); } finally { if (reader != null) { reader.close(); } if (writer != null) { writer.close(); } } } catch (XMLStreamException ex) { log.error("Failed to rewrite metadata for file with extension {} and blob {} with reason: {} ", ex, artifact.getBlob().getId(), ex); return artifact; } return convertFileToTempBlob(tempFile, repository); } finally { delete(tempFile); delete(artifactsTempFile); } }
Example #30
Source File: Scorpion.java From JavaMainRepo with Apache License 2.0 | 4 votes |
public void encodeToXML(XMLEventWriter eventWriter) throws XMLStreamException { super.encodeToXML(eventWriter); createNode(eventWriter, Constants.XML_TAGS.DISCRIMINANT, String.valueOf(Constants.Animals.Insect.SCORPION)); }