/** * @param href * @param base * @return * @throws TransformerException */ public Source resolve(String href, String base) throws TransformerException { Resolver resolver = ResolverWrapper.getInstance(); CatalogResolver catResolver = resolver.getCatalogResolver(); if (Log.isDebugEnabled(Log.XML_RESOLVER)) { Log.debug(Log.XML_RESOLVER, "Trying to resolve " + href + ":" + base); } String decodedBase; try { decodedBase = URLDecoder.decode(base, Jeeves.ENCODING); } catch (UnsupportedEncodingException e1) { decodedBase = base; } String decodedHref; try { decodedHref = URLDecoder.decode(href, Jeeves.ENCODING); } catch (UnsupportedEncodingException e1) { decodedHref = href; } Source s = catResolver.resolve(decodedHref, decodedBase); // If resolver has a blank XSL file to replace non existing resolved file ... String blankXSLFile = resolver.getBlankXSLFile(); if (blankXSLFile != null && s.getSystemId().endsWith(".xsl")) { // The resolved resource does not exist, set it to blank file path to not trigger // FileNotFound Exception try { if (Log.isDebugEnabled(Log.XML_RESOLVER)) { Log.debug(Log.XML_RESOLVER, " Check if exist " + s.getSystemId()); } File f; if (SystemUtils.IS_OS_WINDOWS) { String path = s.getSystemId(); // fxp path = path.replaceAll("file:\\/", ""); // heikki path = path.replaceAll("file:", ""); f = new File(path); } else { f = new File(new URI(s.getSystemId())); } if (!(f.exists())) { if (Log.isDebugEnabled(Log.XML_RESOLVER)) { Log.debug( Log.XML_RESOLVER, " Resolved resource " + s.getSystemId() + " does not exist. blankXSLFile returned instead."); } s.setSystemId(blankXSLFile); } } catch (URISyntaxException e) { e.printStackTrace(); } } if (Log.isDebugEnabled(Log.XML_RESOLVER) && s != null) { Log.debug(Log.XML_RESOLVER, "Resolved as " + s.getSystemId()); } return s; }
/** * Get CatalogResolver. * * @return CatalogResolver */ public static synchronized CatalogResolver getCatalogResolver() { if (catalogResolver == null) { final CatalogManager manager = new CatalogManager(); manager.setIgnoreMissingProperties(true); manager.setUseStaticCatalog(false); // We'll use a private catalog. manager.setPreferPublic(true); // manager.setVerbosity(10); catalogResolver = new CatalogResolver(manager); final File catalogFilePath = new File(ditaDir, FILE_NAME_CATALOG); final Catalog catalog = catalogResolver.getCatalog(); try { catalog.parseCatalog(catalogFilePath.toURI().toURL()); } catch (final Exception e) { logger.logException(e); } } return catalogResolver; }