private void policePartSize(File f, long length, String entryName) throws PartTooLargeException { if (MAX_BYTES_Unzip_Error>-1 && length>MAX_BYTES_Unzip_Error) { if (f==null) { throw new PartTooLargeException(entryName + ", length " + length + " exceeds your configured maximum allowed size for unzip."); } else { throw new PartTooLargeException(f.getName() + ", " + entryName + ", length " + length + " exceeds your configured maximum allowed size for unzip."); } } }
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; }
/** * Throws an exception if the specified URI is absolute. * * @param partUri * The URI to check. * @throws InvalidFormatException * Throws if the specified URI is absolute. */ private static void throwExceptionIfAbsoluteUri(URI partUri) throws InvalidFormatException { if (partUri.isAbsolute()) { log.error( "" ); throw new InvalidFormatException("Absolute URI forbidden: " + partUri); } }
public CustomXmlDataStorage factory() { try { return new CustomXmlDataStorageImpl(); } catch (InvalidFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
public PropertyResolver getPropertyResolver() { if (propertyResolver==null) { try { propertyResolver = new PropertyResolver( (WordprocessingMLPackage)this.pack); } catch (Docx4JException e) { e.printStackTrace(); } } return propertyResolver; }
/** * Get the live contents of this part. * (getContents() is preferred, this is the older/less friendly method name) * @return */ public E getJaxbElement() { try { return getContents(); } catch (Docx4JException e) { log.error(e.getMessage(), e); return null; } }
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); } }
/** * @return the customXmlDataStorageClass */ static public CustomXmlDataStorage getCustomXmlDataStorageClass() { try { if (customXmlDataStorageClass==null) { customXmlDataStorageClass = new CustomXmlDataStorageImpl(); } return customXmlDataStorageClass; } catch (InvalidFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
private void ensureContent() throws Pptx4jException { try { if (this.getContents()==null ) { throw new Pptx4jException("MainPresentationPart has no content"); } } catch (Docx4JException e) { throw new Pptx4jException(e.getMessage(), e); } }
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 void ensureSldIdLst() throws Pptx4jException { try { if (this.getContents().getSldIdLst()==null) { throw new Pptx4jException("SldIdLst missing from MainPresentationPart"); } } catch (Docx4JException e) { throw new Pptx4jException(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 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(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 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()); }
@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 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); } }