Examples of CShaniDomParser


Examples of org.allcolor.xml.parser.CShaniDomParser

          } // end for

          this.value = result.toString();
        } // end if
        else {
          CShaniDomParser parser = new CShaniDomParser();

          if (this.value.startsWith("http://") ||
              this.value.startsWith("https://") ||
              this.value.startsWith("ftp://")) {
            this.docValue = (ADocument) parser.parse(this.value);
          } // end if
          else {
            this.docValue = (ADocument) parser.parse(new StringReader(
                  this.value));
          } // end else
          this.docValue.setDocumentURI(this.systemId);
          inputEncoding     = docValue.getInputEncoding();
          xmlEncoding      = docValue.getXmlEncoding();
          xmlVersion      = docValue._getXmlVersion();

          if (inputEncoding == null && xmlEncoding != null) {
            inputEncoding = xmlEncoding.toUpperCase();
          } else
          if (inputEncoding == null) {
            inputEncoding = "UTF-8";
          } // end if

          if (docValue.getDocumentElement().getNodeType() != Node.ELEMENT_NODE) {
            this.docValue     = null;
          } // end if
          else {
            this.value = null;
          } // end else
        } // end else
      } // end try
      catch (final Exception ignore) {
        this.value = delimiter + name + ";";
      } // end catch
    } // end if
    else {
      CShaniDomParser parser = new CShaniDomParser();
      if (this.value.startsWith("http://") ||
          this.value.startsWith("https://") ||
          this.value.startsWith("ftp://")) {
        this.docValue = (ADocument) parser.parse(this.value);
      } // end if
      else {
        this.docValue = (ADocument) parser.parse(new StringReader(
              this.value));
      } // end else
      this.docValue.setDocumentURI(this.systemId);

      if ((docValue.getDocumentElement() == null) ||
View Full Code Here

Examples of org.allcolor.xml.parser.CShaniDomParser

  /**
   * @param args
   */
  public static void main(String[] args)
  throws Exception {
    CShaniDomParser p = new CShaniDomParser();
    for (int i=0;i<100;i++) {
      System.out.println("Creating doc "+i);
      Document doc = p.getDOMImplementation().createDocument(null,null,null);
      Element root = doc.createElement("root");
      doc.appendChild(root);
      System.out.println("Append random elements on doc "+i);
      createDoc(doc,root,MAX_NODE,0);
      File result = new File("/home/qan/tmp/xml/xml_test_"+MAX_NODE+"_"+i+".xml");
View Full Code Here

Examples of org.allcolor.xml.parser.CShaniDomParser

  }

  private CShaniDomParser getCShaniDomParser() {
    final Reference ref = (Reference) this.tlparser.get();
    final CShaniDomParser parser = (CShaniDomParser) (ref == null ? null
        : ref.get());
    if (parser != null) {
      return parser;
    }
    final CShaniDomParser ret = new CShaniDomParser(true, false);
    ret.setAutodoctype(false);
    ret.setIgnoreDTD(true);
    this.tlparser.set(new SoftReference(ret));
    return ret;
  }
View Full Code Here

Examples of org.allcolor.xml.parser.CShaniDomParser

      final PageSize size, final List hf, final Map properties,
      final OutputStream out) throws CConvertException {
    final List files = new ArrayList();
    try {
      final Tidy tidy = this.getTidy();
      final CShaniDomParser parser = this.getCShaniDomParser();
      final _ITextRenderer renderer = this.getITextRenderer();
      final Reader r = CXmlParser.getReader(in);
      final StringBuffer s = new StringBuffer();
      final char[] buffer = new char[2048];
      int inb = -1;
      while ((inb = r.read(buffer)) != -1) {
        s.append(buffer, 0, inb);
      }
      r.close();
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      tidy.parse(
          new ByteArrayInputStream(s.toString().getBytes("utf-8")),
          bout);
      final String result = CHtmlToPdfFlyingSaucerTransformer
          .removeScript(new String(bout.toByteArray(), "utf-8"));
      Document theDoc = parser
          .parse(new InputStreamReader(new ByteArrayInputStream(
              result.getBytes("utf-8")), "utf-8"));
      if (theDoc.toString().length() == 0) {
        theDoc = parser.parse(new StringReader(
            CHtmlToPdfFlyingSaucerTransformer.removeScript(s
                .toString())));
      }
      this.convertInputToVisibleHTML(theDoc);
      this.convertComboboxToVisibleHTML(theDoc);
      this.convertTextAreaToVisibleHTML(theDoc);
      final NodeList styles = theDoc.getElementsByTagName("style");
      for (int i = 0; i < styles.getLength(); i++) {
        final Node n = styles.item(i);
        final StringBuffer style = new StringBuffer();
        while (n.getChildNodes().getLength() > 0) {
          final Node child = n.getChildNodes().item(0);
          if (child.getNodeType() == Node.COMMENT_NODE) {
            final Comment c = (Comment) child;
            style.append(c.getData());
          } else if (child.getNodeType() == Node.TEXT_NODE) {
            final Text c = (Text) child;
            style.append(c.getData());
          } else if (child.getNodeType() == Node.CDATA_SECTION_NODE) {
            final CDATASection c = (CDATASection) child;
            style.append(c.getData());
          }
          n.removeChild(child);
        }

        final String content = style.toString().trim();
        final Text start = theDoc.createTextNode("/*");
        final CDATASection cd = theDoc.createCDATASection("*/\n"
            + content + "\n/*");
        final Text end = theDoc.createTextNode("*/\n");
        n.appendChild(start);
        n.appendChild(cd);
        n.appendChild(end);
      }
      final List toRemove = new ArrayList();
      final NodeList tnl = theDoc.getChildNodes();
      for (int i = 0; i < tnl.getLength(); i++) {
        final Node n = tnl.item(i);
        if (n != theDoc.getDocumentElement()) {
          toRemove.add(n);
        }
      }
      final Node title = theDoc.getDocumentElement()
          .getElementsByTagName("title").item(0);
      if ((title != null)
          && (properties.get(IHtmlToPdfTransformer.PDF_TITLE) == null)) {
        properties.put(IHtmlToPdfTransformer.PDF_TITLE, title
            .getTextContent());
      }

      Node body = theDoc.getDocumentElement()
          .getElementsByTagName("body").item(0);
      Node head = theDoc.getDocumentElement()
          .getElementsByTagName("head").item(0);
      for (int i = 0; i < toRemove.size(); i++) {
        final Node n = (Node) toRemove.get(i);
        n.getParentNode().removeChild(n);
        if (n.getNodeType() == Node.TEXT_NODE) {
          final Text t = (Text) n;
          if (t.getData().trim().length() == 0) {
            continue;
          }
        }
        if ("link".equals(n.getNodeName())
            || "style".equals(n.getNodeName())) {
          head.appendChild(n);
        } else {
          body.appendChild(n);
        }
      }
      final DocumentAndSize docs[] = CDocumentCut.cut(theDoc, size);
      for (int jj = 0; jj < docs.length; jj++) {
        Document mydoc = docs[jj].doc;
        body = mydoc.getDocumentElement().getElementsByTagName("body")
            .item(0);
        head = mydoc.getDocumentElement().getElementsByTagName("head")
            .item(0);
        try {
          String surlForBase = ((Element) mydoc.getElementsByTagName(
              "base").item(0)).getAttribute("href");
          if ((surlForBase == null) || "".equals(surlForBase)) {
            surlForBase = null;
          }
          if (surlForBase != null) {
            urlForBase = surlForBase;
          }
        } catch (final Exception ignore) {
        }
        if (urlForBase != null) {
          ((ADocument) mydoc).setDocumentURI(urlForBase);
        }
        final NodeList nl = mydoc.getElementsByTagName("base");

        if (nl.getLength() == 0) {
          final ADocument doc = (ADocument) mydoc;
          final Element base = doc.createElement("base");
          base.setAttribute("href", urlForBase);

          if (head.getFirstChild() != null) {
            head.insertBefore(base, head.getFirstChild());
          } // end if
          else {
            head.appendChild(base);
          } // end else
        } else {
          final Element base = (Element) nl.item(0);
          base.setAttribute("href", urlForBase);
        }
        /* STEF: remove this, because it works well without this code, and when enabled, CSS selectors
         * separated by commas are ignored for some reason.
        final NodeList linknl = mydoc.getElementsByTagName("link");
        for (int zi=0;zi<linknl.getLength();zi++) {
          try {
            Element e = (Element)linknl.item(zi);
            if ("stylesheet".equals(e.getAttribute("rel"))) {
              String url =  normalizeLink(urlForBase, e.getAttribute("href"));
              InputStream iin = null;
              try {
                iin = new URL(url).openStream();
                ByteArrayOutputStream bOut = new ByteArrayOutputStream();
                int iNbByteRead = -1;
                byte bbuffer[] = new byte[16384];

                while ((iNbByteRead = iin.read(bbuffer)) != -1) {
                  bOut.write(bbuffer, 0, iNbByteRead);
                } // end while
                String document = new String(bOut.toByteArray(), "utf-8");
                CSSStyleSheet sheet = CCSSParser.parse(document, null,
                    null, url);
                if (sheet != null) {
                  Element style = mydoc.createElement("style");
                  style.setAttribute("type", "text/css");
                  style.setTextContent(sheet.toString());
                  e.getParentNode().insertBefore(style, e);
                  e.getParentNode().removeChild(e);
                }
              } // end try
              catch (final Throwable ignore) {
              } // end catch
              finally {
                try{iin.close();}catch(Throwable ignore){}
              }
            }
          }
          catch (Throwable ignore){}
        }
        */
        final NumberFormat nf = NumberFormat.getInstance(Locale.US);
        nf.setMaximumFractionDigits(2);
        nf.setMinimumFractionDigits(0);
        final Element style = mydoc.createElement("style");
        style.setAttribute("type", "text/css");
        final double[] dsize = docs[jj].size.getCMSize();
        final double[] dmargin = docs[jj].size.getCMMargin();
        style.setTextContent("\n@page {\n" + "size: "
            + nf.format(dsize[0] / 2.54) + "in "
            + nf.format(dsize[1] / 2.54) + "in;\n"
            + "margin-left: " + nf.format(dmargin[0] / 2.54)
            + "in;\n" + "margin-right: "
            + nf.format(dmargin[1] / 2.54) + "in;\n"
            + "margin-bottom: " + nf.format(dmargin[2] / 2.54)
            + "in;\n" + "margin-top: "
            + nf.format(dmargin[3] / 2.54) + "in;\npadding: 0in;\n"
            + "}\n"

        );
        head.appendChild(style);
        if (properties.get(IHtmlToPdfTransformer.FOP_TTF_FONT_PATH) != null) {
          final File dir = new File((String) properties
              .get(IHtmlToPdfTransformer.FOP_TTF_FONT_PATH));
          if (dir.isDirectory()) {
            CHtmlToPdfFlyingSaucerTransformer.registerTTF(dir,
                renderer);
          }
        }
        ((ADocument) mydoc).setInputEncoding("utf-8");
        ((ADocument) mydoc).setXmlEncoding("utf-8");
        renderer.getSharedContext().setBaseURL(urlForBase);
        mydoc = parser.parse(new StringReader(mydoc.toString()));
        mydoc.getDomConfig().setParameter("entities", Boolean.FALSE );
        mydoc.normalizeDocument();
        renderer.setDocument(mydoc, urlForBase);
        renderer.layout();
        final java.io.File f = java.io.File.createTempFile("pdf",
View Full Code Here

Examples of org.allcolor.xml.parser.CShaniDomParser

          NodeList child = val.getChildNodes();
          for (int i=0;i<child.getLength();i++) {
            appendChild(ownerDocument.importNode(child.item(i),true));
          }
        } else {
          CShaniDomParser parser = new CShaniDomParser();
          Document docValue = null;
          if (ent.getValue().equals("&"+ent.getNodeName()+";")) {
            representation     = "&" + name + ";";
            return;
          } else
          if ( ent.getValue().startsWith("http://") ||
               ent.getValue().startsWith("https://") ||
               ent.getValue().startsWith("ftp://")) {
            docValue = parser.parse(ent.getValue());
          } else {
            docValue = parser.parse(new StringReader(
                 ent.getValue()));
          }
          NodeList nl = docValue.getChildNodes();
          for (int i=0;i<nl.getLength();i++) {
            appendChild(ownerDocument.importNode(nl.item(i),true));
View Full Code Here

Examples of org.allcolor.xml.parser.CShaniDomParser

    isReadOnly = false;
    for (int i=0;i<l.size();i++) {
      removeChild((Node)l.get(i));
    }
    if (ownerDocument != null) {
      CShaniDomParser parser = new CShaniDomParser();
      Document docValue = null;
      if (nodeValue.startsWith("http://") ||
          nodeValue.startsWith("https://") ||
          nodeValue.startsWith("ftp://")) {
        docValue = parser.parse(nodeValue);
      } else {
        docValue = parser.parse(new StringReader(
            nodeValue));
      }
      nl = docValue.getChildNodes();
      for (int i=0;i<nl.getLength();i++) {
        appendChild(ownerDocument.importNode(nl.item(i).cloneNode(true),true));
View Full Code Here

Examples of org.allcolor.xml.parser.CShaniDomParser

  /**
   * DOCUMENT ME!
   */
  public void close() {
    if (this.documentOpen) {
      Document doc = new CShaniDomParser().parse(new StringReader(this.docBuffer
          .toString()));
      this.docBuffer = null;
      this.emptyDocument();
      this.isBuildStage = true;
      NodeList newNl = doc.getChildNodes();
View Full Code Here

Examples of org.allcolor.xml.parser.CShaniDomParser

  /**
   * DOCUMENT ME!
   */
  public void close() {
    if (this.documentOpen) {
      Document doc = new CShaniDomParser().parse(new StringReader(this.docBuffer
          .toString()));
      this.docBuffer = null;
      this.emptyDocument();
      this.isBuildStage = true;
      NodeList newNl = doc.getChildNodes();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.