com.sun.xml.txw2.output.IndentingXMLStreamWriter Java Examples
The following examples show how to use
com.sun.xml.txw2.output.IndentingXMLStreamWriter.
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: TemplateSerializer.java From localization_nifi with Apache License 2.0 | 6 votes |
/** * This method when called assumes the Framework Nar ClassLoader is in the * classloader hierarchy of the current context class loader. * @param dto the template dto to serialize * @return serialized representation of the DTO */ public static byte[] serialize(final TemplateDTO dto) { try { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final BufferedOutputStream bos = new BufferedOutputStream(baos); JAXBContext context = JAXBContext.newInstance(TemplateDTO.class); Marshaller marshaller = context.createMarshaller(); XMLOutputFactory xmlof = XMLOutputFactory.newInstance(); XMLStreamWriter writer = new IndentingXMLStreamWriter(xmlof.createXMLStreamWriter(bos)); marshaller.marshal(dto, writer); bos.flush(); return baos.toByteArray(); //Note: For really large templates this could use a lot of heap space } catch (final IOException | JAXBException | XMLStreamException e) { throw new FlowSerializationException(e); } }
Example #2
Source File: ParamData.java From Course_Generator with GNU General Public License v3.0 | 5 votes |
/** * Save parameters on disk * * @param fname Name of the file */ public void SaveCurve(String fname, int unit) { if (data.size() <= 0) { return; } // -- Save the data in the home directory XMLOutputFactory factory = XMLOutputFactory.newInstance(); try { BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(fname)); XMLStreamWriter writer = new IndentingXMLStreamWriter( factory.createXMLStreamWriter(bufferedOutputStream, "UTF-8")); writer.writeStartDocument("UTF-8", "1.0"); writer.writeStartElement("Project"); Utils.WriteStringToXML(writer, "Name", name); Utils.WriteStringToXML(writer, "Comment", comment); writer.writeStartElement("Param"); for (CgParam curvePoint : data) { writer.writeStartElement("Item"); Utils.WriteStringToXML(writer, "Slope", String.format(Locale.ROOT, "%f", curvePoint.getSlope())); // Saving the curve speeds using the metric system. Utils.WriteStringToXML(writer, "Speed", String.format(Locale.ROOT, "%f", curvePoint.getSpeedNumber())); writer.writeEndElement(); // Item } writer.writeEndElement(); // Param writer.writeEndElement(); // Project writer.writeEndDocument(); writer.flush(); writer.close(); bufferedOutputStream.close(); } catch (XMLStreamException | IOException e) { e.printStackTrace(); } }
Example #3
Source File: JPanelAnalysisSpeedSlope.java From Course_Generator with GNU General Public License v3.0 | 5 votes |
/** * Save the generated curve as a standard curve * * @param name Name of the curve * @param comment Comment for the curve */ private void SaveCurve(String name, String comment) { int n = datasetSpeedSlopeLine.getSeries(0).getItemCount(); // -- Save the data in the home directory XMLOutputFactory factory = XMLOutputFactory.newInstance(); try { BufferedOutputStream bufferedOutputStream = new BufferedOutputStream( new FileOutputStream(Utils.getSelectedCurveFolder(CgConst.CURVE_FOLDER_USER) + name + ".par")); XMLStreamWriter writer = new IndentingXMLStreamWriter( factory.createXMLStreamWriter(bufferedOutputStream, "UTF-8")); writer.writeStartDocument("UTF-8", "1.0"); writer.writeStartElement("Project"); Utils.WriteStringToXML(writer, "Name", name); Utils.WriteStringToXML(writer, "Comment", comment); writer.writeStartElement("Param"); for (int i = 0; i < n; i++) { writer.writeStartElement("Item"); Utils.WriteStringToXML(writer, "Slope", String.format(Locale.ROOT, "%f", datasetSpeedSlopeLine.getSeries(0).getX(i))); double speed = datasetSpeedSlopeLine.getSeries(0).getY(i).doubleValue(); Utils.WriteStringToXML(writer, "Speed", String.format(Locale.ROOT, "%f", speed)); writer.writeEndElement(); // Item } writer.writeEndElement(); // Param writer.writeEndElement(); // Project writer.writeEndDocument(); writer.flush(); writer.close(); bufferedOutputStream.close(); } catch (XMLStreamException | IOException e) { e.printStackTrace(); } }
Example #4
Source File: frmSettings.java From Course_Generator with GNU General Public License v3.0 | 5 votes |
private void SaveTheme() { String s = Utils.SaveDialog(this, DataDir + "/" + CgConst.CG_DIR + "/themes/", "", ".theme", bundle.getString("frmMain.themeFile"), true, bundle.getString("frmMain.FileExist")); if (!s.isEmpty()) { // -- Save the data in the home directory XMLOutputFactory factory = XMLOutputFactory.newInstance(); try { BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(s)); XMLStreamWriter writer = new IndentingXMLStreamWriter( factory.createXMLStreamWriter(bufferedOutputStream, "UTF-8")); writer.writeStartDocument("UTF-8", "1.0"); writer.writeComment("Course Generator (C) Pierre DELORE"); writer.writeStartElement("THEME"); Utils.WriteIntToXML(writer, "COLORDIFFVERYEASY", ColorVeryEasy.getRGB()); Utils.WriteIntToXML(writer, "COLORDIFFEASY", ColorEasy.getRGB()); Utils.WriteIntToXML(writer, "COLORDIFFAVERAGE", ColorAverage.getRGB()); Utils.WriteIntToXML(writer, "COLORDIFFHARD", ColorHard.getRGB()); Utils.WriteIntToXML(writer, "COLORDIFFVERYHARD", ColorVeryHard.getRGB()); Utils.WriteIntToXML(writer, "COLORNIGHT", ColorNight.getRGB()); Utils.WriteIntToXML(writer, "NORMALTRACKWIDTH", spinNormalTrackWidth.getValueAsInt()); Utils.WriteIntToXML(writer, "NIGHTTRACKWIDTH", spinNightTrackWidth.getValueAsInt()); Utils.WriteIntToXML(writer, "NORMALTRACKTRANSPARENCY", spinNormalTrackTransparency.getValueAsInt()); Utils.WriteIntToXML(writer, "NIGHTTRACKTRANSPARENCY", spinNightTrackTransparency.getValueAsInt()); writer.writeEndElement(); writer.writeEndDocument(); writer.flush(); writer.close(); bufferedOutputStream.close(); } catch (XMLStreamException | IOException e) { e.printStackTrace(); } } }
Example #5
Source File: FormattingXmlStreamWriter.java From jackrabbit-filevault with Apache License 2.0 | 5 votes |
private FormattingXmlStreamWriter(XMLStreamWriter writer, OutputFormat output) { this.output = output; this.writer = writer; this.rawWriter = (Writer) writer.getProperty(WstxOutputProperties.P_OUTPUT_UNDERLYING_WRITER); if (this.rawWriter == null) { throw new IllegalStateException("Could not get underlying writer!"); } this.elementIndentingXmlWriter = new IndentingXMLStreamWriter(writer); this.elementIndentingXmlWriter.setIndentStep(output.getIndent()); }
Example #6
Source File: GraphMlTest.java From timbuctoo with GNU General Public License v3.0 | 5 votes |
@Test public void testSreaming() throws Exception { OutputStream out = new ByteArrayOutputStream(); XMLOutputFactory xof = XMLOutputFactory.newFactory(); XMLStreamWriter xsw = new IndentingXMLStreamWriter(xof.createXMLStreamWriter(out, StandardCharsets.UTF_8.name())); xsw.setDefaultNamespace("http://graphml.graphdrawing.org/xmlns"); xsw.writeStartDocument("UTF-8", "1.0"); xsw.writeStartElement("http://graphml.graphdrawing.org/xmlns","graphml"); xsw.writeDefaultNamespace("http://graphml.graphdrawing.org/xmlns"); GraphMlContext graphMlContext = new GraphMlContext(); Marshaller jaxbMarshaller = graphMlContext.createMarshaller(); //jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); for (int i = 0; i < 5; i++) { JAXBElement<Key> je = new Key("d" + i).withAttrName("r").withAttrType("int").withFor("edge").asJaxbElement(); jaxbMarshaller.marshal(je, xsw); } xsw.writeStartElement("http://graphml.graphdrawing.org/xmlns","graph"); xsw.writeAttribute("edgedefault", "directed"); for (int h = 0; h < 3; h++) { Node node = new Node("n" + h); for (int i = 0; i < 5; i++) { node.addData(new Data().withKey("d" + i).withValue("42")); } jaxbMarshaller.marshal(node.asJaxbElement(), xsw); } xsw.writeEndElement(); xsw.writeEndElement(); xsw.writeEndDocument(); xsw.close(); //System.out.println(out.toString()); }
Example #7
Source File: TrackData.java From Course_Generator with GNU General Public License v3.0 | 4 votes |
public void SaveWaypoint(String name, int mask) { if (data.size() <= 0) { return; } // -- Save the data in the home directory XMLOutputFactory factory = XMLOutputFactory.newInstance(); try { BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(name)); XMLStreamWriter writer = new IndentingXMLStreamWriter( factory.createXMLStreamWriter(bufferedOutputStream, "UTF-8")); writer.writeStartDocument("UTF-8", "1.0"); writer.writeStartElement("gpx"); writer.writeAttribute("creator", "Course Generator http://www.techandrun.com"); writer.writeAttribute("version", "1.1"); writer.writeAttribute("xsi:schemaLocation", "http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/WaypointExtension/v1 http://www8.garmin.com/xmlschemas/WaypointExtensionv1.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/ActivityExtension/v1 http://www8.garmin.com/xmlschemas/ActivityExtensionv1.xsd http://www.garmin.com/xmlschemas/AdventuresExtensions/v1 http://www8.garmin.com/xmlschemas/AdventuresExtensionv1.xsd http://www.garmin.com/xmlschemas/PressureExtension/v1 http://www.garmin.com/xmlschemas/PressureExtensionv1.xsd http://www.garmin.com/xmlschemas/TripExtensions/v1 http://www.garmin.com/xmlschemas/TripExtensionsv1.xsd http://www.garmin.com/xmlschemas/TripMetaDataExtensions/v1 http://www.garmin.com/xmlschemas/TripMetaDataExtensionsv1.xsd http://www.garmin.com/xmlschemas/ViaPointTransportationModeExtensions/v1 http://www.garmin.com/xmlschemas/ViaPointTransportationModeExtensionsv1.xsd http://www.garmin.com/xmlschemas/CreationTimeExtension/v1 http://www.garmin.com/xmlschemas/CreationTimeExtensionsv1.xsd http://www.garmin.com/xmlschemas/AccelerationExtension/v1 http://www.garmin.com/xmlschemas/AccelerationExtensionv1.xsd http://www.garmin.com/xmlschemas/PowerExtension/v1 http://www.garmin.com/xmlschemas/PowerExtensionv1.xsd http://www.garmin.com/xmlschemas/VideoExtension/v1 http://www.garmin.com/xmlschemas/VideoExtensionv1.xsd"); writer.writeAttribute("xmlns", "http://www.topografix.com/GPX/1/1"); writer.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); writer.writeAttribute("xmlns:wptx1", "http://www.garmin.com/xmlschemas/WaypointExtension/v1"); writer.writeAttribute("xmlns:gpxtrx", "http://www.garmin.com/xmlschemas/GpxExtensions/v3"); writer.writeAttribute("xmlns:gpxtpx", "http://www.garmin.com/xmlschemas/TrackPointExtension/v1"); writer.writeAttribute("xmlns:gpxx", "http://www.garmin.com/xmlschemas/GpxExtensions/v3"); writer.writeAttribute("xmlns:trp", "http://www.garmin.com/xmlschemas/TripExtensions/v1"); writer.writeAttribute("xmlns:adv", "http://www.garmin.com/xmlschemas/AdventuresExtensions/v1"); writer.writeAttribute("xmlns:prs", "http://www.garmin.com/xmlschemas/PressureExtension/v1"); writer.writeAttribute("xmlns:tmd", "http://www.garmin.com/xmlschemas/TripMetaDataExtensions/v1"); writer.writeAttribute("xmlns:vptm", "http://www.garmin.com/xmlschemas/ViaPointTransportationModeExtensions/v1"); writer.writeAttribute("xmlns:ctx", "http://www.garmin.com/xmlschemas/CreationTimeExtension/v1"); writer.writeAttribute("xmlns:gpxacc", "http://www.garmin.com/xmlschemas/AccelerationExtension/v1"); writer.writeAttribute("xmlns:gpxpx", "http://www.garmin.com/xmlschemas/PowerExtension/v1"); writer.writeAttribute("xmlns:vidx1", "http://www.garmin.com/xmlschemas/VideoExtension/v1"); int i = 1; String s; for (CgData r : data) { if ((r.getTag() != 0) && ((r.getTag() & mask) != 0)) { // <wpt> writer.writeStartElement("wpt"); writer.writeAttribute("lat", String.format(Locale.ROOT, "%1.14f", r.getLatitude())); writer.writeAttribute("lon", String.format(Locale.ROOT, "%1.14f", r.getLongitude())); // <time>2010-08-18T07:57:07.000Z</time> // Utils.WriteStringToXML(writer,"time", // r.getHour().toString()+"Z"); // <name>toto</name> if (r.getName().isEmpty()) { Utils.WriteStringToXML(writer, "name", String.format("NoName%d", i)); i++; } else Utils.WriteStringToXML(writer, "name", r.getName()); // <sym>Flag, Green</sym> s = "Flag, Green"; // Par defaut if ((r.getTag() & CgConst.TAG_HIGH_PT) != 0) s = "Summit"; if ((r.getTag() & CgConst.TAG_WATER_PT) != 0) s = "Bar"; if ((r.getTag() & CgConst.TAG_EAT_PT) != 0) s = "Restaurant"; Utils.WriteStringToXML(writer, "sym", s); // <type>user</type> Utils.WriteStringToXML(writer, "type", "user"); writer.writeEndElement();// wpt } // if } // for writer.writeEndElement();// gpx writer.writeEndDocument(); writer.flush(); writer.close(); CgLog.info("TrackData.SaveWaypoint : '" + name + "' saved"); } catch (XMLStreamException | IOException e) { e.printStackTrace(); } }
Example #8
Source File: TrackData.java From Course_Generator with GNU General Public License v3.0 | 4 votes |
public void ExportCGP(String name, int mask) { if (data.size() <= 0) { return; } // -- Save the data in the home directory XMLOutputFactory factory = XMLOutputFactory.newInstance(); try { XMLStreamWriter writer = new IndentingXMLStreamWriter( factory.createXMLStreamWriter(new FileOutputStream(name), "UTF-8")); writer.writeStartDocument("UTF-8", "1.0"); writer.writeStartElement("COURSEGENERATOR"); writer.writeAttribute("VERSION", "1"); // <Points> node writer.writeStartElement("Points"); for (CgData r : data) { if ((((mask & CgConst.TAG_HIGH_PT) != 0) && ((r.getTag() & CgConst.TAG_HIGH_PT) != 0)) || (((mask & CgConst.TAG_LOW_PT) != 0) && ((r.getTag() & CgConst.TAG_LOW_PT) != 0)) || (((mask & CgConst.TAG_EAT_PT) != 0) && ((r.getTag() & CgConst.TAG_EAT_PT) != 0)) || (((mask & CgConst.TAG_WATER_PT) != 0) && ((r.getTag() & CgConst.TAG_WATER_PT) != 0)) || (((mask & CgConst.TAG_MARK) != 0) && ((r.getTag() & CgConst.TAG_MARK) != 0)) || (((mask & CgConst.TAG_COOL_PT) != 0) && ((r.getTag() & CgConst.TAG_COOL_PT) != 0)) || (((mask & CgConst.TAG_NOTE) != 0) && ((r.getTag() & CgConst.TAG_NOTE) != 0)) || (((mask & CgConst.TAG_ROADBOOK) != 0) && ((r.getTag() & CgConst.TAG_ROADBOOK) != 0)) || (((mask & CgConst.TAG_DROPBAG) != 0) && ((r.getTag() & CgConst.TAG_DROPBAG) != 0)) || (((mask & CgConst.TAG_CREW) != 0) && ((r.getTag() & CgConst.TAG_CREW) != 0)) || (((mask & CgConst.TAG_FIRST_AID) != 0) && ((r.getTag() & CgConst.TAG_FIRST_AID) != 0)) || (((mask & CgConst.TAG_INFO) != 0) && ((r.getTag() & CgConst.TAG_INFO) != 0))) { // <Pt> writer.writeStartElement("Pt"); // <LatitudeDegrees>123.456</LatitudeDegrees> Utils.WriteStringToXML(writer, "LatitudeDegrees", String.format(Locale.ROOT, "%1.14f", r.getLatitude())); // <LongitudeDegrees>12345.678</LongitudeDegrees> Utils.WriteStringToXML(writer, "LongitudeDegrees", String.format(Locale.ROOT, "%1.14f", r.getLongitude())); // <AltitudeMeters>625.03515</AltitudeMeters> Utils.WriteStringToXML(writer, "AltitudeMeters", String.format(Locale.ROOT, "%1.1f", r.getElevation(CgConst.UNIT_METER))); // <Comment>AAA</Comment> String s = r.getComment().trim(); if (s.equals("")) s = " "; Utils.WriteStringToXML(writer, "Comment", s); // <Name>AAA</Name> s = r.getName().trim(); if (s.equals("")) s = " "; Utils.WriteStringToXML(writer, "Name", s); // <Tag>1234</Tag> Utils.WriteStringToXML(writer, "Tag", String.format("%d", r.getTag())); // <EatTime>1234</EatTime> Utils.WriteIntToXML(writer, "EatTime", r.getStation()); // <TimeLimit>1234</TimeLimit> Utils.WriteIntToXML(writer, "TimeLimit", r.getTimeLimit()); // <FmtLbMiniRoadbook>1234</FmtLbMiniRoadbook> Utils.WriteStringToXML(writer, "FmtLbMiniRoadbook", r.FmtLbMiniRoadbook); // <OptMiniRoadbook>1234</OptMiniRoadbook> Utils.WriteIntToXML(writer, "OptMiniRoadbook", r.OptionMiniRoadbook); // <VPosMiniRoadbook>1234</VPosMiniRoadbook> Utils.WriteIntToXML(writer, "VPosMiniRoadbook", r.VPosMiniRoadbook); // <CommentMiniRoadbook>1234</CommentMiniRoadbook> Utils.WriteStringToXML(writer, "CommentMiniRoadbook", r.CommentMiniRoadbook); // <FontSizeMiniRoadbook>1234</FontSizeMiniRoadbook> Utils.WriteIntToXML(writer, "FontSizeMiniRoadbook", r.FontSizeMiniRoadbook); writer.writeEndElement(); // Pt } // if } // for writer.writeEndElement(); // Points writer.writeEndElement(); // COURSEGENERATOR writer.writeEndDocument(); writer.flush(); writer.close(); } catch (XMLStreamException | IOException e) { e.printStackTrace(); } }