private static void createPlaceholderBytes() throws Exception { // Only want to do this once InputStream is; try { is = ResourceUtils.getResourceViaProperty("docx4j.model.datastorage.placeholder" , placeholderResource); } catch (IOException e) { log.info("No resource on classpath at docx4j.model.datastorage.placeholder; falling back to using org/docx4j/model/datastorage/placeholder.xml"); is = ResourceUtils.getResource(placeholderResourceFallback); } placeholderBytes = IOUtils.toByteArray(is); }
private static void init() { properties = new Properties(); try { properties.load( ResourceUtils.getResource("docx4j.properties")); } catch (Exception e) { log.warn("Couldn't find/read docx4j.properties; " + e.getMessage()); } }
private static void init() { properties = new Properties(); try { properties.load( ResourceUtils.getResource("docx4j_version.properties")); } catch (Exception e) { log.warn("Couldn't find/read docx4j_version.properties; " + e.getMessage()); } }
private static void createPlaceholderFragment() throws Exception { // create it - one time operation InputStream is; try { is = ResourceUtils.getResourceViaProperty("docx4j.model.datastorage.placeholder" , placeholderResource); } catch (IOException e) { log.info("No resource on classpath for property docx4j.model.datastorage.placeholder; falling back to using org/docx4j/model/datastorage/placeholder.xml"); is = ResourceUtils.getResource(placeholderResourceFallback); } Document tmpDoc = XmlUtils.getNewDocumentBuilder().parse(is); placeholderFragment = tmpDoc.createDocumentFragment(); XmlUtils.treeCopy(tmpDoc.getDocumentElement(), placeholderFragment); }
@Override public Source resolve(String href, String base) throws TransformerException { try { return new StreamSource( org.docx4j.utils.ResourceUtils.getResource( XSLT_RESOURCE_ROOT + href)); } catch (IOException e) { throw new TransformerException(e); } } }
public Object unmarshal(String filename) throws JAXBException { java.io.InputStream is = null; try { is = org.docx4j.utils.ResourceUtils.getResource( "org/docx4j/openpackaging/parts/DrawingML/" + filename); } catch (IOException e) { e.printStackTrace(); } return unmarshal( is ); // side-effect is to set jaxbElement }
private PresetGeometries(){ try { InputStream is = ResourceUtils.getResource("org/docx4j/model/shapes/presetShapeDefinitions.xml"); read(is); } catch (Exception e){ throw new RuntimeException(e); } }
private static java.io.InputStream getResourceViaProperty(String propName, String defaultPath) throws java.io.IOException { String resourcePath= Docx4jProperties.getProperty(propName, defaultPath); log.debug(propName + " resolved to " + resourcePath); InputStream resourceIS = null; try { resourceIS = ResourceUtils.getResource(resourcePath); } catch (IOException ioe) { log.warn(resourcePath + ": " + ioe.getMessage()); } if (resourceIS==null) { log.warn("Property " + propName + " resolved to missing resource " + resourcePath + "; using " + defaultPath); return ResourceUtils.getResource(defaultPath); } else { return resourceIS; } }
public Object unmarshal(String filename) throws JAXBException { java.io.InputStream is = null; try { is = org.docx4j.utils.ResourceUtils.getResource( "org/docx4j/openpackaging/parts/DrawingML/" + filename); } catch (IOException e) { e.printStackTrace(); } return unmarshal( is ); // side-effect is to set jaxbElement }
/** * Get this resource from the location specified in docx4j.properties; * if none is specified, fallback to the default specified * * @param propName * @param defaultPath * @return * @throws java.io.IOException * @since 3.2.0 */ public static java.io.InputStream getResourceViaProperty(String propName, String defaultPath) throws java.io.IOException { String resourcePath= Docx4jProperties.getProperty(propName, defaultPath); log.debug(propName + " resolved to " + resourcePath); InputStream resourceIS = null; try { resourceIS = getResource(resourcePath); } catch (IOException ioe) { log.warn(resourcePath + ": " + ioe.getMessage()); } if (resourceIS==null) { log.warn("Property " + propName + " resolved to missing resource " + resourcePath + "; using " + defaultPath); return getResource(defaultPath); } else { return resourceIS; } }
public static Templates generateLayoutTreeXSLT(CTDiagramDefinition pictureLayout) throws Exception { System.out.println(XmlUtils.marshaltoString(pictureLayout, true)); // System.out.println("Generating xslt.."); Source xsltSource = new StreamSource( org.docx4j.utils.ResourceUtils.getResource( "org/docx4j/openpackaging/parts/DrawingML/DiagramLayoutMeta.xslt")); Templates xsltMeta = XmlUtils.getTransformerTemplate(xsltSource); Document source = XmlUtils.marshaltoW3CDomDocument(pictureLayout, Context.jc); ByteArrayOutputStream intermediate = new ByteArrayOutputStream(); Result intermediateResult = new StreamResult(intermediate); XmlUtils.transform(source, xsltMeta, null, intermediateResult); String tmpXslStr = intermediate.toString("UTF-8"); System.out.println(tmpXslStr); return XmlUtils.getTransformerTemplate( new StreamSource(new StringReader(tmpXslStr))); }
@Deprecated // since its questionable whether this // is important enough to live in WordprocessingMLPackage, // and in any case probably should be replaced with a TraversalUtil // approach (which wouldn't involve marshal/unmarshall, and // so should be more efficient). public void filter( FilterSettings filterSettings ) throws Exception { if (filterTemplate==null) { // first use Source xsltSource = new StreamSource( org.docx4j.utils.ResourceUtils.getResource( "org/docx4j/openpackaging/packages/filter.xslt")); filterTemplate = XmlUtils.getTransformerTemplate(xsltSource); } transform(filterTemplate, filterSettings.getSettings() ); }
/** * Get Microsoft fonts * We need these: * 1. On Microsoft platform, to embed in PDF output * 2. docx4all - all platforms - to populate font dropdown list */ private final static void setupMicrosoftFontFilenames() throws Exception { java.lang.ClassLoader classLoader = BestMatchingMapper.class.getClassLoader(); JAXBContext msFontsContext = JAXBContext.newInstance("org.docx4j.fonts.microsoft", classLoader); Unmarshaller u = msFontsContext.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); log.info("unmarshalling fonts.microsoft \n\n" ); // Get the xml file java.io.InputStream is = null; // Works in Eclipse - note absence of leading '/' is = org.docx4j.utils.ResourceUtils.getResource("org/docx4j/fonts/microsoft/MicrosoftFonts.xml"); org.docx4j.fonts.microsoft.MicrosoftFonts msFonts = (org.docx4j.fonts.microsoft.MicrosoftFonts)u.unmarshal( is ); List<MicrosoftFonts.Font> msFontsList = msFonts.getFont(); for (MicrosoftFonts.Font font : msFontsList ) { msFontsFilenames.put( (font.getName()), font); // 20080318 - normalised //log.debug( "put msFontsFilenames: " + normalise(font.getName()) ); } }
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; }
is2 = org.docx4j.utils.ResourceUtils.getResource("org/docx4j/fonts/substitutions/FontSubstitutions.xml");
byte[] bytes = IOUtils.toByteArray(org.docx4j.utils.ResourceUtils.getResource( "image_broken.gif"));
org.docx4j.utils.ResourceUtils.getResource( "org/docx4j/openpackaging/parts/DrawingML/DiagramLayoutTree4AlgHier.xslt")));
org.docx4j.utils.ResourceUtils.getResource( "org/docx4j/openpackaging/parts/DrawingML/DiagramLayoutTree4AlgHier.xslt")));
org.docx4j.utils.ResourceUtils.getResource( "org/docx4j/openpackaging/parts/DrawingML/DiagramLayoutTree4pictureOrgChart2DiagramData.xslt")));
defaultTemplatesResource = HTML_TEMPLATE_RESOURCE; xsltSource = new StreamSource(org.docx4j.utils.ResourceUtils.getResource( defaultTemplatesResource)); ret = XmlUtils.getTransformerTemplate(xsltSource);