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(); }
public void save(ArrayList<Employee> employees) 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 employee : employees) { StartElement sElement = eventFactory.createStartElement("", "", Constants.XML_TAGS.EMPLOYEE); eventWriter.add(sElement); eventWriter.add(end); employee.encodeToXml(eventWriter); EndElement eElement = eventFactory.createEndElement("", "", Constants.XML_TAGS.EMPLOYEE); eventWriter.add(eElement); eventWriter.add(end); } eventWriter.add(eventFactory.createEndElement("", "", "content")); eventWriter.add(eventFactory.createEndDocument()); eventWriter.close(); }
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(); }
/** * Create a document from the specified reader. * @param reader The XMLEvent reader. * @return The Document. * @throws ParserConfigurationException For errors creating the document. * @throws XMLStreamException For errors reading the event reader. */ public static Document createDocument(final XMLEventReader reader) throws ParserConfigurationException, XMLStreamException { final Document doc = getNewDocument(); final XMLEventWriter writer = EVENT_WRITER_CREATOR.createXMLEventWriter(doc); final XMLEvent event = reader.peek(); int type = event.getEventType(); boolean omitDoc = false; if (type == XMLStreamConstants.START_DOCUMENT) { StartDocument startDocument = (StartDocument) event; if (startDocument.getVersion() == null) { omitDoc = true; } } XMLHelper.copyXMLEventStream(reader, writer, omitDoc); return doc; }
@Test public void testEncodingSet() { XMLEventFactory f = XMLEventFactory.newInstance(); try { StartDocument sd = f.createStartDocument("UTF-8"); System.out.println("Encoding: " + sd.getCharacterEncodingScheme()); System.out.println("Encoding set: " + sd.encodingSet()); Assert.assertTrue(sd.encodingSet(), "encoding is set, should return true."); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Test public void testStandaloneSet() { XMLEventFactory f = XMLEventFactory.newInstance(); try { StartDocument sd = f.createStartDocument("UTF-8", "1.0", true); System.out.println(sd.isStandalone()); System.out.println(sd.standaloneSet()); Assert.assertTrue(sd.standaloneSet(), "standalone is set, should return true."); } catch (Exception e) { Assert.fail(e.getMessage()); } }
@Override public String getVersion() { if (this.event.isStartDocument()) { return ((StartDocument) this.event).getVersion(); } else { return null; } }
@Override public boolean isStandalone() { if (this.event.isStartDocument()) { return ((StartDocument) event).isStandalone(); } else { throw new IllegalStateException(); } }
@Override public boolean standaloneSet() { if (this.event.isStartDocument()) { return ((StartDocument) this.event).standaloneSet(); } else { throw new IllegalStateException(); } }
public StartDocument createStartDocument(String encoding, String version, boolean standalone) { return new StartDocumentImpl(location, null, encoding, version, standalone, true, true); }
public boolean isStandalone() { if (event.isStartDocument()) { return ((StartDocument) event).isStandalone(); } else { throw new IllegalStateException(); } }
public String getVersion() { if (event.isStartDocument()) { return ((StartDocument) event).getVersion(); } else { return null; } }
public boolean standaloneSet() { if (event.isStartDocument()) { return ((StartDocument) event).standaloneSet(); } else { throw new IllegalStateException(); } }
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"); // Create and write start tag StartDocument startDocument = eventFactory.createStartDocument(); eventWriter.add(startDocument); // Create content open tag 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(); }
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 entitity : entities) { StartElement sElement = eventFactory.createStartElement("", "", this.entityTag); eventWriter.add(sElement); eventWriter.add(end); entitity.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(); }
public void save(ArrayList<T> entities) throws FileNotFoundException, XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); // Create XMLEventWriter XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(this.xmlFilename)); // Create a EventFactory XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); // Create and write Start Tag StartDocument startDocument = eventFactory.createStartDocument(); eventWriter.add(startDocument); // Create content open tag 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(); }
public void save(ArrayList<Animal> animals) throws FileNotFoundException, XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); // Create XMLEventWriter XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(XML_FILENAME)); // Create a EventFactory XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); // Create and write Start Tag StartDocument startDocument = eventFactory.createStartDocument(); eventWriter.add(startDocument); // Create content open tag 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(); }
public void save(ArrayList<Employee> employees) throws FileNotFoundException, XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); // Create XMLEventWriter XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(XML_FILENAME)); // Create a EventFactory XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); // Create and write Start Tag StartDocument startDocument = eventFactory.createStartDocument(); eventWriter.add(startDocument); // Create content open tag StartElement configStartElement = eventFactory.createStartElement("", "", "content"); eventWriter.add(configStartElement); eventWriter.add(end); for (XML_Parsable animal : employees) { StartElement sElement = eventFactory.createStartElement("", "", Constants.XML_TAGS.EMPLOYEE); eventWriter.add(sElement); eventWriter.add(end); animal.encodeToXml(eventWriter); EndElement eElement = eventFactory.createEndElement("", "", Constants.XML_TAGS.EMPLOYEE); eventWriter.add(eElement); eventWriter.add(end); } eventWriter.add(eventFactory.createEndElement("", "", "content")); eventWriter.add(eventFactory.createEndDocument()); eventWriter.close(); }
public void save(ArrayList<Animal> animals) throws FileNotFoundException, XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newFactory(); // Create XMLEventWriter XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(XML_FILENAME)); // Create an EventFactory XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); // Create and write Start Tag StartDocument startDocument = eventFactory.createStartDocument(); eventWriter.add(startDocument); // Create content open tag 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(); }
public void save(ArrayList<Employee> employees) throws FileNotFoundException, XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newFactory(); // Create XMLEventWriter XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(XML_FILENAME)); // Create an EventFactory XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); // Create and write Start Tag StartDocument startDocument = eventFactory.createStartDocument(); eventWriter.add(startDocument); // Create content open tag StartElement configStartElement = eventFactory.createStartElement("", "", "content"); eventWriter.add(configStartElement); eventWriter.add(end); for (XML_Parsable employee : employees) { StartElement sElement = eventFactory.createStartElement("", "", Constants.XML_TAGS.EMPLOYEE); eventWriter.add(sElement); eventWriter.add(end); employee.encodeToXml(eventWriter); EndElement eElement = eventFactory.createEndElement("", "", Constants.XML_TAGS.EMPLOYEE); eventWriter.add(eElement); eventWriter.add(end); } eventWriter.add(eventFactory.createEndElement("", "", "content")); eventWriter.add(eventFactory.createEndDocument()); eventWriter.close(); }
public void save(ArrayList<T> entities) throws FileNotFoundException, XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newFactory(); // Create XMLEventWriter XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(this.xmlFilename)); // Create an EventFactory XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); // Create and write Start Tag StartDocument startDocument = eventFactory.createStartDocument(); eventWriter.add(startDocument); // Create content open tag 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(); }
public void save(ArrayList<Employee> employees) throws FileNotFoundException, XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); // Create XMLEventWriter XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(XML_FILENAME)); // Create a EventFactory XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); // Create and write Start Tag StartDocument startDocument = eventFactory.createStartDocument(); eventWriter.add(startDocument); // Create content open tag StartElement configStartElement = eventFactory.createStartElement("", "", "content"); eventWriter.add(configStartElement); eventWriter.add(end); for (XML_Parsable employee : employees) { StartElement sElement = eventFactory.createStartElement("", "", Constants.XML_TAGS.EMPLOYEE); eventWriter.add(sElement); eventWriter.add(end); employee.encodeToXml(eventWriter); EndElement eElement = eventFactory.createEndElement("", "", Constants.XML_TAGS.EMPLOYEE); eventWriter.add(eElement); eventWriter.add(end); } eventWriter.add(eventFactory.createEndElement("", "", "content")); eventWriter.add(eventFactory.createEndDocument()); eventWriter.close(); }
public void save(ArrayList<T> entities) throws FileNotFoundException, XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); // Create XMLEventWriter XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(new FileOutputStream(this.xmlFilename)); // Create a EventFactory XMLEventFactory eventFactory = XMLEventFactory.newInstance(); XMLEvent end = eventFactory.createDTD("\n"); // Create and write Start Tag StartDocument startDocument = eventFactory.createStartDocument(); eventWriter.add(startDocument); // Create content open tag StartElement configStartElement = eventFactory.createStartElement("", "", "content"); eventWriter.add(configStartElement); eventWriter.add(end); for (XML_Parsable animal : entities) { StartElement sElement = eventFactory.createStartElement("", "", this.entityTag); eventWriter.add(sElement); eventWriter.add(end); animal.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(); }