Package org.docx4j.openpackaging.exceptions

Examples of org.docx4j.openpackaging.exceptions.Docx4JException


          savePart(part);
         
        }
         
      } catch (Exception e) {
        throw new Docx4JException("Failed to add parts from relationships of " + rp.getSourceP().getPartName(), e);       
      }
    }
   
   
  }
View Full Code Here


        result = xPath.evaluate(xpathString, doc );
      }
      log.debug(xpathString + " ---> " + result);
      return result;
    } catch (Exception e) {
      throw new Docx4JException("Problems evaluating xpath '" + xpathString + "'", e);
    }
  }
View Full Code Here

      final Unmarshaller unmarshaller = context.createUnmarshaller();
      unmarshaller.setEventHandler(new JaxbValidationEventHandler());
      result = new JAXBResult(unmarshaller);

    } catch (JAXBException e) {
      throw new Docx4JException("Error preparing empty JAXB result", e);
    }
    return result;
  }
View Full Code Here

        Map<String, Object> transformParameters,
        javax.xml.transform.Result result) throws Docx4JException {

      if (doc == null ) {
        Throwable t = new Throwable();
        throw new Docx4JException( "Null DOM Doc", t);
      }
     
    javax.xml.transform.dom.DOMSource domSource = new javax.xml.transform.dom.DOMSource(doc);
   
      transform(domSource,
View Full Code Here

                Map<String, Object> transformParameters,
                javax.xml.transform.Result result) throws Docx4JException {
     
      if (source == null ) {
        Throwable t = new Throwable();
        throw new Docx4JException( "Null Source doc", t);
      }
   
    // Use the template to create a transformer
    // A Transformer may not be used in multiple threads running concurrently.
    // Different Transformers may be used concurrently by different threads.
    // A Transformer may be used multiple times. Parameters and output properties
    // are preserved across transformations.   
    javax.xml.transform.Transformer xformer;
    try {
      xformer = template.newTransformer();
    } catch (TransformerConfigurationException e) {
      throw new Docx4JException("The Transformer is ill-configured", e);
    }
    if (!xformer.getClass().getName().equals(
        "org.apache.xalan.transformer.TransformerImpl")) {
      log
          .error("Detected "
              + xformer.getClass().getName()
              + ", but require org.apache.xalan.transformer.TransformerImpl. "
              + "Ensure Xalan 2.7.0 is on your classpath!");
    }
    LoggingErrorListener errorListener = new LoggingErrorListener(false);
    xformer.setErrorListener(errorListener);

    if (transformParameters != null) {
      Iterator parameterIterator = transformParameters.entrySet()
          .iterator();
      while (parameterIterator.hasNext()) {
        Map.Entry pairs = (Map.Entry) parameterIterator.next();

        if (pairs.getKey() == null) {
          log.info("Skipped null key");
          // pairs = (Map.Entry)parameterIterator.next();
          continue;
        }

        if (pairs.getKey().equals("customXsltTemplates")) continue;
       
        if (pairs.getValue() == null) {
          log.warn("parameter '" + pairs.getKey() + "' was null.");
        } else {
          xformer.setParameter((String) pairs.getKey(), pairs
              .getValue());
        }
      }
    }

        /* SUPER DEBUGGING
            // http://xml.apache.org/xalan-j/usagepatterns.html#debugging
            // debugging
            // Set up a PrintTraceListener object to print to a file.
            java.io.FileWriter fw = new java.io.FileWriter("/tmp/xslt-events" + xsltCount++ + ".log");
            java.io.PrintWriter pw = new java.io.PrintWriter(fw);
            PrintTraceListener ptl = new PrintTraceListener(pw);

            // Print information as each node is 'executed' in the stylesheet.
            ptl.m_traceElements = true;
            // Print information after each result-tree generation event.
            ptl.m_traceGeneration = true;
            // Print information after each selection event.
            ptl.m_traceSelection = true;
            // Print information whenever a template is invoked.
            ptl.m_traceTemplates = true;
            // Print information whenever an extension is called.
            ptl.m_traceExtension = true;
            TransformerImpl transformerImpl = (TransformerImpl)xformer;

              // Register the TraceListener with the TraceManager associated
              // with the TransformerImpl.
              TraceManager trMgr = transformerImpl.getTraceManager();
              trMgr.addTraceListener(ptl);

*/
    // DEBUGGING
    // use the identity transform if you want to send wordDocument;
    // otherwise you'll get the XHTML
    // javax.xml.transform.Transformer xformer = tfactory.newTransformer();
        try {
            xformer.transform(source, result);
        } catch (TransformerException e) {
          throw new Docx4JException("Cannot perform the transformation", e);
        } finally {
            //pw.flush();
        }
     
    }
View Full Code Here

    InputStream is = null;
    try {
      is = partStore.loadPart("[Content_Types].xml");   
      ctm.parseContentTypesFile(is);
    } catch (Docx4JException e) {
      throw new Docx4JException("Couldn't get [Content_Types].xml from ZipFile", e);
    } catch (NullPointerException e) {
      throw new Docx4JException("Couldn't get [Content_Types].xml from ZipFile", e);
    } finally {
      IOUtils.closeQuietly(is);
    }
   
    // .. now find the name of the main part
View Full Code Here

   
    InputStream is = null;
    try {
      is =  partStore.loadPart( "_rels/.rels");
      if (is==null) {
        throw new Docx4JException("_rels/.rels appears to be missing from this package!");
      }
      rp.unmarshal(is);
     
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      throw new Docx4JException("Error getting document from Zipped Part: _rels/.rels " , e);
     
    } finally {
      IOUtils.closeQuietly(is);
    }
  }
View Full Code Here

      rp = p.getRelationshipsPart(true);
      rp.unmarshal(is);
     
    } catch (Exception e) {
      e.printStackTrace();
      throw new Docx4JException("Error getting document from Zipped Part:" + partName, e);
     
    } finally {
      IOUtils.closeQuietly(is);
    }
    return rp;
View Full Code Here

        // This is usually the first logged comment for
        // a part, so start with a line break.
      try {       
        getPart(pkg, rp, r, ctm);
      } catch (Exception e) {
        throw new Docx4JException("Failed to add parts from relationships", e);
      }
    }
   
   
  }
View Full Code Here

    CTAltChunk ac = Context.getWmlObjectFactory().createCTAltChunk();
    ac.setId(altChunkRel.getId() );
    if (this instanceof ContentAccessor) {
     ((ContentAccessor)this).getContent().add(ac);
    } else {
      throw new Docx4JException(this.getClass().getName() + " doesn't implement ContentAccessor");
    }
   
    return afiPart;
  }
View Full Code Here

TOP

Related Classes of org.docx4j.openpackaging.exceptions.Docx4JException

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.