Package com.adobe.dp.xml.util

Examples of com.adobe.dp.xml.util.XMLSerializer


    subsetter.setStyles(styleResources);
    body.addFonts(subsetter);
  }

  public void serialize(OutputStream out) throws IOException {
    XMLSerializer ser = new XMLSerializer(out);
    serialize(ser);
  }
View Full Code Here


      }
      OutputStream out = container.getOutputStream(name, res.canCompress());
      res.serialize(out);
    }
    if (needEnc) {
      XMLSerializer ser = new XMLSerializer(container.getOutputStream("META-INF/encryption.xml"));
      ser.startDocument("1.0", "UTF-8");
      ser.startElement(ocfns, "encryption", null, true);
      ser.newLine();
      names = resourcesByName.keys();
      while (names.hasMoreElements()) {
        String name = (String) names.nextElement();
        Resource res = (Resource) resourcesByName.get(name);
        if (res instanceof FontResource) {
          SMapImpl attrs = new SMapImpl();
          ser.startElement(encns, "EncryptedData", null, true);
          ser.newLine();
          if (useIDPFFontMangling)
            attrs.put(null, "Algorithm", "http://www.idpf.org/2008/embedding");
          else
            attrs.put(null, "Algorithm", "http://ns.adobe.com/pdf/enc#RC");
          ser.startElement(encns, "EncryptionMethod", attrs, false);
          ser.endElement(encns, "EncryptionMethod");
          ser.newLine();
          ser.startElement(encns, "CipherData", null, false);
          ser.newLine();
          attrs = new SMapImpl();
          attrs.put(null, "URI", name);
          ser.startElement(encns, "CipherReference", attrs, false);
          ser.endElement(encns, "CipherReference");
          ser.newLine();
          ser.endElement(encns, "CipherData");
          ser.newLine();
          ser.endElement(encns, "EncryptedData");
          ser.newLine();
        }
      }
      ser.endElement(ocfns, "encryption");
      ser.newLine();
      ser.endDocument();
    }
    XMLSerializer ser = new XMLSerializer(container.getOutputStream("META-INF/container.xml"));
    ser.startDocument("1.0", "UTF-8");
    SMapImpl attrs = new SMapImpl();
    attrs.put(null, "version", "1.0");
    ser.startElement(ocfns, "container", attrs, true);
    ser.newLine();
    ser.startElement(ocfns, "rootfiles", null, false);
    ser.newLine();
    attrs = new SMapImpl();
    attrs.put(null, "full-path", opf.name);
    attrs.put(null, "media-type", opf.mediaType);
    ser.startElement(ocfns, "rootfile", attrs, true);
    ser.endElement(ocfns, "rootfile");
    ser.newLine();
    ser.endElement(ocfns, "rootfiles");
    ser.newLine();
    ser.endElement(ocfns, "container");
    ser.newLine();
    ser.endDocument();
    container.close();
  }
