List of usage examples for org.apache.commons.vfs FileObject exists
public boolean exists() throws FileSystemException;
From source file:org.gatherdata.archiver.dao.vfs.internal.VfsArchiverDao.java
public GatherArchive save(GatherArchive envelopeToSave) { try {/*from ww w.j av a2 s .com*/ FileObject envelopeFile = fsManager.resolveFile(fsBase, envelopeToSave.getUid().toASCIIString()); if (envelopeFile.exists()) { envelopeFile.delete(); } envelopeFile.createFile(); SerializationUtils.serialize(envelopeToSave, envelopeFile.getContent().getOutputStream()); } catch (FileSystemException e) { e.printStackTrace(); } return envelopeToSave; }
From source file:org.inquidia.kettle.plugins.tokenreplacement.TokenReplacement.java
private void createParentFolder(String filename) throws Exception { // Check for parent folder FileObject parentfolder = null; try {//from ww w.j a va 2 s.co m // Get parent folder parentfolder = KettleVFS.getFileObject(filename).getParent(); if (parentfolder.exists()) { if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "TokenReplacement.Log.ParentFolderExist", parentfolder.getName())); } } else { if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "TokenReplacement.Log.ParentFolderNotExist", parentfolder.getName())); } if (meta.isCreateParentFolder()) { parentfolder.createFolder(); if (isDetailed()) { logDetailed(BaseMessages.getString(PKG, "TokenReplacement.Log.ParentFolderCreated", parentfolder.getName())); } } else { throw new KettleException(BaseMessages.getString(PKG, "TokenReplacement.Log.ParentFolderNotExistCreateIt", parentfolder.getName(), filename)); } } } finally { if (parentfolder != null) { try { parentfolder.close(); } catch (Exception ex) { // Ignore } } } }
From source file:org.jahia.configuration.configurators.JahiaGlobalConfigurator.java
private void updateConfigurationFiles(String sourceWebAppPath, String webappPath, Properties dbProps, JahiaConfigInterface jahiaConfigInterface) throws Exception { getLogger().info("Configuring file using source " + sourceWebAppPath + " to target " + webappPath); FileSystemManager fsManager = VFS.getManager(); new JackrabbitConfigurator(dbProps, jahiaConfigInterface, getLogger()).updateConfiguration( new VFSConfigFile(fsManager, sourceWebAppPath + "/WEB-INF/etc/repository/jackrabbit/repository.xml"), webappPath + "/WEB-INF/etc/repository/jackrabbit/repository.xml"); new TomcatContextXmlConfigurator(dbProps, jahiaConfigInterface).updateConfiguration( new VFSConfigFile(fsManager, sourceWebAppPath + "/META-INF/context.xml"), webappPath + "/META-INF/context.xml"); String rootUserTemplate = sourceWebAppPath + "/WEB-INF/etc/repository/template-root-user.xml"; FileObject rootUserTemplateFile = fsManager.resolveFile(rootUserTemplate); if (rootUserTemplateFile.exists()) { if (Boolean.valueOf(jahiaConfigInterface.getProcessingServer())) { new RootUserConfigurator(dbProps, jahiaConfigInterface, encryptPassword(jahiaConfigInterface.getJahiaRootPassword())).updateConfiguration( new VFSConfigFile(fsManager, rootUserTemplate), webappPath + "/WEB-INF/etc/repository/root-user.xml"); }// w w w . ja v a 2s . c om } else { new RootUserConfigurator(dbProps, jahiaConfigInterface, encryptPassword(jahiaConfigInterface.getJahiaRootPassword())).updateConfiguration( new VFSConfigFile(fsManager, sourceWebAppPath + "/WEB-INF/etc/repository/root.xml"), webappPath + "/WEB-INF/etc/repository/root.xml"); } String mailServerTemplate = sourceWebAppPath + "/WEB-INF/etc/repository/template-root-mail-server.xml"; if (fsManager.resolveFile(mailServerTemplate).exists() && Boolean.valueOf(jahiaConfigInterface.getProcessingServer())) { new MailServerConfigurator(dbProps, jahiaConfigInterface).updateConfiguration( new VFSConfigFile(fsManager, mailServerTemplate), webappPath + "/WEB-INF/etc/repository/root-mail-server.xml"); } if ("jboss".equalsIgnoreCase(jahiaConfigInterface.getTargetServerType())) { updateForJBoss(dbProps, jahiaConfigInterface, fsManager); } String targetConfigPath = webappPath + "/WEB-INF/etc/config"; String jahiaPropertiesFileName = "jahia.properties"; String jahiaNodePropertiesFileName = "jahia.node.properties"; if (externalizedConfigTempPath != null) { targetConfigPath = externalizedConfigTempPath; if (!StringUtils.isBlank(jahiaConfigInterface.getExternalizedConfigClassifier())) { jahiaPropertiesFileName = "jahia." + jahiaConfigInterface.getExternalizedConfigClassifier() + ".properties"; jahiaNodePropertiesFileName = "jahia.node." + jahiaConfigInterface.getExternalizedConfigClassifier() + ".properties"; } } ConfigFile jahiaPropertiesConfigFile = readJahiaProperties(sourceWebAppPath, fsManager); new JahiaPropertiesConfigurator(dbProps, jahiaConfigInterface) .updateConfiguration(jahiaPropertiesConfigFile, targetConfigPath + "/" + jahiaPropertiesFileName); try { ConfigFile jahiaNodePropertiesConfigFile = readJahiaNodeProperties(sourceWebAppPath, fsManager); if (jahiaNodePropertiesConfigFile != null) { new JahiaNodePropertiesConfigurator(logger, jahiaConfigInterface).updateConfiguration( jahiaNodePropertiesConfigFile, targetConfigPath + "/" + jahiaNodePropertiesFileName); } } catch (FileSystemException fse) { // in the case we cannot access the file, it means we should not do the advanced configuration, which is expected for community edition. } // create empty Spring config file for custom configuration InputStream is = getClass().getResourceAsStream("/applicationcontext-custom.xml"); FileOutputStream os = new FileOutputStream(new File(targetConfigPath, "applicationcontext-custom.xml")); try { IOUtils.copy(is, os); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } String ldapTargetFile = new File(getDataDir(), "modules").getAbsolutePath(); new LDAPConfigurator(dbProps, jahiaConfigInterface) .updateConfiguration(new VFSConfigFile(fsManager, sourceWebAppPath), ldapTargetFile); String jeeApplicationLocation = jahiaConfigInterface.getJeeApplicationLocation(); boolean jeeLocationSpecified = !StringUtils.isEmpty(jeeApplicationLocation); if (jeeLocationSpecified || getDeployer().isEarDeployment()) { if (!jeeLocationSpecified) { jeeApplicationLocation = getDeployer().getDeploymentFilePath("digitalfactory", "ear") .getAbsolutePath(); } String jeeApplicationModuleList = jahiaConfigInterface.getJeeApplicationModuleList(); if (StringUtils.isEmpty(jeeApplicationModuleList)) { jeeApplicationModuleList = "ROOT".equals(jahiaConfigInterface.getWebAppDirName()) ? "jahia-war:web:jahia.war:" : ("jahia-war:web:jahia.war:" + jahiaConfigInterface.getWebAppDirName()); } new ApplicationXmlConfigurator(jahiaConfigInterface, jeeApplicationModuleList).updateConfiguration( new VFSConfigFile(fsManager, jeeApplicationLocation + "/META-INF/application.xml"), jeeApplicationLocation + "/META-INF/application.xml"); } }
From source file:org.jahia.services.content.impl.external.vfs.VFSDataSource.java
public ExternalData getItemByIdentifier(String identifier) throws ItemNotFoundException { try {//from w w w.j ava 2s . c o m UUID.fromString(identifier); throw new ItemNotFoundException("This repository does not support UUID as identifiers"); } catch (IllegalArgumentException iae) { // this is expected, we should not be using UUIDs } if (identifier.startsWith("/")) { try { return getItemByPath(identifier); } catch (PathNotFoundException e) { throw new ItemNotFoundException(identifier); } } FileObject fileObject = null; try { if (identifier.startsWith(root)) { fileObject = manager.resolveFile(identifier); if (!fileObject.exists()) { throw new ItemNotFoundException(identifier); } return getFile(fileObject); } else { throw new ItemNotFoundException("File system exception while trying to retrieve " + identifier); } } catch (FileSystemException fse) { throw new ItemNotFoundException("File system exception while trying to retrieve " + identifier, fse); } }
From source file:org.jahia.services.content.impl.external.vfs.VFSDataSource.java
public ExternalData getItemByPath(String path) throws PathNotFoundException { try {/*w w w . j a v a2s . c o m*/ if (path.endsWith("/" + Constants.JCR_CONTENT)) { FileContent content = getFile(StringUtils.substringBeforeLast(path, "/" + Constants.JCR_CONTENT)) .getContent(); return getFileContent(content); } else { FileObject fileObject = getFile(path); if (!fileObject.exists()) { throw new PathNotFoundException(path); } return getFile(fileObject); } } catch (FileSystemException e) { throw new PathNotFoundException("File system exception while trying to retrieve " + path, e); } }
From source file:org.jahia.services.content.impl.vfs.VFSNodeImpl.java
public VFSNodeImpl(FileObject fileObject, VFSSessionImpl session) { this.fileObject = fileObject; this.session = session; this.properties = new HashMap<String, VFSPropertyImpl>(); try {//from w w w. j a v a 2 s . c o m if (fileObject.exists() && (fileObject.getContent() != null)) { long lastModifiedTime = fileObject.getContent().getLastModifiedTime(); if (lastModifiedTime > 0) { ValueFactory valueFactory = session.getValueFactory(); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(lastModifiedTime); properties.put(Constants.JCR_CREATED, new VFSPropertyImpl( new Name("created", org.apache.jackrabbit.spi.Name.NS_JCR_PREFIX, org.apache.jackrabbit.spi.Name.NS_JCR_URI), this, session, valueFactory.createValue(calendar))); properties.put(Constants.JCR_LASTMODIFIED, new VFSPropertyImpl( new Name("lastModified", org.apache.jackrabbit.spi.Name.NS_JCR_PREFIX, org.apache.jackrabbit.spi.Name.NS_JCR_URI), this, session, valueFactory.createValue(calendar))); } } } catch (FileSystemException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (UnsupportedRepositoryOperationException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (RepositoryException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } }
From source file:org.jahia.services.content.impl.vfs.VFSNodeImpl.java
public boolean hasNode(String s) throws RepositoryException { try {/* w ww.j av a 2 s . c o m*/ if (fileObject.getType() == FileType.FILE) { if ("jcr:content".equals(s)) { return true; } } else if (fileObject.isReadable() && fileObject.getType() == FileType.FOLDER) { FileObject child = fileObject.getChild(s); return child != null && child.exists(); } else if (fileObject.isReadable()) { logger.warn( "Found non file or folder entry, maybe an alias. VFS file type=" + fileObject.getType()); return false; } else { logger.warn( "Item " + fileObject.getName() + " is not readable. VFS file type=" + fileObject.getType()); return false; } } catch (FileSystemException e) { throw new RepositoryException(e); } return false; }
From source file:org.jahia.services.content.impl.vfs.VFSSessionImpl.java
public Node getRootNode() throws RepositoryException { try {/*from w w w . j a v a2 s .c om*/ FileObject rootFileObject = repository.getFile("/"); if (rootFileObject.exists()) { return new VFSNodeImpl(rootFileObject, this); } else { throw new PathNotFoundException("File " + rootFileObject.getURL() + " does not exist"); } } catch (FileSystemException e) { throw new RepositoryException(e); } }
From source file:org.jahia.services.content.impl.vfs.VFSSessionImpl.java
public Node getNodeByUUID(String uuid) throws ItemNotFoundException, RepositoryException { try {/*from w w w . j av a 2s .com*/ UUID testUUID = UUID.fromString(uuid); throw new ItemNotFoundException("This repository does not support UUID as identifiers"); } catch (IllegalArgumentException iae) { // this is expected, we should not be using UUIDs } FileObject fileObject = null; try { fileObject = repository.getFileByIdentifier(uuid); if (!fileObject.exists()) { throw new ItemNotFoundException(uuid); } return new VFSNodeImpl(fileObject, this); } catch (FileSystemException fse) { throw new ItemNotFoundException("File system exception while trying to retrieve " + uuid, fse); } }
From source file:org.jahia.services.content.impl.vfs.VFSSessionImpl.java
public Item getItem(String path) throws PathNotFoundException, RepositoryException { try {/*from w w w . j ava2s. c om*/ FileObject object = repository.getFile(path); if (!object.exists()) { /* // if it's a property, let's try to find the file by removing the last part of the path. int lastSlashPos = s.lastIndexOf("/"); if (lastSlashPos > -1) { String nodePath = s.substring(0, lastSlashPos); object = repository.getFile(nodePath); if (!object.exists()) { throw new PathNotFoundException(s); } // we found the node, let's build it and return it. String propertyName = s.substring(lastSlashPos+1); Name propertyQName = null; int prefixSeparatorPos = propertyName.indexOf(":"); if (prefixSeparatorPos > -1) { propertyQName = new Name(propertyName.substring(prefixSeparatorPos+1), propertyName.substring(0, prefixSeparatorPos), ""); } else { propertyQName = new Name(propertyName, "", ""); } return new VFSPropertyImpl(propertyQName, new VFSNodeImpl(object, this), this); } else { throw new PathNotFoundException(s); } */ throw new PathNotFoundException(path); } return new VFSNodeImpl(object, this); } catch (FileSystemException fse) { throw new PathNotFoundException("Couldn't retrieve path " + path + " because of file system exception", fse); } }