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

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


  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

            throws XmlPullParserException, IOException {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser pp = factory.newPullParser();
        pp.setInput(reader);
        XmlSerializer serializer = factory.newSerializer();
        serializer.setOutput(writer);
        if (indent != null) {
            serializer.setProperty(PROPERTY_SERIALIZER_INDENTATION, indent);
        }
        (new RoundTrip(pp, serializer)).roundTrip();
    }
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

            IOException {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser pp = factory.newPullParser();
        pp.setInput(reader);
        XmlSerializer serializer = factory.newSerializer();
        serializer.setOutput(writer);
        if (indent != null) {
            serializer.setProperty(PROPERTY_SERIALIZER_INDENTATION, indent);
        }
        (new RoundTrip(pp, serializer)).roundTrip();
    }
View Full Code Here

      int currentMetadataId = 1;
      HashMap<Integer, Stage> stageMetadata = new HashMap<Integer, Stage>();
      HashMap<Integer, Show> showMetadata = new HashMap<Integer, Show>();
      HashMap<Show, Integer> changeMapping = new HashMap<Show, Integer>();

      XmlSerializer ser = new MXSerializer();
      ser.setOutput(os, "UTF-8");
      ser.setProperty(
          "http://xmlpull.org/v1/doc/properties.html#serializer-indentation",
          "\t");
      ser.startDocument("UTF-8", true);
      ser.startTag(NS, "event");
      attribute(ser, "xmlns", "http://michal.linhard.sk/openair/event");
      attribute(ser, "uri", e.getUri());
      attribute(ser, "name", e.getName());
      attribute(ser, "shortName", e.getShortName());
      attribute(ser, "version", e.getVersion());
      attribute(ser, "versionTime",
          Util.formatDateTime(e.getVersionTime()));

      ser.startTag(NS, "program");
      for (Stage eachStage : e) {
        ser.startTag(NS, "stage");
        attribute(ser, "name", eachStage.getName());
        attribute(ser, "shortName", eachStage.getShortName());
        if (eachStage.getMetadata() != null) {
          attribute(ser, "id", "st" + currentMetadataId);
          stageMetadata.put(currentMetadataId, eachStage);
          currentMetadataId++;
        }
        for (DayProgram eachDay : eachStage) {
          ser.startTag(NS, "day");
          attribute(ser, "date",
              Util.formatDate(eachDay.getDayStart()));
          for (Show eachShow : eachDay) {
            ser.startTag(NS, "show");
            attribute(ser, "start",
                Util.formatDateTime(eachShow.getStart()));
            attribute(ser, "duration",
                Util.formatDuration(eachShow.getDuration()));
            attribute(ser, "name", eachShow.getName());
            attribute(ser, "shortName", eachShow.getShortName());
            if (eachShow.isCancelled()) {
              attribute(ser, "cancelled", Boolean.TRUE);
            }
            Integer showID = changeMapping.get(eachShow);

            if (showID == null
                && (eachShow.getMetadata() != null || eachShow
                    .isMoved())) {
              showID = currentMetadataId;
              currentMetadataId++;
            }
            if (showID != null) {
              attribute(ser, "id", "sh" + showID);
              if (eachShow.getMetadata() != null) {
                showMetadata.put(showID, eachShow);
              }
              if (eachShow.isMoved()) {
                if (eachShow.isOldVersion()) {
                  changeMapping.put(eachShow.getNewVersion(),
                      showID);
                  attribute(ser, "oldVersion", true);
                } else {
                  changeMapping.put(eachShow.getOldVersion(),
                      showID);
                }
              }
            }
            ser.endTag(NS, "show");
          }
          ser.endTag(NS, "day");
        }

        ser.endTag(NS, "stage");
      }
      ser.endTag(NS, "program");

      ser.startTag(NS, "metadata");
      if (e.getMetadata() != null) {
        ser.startTag(NS, "event");
        attribute(ser, "url", e.getUrl());
        attribute(ser, "description", e.getDescription());
        ser.endTag(NS, "event");
      }
      for (Entry<Integer, Stage> stageEntry : stageMetadata.entrySet()) {
        ser.startTag(NS, "stage");
        attribute(ser, "id", "st" + stageEntry.getKey());
        attribute(ser, "url", stageEntry.getValue().getUrl());
        attribute(ser, "description", stageEntry.getValue()
            .getDescription());
        ser.endTag(NS, "stage");
      }
      for (Entry<Integer, Show> showEntry : showMetadata.entrySet()) {
        ser.startTag(NS, "show");
        attribute(ser, "id", "sh" + showEntry.getKey());
        attribute(ser, "url", showEntry.getValue().getUrl());
        attribute(ser, "description", showEntry.getValue()
            .getDescription());
        ser.endTag(NS, "show");
      }

      ser.endTag(NS, "metadata");

      ser.endTag(NS, "event");
      ser.endDocument();
      ser.flush();
    } catch (IllegalArgumentException e1) {
      throw new RuntimeException(e1);
    } catch (IllegalStateException e1) {
      throw new RuntimeException(e1);
    } catch (IOException e1) {
View Full Code Here

  }
 

  private void writePackageDocument(Book book, ZipOutputStream resultStream) throws IOException {
    resultStream.putNextEntry(new ZipEntry("OEBPS/content.opf"));
    XmlSerializer xmlSerializer = EpubProcessorSupport.createXmlSerializer(resultStream);
    PackageDocumentWriter.write(this, xmlSerializer, book);
    xmlSerializer.flush();
//    String resultAsString = result.toString();
//    resultStream.write(resultAsString.getBytes(Constants.ENCODING));
  }
View Full Code Here

  public static XmlSerializer createXmlSerializer(OutputStream out) throws UnsupportedEncodingException {
    return createXmlSerializer(new OutputStreamWriter(out, Constants.CHARACTER_ENCODING));
  }
 
  public static XmlSerializer createXmlSerializer(Writer out) {
    XmlSerializer result = null;
    try {
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      factory.setValidating(true);
      result = factory.newSerializer();
      result.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
      result.setOutput(out);
    } catch (Exception e) {
      log.error("When creating XmlSerializer: " + e.getClass().getName() + ": " + e.getMessage());
    }
    return result;
  }
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.