private static void init() { properties = new Properties(); try { properties.load(ResourceUtils.getResource("docx4j.properties")); } catch (Exception e) { log.error("Error reading docx4j.properties", e); } }
static { try { jcSVG = JAXBContext.newInstance("org.plutext.jaxb.svg11"); oFactory = new ObjectFactory(); Source xsltSource = new StreamSource( org.docx4j.utils.ResourceUtils.getResource( "org/pptx4j/convert/out/svginhtml/pptx2svginhtml.xslt")); xslt = XmlUtils.getTransformerTemplate(xsltSource); } catch (Exception e) { e.printStackTrace(); } }
/** * Unmarshal a default font table, useful when creating this part from scratch. * * @return the newly created root object of the java content tree * @throws JAXBException If any unexpected errors occur while unmarshalling */ public Object unmarshalDefaultFonts() throws JAXBException { java.io.InputStream is = null; try { // Works in Eclipse - not absence of leading '/' is = org.docx4j.utils.ResourceUtils.getResource( "org/docx4j/openpackaging/parts/WordprocessingML/fontTable.xml"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return unmarshal(is); }
/** Get Microsoft fonts docx4all - all platforms - to populate font dropdown list */ private static final void setupMicrosoftFontsRegistry() throws Exception { msFontsByName = new HashMap<String, MicrosoftFonts.Font>(); // filenamesToMsFontNames = new HashMap<String, String>(); JAXBContext msFontsContext = JAXBContext.newInstance("org.docx4j.fonts.microsoft"); Unmarshaller u = msFontsContext.createUnmarshaller(); u.setEventHandler(new org.docx4j.jaxb.JaxbValidationEventHandler()); log.info("unmarshalling fonts.microsoft"); // 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) { msFontsByName.put((font.getName()), font); // 20080318 - normalised // log.debug( "put msFontsFilenames: " + normalise(font.getName()) ); // filenamesToMsFontNames.put( font.getFilename().toLowerCase() , font.getName()); //// log.debug( "put msFontsFilenames: " + font.getName() ); // // if (font.getBold()!=null) { // filenamesToMsFontNames.put( font.getBold().getFilename().toLowerCase(), // font.getName()+SEPARATOR+Mapper.BOLD); //// log.debug( "put bold: " + font.getName()+SEPARATOR+Substituter.BOLD ); // } // if (font.getItalic()!=null) { // filenamesToMsFontNames.put( font.getItalic().getFilename().toLowerCase(), // font.getName()+SEPARATOR+Mapper.ITALIC); //// log.debug( "put italic: " + font.getName()+SEPARATOR+Substituter.ITALIC ); // } // if (font.getBolditalic() !=null) { // filenamesToMsFontNames.put( font.getBolditalic().getFilename().toLowerCase(), // font.getName()+SEPARATOR+Mapper.BOLD_ITALIC); //// log.debug( "put bold italic: " + font.getName()+SEPARATOR+Substituter.BOLD_ITALIC ); // } } }
@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()); }