Examples of Docx4JException


Examples of org.docx4j.openpackaging.exceptions.Docx4JException

  }
 
  protected File setupRootFolder(BinaryPart binaryPart) throws Docx4JException {
  File folder = new File(imageDirPath);
    if ((folder.exists()) && (!folder.isDirectory())) {
      throw new Docx4JException("Invalid imageDirPath '" + imageDirPath + ", it isn't a directory");
    }
    if (!folder.exists()) {
      if (!folder.mkdirs()) {
        throw new Docx4JException("Invalid imageDirPath '" + imageDirPath + ", could not create the directory");
      }
    }
    return folder;
  }
View Full Code Here

Examples of org.docx4j.openpackaging.exceptions.Docx4JException

      throws Docx4JException {

    this.wordMLPackage = wordMLPackage;

    if (wordMLPackage.getMainDocumentPart().getXPathsPart() == null) {
      throw new Docx4JException("OpenDoPE XPaths part missing");
    } else {
      xPaths = wordMLPackage.getMainDocumentPart().getXPathsPart()
          .getJaxbElement();
      log.debug(XmlUtils.marshaltoString(xPaths, true, true));
    }
View Full Code Here

Examples of org.docx4j.openpackaging.exceptions.Docx4JException

      try {
        for (ContentAccessor part : partList) {
          new TraversalUtil(part, shallowTraversor);
        }
      } catch (InputIntegrityException iie) { // RuntimeException
        throw new Docx4JException(iie.getMessage(), iie);
      }

      // Convert any sdt with <w:tag w:val="od:component=comp1"/>
      // to altChunk, and for MergeDocx users, to
      // real WordML.
View Full Code Here

Examples of org.docx4j.openpackaging.exceptions.Docx4JException

      extensionMissing(e);
      justGotAComponent = false;
      return srcPackage;
      // throw new Docx4JException("Problem processing w:altChunk", e);
    } catch (Exception e) {
      throw new Docx4JException("Problem processing w:altChunk", e);
    }
  }
View Full Code Here

Examples of org.docx4j.openpackaging.exceptions.Docx4JException

        index = ((CTTextbox) p.getParent()).getTxbxContent().getContent().indexOf(p);
        P newP = FieldsPreprocessor.canonicalise(p, fieldRefs);
        log.debug("Canonicalised: "+ XmlUtils.marshaltoString(newP, true, true));
        ((CTTextbox) p.getParent()).getTxbxContent().getContent().set(index, newP);
      } else {
        throw new Docx4JException("Unexpected parent: "+ p.getParent().getClass().getName());
      }
    }
  }
View Full Code Here

Examples of org.docx4j.openpackaging.exceptions.Docx4JException

 
  @Override
  public void output(javax.xml.transform.Result result) throws Docx4JException {
   
    if (wmlPackage==null) {
      throw new Docx4JException("Must setWmlPackage");
    }
   
    if (htmlSettings==null) {
      log.debug("Using empty HtmlSettings");
      htmlSettings = new HTMLSettings();     
    }   
   
    try {
      html(wmlPackage, result, htmlSettings);
    } catch (Exception e) {
      throw new Docx4JException("Failed to create HTML output", e);
    }   
   
  }
View Full Code Here

Examples of org.docx4j.openpackaging.exceptions.Docx4JException

    }
    Docx4J.toHTML(htmlSettings, outStream, Docx4J.FLAG_EXPORT_PREFER_XSL);
    try {
      transformer = XmlUtils.getTransformerFactory().newTransformer();
    } catch (TransformerConfigurationException e) {
      throw new Docx4JException("Exception creating identity transformer to output result: " + e.getMessage(), e);
    }
    try {
     
      // Resolution of doctype eg
      // <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      // may be extremely slow, so instead of
      // transformer.transform(new StreamSource(new ByteArrayInputStream(bytes)), result);
      // use
     
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); // as opposed to XmlUtils.getNewDocumentBuilder()
        dbFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
        DocumentBuilder db = dbFactory.newDocumentBuilder();
        // that feature is enough; alternatively, the below also works.  Use both for good measure.
        db.setEntityResolver(new EntityResolver() {

            @Override
            public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
                return new InputSource(new StringReader("")); // Returns a valid dummy source
                // returning null here is no good; it seems to cause:
              //    XMLEntityManager.reset(XMLComponentManager)
              //    XIncludeAwareParserConfiguration(XML11Configuration).resetCommon()
                // with the result that this entity resolver is not used!
            }
        })
       
        org.w3c.dom.Document doc = null;
        if (log.isDebugEnabled()) {
          byte[] bytes = outStream.toByteArray();
          log.debug(new String(bytes));
          doc = db.parse(new ByteArrayInputStream(bytes));
        } else {
          doc = db.parse(new ByteArrayInputStream(outStream.toByteArray()));
        }
        transformer.transform(new DOMSource(doc.getDocumentElement()), result);
     
    } catch (TransformerException e) {
      throw new Docx4JException("Exception dumping outputstream to output result: " + e.getMessage(), e);
    }
  }
View Full Code Here

Examples of org.docx4j.openpackaging.exceptions.Docx4JException

        }
        xsltSource = new StreamSource(org.docx4j.utils.ResourceUtils.getResource(
            defaultTemplatesResource));       
        ret = XmlUtils.getTransformerTemplate(xsltSource);
      } catch (IOException e) {
        throw new Docx4JException("Exception loading template \"" + defaultTemplatesResource + "\", " + e.getMessage(), e);
      } catch (TransformerConfigurationException e) {
        throw new Docx4JException("Exception loading template \"" + defaultTemplatesResource + "\", " + e.getMessage(), e);
      }
      finally {
        XmlUtils.getTransformerFactory().setURIResolver(originalURIResolver);
      }
      return ret;
View Full Code Here

Examples of org.docx4j.openpackaging.exceptions.Docx4JException

          if (c==BigInteger.class) {
            if (id instanceof Long) {
              return BigInteger.valueOf( (Long)id);
            }
          }
      throw new Docx4JException("TODO: Convert " + id.getClass().getName() + " to "+ c.getName() );
         
        }
View Full Code Here

Examples of org.docx4j.openpackaging.exceptions.Docx4JException

      Marshaller marshaller=jc.createMarshaller();
      doc = org.docx4j.XmlUtils.neww3cDomDocument();

      marshaller.marshal(pkg, doc);
    } catch (JAXBException e) {
      throw new Docx4JException("Couldn't marshal Flat OPC to DOM", e);
    }
   
    return doc;
   
  }
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.