Package org.xmlpull.v1

Examples of org.xmlpull.v1.XmlSerializer


   
    /// methods for XML Pull parsing / serialization
   
    public static XmlSerializer getXmlSerializer(boolean whitespace)
            throws IOException {
        XmlSerializer result;
        try {
            result = xmlPullParserFactory.newSerializer();
        } catch (Exception e) {
            IOException ioe = new IOException("Couldn't obtain xml serializer");
            ioe.initCause(e);
            throw ioe;
        }

        if (whitespace)
            try {
                result.setFeature(
                        "http://xmlpull.org/v1/doc/features.html#indent-output",
                        true);
            } catch (Exception e) {
                // pretty whitespace output is a preference, but rarely a
                // requirement.  If the current XmlPull implementation doesn't
View Full Code Here


    private void writeManifest(ZipOutputStream zipOut, boolean includeTaskLists)
            throws IOException {
        zipOut.putNextEntry(new ZipEntry(MANIFEST_FILE_NAME));

        XmlSerializer xml = null;
        try {
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            xml = factory.newSerializer();
        } catch (XmlPullParserException xppe) {
            throw new RuntimeException("Couldn't obtain xml serializer", xppe);
        }

        xml.setOutput(zipOut, ENCODING);
        xml.startDocument(ENCODING, Boolean.TRUE);
        xml.ignorableWhitespace(NEWLINE + NEWLINE);

        xml.startTag(null, ARCHIVE_ELEM);
        xml.attribute(null, TYPE_ATTR, FILE_TYPE_ARCHIVE);
        xml.ignorableWhitespace(NEWLINE);

        writeManifestMetaData(xml);
        writeManifestFileEntry(xml, DATA_FILE_NAME, FILE_TYPE_METRICS, "1");
        writeManifestFileEntry(xml, DEFECT_FILE_NAME, FILE_TYPE_DEFECTS, "1");
        writeManifestFileEntry(xml, TIME_FILE_NAME, FILE_TYPE_TIME_LOG, "1");
        if (includeTaskLists)
            writeManifestFileEntry(xml, EV_FILE_NAME, FILE_TYPE_EARNED_VALUE,
                    "1");
       
        if (additionalEntries != null)
            for (Iterator i = additionalEntries.iterator(); i.hasNext();) {
                ExportFileEntry file = (ExportFileEntry) i.next();
                writeManifestFileEntry(xml, file.getFilename(), file.getType(),
                    file.getVersion());
            }
       
        xml.endTag(null, ARCHIVE_ELEM);
        xml.ignorableWhitespace(NEWLINE);
        xml.endDocument();

        zipOut.closeEntry();
    }
View Full Code Here

        write(out, timeLogEntries, true);
    }

    public static void write(Writer out, Iterator timeLogEntries, boolean close)
            throws IOException {
        XmlSerializer ser = null;
        try {
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            ser = factory.newSerializer();
        } catch (XmlPullParserException xppe) {
            throw new RuntimeException("Couldn't obtain xml serializer", xppe);
        }

        ser.setOutput(out);
        ser.startDocument(ENCODING, null);
        ser.ignorableWhitespace(NEWLINE);
        ser.startTag(null, DOC_ROOT_ELEM);
        ser.ignorableWhitespace(NEWLINE);

        try {
            while (timeLogEntries.hasNext())
                writeTimeLogEntry(ser, (TimeLogEntry) timeLogEntries.next());

        } catch (IONoSuchElementException ionsee) {
            throw ionsee.getIOException();
        }

        ser.endTag(null, DOC_ROOT_ELEM);
        ser.ignorableWhitespace(NEWLINE);
        ser.endDocument();
       
        if (close)
            out.close();
        else
            out.flush();
View Full Code Here

    private static final String OD_NAMESPACE_ATTR =
            "urn:schemas-microsoft-com:officedata";

    public static void writeXmlData(OutputStream out, DataContext profileData,
            List<String> projectPaths, ResultSet data) throws IOException {
        XmlSerializer xml = XMLUtils.getXmlSerializer(true);
        xml.setOutput(out, ENCODING);
        xml.startDocument(ENCODING, null);

        xml.startTag(null, "dataroot");
        xml.attribute(null, "xmlns:od", OD_NAMESPACE_ATTR);
        xml.attribute(null, "generated", DATE_FMT.format(new Date()));

        StudataExporterXmlProfile profileExporter = new StudataExporterXmlProfile(
                xml, profileData);
        profileExporter.writeXmlProfileData();
       
        StudataExporterXmlPrograms programExporter = new StudataExporterXmlPrograms(
                xml, projectPaths, data);
        programExporter.writeProgramData();

        xml.endTag(null, "dataroot");
        xml.endDocument();
    }
View Full Code Here

        return result;
    }

    private void writeDataElements(Writer out, HashTree sorted)
            throws IOException {
        XmlSerializer xml = null;
        try {
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            xml = factory.newSerializer();
        } catch (XmlPullParserException xppe) {
            throw new RuntimeException("Couldn't obtain xml serializer", xppe);
        }

        // we need to write our header manually, because we need to specify
        // XML version 1.1
        out.write(DATA_XML_HEADER + NEWLINE + NEWLINE);

        xml.setOutput(out);
        xml.startTag(null, DATA_ELEM);
        xml.ignorableWhitespace(NEWLINE);

        writeDataElementsForNode(xml, sorted, 0);

        xml.endTag(null, DATA_ELEM);
        xml.ignorableWhitespace(NEWLINE);
        xml.endDocument();

        out.flush();
    }
View Full Code Here

        write((OutputStream) out);
        out.closeEntry();
    }
   
    public void write(OutputStream out) throws IOException {
        XmlSerializer ser = XMLUtils.getXmlSerializer(true);
        ser.setOutput(out, ENCODING);
        ser.startDocument(ENCODING, null);
        ser.startTag(null, DOC_ROOT_ELEM);

        Collections.sort(mappingEntries);
        for (MappingEntry e : mappingEntries)
            e.write(ser);
       
        Collections.sort(mcfEntries);
        for (MCFEntry e : mcfEntries)
            e.write(ser);

        ser.endTag(null, DOC_ROOT_ELEM);
        ser.endDocument();
    }