View Full Code Here

      factory.setNamespaceAware(true);

      final CascadeEngine styler = new CascadeEngine();
      styler.add(stylesheet, null);

      final XMLSerializer ser = new XMLSerializer(System.out);
      ser.startDocument("1.0", "UTF-8");

      SAXParser parser = factory.newSAXParser();
      XMLReader reader = parser.getXMLReader();
      reader.setContentHandler(new ContentHandler() {
        public void characters(char[] text, int offset, int len) throws SAXException {
          ser.text(text, offset, len);
        }

        public void endDocument() throws SAXException {
        }

        public void endElement(String ns, String local, String qname) throws SAXException {
          styler.popElement();
          ser.endElement(ns, local);
        }

        public void endPrefixMapping(String arg0) throws SAXException {
        }

        public void ignorableWhitespace(char[] arg0, int arg1, int arg2) throws SAXException {
        }

        public void processingInstruction(String arg0, String arg1) throws SAXException {
        }

        public void setDocumentLocator(Locator arg0) {
        }

        public void skippedEntity(String arg0) throws SAXException {
        }

        public void startDocument() throws SAXException {
        }

        public void startElement(String ns, String local, String qname, Attributes attrs) throws SAXException {
          SMapImpl smap = new SMapImpl(new SMapAttributesAdapter(attrs));
          styler.pushElement(ns, local, smap);
          BaseRule es = styler.getCascadeResult().getProperties().getPropertySet();
          smap.put(null, "style", (es.isEmpty() ? null : es.toString()));
          ser.startElement(ns, local, smap, qname.indexOf(':') < 0);
        }

        public void startPrefixMapping(String arg0, String arg1) throws SAXException {
        }

      });

      reader.parse(new InputSource(in));
      ser.endDocument();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here

      }
    }
  }

  public void serialize(OutputStream out) throws IOException {
    XMLSerializer ser = new XMLSerializer(out);
    ser.startDocument("1.0", "UTF-8");
    SMapImpl nsmap = new SMapImpl();
    nsmap.put(null, "opf", opfns);
    nsmap.put(null, "dc", dcns);
    nsmap.put(null, "dcterms", dctermsns);
    nsmap.put(null, "xsi", xsins);
    ser.setPreferredPrefixMap(nsmap);
    SMapImpl attrs = new SMapImpl();
    attrs.put(null, "version", "2.0");
    attrs.put(null, "unique-identifier", "bookid");
    ser.startElement(opfns, "package", attrs, true);
    ser.newLine();
    ser.startElement(opfns, "metadata", null, false);
    ser.newLine();
    Iterator it = epub.metadata.iterator();
    int identifierCount = 0;
    while (it.hasNext()) {
      Publication.SimpleMetadata item = (Publication.SimpleMetadata) it.next();
      if (item.ns != null && item.ns.equals(dcns) && item.name.equals("identifier")) {
        //[LC] improved: added the possibility to control from the outside de UUID
        attrs =(SMapImpl) item.attribs;
        if(attrs==null){
          attrs = new SMapImpl();
         
        }
        if(attrs.get(opfns, "scheme")!=null&&attrs.get(opfns, "scheme").equals("UUID")){
          attrs.put(null, "id", (identifierCount == 0 ? "bookid" : "bookid" + identifierCount));
          identifierCount++;
        }
       
       
      } else {
        attrs = null;
      }
      String value = item.value;
      if (epub.isTranslit())
        value = Translit.translit(value);
      if (item.ns == null) {
        attrs = new SMapImpl();
        attrs.put(null, "name", item.name);
        attrs.put(null, "content", value);
        ser.startElement(opfns, "meta", attrs, false);
        ser.endElement(opfns, "meta");
        ser.newLine();
      } else {
        ser.startElement(item.ns, item.name, attrs, false);
        char[] arr = value.toCharArray();
        ser.text(arr, 0, arr.length);
        ser.endElement(item.ns, item.name);
        ser.newLine();
      }
    }
    ser.endElement(opfns, "metadata");
    ser.newLine();
    ser.startElement(opfns, "manifest", null, false);
    ser.newLine();
    it = epub.resources();
    while (it.hasNext()) {
      Resource r = (Resource) it.next();
      if (r != this) {
        attrs = new SMapImpl();
        attrs.put(null, "id", epub.assignId(r));
        attrs.put(null, "href", makeReference(r.getName(), null));
        attrs.put(null, "media-type", r.mediaType);
        ser.startElement(opfns, "item", attrs, false);
        ser.endElement(opfns, "item");
        ser.newLine();
      }
    }
    ser.endElement(opfns, "manifest");
    ser.newLine();
    attrs = new SMapImpl();
    if (epub.toc != null)
      attrs.put(null, "toc", epub.assignId(epub.toc));
    if (epub.pageMap != null)
      attrs.put(null, "page-map", epub.assignId(epub.pageMap));
    ser.startElement(opfns, "spine", attrs, false);
    ser.newLine();
    it = epub.spine();
    while (it.hasNext()) {
      Resource r = (Resource) it.next();
        //[LC] improved: added the possibility to control from the outside de UUID     
      attrs=r.getSerializationAttributes();
      if(attrs==null){
        attrs = new SMapImpl();
      }
      attrs.put(null, "idref", epub.assignId(r));
      ser.startElement(opfns, "itemref", attrs, false);
      ser.endElement(opfns, "itemref");
      ser.newLine();
    }
    ser.endElement(opfns, "spine");
    ser.newLine();
    ser.endElement(opfns, "package");
    ser.newLine();
    ser.endDocument();
  }
