List of usage examples for org.apache.commons.vfs2 FileSystemException getMessage
@Override
public String getMessage()
From source file:org.esupportail.portlet.filemanager.services.vfs.VfsAccessImpl.java
@Override public boolean putFile(String dir, String filename, InputStream inputStream, SharedUserPortletParameters userParameters, UploadActionType uploadOption) { boolean success = false; FileObject newFile = null;/*from w w w . j a v a 2s . com*/ try { FileObject folder = cd(dir, userParameters); newFile = folder.resolveFile(filename); if (newFile.exists()) { switch (uploadOption) { case ERROR: throw new EsupStockFileExistException(); case OVERRIDE: newFile.delete(); break; case RENAME_NEW: newFile = folder.resolveFile(this.getUniqueFilename(filename, "-new-")); break; case RENAME_OLD: newFile.moveTo(folder.resolveFile(this.getUniqueFilename(filename, "-old-"))); break; } } newFile.createFile(); OutputStream outstr = newFile.getContent().getOutputStream(); FileCopyUtils.copy(inputStream, outstr); success = true; } catch (FileSystemException e) { log.info("can't upload file : " + e.getMessage(), e); } catch (IOException e) { log.warn("can't upload file : " + e.getMessage(), e); } if (!success && newFile != null) { // problem when uploading the file -> the file uploaded is corrupted // best is to delete it try { newFile.delete(); log.debug("delete corrupted file after bad upload ok ..."); } catch (Exception e) { log.debug("can't delete corrupted file after bad upload " + e.getMessage()); } } return success; }
From source file:org.jahia.modules.external.modules.ModulesDataSource.java
public void start() { final String fullFolderPath = module.getSourcesFolder().getPath() + File.separator; final String importFilesRootFolder = fullFolderPath + "src" + File.separator + "main" + File.separator + "import" + File.separator + "content" + File.separator + "modules" + File.separator + module.getId() + File.separator + "files" + File.separator; final String filesNodePath = "/modules/" + module.getIdWithVersion() + "/files"; FileMonitor monitor = new FileMonitor(new FileMonitorCallback() { @Override// w w w . j ava 2 s .com public void process(FileMonitorResult result) { logger.info("Detected changes in sources of the module in folder {}: {}", fullFolderPath, result); if (logger.isDebugEnabled()) { logger.debug(result.getInfo()); } boolean nodeTypeLabelsFlushed = false; List<File> importFiles = new ArrayList<File>(); for (final File file : result.getAllAsList()) { invalidateVfsParentCache(fullFolderPath, file); if (file.getPath().startsWith(importFilesRootFolder)) { importFiles.add(file); continue; } String type; try { type = getDataType(getFile(file.getPath())); } catch (FileSystemException e) { if (logger.isDebugEnabled()) { logger.error(e.getMessage(), e); } // Unable to resolve file, continue continue; } if (StringUtils.equals(type, "jnt:propertiesFile")) { // we've detected a properties file, check if its parent is of type jnt:resourceBundleFolder // -> than this one gets the type jnt:resourceBundleFile; otherwise just jnt:file File parent = file.getParentFile(); type = parent != null && StringUtils.equals(Constants.JAHIANT_RESOURCEBUNDLE_FOLDER, folderTypeMapping.get(parent.getName())) ? Constants.JAHIANT_RESOURCEBUNDLE_FILE : type; } if (StringUtils.equals(type, "jnt:resourceBundleFile") && !nodeTypeLabelsFlushed) { NodeTypeRegistry.getInstance().flushLabels(); logger.debug("Flushing node type label caches"); for (NodeTypeRegistry registry : nodeTypeRegistryMap.values()) { registry.flushLabels(); } nodeTypeLabelsFlushed = true; try { JCRTemplate.getInstance().doExecuteWithSystemSession(new JCRCallback<Object>() { @Override public Object doInJCR(JCRSessionWrapper session) throws RepositoryException { JCRSiteNode site = (JCRSiteNode) session.getNode("/modules/" + module.getId()); Set<String> langs = new HashSet<String>(site.getLanguages()); boolean changed = false; if (file.getParentFile().listFiles() != null) { File[] files = file.getParentFile().listFiles(); if (files != null) { for (File f : files) { String s = StringUtils.substringAfterLast( StringUtils.substringBeforeLast(f.getName(), "."), "_"); if (!StringUtils.isEmpty(s) && !langs.contains(s)) { langs.add(s); changed = true; } } } if (changed) { site.setLanguages(langs); session.save(); } } return null; } }); } catch (RepositoryException e) { logger.error(e.getMessage(), e); } } else if (StringUtils.equals(type, JNT_DEFINITION_FILE)) { try { registerCndFiles(file); } catch (IOException | ParseException | RepositoryException e) { logger.error(e.getMessage(), e); } } else if (StringUtils.equals(type, Constants.JAHIANT_VIEWFILE)) { ModulesSourceHttpServiceTracker httpServiceTracker = modulesSourceSpringInitializer .getHttpServiceTracker(module.getId()); if (result.getCreated().contains(file)) { httpServiceTracker.registerResource(file); } else if (result.getDeleted().contains(file)) { httpServiceTracker.unregisterResouce(file); } // in case of jsp, flush the cache if (StringUtils.endsWith(file.getName(), ".jsp")) { httpServiceTracker.flushJspCache(file); } } } if (!importFiles.isEmpty()) { modulesImportExportHelper.updateImportFileNodes(importFiles, importFilesRootFolder, filesNodePath); } SourceControlManagement sourceControl = module.getSourceControl(); if (sourceControl != null) { sourceControl.invalidateStatusCache(); logger.debug("Invalidating SCM status caches for module {}", module.getId()); for (File file : result.getDeleted()) { try { sourceControl.remove(file); } catch (IOException e) { logger.error("An error occurred when trying to remove file from source control", e); } } for (File file : result.getCreated()) { try { sourceControl.add(file); } catch (IOException e) { logger.error("An error occurred when trying to add file in source control", e); } } } } }); monitor.setRecursive(true); Set<String> ignored = new HashSet<>(sourceControlFactory.getIgnoredFiles()); ignored.add(".svn"); ignored.add(".git"); monitor.setFilesToIgnore(ignored); monitor.addFile(module.getSourcesFolder()); fileMonitorJobName = "ModuleSourcesJob-" + module.getId(); FileMonitorJob.schedule(fileMonitorJobName, 5000, monitor); for (String cndFilePath : module.getDefinitionsFiles()) { try { registerCndFiles(new File(fullFolderPath + "src" + File.separator + "main" + File.separator + "resources" + File.separator + cndFilePath)); } catch (IOException | ParseException | RepositoryException e) { logger.error(e.getMessage(), e); } } }
From source file:org.jahia.modules.external.modules.ModulesDataSource.java
protected void invalidateVfsParentCache(String fullFolderPath, File file) { String relativePath = StringUtils.substringAfter(file.getPath(), fullFolderPath); if (StringUtils.isNotEmpty(relativePath)) { try {/*w w w .ja v a 2 s . com*/ getFile(relativePath).getParent().refresh(); } catch (FileSystemException e) { logger.warn("Unable to find parent for {}. Skipped invalidating VFS caches.", relativePath); if (logger.isDebugEnabled()) { logger.debug(e.getMessage(), e); } } } }
From source file:org.jahia.modules.external.modules.ModulesDataSource.java
private void saveProperties(ExternalData data) throws RepositoryException { OutputStream outputStream = null; try {/* w w w.jav a2s . c o m*/ ExtendedNodeType propertiesType = NodeTypeRegistry.getInstance() .getNodeType(Constants.JAHIAMIX_VIEWPROPERTIES); Map<String, ExtendedPropertyDefinition> propertyDefinitionMap = propertiesType .getDeclaredPropertyDefinitionsAsMap(); Properties properties = new SortedProperties(); for (Map.Entry<String, String[]> property : data.getProperties().entrySet()) { if (propertyDefinitionMap.containsKey(property.getKey())) { String[] v = property.getValue(); if (v != null) { String propertyValue = StringUtils.join(v, ","); if (propertyDefinitionMap.get(property.getKey()).getRequiredType() != PropertyType.BOOLEAN || !propertyValue.equals("false")) { properties.put(property.getKey(), propertyValue); } } } } FileObject file = getFile(StringUtils.substringBeforeLast(data.getPath(), ".") + PROPERTIES_EXTENSION); Properties original = new Properties(); if (file.exists()) { original.load(file.getContent().getInputStream()); for (String s : propertyDefinitionMap.keySet()) { original.remove(s); } } properties.putAll(original); if (!properties.isEmpty()) { outputStream = file.getContent().getOutputStream(); properties.store(outputStream, data.getPath()); } else { if (file.exists()) { file.delete(); } } ResourceBundle.clearCache(); } catch (FileSystemException e) { logger.error(e.getMessage(), e); throw new RepositoryException("Failed to write source code", e); } catch (IOException e) { logger.error(e.getMessage(), e); throw new RepositoryException("Failed to write source code", e); } catch (NoSuchNodeTypeException e) { logger.error("Unable to find type : " + data.getType() + " for node " + data.getPath(), e); throw e; } finally { IOUtils.closeQuietly(outputStream); } }
From source file:org.jahia.modules.external.modules.ModulesDataSource.java
protected File getRealRoot() { if (realRoot == null) { try {// ww w . jav a2 s. c o m FileName name = getFile("/").getName(); realRoot = new File(((LocalFileName) name).getRootFile(), name.getPath()); } catch (FileSystemException e) { logger.error(e.getMessage(), e); throw new IllegalArgumentException(e); } } return realRoot; }
From source file:org.jahia.modules.external.vfs.factory.VFSMountPointFactoryHandler.java
/** * Return the validation state of a vfs mount point * @param vfsMountPointFactory/*ww w . j av a2s . com*/ * @return */ private boolean validateVFS(VFSMountPointFactory vfsMountPointFactory) { try { VFS.getManager().resolveFile(vfsMountPointFactory.getRoot()); } catch (FileSystemException e) { logger.warn("VFS mount point " + vfsMountPointFactory.getName() + " has validation problem " + e.getMessage()); return false; } return true; }
From source file:org.jahia.modules.external.vfs.VFSBinaryImpl.java
@Override public void dispose() { try {/*from www .j ava 2s . com*/ fileContent.close(); } catch (FileSystemException e) { logger.warn(e.getMessage(), e); } }
From source file:org.luwrain.app.commander.PanelArea.java
boolean openLocalPath(String path) { NullCheck.notNull(path, "path"); try {/* ww w . j a v a2 s . co m*/ open(CommanderUtilsVfs.prepareLocation((CommanderUtilsVfs.Model) getCommanderModel(), path)); return true; } catch (org.apache.commons.vfs2.FileSystemException e) { Log.error("commander", "opening " + path + ":" + e.getClass().getName() + ":" + e.getMessage()); return false; } }
From source file:org.luwrain.app.commander.PanelArea.java
boolean openInitial(String path) { NullCheck.notNull(path, "path"); try {//from w w w . j a v a2 s .c om return open(CommanderUtilsVfs.prepareLocation((CommanderUtilsVfs.Model) getCommanderModel(), path), false); } catch (org.apache.commons.vfs2.FileSystemException e) { Log.error("commander", "opening " + path + ":" + e.getClass().getName() + ":" + e.getMessage()); return false; } }
From source file:org.pentaho.googlecloudstorage.lifecycle.GoogleCloudStoragePluginLifecycleListener.java
public void onEnvironmentInit() throws LifecycleException { try {/*from w ww .j a v a 2s .c om*/ FileSystemManager fsm = KettleVFS.getInstance().getFileSystemManager(); if (fsm instanceof DefaultFileSystemManager) { if (!Arrays.asList(fsm.getSchemes()).contains(GoogleCloudStorageFileProvider.SCHEME)) { ((DefaultFileSystemManager) fsm).addProvider(GoogleCloudStorageFileProvider.SCHEME, new GoogleCloudStorageFileProvider()); } } } catch (FileSystemException e) { throw new LifecycleException(e.getMessage(), false); } }