/** * Returns the name of the archived file * * @param time the archive date */ protected Path getArchivePath(long time) { Path path = getPath(); String archiveFormat = getArchiveFormat(); String name = getFormatName(archiveFormat + _archiveSuffix, time); Path newPath = path.getParent().lookup(name); if (newPath.exists()) { if (archiveFormat.indexOf("%H") < 0) archiveFormat = archiveFormat + ".%H%M"; else if (archiveFormat.indexOf("%M") < 0) archiveFormat = archiveFormat + ".%M"; for (int i = 0; i < 100; i++) { String suffix; if (i == 0) suffix = _archiveSuffix; else suffix = "." + i + _archiveSuffix; name = getFormatName(archiveFormat + suffix, time); newPath = path.getParent().lookup(name); if (!newPath.exists()) break; } } return newPath; }
public URLConnection getResource(URL url) throws IOException { if (!"jndi".equals(url.getProtocol())) return null; // handle jndi:/server (single slash) parsing (gf) String file = url.getFile(); if ("".equals(url.getHost()) && file.startsWith("/server")) { file = file.substring(7, file.length()); if (file.startsWith(getContextPath())) file = file.substring(getContextPath().length()); else { // server/102p int p = file.indexOf('/', 1); if (p > 0) { String contextPath = file.substring(0, p); WebApp webApp = (WebApp) getContext(contextPath); if (webApp != null) return webApp.getResource(url); } } } String realPath = getRealPath(file); Path rootDirectory = getRootDirectory(); Path path = rootDirectory.lookup(realPath); if (path.exists()) return new URL(path.getURL()).openConnection(); int fileIdx; URLConnection connection = null; if (file.length() > 1 && (fileIdx = file.indexOf("/", 1)) > -1) { String context = file.substring(0, file.indexOf("/", 1)); if (context.equals(getContextPath())) { // disable cross-context lookup file = file.substring(fileIdx, file.length()); realPath = getRealPath(file); path = rootDirectory.lookup(realPath); if (path.exists()) connection = new URL(path.getURL()).openConnection(); } } if (connection != null) return connection; return new FileNotFoundURLConnection(url); }
/** * Returns a resource for the given uri. * * <p>XXX: jdk 1.1.x doesn't appear to allow creation of private URL streams. */ @Override public URL getResource(String name) throws java.net.MalformedURLException { if (!name.startsWith("/")) throw new java.net.MalformedURLException(name); String realPath = getRealPath(name); Path rootDirectory = getRootDirectory(); Path path = rootDirectory.lookupNative(realPath); URL url = new URL("jndi:/server" + getContextPath() + name); if (path.exists() && name.startsWith("/resources/")) { return url; } else if (path.isFile()) { return url; } else if (getClassLoader().getResource("META-INF/resources/" + realPath) != null) { return url; } else if (path.exists()) { return new URL(path.getURL()); } return null; }
/** Opens a relative path. */ ReadStream openPath(String href, String base) throws TransformerException, IOException { if (_uriResolver != null) { Source source = _uriResolver.resolve(href, base); if (source != null) return openPath(source); } if (href.startsWith("/") || base.equals("/")) return getSearchPath().lookup(href).openRead(); else { Path path = getSearchPath().lookup(base).getParent().lookup(href); if (path.exists()) return path.openRead(); else return getSearchPath().lookup(href).openRead(); } }
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; } }
public String commitPath(CommitBuilder commit, Path path, long timeout) { commit.validate(); GitCommitJar gitCommit = null; if (!path.exists()) { throw new ConfigException(L.l("'{0}' is not an existing path for deploy commit.", path)); } try { gitCommit = GitCommitJar.createDirectory(path); String tag = commit.getId(); return deployJar(tag, gitCommit, commit.getAttributes(), timeout); } catch (IOException e) { throw new RepositoryException(e); } finally { if (gitCommit != null) gitCommit.close(); } }
/** Returns true if the source has modified for this page. */ public boolean _caucho_isModified() { return !_cacheEntry.exists() || super._caucho_isModified(); }
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(); }