View Full Code Here

  private void saveAsXML(Defect [] defects) {
      try {
          RobustFileOutputStream out = new RobustFileOutputStream(
                    defectLogFilename);
          if (defects != null && defects.length > 0) {
              XmlSerializer ser = XMLUtils.getXmlSerializer(true);
              ser.setOutput(out, XmlConstants.ENCODING);
              ser.startDocument(XmlConstants.ENCODING, null);
              ser.startTag(null, "defectLog");
              for (int i = 0; i < defects.length; i++)
                  if (defects[i] != null)
                      defects[i].toXml(ser);
              ser.endTag(null, "defectLog");
              ser.endDocument();
          }
          out.close();

      } catch (IOException e) { System.out.println("IOException: " + e); };
  }
View Full Code Here

        }
        return PageContentTO.REGION_CONTENT;
    }

    public void format(PageContentTO page, OutputStream out) throws IOException {
        XmlSerializer ser = null;
        try {
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            ser = factory.newSerializer();
        } catch (XmlPullParserException xppe) {
            throw new RuntimeException("Couldn't obtain xml serializer", xppe);
        }

        ser.setOutput(out, ENCODING);
        ser.startDocument(ENCODING, null);
        ser.ignorableWhitespace(NEWLINE);
        ser.startTag(null, DOC_ROOT_ELEM);
        ser.ignorableWhitespace(NEWLINE + NEWLINE);

        writePageMetadata(page, ser);
       
        Iterator headerSnippets = page.getHeaderSnippets();
        writeWrappedSnippets(ser, PAGE_HEADING_TAG, headerSnippets);
           
        Iterator contentSnippets = page.getContentSnippets();
        writeSnippets(ser, contentSnippets);

        Iterator footerSnippets = page.getFooterSnippets();
        writeWrappedSnippets(ser, PAGE_FOOTER_TAG, footerSnippets);

        ser.endTag(null, DOC_ROOT_ELEM);
        ser.ignorableWhitespace(NEWLINE);
        ser.endDocument();

        out.close();
    }
View Full Code Here

            return null;
        }
    }

    private String getTextToPersistImpl(Map postedData) throws IOException {
        XmlSerializer ser = null;
        try {
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            ser = factory.newSerializer();
        } catch (XmlPullParserException xppe) {
            throw new RuntimeException("Couldn't obtain xml serializer", xppe);
        }
        try {
            if (generateWhitespace)
                ser.setFeature(
                        "http://xmlpull.org/v1/doc/features.html#indent-output",
                        true);
        } catch (Exception e) {
        }

        StringWriter out = new StringWriter();
        ser.setOutput(out);
        ser.startDocument("utf-16", Boolean.TRUE);
        ser.flush();
        out.getBuffer().setLength(0);

        ser.startTag(null, TOP_TAG);

        // filter the posted data so we are only working with items that end
        // in "_ALL".  This simplifies our work.
        if (lenientPostedDataMode)
            addMissingALLParams(postedData);
        postedData = EditedPageDataParser.filterParamMap(postedData,
                new TreeMap(), null, "_ALL", false, true);

        writeParamList(ser, postedData);

        ser.endTag(null, TOP_TAG);
        ser.endDocument();

        return out.toString();
    }
View Full Code Here

        logger.info("before:");
        logger.info(testString);

        XmlPullParserFactory xppFactory = XmlPullParserFactory.newInstance();
        XmlSerializer xmlSerializer = xppFactory.newSerializer();
        StringWriter stringwriter = new StringWriter();
        xmlSerializer.setOutput(stringwriter);
        xmlSerializer.text(testString);
        String afterString = stringwriter.toString();

        logger.info("after:");
        logger.info(afterString);
    }
View Full Code Here

TOP

Related Classes of org.xmlpull.v1.XmlSerializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.