/** @return returns a string list of all pathes */ public static Resource[] getClassPathes() { if (classPathes != null) return classPathes; ArrayList pathes = new ArrayList(); String pathSeperator = System.getProperty("path.separator"); if (pathSeperator == null) pathSeperator = ";"; // java.ext.dirs ResourceProvider frp = ResourcesImpl.getFileResourceProvider(); // pathes from system properties String strPathes = System.getProperty("java.class.path"); if (strPathes != null) { Array arr = ListUtil.listToArrayRemoveEmpty(strPathes, pathSeperator); int len = arr.size(); for (int i = 1; i <= len; i++) { Resource file = frp.getResource(Caster.toString(arr.get(i, ""), "").trim()); if (file.exists()) pathes.add(ResourceUtil.getCanonicalResourceEL(file)); } } // pathes from url class Loader (dynamic loaded classes) ClassLoader cl = new Info().getClass().getClassLoader(); if (cl instanceof URLClassLoader) getClassPathesFromClassLoader((URLClassLoader) cl, pathes); return classPathes = (Resource[]) pathes.toArray(new Resource[pathes.size()]); }
/** @throws PageException */ private void doUpdate() throws PageException { String message = "missing attribute for tag schedule with action update"; String detail = "required attributes are [startDate, startTime, URL, interval, operation]"; Resource file = null; // if(publish) { if (!StringUtil.isEmpty(strFile) && !StringUtil.isEmpty(strPath)) { file = ResourceUtil.toResourceNotExisting(pageContext, strPath); file = file.getRealResource(strFile); } else if (!StringUtil.isEmpty(strFile)) { file = ResourceUtil.toResourceNotExisting(pageContext, strFile); } else if (!StringUtil.isEmpty(strPath)) { file = ResourceUtil.toResourceNotExisting(pageContext, strPath); } if (file != null) pageContext .getConfig() .getSecurityManager() .checkFileLocation(pageContext.getConfig(), file, serverPassword); // missing attributes if (startdate == null || starttime == null || url == null || interval == null) throw new ApplicationException(message, detail); // timeout if (requesttimeout < 0) requesttimeout = pageContext.getRequestTimeout(); // username/password Credentials cr = null; if (username != null) cr = CredentialsImpl.toCredentials(username, password); try { ScheduleTask st = new ScheduleTaskImpl( task, file, startdate, starttime, enddate, endtime, url, port, interval, requesttimeout, cr, ProxyDataImpl.getInstance(proxyserver, proxyport, proxyuser, proxypassword), resolveurl, publish, hidden, readonly, paused, autoDelete); scheduler.addScheduleTask(st, true); } catch (Exception e) { throw Caster.toPageException(e); } // }
@Override public Resource getResource(String path) { path = ResourceUtil.removeScheme(scheme, path); path = ResourceUtil.prettifyPath(path); if (!StringUtil.startsWith(path, '/')) path = "/" + path; return callResourceRTE(null, null, "getResource", new Object[] {path}, false); }
private void checkSize(ConfigWeb config, Resource dir, long maxSize, ResourceFilter filter) { if (!dir.exists()) return; Resource res = null; int count = ArrayUtil.size(filter == null ? dir.list() : dir.list(filter)); long size = ResourceUtil.getRealSize(dir, filter); PrintWriter out = config.getOutWriter(); SystemOut.printDate(out, "check size of directory [" + dir + "]"); SystemOut.printDate(out, "- current size [" + size + "]"); SystemOut.printDate(out, "- max size [" + maxSize + "]"); int len = -1; while (count > 100000 || size > maxSize) { Resource[] files = filter == null ? dir.listResources() : dir.listResources(filter); if (len == files.length) break; // protect from inifinti loop len = files.length; for (int i = 0; i < files.length; i++) { if (res == null || res.lastModified() > files[i].lastModified()) { res = files[i]; } } if (res != null) { size -= res.length(); try { res.remove(true); count--; } catch (IOException e) { SystemOut.printDate(out, "cannot remove resource " + res.getAbsolutePath()); break; } } res = null; } }
private void checkOldClientFile(ConfigWeb config) { ExtensionResourceFilter filter = new ExtensionResourceFilter(".script", false); // move old structured file in new structure try { Resource dir = config.getClientScopeDir(), trgres; Resource[] children = dir.listResources(filter); String src, trg; int index; for (int i = 0; i < children.length; i++) { src = children[i].getName(); index = src.indexOf('-'); trg = StorageScopeFile.getFolderName( src.substring(0, index), src.substring(index + 1), false); trgres = dir.getRealResource(trg); if (!trgres.exists()) { trgres.createFile(true); ResourceUtil.copy(children[i], trgres); } // children[i].moveTo(trgres); children[i].delete(); } } catch (Throwable t) { } }
/** * gets a file from server and copy it local * * @return FTPCLient * @throws PageException * @throws IOException */ private AFTPClient actionGetFile() throws PageException, IOException { required("remotefile", remotefile); required("localfile", localfile); AFTPClient client = getClient(); Resource local = ResourceUtil.toResourceExistingParent(pageContext, localfile); // new File(localfile); pageContext.getConfig().getSecurityManager().checkFileLocation(local); if (failifexists && local.exists()) throw new ApplicationException( "File [" + local + "] already exist, if you want to overwrite, set attribute failIfExists to false"); OutputStream fos = null; client.setFileType(getType(local)); boolean success = false; try { fos = IOUtil.toBufferedOutputStream(local.getOutputStream()); success = client.retrieveFile(remotefile, fos); } finally { IOUtil.closeEL(fos); if (!success) local.delete(); } writeCfftp(client); return client; }
private static Resource getDeployDirectory(Config config) { Resource dir = ConfigWebUtil.getConfigServerDirectory(config); if (dir == null || !dir.isWriteable() || !dir.isReadable()) dir = ResourceUtil.toResource( CFMLEngineFactory.getClassLoaderRoot(SystemUtil.getLoaderClassLoader())); return dir; }
private static String addPlaceHolder(Resource dir, Resource file, String placeholder) { if (ResourceUtil.isChildOf(file, dir)) { try { return StringUtil.replace( file.getCanonicalPath(), dir.getCanonicalPath(), placeholder, true); } catch (IOException e) { } } return null; }
/** * returns the a unique temp file (with no auto delete) * * @param extension * @return temp directory * @throws IOException */ public static Resource getTempFile(String extension, boolean touch) throws IOException { String filename = CreateUniqueId.invoke(); if (!StringUtil.isEmpty(extension, true)) { if (extension.startsWith(".")) filename += extension; else filename += "." + extension; } Resource file = getTempDirectory().getRealResource(filename); if (touch) ResourceUtil.touch(file); return file; }
/** * get FTP. ... _FILE_TYPE * * @param file * @return type */ private int getType(Resource file) { if (transferMode == FTPConstant.TRANSFER_MODE_BINARY) return AFTPClient.FILE_TYPE_BINARY; else if (transferMode == FTPConstant.TRANSFER_MODE_ASCCI) return AFTPClient.FILE_TYPE_TEXT; else { String ext = ResourceUtil.getExtension(file, null); if (ext == null || ListUtil.listContainsNoCase(ASCIIExtensionList, ext, ";", true, false) == -1) return AFTPClient.FILE_TYPE_BINARY; return AFTPClient.FILE_TYPE_TEXT; } }
/** @return return System directory */ public static Resource getSystemDirectory() { String pathes = System.getProperty("java.library.path"); ResourceProvider fr = ResourcesImpl.getFileResourceProvider(); if (pathes != null) { String[] arr = ListUtil.toStringArrayEL(ListUtil.listToArray(pathes, File.pathSeparatorChar)); for (int i = 0; i < arr.length; i++) { if (arr[i].toLowerCase().indexOf("windows\\system") != -1) { Resource file = fr.getResource(arr[i]); if (file.exists() && file.isDirectory() && file.isWriteable()) return ResourceUtil.getCanonicalResourceEL(file); } } for (int i = 0; i < arr.length; i++) { if (arr[i].toLowerCase().indexOf("windows") != -1) { Resource file = fr.getResource(arr[i]); if (file.exists() && file.isDirectory() && file.isWriteable()) return ResourceUtil.getCanonicalResourceEL(file); } } for (int i = 0; i < arr.length; i++) { if (arr[i].toLowerCase().indexOf("winnt") != -1) { Resource file = fr.getResource(arr[i]); if (file.exists() && file.isDirectory() && file.isWriteable()) return ResourceUtil.getCanonicalResourceEL(file); } } for (int i = 0; i < arr.length; i++) { if (arr[i].toLowerCase().indexOf("win") != -1) { Resource file = fr.getResource(arr[i]); if (file.exists() && file.isDirectory() && file.isWriteable()) return ResourceUtil.getCanonicalResourceEL(file); } } for (int i = 0; i < arr.length; i++) { Resource file = fr.getResource(arr[i]); if (file.exists() && file.isDirectory() && file.isWriteable()) return ResourceUtil.getCanonicalResourceEL(file); } } return null; }
private static Resource getBinDirectory(Config config) { Resource dir = ConfigWebUtil.getConfigServerDirectory(config); if (dir == null || !dir.isWriteable() || !dir.isReadable()) dir = ResourceUtil.toResource( CFMLEngineFactory.getClassLoaderRoot(SystemUtil.getLoaderClassLoader())); else { dir = dir.getRealResource("bin"); if (!dir.exists()) dir.mkdir(); } return dir; }
/** * returns the Hoome Directory of the System * * @return home directory */ public static Resource getHomeDirectory() { if (homeFile != null) return homeFile; ResourceProvider frp = ResourcesImpl.getFileResourceProvider(); String homeStr = System.getProperty("user.home"); if (homeStr != null) { homeFile = frp.getResource(homeStr); homeFile = ResourceUtil.getCanonicalResourceEL(homeFile); } return homeFile; }
/** * get class pathes from all url ClassLoaders * * @param ucl URL Class Loader * @param pathes Hashmap with allpathes */ private static void getClassPathesFromClassLoader(URLClassLoader ucl, ArrayList pathes) { ClassLoader pcl = ucl.getParent(); // parent first if (pcl instanceof URLClassLoader) getClassPathesFromClassLoader((URLClassLoader) pcl, pathes); ResourceProvider frp = ResourcesImpl.getFileResourceProvider(); // get all pathes URL[] urls = ucl.getURLs(); for (int i = 0; i < urls.length; i++) { Resource file = frp.getResource(urls[i].getPath()); if (file.exists()) pathes.add(ResourceUtil.getCanonicalResourceEL(file)); } }
/** * returns the Temp Directory of the System * * @return temp directory */ public static Resource getTempDirectory() { if (tempFile != null) return tempFile; ResourceProvider fr = ResourcesImpl.getFileResourceProvider(); String tmpStr = System.getProperty("java.io.tmpdir"); if (tmpStr != null) { tempFile = fr.getResource(tmpStr); if (tempFile.exists()) { tempFile = ResourceUtil.getCanonicalResourceEL(tempFile); return tempFile; } } File tmp = null; try { tmp = File.createTempFile("a", "a"); tempFile = fr.getResource(tmp.getParent()); tempFile = ResourceUtil.getCanonicalResourceEL(tempFile); } catch (IOException ioe) { } finally { if (tmp != null) tmp.delete(); } return tempFile; }
public static TemplateLine getCurrentContext() { StackTraceElement[] traces = Thread.currentThread().getStackTrace(); int line = 0; String template; StackTraceElement trace = null; for (int i = 0; i < traces.length; i++) { trace = traces[i]; template = trace.getFileName(); if (trace.getLineNumber() <= 0 || template == null || ResourceUtil.getExtension(template, "").equals("java")) continue; line = trace.getLineNumber(); return new TemplateLine(template, line); } return null; }
/** * copy a local file to server * * @return FTPClient * @throws IOException * @throws PageException */ private AFTPClient actionPutFile() throws IOException, PageException { required("remotefile", remotefile); required("localfile", localfile); AFTPClient client = getClient(); Resource local = ResourceUtil.toResourceExisting(pageContext, localfile); // new File(localfile); // if(failifexists && local.exists()) throw new ApplicationException("File ["+local+"] already // exist, if you want to overwrite, set attribute failIfExists to false"); InputStream is = null; try { is = IOUtil.toBufferedInputStream(local.getInputStream()); client.setFileType(getType(local)); client.storeFile(remotefile, is); } finally { IOUtil.closeEL(is); } writeCfftp(client); return client; }
public static Resource getClassLoadeDirectory() { return ResourceUtil.toResource(CFMLEngineFactory.getClassLoaderRoot(TP.class.getClassLoader())); }