/** * Returns existing compiled Templates if it exists. * * @param systemId source path for the stylesheet. * @return a compiled stylesheet */ StylesheetImpl loadPrecompiledStylesheet(String systemId, String userId, boolean checkModified) { if (!_loadPrecompiledStylesheet) return null; try { // look for compiled template base on SystemID StylesheetImpl stylesheet = loadStylesheet(systemId, getMangledName(userId)); if (stylesheet == null) return null; stylesheet.setURIResolver(_uriResolver); // and check if it's modified or not if (!checkModified || !stylesheet.isModified()) { stylesheet.setURIResolver(_uriResolver); return stylesheet; } } catch (Throwable e) { log.log(Level.FINER, e.toString(), e); } return null; }
/** * Loads the compiled stylesheet .class file * * @param className the mangled classname for the stylesheet */ protected StylesheetImpl loadStylesheet(String systemId, String className) throws Exception { LruCache<String, SoftReference<StylesheetImpl>> cache; ClassLoader parentLoader = Thread.currentThread().getContextClassLoader(); cache = _stylesheetCache.getLevel(parentLoader); if (cache == null) { cache = new LruCache<String, SoftReference<StylesheetImpl>>(256); _stylesheetCache.set(cache, parentLoader); } SoftReference<StylesheetImpl> stylesheetRef; stylesheetRef = cache.get(className); StylesheetImpl stylesheet = null; if (stylesheetRef != null) stylesheet = stylesheetRef.get(); try { if (stylesheet != null && !stylesheet.isModified()) return stylesheet; } catch (Throwable e) { log.log(Level.FINER, e.toString(), e); } Path classPath = getWorkPath().lookup(className.replace('.', '/') + ".class"); if (!classPath.canRead()) throw new ClassNotFoundException("can't find compiled XSL `" + className + "'"); DynamicClassLoader loader; loader = SimpleLoader.create(parentLoader, getWorkPath(), className); Class cl = null; // If the loading fails, remove the class because it may be corrupted try { cl = CauchoSystem.loadClass(className, false, loader); } catch (Error e) { try { classPath.remove(); } catch (IOException e1) { log.log(Level.FINE, e1.toString(), e1); } throw e; } stylesheet = (StylesheetImpl) cl.newInstance(); Path path; path = getSearchPath().lookup("").lookup(systemId); /* try { } catch (TransformerException e) { log.log(Level.FINE, e.toString(), e); path = Vfs.lookup(systemId); } */ // stylesheet.init(path); stylesheet.init(getStylePath()); stylesheet.setURIResolver(_uriResolver); stylesheetRef = new SoftReference<StylesheetImpl>(stylesheet); cache.put(className, stylesheetRef); return stylesheet; }