private void movePathToArchive(Path savedPath) { if (savedPath == null) return; synchronized (_logLock) { closeLogStream(); } Path path = getPath(); String savedName = savedPath.getTail(); try { if (!savedPath.getParent().isDirectory()) savedPath.getParent().mkdirs(); } catch (Exception e) { logWarning(L.l("Can't open archive directory {0}", savedPath.getParent()), e); } try { if (path.exists()) { WriteStream os = null; OutputStream out = null; // *.gz and *.zip are copied. Others are just renamed if (savedName.endsWith(".gz")) { os = savedPath.openWrite(); out = new GZIPOutputStream(os); } else if (savedName.endsWith(".zip")) { os = savedPath.openWrite(); ZipOutputStream zip = new ZipOutputStream(os); String entryName = savedName.substring(0, savedName.length() - 4); ZipEntry entry = new ZipEntry(entryName); zip.putNextEntry(entry); out = zip; } if (out != null) { try { path.writeToStream(out); } finally { try { out.close(); } catch (Exception e) { // can't log in log rotation routines } try { if (out != os) os.close(); } catch (Exception e) { // can't log in log rotation routines } } } else { path.renameTo(savedPath); } } } catch (Exception e) { logWarning(L.l("Error rotating logs: {0}", e.toString()), e); } try { path.remove(); /* try { if (! path.truncate()) path.remove(); } catch (IOException e) { path.remove(); throw e; } */ } catch (Exception e) { logWarning(L.l("Error truncating logs"), e); } if (_rolloverCount > 0) removeOldLogs(); }
/** * 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; }