View Full Code Here

    location.addUsage(XRef.USAGE_PAGE);
    pages.add(new Page(name, location));
  }

  public void serialize(OutputStream out) throws IOException {
    XMLSerializer ser = new XMLSerializer(out);
    ser.startDocument("1.0", "UTF-8");
    SMapImpl attrs = new SMapImpl();
    attrs.put(null, "version", "2005-1");
    String lang = epub.getDCMetadata("language");
    if (lang != null)
      attrs.put(null, "xml:lang", lang);
    ser.startElement(ncxns, "ncx", attrs, true);
    ser.newLine();
    ser.startElement(ncxns, "head", null, false);
    ser.newLine();
    attrs = new SMapImpl();
    attrs.put(null, "name", "dtb:uid");
    String uid = epub.getDCMetadata("identifier");
    if (uid == null)
      uid = "";
    attrs.put(null, "content", uid);
    ser.startElement(ncxns, "meta", attrs, false);
    ser.endElement(ncxns, "meta");
    ser.newLine();
    attrs = new SMapImpl();
    attrs.put(null, "name", "dtb:depth");
    int depth = calculateDepth(rootTOCEntry);
    attrs.put(null, "content", Integer.toString(depth));
    ser.startElement(ncxns, "meta", attrs, false);
    ser.endElement(ncxns, "meta");
    ser.newLine();
    attrs = new SMapImpl();
    attrs.put(null, "name", "dtb:totalPageNumber");
    attrs.put(null, "content", Integer.toString(pages.size()));
    ser.startElement(ncxns, "meta", attrs, false);
    ser.endElement(ncxns, "meta");
    ser.newLine();
    attrs = new SMapImpl();
    attrs.put(null, "name", "dtb:maxPageNumber");
    attrs.put(null, "content", Integer.toString(pages.size()));
    ser.startElement(ncxns, "meta", attrs, false);
    ser.endElement(ncxns, "meta");
    ser.newLine();
    ser.endElement(ncxns, "head");
    ser.newLine();
    ser.startElement(ncxns, "docTitle", null, false);
    ser.startElement(ncxns, "text", null, false);
    String title = epub.getDCMetadata("title");
    if (title == null)
      title = "";
    if (epub.isTranslit())
      title = Translit.translit(title);
    char[] arr = title.toCharArray();
    ser.text(arr, 0, arr.length);
    ser.endElement(ncxns, "text");
    ser.endElement(ncxns, "docTitle");
    ser.newLine();
    ser.startElement(ncxns, "navMap", null, false);
    ser.newLine();
    entryCount = 1;
    serializeChildEntries(rootTOCEntry, ser);
    ser.endElement(ncxns, "navMap");
    ser.newLine();
    if (pages.size() > 0) {
      ser.startElement(ncxns, "pageList", null, false);
      ser.startElement(ncxns, "navLabel", null, false);
      ser.startElement(ncxns, "text", null, false);
      ser.endElement(ncxns, "text");
      ser.endElement(ncxns, "navLabel");
      ser.newLine();
      Iterator pages = this.pages.iterator();
      int count = 1;
      while (pages.hasNext()) {
        Page page = (Page) pages.next();
        attrs = new SMapImpl();
        String countStr = Integer.toString(count++);
        attrs.put(null, "value", countStr);
        attrs.put(null, "type", "normal");
        attrs.put(null, "playOrder", Integer.toString(page.xref.getPlayOrder()));
        ser.startElement(ncxns, "pageTarget", attrs, false);
        ser.newLine();
        ser.startElement(ncxns, "navLabel", null, false);
        ser.startElement(ncxns, "text", null, false);
        char[] text = page.name.toCharArray();
        ser.text(text, 0, text.length);
        ser.endElement(ncxns, "text");
        ser.endElement(ncxns, "navLabel");
        ser.newLine();
        attrs = new SMapImpl();
        attrs.put(null, "src", page.xref.makeReference(this));
        ser.startElement(ncxns, "content", attrs, false);
        ser.endElement(ncxns, "content");
        ser.newLine();
        ser.endElement(ncxns, "pageTarget");
        ser.newLine();
      }
      ser.endElement(ncxns, "pageList");
    }
    ser.endElement(ncxns, "ncx");
    ser.newLine();
    ser.endDocument();
  }
View Full Code Here

    }
  }

  void serializePageMap(PageMapResource pageMap, OutputStream out) throws IOException {
    final String pagemapns = "http://www.idpf.org/2007/opf";
    XMLSerializer ser = new XMLSerializer(out);
    ser.startDocument("1.0", "UTF-8");
    ser.startElement(pagemapns, "page-map", null, true);
    ser.newLine();
    Iterator pages = this.pages.iterator();
    while (pages.hasNext()) {
      Page page = (Page) pages.next();
      SMapImpl attrs = new SMapImpl();
      attrs.put(null, "name", page.name);
      attrs.put(null, "href", page.xref.makeReference(pageMap));
      ser.startElement(pagemapns, "page", attrs, false);
      ser.endElement(pagemapns, "page");
      ser.newLine();
    }
    ser.endElement(pagemapns, "page-map");
    ser.endDocument();
  }
View Full Code Here

TOP

Related Classes of com.adobe.dp.xml.util.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.