/** Sets the resource directory. */ public void setPath(Path path) { if (path.getPath().endsWith(".jar") || path.getPath().endsWith(".zip")) { path = JarPath.create(path); } _path = path; }
public void init() throws ConfigException { if (_id == null) throw new ConfigException(L.l("`{0}' is required", "id")); if (_location == null) throw new ConfigException(L.l("`{0}' is required", "location")); if (_name == null) _name = _location.toString(); if (_indexString == null) _indexString = "index-all.html"; _locationPath = Vfs.lookup(_location); int split = _indexString.indexOf('#'); if (split > -1) { CharBuffer before = new CharBuffer(_indexString.substring(0, split)); CharBuffer after = new CharBuffer(_indexString.substring(split + 1)); CharBuffer index = CharBuffer.allocate(); boolean isIndex = false; for (int i = 1; i <= 27; i++) { index.append(before); index.append(i); index.append(after); Path indexPath = _locationPath.lookup(index.toString()); if (indexPath.exists()) { isIndex = true; _index.add(indexPath); } index.clear(); } if (!isIndex) { throw new ConfigException(L.l("`{0}' not found", _locationPath.lookup(_indexString))); } } else _index.add(_locationPath.lookup(_indexString)); if (_locationPath.getScheme().equals("file")) { _isLocal = true; Path pwd = Vfs.getPwd(); if (!_locationPath.getPath().startsWith(pwd.getPath())) _isLocalAbsolute = true; } }
/** Tries to open the log. Called from inside _logLock */ private void openLog() { closeLogStream(); WriteStream os = _os; _os = null; IoUtil.close(os); Path path = getPath(); if (path == null) { path = getPath(CurrentTime.getCurrentTime()); } Path parent = path.getParent(); try { if (!parent.isDirectory()) { if (!parent.mkdirs()) { /* XXX: logWarning(L.l("Can't create log directory {0}.\n", parent)); */ } } } catch (Exception e) { logWarning(L.l("Can't create log directory {0}.\n Exception={1}", parent, e), e); } Exception exn = null; for (int i = 0; i < 3 && _os == null; i++) { try { _os = path.openAppend(); } catch (IOException e) { exn = e; } } String pathName = path.getPath(); try { if (pathName.endsWith(".gz")) { _zipOut = _os; _os = Vfs.openWrite(new GZIPOutputStream(_zipOut)); } else if (pathName.endsWith(".zip")) { throw new ConfigException("Can't support .zip in path-format"); } } catch (Exception e) { if (exn == null) exn = e; } if (exn != null) logWarning( L.l( "Can't create log for {0}.\n User={1} Exception={2}", path, System.getProperty("user.name"), exn), exn); }