Package org.apache.sling.rewriter.impl.components

Examples of org.apache.sling.rewriter.impl.components.XMLSerializerFactory$XMLSerializer


  /** XML namespace dictionary. */
  private final XmlNamespaceDictionary namespaceDictionary;

  public final void writeTo(OutputStream out) throws IOException {
    XmlSerializer serializer = Xml.createSerializer();
    serializer.setOutput(out, getCharset().name());
    writeTo(serializer);
  }
View Full Code Here


        writeManifest(zipOut);
        zipOut.closeEntry();
    }

    protected void writeManifest(OutputStream out) throws IOException {
        XmlSerializer xml = XMLUtils.getXmlSerializer(true);
        xml.setOutput(out, "UTF-8");
        xml.startDocument("UTF-8", null);

        xml.startTag(null, "pdashReportArchive");
        xml.attribute(null, "version", "1.0");

        for (Map.Entry<String, String> e : contentTypeMap.entrySet()) {
            xml.startTag(null, "file");
            xml.attribute(null, "name", e.getKey());
            xml.attribute(null, "contentType", e.getValue());
            if (defaultFile.equals(e.getKey()))
                xml.attribute(null, "isDefault", "true");
            xml.endTag(null, "file");
        }

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

        return "text/xml";
    }

    public void runReport(ResourceCollection c, List<String> resources,
            OutputStream out) throws IOException {
        XmlSerializer ser = XMLUtils.getXmlSerializer(true);

        ser.setOutput(out, ENCODING);
        ser.startDocument(ENCODING, null);
        ser.startTag(null, DOCUMENT_TAG);

        for (String resourceName : resources) {
            long lastMod = c.getLastModified(resourceName);
            if (lastMod < 1)
                continue;

            Long checksum = c.getChecksum(resourceName);
            if (checksum == null)
                continue;

            ser.startTag(null, RESOURCE_TAG);
            ser.attribute(null, NAME_ATTR, resourceName);
            ser.attribute(null, MOD_TIME_ATTR, Long.toString(lastMod));
            ser.attribute(null, CHECKSUM_ATTR, checksum.toString());
            ser.endTag(null, RESOURCE_TAG);
        }

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

                String attrName = textToSafeAttrName(colName);
                resultSet.setColName(col, attrName);
            }
        }

        XmlSerializer xml = XMLUtils.getXmlSerializer(whitespace);
        xml.setOutput(outStream, ENCODING);
        xml.startDocument(ENCODING, null);

        xml.startTag(null, RESULT_SET_TAG);

        for (int row = 1; row <= resultSet.numRows(); row++) {
            xml.startTag(null, RESULT_ITEM_TAG);
            xml.attribute(null, PATH_ATTR, resultSet.getRowName(row));

            for (int col = 1; col <= resultSet.numCols(); col++) {
                String name = resultSet.getColName(col);
                SimpleData d = resultSet.getData(row, col);
                String value = (d == null ? null : d.format());

                if (inlineAttributes) {
                    if (value != null)
                        xml.attribute(null, name, value);
                } else {
                    xml.startTag(null, RESULT_DATA_TAG);
                    xml.attribute(null, NAME_ATTR, name);
                    if (value != null)
                        xml.attribute(null, VALUE_ATTR, value);
                    xml.endTag(null, RESULT_DATA_TAG);
                }
            }

            xml.endTag(null, RESULT_ITEM_TAG);
        }

        xml.endTag(null, RESULT_SET_TAG);

        xml.endDocument();
    }
View Full Code Here

   
    /// 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

TOP

Related Classes of org.apache.sling.rewriter.impl.components.XMLSerializerFactory$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.