List of usage examples for org.apache.commons.vfs2 FileObject getName
FileName getName();
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignManager.java
private FileObject findMatchingChild(FileObject folder, String baseName, Set<String> suffixes, boolean exactMatch) throws FileSystemException { FileObject matchingChild = null; // First try fast straight fetch using lowercase file for (String suffix : suffixes) { FileObject straightChild = folder.resolveFile(baseName.toLowerCase() + suffix.toLowerCase()); if (straightChild.exists()) { return straightChild; }/*from www . jav a 2 s. co m*/ } // Secondly we iterate over all children and to a case-insensitive // equals FileObject[] children = folder.getChildren(); for (String suffix : suffixes) { for (FileObject child : children) { if (exactMatch) { if (child.getName().getBaseName().equalsIgnoreCase(baseName + suffix)) { matchingChild = child; break; } } else { String fileName = child.getName().getBaseName().toLowerCase(); String elementName = baseName.toLowerCase() + suffix.toLowerCase(); if (fileName.startsWith(elementName) && fileName.indexOf(".", elementName.length()) == -1) { matchingChild = child; break; } } } } return matchingChild; }
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignManager.java
protected String getRelativePath(FileObject file) throws FileSystemException, WGDesignSyncException { return getBaseFolder().getName().getRelativeName(file.getName()); }
From source file:com.sonicle.webtop.vfs.Service.java
public void processDownloadFiles(HttpServletRequest request, HttpServletResponse response) { try {/* www.j a v a2 s. co m*/ StringArray fileIds = ServletUtils.getObjectParameter(request, "fileIds", StringArray.class, true); if (fileIds.size() > 1) throw new WTException("Unable to download multiple files for now"); String fileId = fileIds.get(0); //TODO: Implementare download file multipli StoreNodeId nodeId = (StoreNodeId) new StoreNodeId().parse(fileId); int storeId = Integer.valueOf(nodeId.getStoreId()); FileObject fo = null; try { fo = manager.getStoreFile(storeId, nodeId.getPath()); if (!fo.isFile()) { logger.warn("Cannot download a non-file [{}, {}]", storeId, nodeId.getPath()); throw new WTException("Requested file is not a real file"); } String filename = fo.getName().getBaseName(); String mediaType = ServletHelper.guessMediaType(filename, true); IOUtils.copy(fo.getContent().getInputStream(), response.getOutputStream()); ServletUtils.setFileStreamHeaders(response, mediaType, DispositionType.ATTACHMENT, filename); ServletUtils.setContentLengthHeader(response, fo.getContent().getSize()); } finally { IOUtils.closeQuietly(fo); } } catch (Exception ex) { logger.error("Error in action DownloadFiles", ex); ServletUtils.writeErrorHandlingJs(response, ex.getMessage()); } }
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignManager.java
protected void doInitialDeployment(String designKey) throws WGAPIException, IOException, InstantiationException, IllegalAccessException, WGDesignSyncException { // Creat folders getOrCreateFolders();/*from w ww .java2 s .c o m*/ // Deploy TMLs Iterator modules = getDB().getTMLModules().iterator(); WGTMLModule mod; while (modules.hasNext()) { mod = (WGTMLModule) modules.next(); if (isValidDesignName(mod.getName())) { initialDeployTMLModule(mod); } else { _log.warn("Could not use '" + mod.getDocumentKey() + "' for design deployment since the name contains invalid characters"); } } // Deploy file containers Iterator containers = getDB().getFileContainers().iterator(); WGFileContainer con; while (containers.hasNext()) { con = (WGFileContainer) containers.next(); if (isValidDesignName(con.getName())) { initialDeployFileContainer(con); } else { _log.warn("Could not use '" + con.getDocumentKey() + "' for design deployment since the name contains invalid characters"); } } // Deploy script modules Iterator scripts = getDB().getCSSJSModules().iterator(); WGCSSJSModule script; while (scripts.hasNext()) { script = (WGCSSJSModule) scripts.next(); if (isValidDesignName(script.getName())) { initialDeployScriptModule(script); } else { _log.warn("Could not use '" + script.getDocumentKey() + "' for design deployment since the name contains invalid characters"); } } // Create sync info and store it to directory _syncInfo = new DesignDefinition(); _syncInfo.setDesignKey(designKey); if (_core.getWgaConfiguration().getDesignConfiguration().getDefaultEncoding() != null) { _syncInfo.setFileEncoding(_core.getWgaConfiguration().getDesignConfiguration().getDefaultEncoding()); } else { // if encoding not specified set to platform encoding _syncInfo.setFileEncoding(System.getProperty("file.encoding")); } FileObject syncInfoFile = getSyncInfoFile(); _log.info("Creating design definition file " + syncInfoFile.getName().getPath()); syncInfoFile.createFile(); storeSyncInfo(syncInfoFile); _log.info("Initial deploy finished"); }
From source file:com.app.server.WarDeployer.java
public void extractWar(FileObject fileObject, WebClassLoader customClassLoader, StandardFileSystemManager fsManager) { int numBytes; try {//from w w w . j a v a 2 s. com String directoryName = fileObject.getName().getBaseName(); fileObject = fsManager.resolveFile("jar:" + fileObject.toString() + "!/"); StringBuffer classPath = new StringBuffer(); ConcurrentHashMap<String, String> jspMap = new ConcurrentHashMap<String, String>(); ArrayList<String> libs = new ArrayList<String>(); // String fileName=file.getName(); directoryName = directoryName.substring(0, directoryName.indexOf('.')); /*try { ((VFSClassLoader)customClassLoader.getParent()). // log.info("file://"+warDirectoryPath+"/WEB-INF/classes/"); customClassLoader.addURL(new URL("file:" + scanDirectory + "/" + directoryName + "/WEB-INF/classes/") ); // new WebServer().addURL(new // URL("file://"+warDirectoryPath+"/"),customClassLoader); } catch (Exception e) { log.error("syntax of the URL is incorrect", e); //e1.printStackTrace(); }*/ Vector<URL> libVec = unpack(fileObject, new File(scanDirectory + "/" + directoryName), fsManager, jspMap); //FileObject[] libraries=((VFSClassLoader)customClassLoader.getParent()).getFileObjects(); libVec.add(new URL("file:" + scanDirectory + "/" + directoryName + "/WEB-INF/classes/")); //URL[] liburl=new URL[libraries.length]; for (URL lib : libVec) { customClassLoader.addURL(lib); } //WebClassLoader web=new WebClassLoader(libVec.toArray(new URL[libVec.size()]),getClass().getClassLoader()); System.out.println(jspMap); System.out.println(libs); /*customClassLoader.addURL(new URL("file:" + scanDirectory + "/" + directoryName + "/WEB-INF/classes/") );*/ /*String fileDirectory; Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ze = entries.nextElement(); // //log.info("Unzipping " + ze.getName()); String filePath = scanDirectory + "/" + directoryName + "/" + ze.getName(); if (!ze.isDirectory()) { fileDirectory = filePath.substring(0, filePath.lastIndexOf('/')); } else { fileDirectory = filePath; } // //log.info(fileDirectory); createDirectory(fileDirectory); if (!ze.isDirectory()) { FileOutputStream fout = new FileOutputStream(filePath); byte[] inputbyt = new byte[8192]; InputStream istream = zip.getInputStream(ze); while ((numBytes = istream.read(inputbyt, 0, inputbyt.length)) >= 0) { fout.write(inputbyt, 0, numBytes); } fout.close(); istream.close(); if (ze.getName().endsWith(".jsp")) { jspMap.put(ze.getName(), filePath); } else if (ze.getName().endsWith(".jar")) { customClassLoader.addURL(new URL("file:///" + scanDirectory + "/" + directoryName + "/" + ze.getName())); classPath.append(filePath); classPath.append(";"); } } } zip.close();*/ Set jsps = jspMap.keySet(); Iterator jspIterator = jsps.iterator(); /*classPath.append(scanDirectory + "/" + directoryName + "/WEB-INF/classes/;");*/ ArrayList<String> jspFiles = new ArrayList(); // log.info(classPath.toString()); if (jspIterator.hasNext()) { /*customClassLoader=new WebClassLoader(new URL[]{new URL("file:" + scanDirectory + "/temp/" + directoryName + "/")},customClassLoader);*/ customClassLoader.addURL(new URL("file:" + scanDirectory + "/temp/" + directoryName + "/")); urlClassLoaderMap.put(serverConfig.getDeploydirectory() + "/" + directoryName, customClassLoader); } else { urlClassLoaderMap.put(serverConfig.getDeploydirectory() + "/" + directoryName, customClassLoader); } while (jspIterator.hasNext()) { String filepackageInternal = (String) jspIterator.next(); String filepackageInternalTmp = filepackageInternal; if (filepackageInternal.lastIndexOf('/') == -1) { filepackageInternal = ""; } else { filepackageInternal = filepackageInternal.substring(0, filepackageInternal.lastIndexOf('/')) .replace("/", "."); filepackageInternal = "." + filepackageInternal; } createDirectory(scanDirectory + "/temp/" + directoryName); File jspFile = new File((String) jspMap.get(filepackageInternalTmp)); String fName = jspFile.getName(); String fileNameWithoutExtension = fName.substring(0, fName.lastIndexOf(".jsp")) + "_jsp"; // String fileCreated=new JspCompiler().compileJsp((String) // jspMap.get(filepackageInternalTmp), // scanDirectory+"/temp/"+fileName, // "com.app.server"+filepackageInternal,classPath.toString()); synchronized (customClassLoader) { String fileNameInWar = filepackageInternalTmp; jspFiles.add(fileNameInWar.replace("/", "\\")); if (fileNameInWar.contains("/") || fileNameInWar.contains("\\")) { customClassLoader.addURL("/" + fileNameInWar.replace("\\", "/"), "com.app.server" + filepackageInternal.replace("WEB-INF", "WEB_002dINF") + "." + fileNameWithoutExtension); } else { customClassLoader.addURL("/" + fileNameInWar, "com.app.server" + filepackageInternal.replace("WEB-INF", "WEB_002dINF") + "." + fileNameWithoutExtension); } } } if (jspFiles.size() > 0) { ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); //Thread.currentThread().setContextClassLoader(customClassLoader); JspCompiler jspc = null; try { jspc = new JspCompiler(); jspc.setUriroot(scanDirectory + "/" + directoryName); jspc.setAddWebXmlMappings(false); jspc.setCompile(true); //jspc.setClassPath("d:/deploy/StrutsProj/WEB-INF/classes/"); jspc.setOutputDir(scanDirectory + "/temp/" + directoryName + "/"); jspc.setPackage("com.app.server"); StringBuffer buffer = new StringBuffer(); for (String jspFile : jspFiles) { buffer.append(","); buffer.append(jspFile); } String jsp = buffer.toString(); jsp = jsp.substring(1, jsp.length()); //log.info(jsp); jspc.setJspFiles(jsp); //jspc.init(); jspc.initCL(customClassLoader); jspc.execute(); //jspc.closeClassLoader(); } catch (Throwable je) { log.error("Error in compiling the jsp page", je); //je.printStackTrace(); } finally { //jspc.closeClassLoader(); //Thread.currentThread().setContextClassLoader(oldCL); } //Thread.currentThread().setContextClassLoader(customClassLoader); } //System.out.println(customClassLoader.loadClass("org.apache.struts.action.ActionForm")); try { File execxml = new File(scanDirectory + "/" + directoryName + "/WEB-INF/" + "executorservices.xml"); if (execxml.exists()) { new ExecutorServicesConstruct().getExecutorServices(serverdigester, executorServiceMap, execxml, customClassLoader); } } catch (Exception e) { log.error("error in getting executor services ", e); // e.printStackTrace(); } try { File messagingxml = new File( scanDirectory + "/" + directoryName + "/WEB-INF/" + "messagingclass.xml"); if (messagingxml.exists()) { new MessagingClassConstruct().getMessagingClass(messagedigester, messagingxml, customClassLoader, messagingClassMap); } } catch (Exception e) { log.error("Error in getting the messaging classes ", e); // e.printStackTrace(); } webxmldigester.setNamespaceAware(true); webxmldigester.setValidating(true); // digester.setRules(null); FileInputStream webxml = new FileInputStream( scanDirectory + "/" + directoryName + "/WEB-INF/" + "web.xml"); InputSource is = new InputSource(webxml); try { //log.info("SCHEMA"); synchronized (webxmldigester) { // webxmldigester.set("config/web-app_2_4.xsd"); WebAppConfig webappConfig = (WebAppConfig) webxmldigester.parse(is); servletMapping.put(scanDirectory + "/" + directoryName.replace("\\", "/"), webappConfig); } webxml.close(); } catch (Exception e) { log.error("Error in pasrsing the web.xml", e); //e.printStackTrace(); } // ClassLoaderUtil.closeClassLoader(customClassLoader); } catch (Exception ex) { log.error("Error in Deploying war " + fileObject.getName().getURI(), ex); } }
From source file:com.googlecode.vfsjfilechooser2.plaf.basic.BasicVFSFileChooserUI.java
public void changeDirectory(FileObject dir) { VFSJFileChooser fc = getFileChooser(); fc.setCurrentDirectoryObject(dir);/*from w ww . j a v a 2 s . c o m*/ if ((fc.getFileSelectionMode() == SELECTION_MODE.FILES_AND_DIRECTORIES) && fc.getFileSystemView().isFileSystem(dir)) { setFileName(dir.getName().getBaseName()); } }
From source file:maspack.fileutil.FileCacher.java
public boolean copy(URIx from, URIx to, FileTransferMonitor monitor) throws FileSystemException { FileObject fromFile = null; FileObject toFile = null;//ww w . ja v a 2s . co m // clear authenticators setAuthenticator(fsOpts, null); setIdentityFactory(fsOpts, null); // loop through authenticators until we either succeed or cancel boolean cancel = false; while (toFile == null && cancel == false) { toFile = resolveRemote(to); } cancel = false; while (fromFile == null && cancel == false) { fromFile = resolveRemote(from); } if (fromFile == null || !fromFile.exists()) { throw new FileSystemException("Cannot find source file <" + from.toString() + ">", new FileNotFoundException("<" + from.toString() + ">")); } if (toFile == null) { throw new FileSystemException("Cannot find destination <" + to.toString() + ">", new FileNotFoundException("<" + to.toString() + ">")); } // monitor the file transfer progress if (monitor != null) { monitor.monitor(fromFile, toFile, -1, fromFile.getName().getBaseName()); monitor.start(); monitor.fireStartEvent(toFile); } // transfer content try { if (fromFile.isFile()) { toFile.copyFrom(fromFile, Selectors.SELECT_SELF); } else if (fromFile.isFolder()) { // final FileObject fileSystem = manager.createFileSystem(remoteFile); toFile.copyFrom(fromFile, new AllFileSelector()); // fileSystem.close(); } if (monitor != null) { monitor.fireCompleteEvent(toFile); } } catch (Exception e) { throw new FileTransferException( "Failed to complete transfer of " + fromFile.getURL() + " to " + toFile.getURL(), e); } finally { // close files if we need to fromFile.close(); toFile.close(); if (monitor != null) { monitor.release(toFile); monitor.stop(); } } return true; }
From source file:hadoopInstaller.installation.Installer.java
private void analyzeBundles() throws InstallationFatalError { getLog().trace("HadoopInstaller.InstallationBundles.Start"); //$NON-NLS-1$ FileObject folder; try {/*www. j a va 2 s . c om*/ folder = getLocalDirectory().resolveFile(InstallerConstants.TGZ_BUNDLES_FOLDER); if (!folder.exists()) { folder.createFolder(); getLog().warn("HadoopInstaller.InstallationBundles.FolderDoesntExist", //$NON-NLS-1$ InstallerConstants.TGZ_BUNDLES_FOLDER, InstallerConstants.CONFIGURATION_FILE); } } catch (FileSystemException e) { throw new InstallationFatalError(e, "HadoopInstaller.InstallationBundles.FolderCouldNotOpen", //$NON-NLS-1$ InstallerConstants.TGZ_BUNDLES_FOLDER); } for (String resource : getConfig().getFiles().keySet()) { String fileName = getConfig().getFiles().get(resource); try { getLog().trace("HadoopInstaller.InstallationBundles.From", resource, //$NON-NLS-1$ fileName); FileObject bundle = folder.resolveFile(fileName); if (!bundle.exists()) { throw new InstallationFatalError("HadoopInstaller.InstallationBundles.Missing", //$NON-NLS-1$ fileName, folder.getName().getBaseName()); } if (doDeploy()) { getBundleHashes(bundle); } getBundleInstallDirectory(resource, bundle); try { bundle.close(); } catch (FileSystemException ex) { getLog().warn(ex, "HadoopInstaller.CouldNotClose", //$NON-NLS-1$ fileName); } } catch (FileSystemException e) { throw new InstallationFatalError(e, "HadoopInstaller.InstallationBundles.Error", //$NON-NLS-1$ resource, fileName); } getLog().trace("HadoopInstaller.InstallationBundles.Success", //$NON-NLS-1$ resource, fileName); } try { folder.close(); } catch (FileSystemException e) { getLog().warn(e, "HadoopInstaller.CouldNotClose", //$NON-NLS-1$ InstallerConstants.TGZ_BUNDLES_FOLDER); } }
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignManager.java
private List<ModuleFile> getFileContainerFiles(FileObject filesFolder, String prefix) throws FileSystemException { FileObject[] files = filesFolder.getChildren(); List<ModuleFile> designFiles = new ArrayList<ModuleFile>(); for (int i = 0; i < files.length; i++) { FileObject file = files[i]; if (file.getType().equals(FileType.FOLDER) && isValidDesignFile(file)) { designFiles.add(new ModuleFile(file, prefix, "", WGDocument.TYPE_FILECONTAINER)); String newPrefix = (prefix.trim().equals("") ? file.getName().getBaseName().toLowerCase() : prefix + DIRECTORY_DIVIDER + file.getName().getBaseName().toLowerCase()); designFiles.addAll(getFileContainerFiles(file, newPrefix)); }/*from ww w. jav a 2s. c o m*/ } return designFiles; }
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignProvider.java
public static OverlayStatus determineOverlayStatus(FileSystemDesignProvider sourceDesignProvider, PluginID baseId, FileObject targetDirectory, String targetEncoding, Logger log, DesignFileValidator validator) throws Exception { OverlayStatus status = new OverlayStatus(); // Copy an overlay flag file to the system file container FileObject targetFCFolder = targetDirectory.resolveFile(DesignDirectory.FOLDERNAME_FILES); FileObject systemFC = targetFCFolder.resolveFile("system"); if (!systemFC.exists()) { systemFC.createFolder();//from w ww .j a v a 2 s.co m } // Import overlay data, if available FileObject overlayDataFile = systemFC.resolveFile(OverlayDesignProvider.OVERLAY_DATA_FILE); if (overlayDataFile.exists()) { try { InputStream in = new BufferedInputStream(overlayDataFile.getContent().getInputStream()); status.setOverlayData(OverlayData.read(in)); in.close(); } catch (Exception e) { log.error("Exception reading overlay status. Creating new status file", e); } if (status.getOverlayData() != null && !status.getOverlayData().getBasepluginName().equals(baseId.getUniqueName())) { throw new WGDesignSyncException("The overlay folder '" + targetDirectory.getName().getPath() + "' is used with plugin '" + status.getOverlayData().getBasepluginName() + "' not '" + baseId.getUniqueName() + "'. Overlay status determination was canceled."); } } Version providerVersion = baseId.getVersion(); if (status.getOverlayData() == null) { OverlayData overlayData = new OverlayData(); overlayData.setBasepluginName(baseId.getUniqueName()); status.setOverlayData(overlayData); status.setNewOverlay(true); overlayData.setInitialBasepluginVersion(providerVersion.toString()); } // Test for version compatibility between base design and overlay status.setCurrentBaseVersion(providerVersion); if (status.getOverlayData().getBasepluginVersion() != null) { Version baseVersion = new Version(status.getOverlayData().getBasepluginVersion()); // Base design version is different than the compliance version of the overlay. Look if it higher (=upgrade) or lower (=error) if (!providerVersion.equals(baseVersion) || providerVersion.getBuildVersion() != baseVersion.getBuildVersion()) { if (providerVersion.compareTo(baseVersion) >= 0 || (providerVersion.equals(baseVersion) && providerVersion.getBuildVersion() > baseVersion.getBuildVersion())) { status.setUpdatedBaseDesign(true); } else if (providerVersion.compareTo(baseVersion) < 0) { throw new WGDesignSyncException("The used base design version (" + providerVersion.toString() + ") is lower than the compliant version for the overlay (" + status.getOverlayData().getBasepluginVersion() + ")."); } } } if (status.isUpdatedBaseDesign()) { log.info("Used version of base design is " + providerVersion.toString() + ". Overlay currently complies with base design version " + status.getOverlayData().getBasepluginVersion() + ". The overlay can be upgraded."); } // Gather changed resources in base design, so we can priorize them against the overlay resources FileObject sourceTmlFolder = sourceDesignProvider.getTmlFolder(); FileObject targetTmlFolder = targetDirectory.resolveFile(DesignDirectory.FOLDERNAME_TML); if (sourceTmlFolder.exists() && sourceTmlFolder.getType().equals(FileType.FOLDER)) { for (FileObject mediaKeyFolder : sourceTmlFolder.getChildren()) { FileObject overlayFolder = mediaKeyFolder.resolveFile(OverlayDesignProvider.OVERLAY_FOLDER); if (overlayFolder.exists()) { FileObject targetMediaKeyFolder = targetTmlFolder .resolveFile(mediaKeyFolder.getName().getBaseName()); determineChangedResources(WGDocument.TYPE_TML, targetMediaKeyFolder, overlayFolder, targetMediaKeyFolder, targetDirectory, sourceDesignProvider.getFileEncoding(), targetEncoding, status, log, validator); } } } FileObject targetScriptFolder = targetDirectory.resolveFile(DesignDirectory.FOLDERNAME_SCRIPT); FileObject sourceScriptFolder = sourceDesignProvider.getScriptFolder(); if (sourceScriptFolder.exists() && sourceScriptFolder.getType().equals(FileType.FOLDER)) { for (FileObject scriptTypeFolder : sourceScriptFolder.getChildren()) { FileObject overlayFolder = scriptTypeFolder.resolveFile(OverlayDesignProvider.OVERLAY_FOLDER); if (overlayFolder.exists()) { FileObject targetScriptTypeFolder = targetScriptFolder .resolveFile(scriptTypeFolder.getName().getBaseName()); determineChangedResources(WGDocument.TYPE_CSSJS, targetScriptTypeFolder, overlayFolder, targetScriptTypeFolder, targetDirectory, sourceDesignProvider.getFileEncoding(), targetEncoding, status, log, validator); } } } FileObject overlayFolder = sourceDesignProvider.getFilesFolder() .resolveFile(OverlayDesignProvider.OVERLAY_FOLDER); if (overlayFolder.exists()) { determineChangedFileContainerResources(targetFCFolder, overlayFolder, targetFCFolder, targetDirectory, null, null, status, log, validator); } return status; }