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; }
private static Exporter<FOSettings> FOExporterVisitorGetInstance() throws Docx4JException { // Use reflection to return FOExporterVisitor.getInstance(); // so docx4j can be built without docx4j-export-FO try { Class<?> clazz = Class.forName("org.docx4j.convert.out.fo.FOExporterVisitor"); Method method = clazz.getMethod("getInstance", null); return (Exporter<FOSettings>)method.invoke(null, null); } catch (Exception e) { throw new Docx4JException("org.docx4j.convert.out.fo.FOExporterVisitor not found; if you want it, add docx4j-export-FO to your path. Doing so will disable Plutext's PDF Converter." + "/n" + e.getMessage(), e); } }
private static Exporter<FOSettings> FOExporterXsltGetInstance() throws Docx4JException { // Use reflection to return FOExporterXslt.getInstance(); // so docx4j can be built without docx4j-export-FO try { Class<?> clazz = Class.forName("org.docx4j.convert.out.fo.FOExporterXslt"); Method method = clazz.getMethod("getInstance", null); return (Exporter<FOSettings>)method.invoke(null, null); } catch (Exception e) { throw new Docx4JException("org.docx4j.convert.out.fo.FOExporterXslt not found; if you want it, add docx4j-export-FO to your path. " + "/n" + e.getMessage(), e); } }
private Object convertObject(Object id, Class c) throws Docx4JException { if (c.isAssignableFrom(id.getClass())) { return id; } if (c==BigInteger.class) { if (id instanceof Long) { return BigInteger.valueOf( (Long)id); } } throw new Docx4JException("TODO: Convert " + id.getClass().getName() + " to "+ c.getName() ); }
public void finishSave() throws Docx4JException { try { // Complete the ZIP file // Don't forget to do this or everything will appear // to work, but when you open the zip file you'll get an error // "End-of-central-directory signature not found." zos.close(); } catch (Exception e ) { throw new Docx4JException("Failed to put binary part", e); } }
public void saveContentTypes(ContentTypeManager ctm) throws Docx4JException { try { String filePath = dir.getPath() + dir.separator + "[Content_Types].xml"; FileOutputStream fos = new FileOutputStream(new File(filePath)); ctm.marshal(fos); fos.close(); } catch (Exception e) { throw new Docx4JException("Error marshalling Content_Types ", e); } }
public static void transform(org.w3c.dom.Document doc, javax.xml.transform.Templates template, 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, template, transformParameters, result); }
private void populatePackageRels(RelationshipsPart rp) throws Docx4JException { 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) { throw new Docx4JException("Error getting document from Zipped Part: _rels/.rels " , e); } finally { IOUtils.closeQuietly(is); } }
private void populatePackageRels(HashMap<String, ByteArray> partByteArrays, RelationshipsPart rp) throws Docx4JException { InputStream is = null; try { is = getInputStreamFromZippedPart( partByteArrays, "_rels/.rels"); if (is==null) { throw new Docx4JException("_rels/.rels appears to be missing from this package!"); } rp.unmarshal(is); } catch (Exception e) { throw new Docx4JException("Error getting document from Zipped Part: _rels/.rels " , e); } finally { IOUtils.closeQuietly(is); } }
public boolean save(java.io.File docxFile) throws Docx4JException { log.info("Saving to" + docxFile.getPath() ); try { if (docxFile.getPath().toLowerCase().endsWith(".xml") ) { return saveFlatOPC(new FileOutputStream(docxFile)); } else return save(new FileOutputStream(docxFile)); } catch (FileNotFoundException e) { throw new Docx4JException("Failed to save package to path " + docxFile.getPath(), e); } }
public boolean isContentEqual(ContentTypeManager other) throws Docx4JException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); try { marshal(baos); other.marshal(baos2); } catch (JAXBException e) { throw new Docx4JException("Error marshalling parts", e); } return java.util.Arrays.equals(baos.toByteArray(), baos2.toByteArray()); }
public boolean save(String filepath) throws Docx4JException { log.info("SAVING to " + filepath ); try { if (filepath.toLowerCase().endsWith(".xml") ) { return saveFlatOPC(new FileOutputStream(filepath)); } else return save(new FileOutputStream(filepath)); } catch (FileNotFoundException e) { throw new Docx4JException("Failed to save package to path " + filepath, e); } }
protected Templates loadDefaultTemplates() throws Docx4JException { Templates ret = null; Source xsltSource = null; //do a lazy loading in case the user has a custom template try { xsltSource = new StreamSource(ResourceUtils.getResource(defaultTemplatesResource)); ret = XmlUtils.getTransformerTemplate(xsltSource); } catch (IOException e) { throw new Docx4JException("Exception loading default template \"" + defaultTemplatesResource + "\", " + e.getMessage(), e); } catch (TransformerConfigurationException e) { throw new Docx4JException("Exception loading default template \"" + defaultTemplatesResource + "\", " + e.getMessage(), e); } return ret; }
protected void saveRawBinaryPart(ZipOutputStream out, Part part) throws Docx4JException { // Drop the leading '/' String resolvedPartUri = part.getPartName().getName().substring(1); try { // Add ZIP entry to output stream. out.putNextEntry(new ZipEntry(resolvedPartUri)); out.write( ((BinaryPart)part).getBytes() ); // Complete the entry out.closeEntry(); } catch (Exception e ) { throw new Docx4JException("Failed to put binary part", e); } log.info( "success writing part: " + resolvedPartUri); }
@Override protected WordprocessingMLPackage preprocess(CS conversionSettings) throws Docx4JException { WordprocessingMLPackage wmlPackage = null; try { wmlPackage = (WordprocessingMLPackage)conversionSettings.getWmlPackage(); } catch (ClassCastException cce) { throw new Docx4JException("Invalid document package in the settings, it isn't a WordprocessingMLPackage"); } if (wmlPackage == null) { throw new Docx4JException("Missing WordprocessingMLPackage in the conversion settings"); } return Preprocess.process(wmlPackage, conversionSettings.getFeatures()); }
@Override public void setXML(Document xmlDocument) throws Docx4JException { try { this.setJaxbElement( (E)XmlUtils.unmarshal(xmlDocument)); } catch (JAXBException e) { throw new Docx4JException("Problem unmarshalling, check content", e); } }
public void saveCustomXmlDataStoragePart(CustomXmlDataStoragePart part) throws Docx4JException { String targetName = part.getPartName().getName().substring(1); String filePath = dir.getPath() + dir.separator + targetName; File file = new File(filePath); file.getParentFile().mkdirs(); try { FileOutputStream fos = new FileOutputStream(file); part.getData().writeDocument( fos ); fos.close(); } catch (Exception e) { throw new Docx4JException("Error marshalling CustomXmlDataStoragePart " + part.getPartName(), e); } }
public void setDocument(InputStream is) throws Docx4JException { try { DocumentBuilder documentBuilder = XmlUtils.getNewDocumentBuilder(); doc = documentBuilder.parse(is); } catch (Exception e) { throw new Docx4JException("Problems parsing InputStream for part " + this.getPartName().getName(), e); } }
public void saveContentTypes(ContentTypeManager ctm) throws Docx4JException { try { zos.putArchiveEntry(new ZipArchiveEntry("[Content_Types].xml")); ctm.marshal(zos); zos.closeArchiveEntry(); } catch (Exception e) { throw new Docx4JException("Error marshalling Content_Types ", e); } }
public void saveCustomXmlDataStoragePart(CustomXmlDataStoragePart part) throws Docx4JException { String targetName = part.getPartName().getName().substring(1); try { // Add ZIP entry to output stream. zos.putArchiveEntry(new ZipArchiveEntry(targetName)); part.getData().writeDocument( zos ); // Complete the entry zos.closeArchiveEntry(); } catch (Exception e) { throw new Docx4JException("Error marshalling CustomXmlDataStoragePart " + part.getPartName(), e); } }