Package org.xmlpull.v1

Examples of org.xmlpull.v1.XmlSerializer


            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

  }

 
  public static void write(EpubWriter epubWriter, Book book, ZipOutputStream resultStream) throws IOException {
    resultStream.putNextEntry(new ZipEntry(book.getSpine().getTocResource().getHref()));
    XmlSerializer out = EpubProcessorSupport.createXmlSerializer(resultStream);
    write(out, book);
    out.flush();
  }
View Full Code Here

  public static Resource createNCXResource(Book book) throws IllegalArgumentException, IllegalStateException, IOException {
    return createNCXResource(book.getMetadata().getIdentifiers(), book.getTitle(), book.getMetadata().getAuthors(), book.getTableOfContents());
  }
  public static Resource createNCXResource(List<Identifier> identifiers, String title, List<Author> authors, TableOfContents tableOfContents) throws IllegalArgumentException, IllegalStateException, IOException {
    ByteArrayOutputStream data = new ByteArrayOutputStream();
    XmlSerializer out = EpubProcessorSupport.createXmlSerializer(data);
    write(out, identifiers, title, authors, tableOfContents);
    Resource resource = new Resource(NCX_ITEM_ID, data.toByteArray(), DEFAULT_NCX_HREF, MediatypeService.NCX);
    return resource;
 
View Full Code Here

                return;
            }

            OutputStream os = null;
            try {
                final XmlSerializer serializer = XmlPullParserFactory.newInstance().newSerializer();
                try {
                    serializer.setProperty("http://xmlpull.org/v1/doc/properties.html#serializer-indentation", "  ");
                } catch (Exception e) {
                    // not recognized
                }
                serializer.setOutput(os = new SafeFileOutputStream(file), myCharset.name());
                saveHistory(serializer);
            } catch (Exception ex) {
                LOG.error(ex);
            } finally {
                try {
View Full Code Here

                QName type = ((WSIFMessageElement) this.inputMessage).getPartType(name);
                if (LEADTypes.isArrayType(type)) {
                    // split string into items using " " as separator
                    Pattern pattern = Pattern.compile("[,\\s]+");
                    String[] result = pattern.split((String) value);
                    XmlElement arrayEl = XmlConstants.BUILDER.newFragment(name);
                    for (int i = 0; i < result.length; i++) {
                        logger.debug("split=" + result[i]);
                        arrayEl.addElement("value").addChild(result[i]);
                    }
                    this.inputMessage.setObjectPart(name, arrayEl);
                    value = null; // no need to set string value below
                }
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.