List of usage examples for org.springframework.core.io Resource getFile
File getFile() throws IOException;
From source file:org.jahia.services.importexport.DocumentViewImportHandler.java
@SuppressWarnings("unchecked") public DocumentViewImportHandler(JCRSessionWrapper session, String rootPath, Resource archive, List<String> fileList) throws IOException { super(session); JCRNodeWrapper node = null;//from w w w.j av a 2s.com try { this.uuidMapping = session.getUuidMapping(); this.pathMapping = session.getPathMapping(); if (rootPath == null) { node = (JCRNodeWrapper) session.getRootNode(); } else { node = (JCRNodeWrapper) session.getNode(rootPath); } } catch (RepositoryException e) { logger.error(e.getMessage() + getLocation(), e); throw new IOException(); } nodes.add(node); this.archive = archive; if (archive != null && !archive.isReadable() && archive instanceof FileSystemResource) { expandImportedFilesOnDiskPath = archive.getFile().getPath(); expandImportedFilesOnDisk = true; } this.fileList = fileList; setPropertiesToSkip( (Set<String>) SpringContextSingleton.getBean("DocumentViewImportHandler.propertiesToSkip")); }
From source file:org.jahia.services.importexport.ImportExportBaseService.java
private ZipInputStream getZipInputStream(Resource file) throws IOException { ZipInputStream zis;// w w w . j a va 2s . c o m if (!file.isReadable() && file instanceof FileSystemResource) { zis = new DirectoryZipInputStream(file.getFile()); } else { zis = new NoCloseZipInputStream(new BufferedInputStream(file.getInputStream())); } return zis; }
From source file:org.jahia.services.templates.TemplatePackageDeployer.java
public void initializeModuleContent(JahiaTemplatesPackage aPackage, JCRSessionWrapper session) throws RepositoryException { resetModuleNodes(aPackage, session); logger.info("Starting import for the module package '" + aPackage.getName() + "' including: " + aPackage.getInitialImports()); for (String imp : aPackage.getInitialImports()) { String targetPath = "/" + StringUtils .substringAfter(StringUtils.substringBeforeLast(imp, "."), "import-").replace('-', '/'); Resource importFile = aPackage.getResource(imp); logger.info("... importing " + importFile + " into " + targetPath); session.getPathMapping().put("/templateSets/", "/modules/"); session.getPathMapping().put("/modules/" + aPackage.getId() + "/", "/modules/" + aPackage.getId() + "/" + aPackage.getVersion() + "/"); try {/* w w w . j a v a 2 s . c o m*/ if (imp.toLowerCase().endsWith(".xml")) { InputStream is = null; try { is = new BufferedInputStream(importFile.getInputStream()); session.importXML(targetPath, is, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW, DocumentViewImportHandler.ROOT_BEHAVIOUR_IGNORE); } finally { IOUtils.closeQuietly(is); } } else if (imp.toLowerCase().contains("/importsite")) { importExportService.importSiteZip(importFile, session); } else { // importExportService.importZip(targetPath, importFile, DocumentViewImportHandler.ROOT_BEHAVIOUR_IGNORE, session); importExportService.importZip(targetPath, importFile, DocumentViewImportHandler.ROOT_BEHAVIOUR_IGNORE, session, new HashSet<String>(Arrays.asList("permissions.xml", "roles.xml")), false); if (targetPath.equals("/")) { List<String> fileList = new ArrayList<String>(); Map<String, Long> sizes = new HashMap<String, Long>(); importExportService.getFileList(importFile, sizes, fileList); if (sizes.containsKey("permissions.xml")) { Set<String> s = new HashSet<String>(sizes.keySet()); s.remove("permissions.xml"); if (!session.itemExists("/modules/" + aPackage.getIdWithVersion() + "/permissions")) { session.getNode("/modules/" + aPackage.getIdWithVersion()).addNode("permissions", "jnt:permission"); } importExportService.importZip("/modules/" + aPackage.getIdWithVersion(), importFile, DocumentViewImportHandler.ROOT_BEHAVIOUR_IGNORE, session, s, false); } if (sizes.containsKey("roles.xml")) { Set<String> s = new HashSet<String>(sizes.keySet()); s.remove("roles.xml"); session.getPathMapping().put("/permissions", "/modules/" + aPackage.getIdWithVersion() + "/permissions"); importExportService.importZip("/", importFile, DocumentViewImportHandler.ROOT_BEHAVIOUR_IGNORE, session, s, false); session.getPathMapping().remove("/permissions"); } } } } catch (IOException e) { throw new RepositoryException(e); } File realImportFile = null; try { realImportFile = importFile.getFile(); } catch (IOException ioe) { realImportFile = null; } if (realImportFile != null) { realImportFile.delete(); } session.save(JCRObservationManager.IMPORT); } cloneModuleInLive(aPackage); logger.info("... finished initial import for module package '" + aPackage.getName() + "'."); componentRegistry.registerComponents(aPackage, session); session.save(); }
From source file:org.jahia.settings.SettingsBean.java
public File getRepositoryHome() throws IOException { String path = getString("jahia.jackrabbit.home", null); if (path == null) { path = interpolate("${jahia.data.dir}/repository"); }// w w w . ja v a2 s. co m File repoHome = new File(path); if (!repoHome.isAbsolute()) { Resource r = applicationContext.getResource(path); if (r != null && r.exists()) { repoHome = r.getFile(); } } return repoHome.exists() ? repoHome.getAbsoluteFile() : null; }
From source file:org.jahia.tools.patches.GroovyPatcher.java
protected static void rename(Resource script, String suffix) { File scriptFile;// w ww . java 2 s . co m try { scriptFile = script.getFile(); File dest = new File(scriptFile.getParentFile(), scriptFile.getName() + suffix); if (dest.exists()) { FileUtils.deleteQuietly(dest); } if (!scriptFile.renameTo(dest)) { logger.warn("Unable to rename script file {} to {}. Skip renaming.", script.getFile().getPath(), dest.getPath()); } } catch (IOException e) { logger.warn("Unable to rename the script file for resurce " + script + " due to an error: " + e.getMessage(), e); } }
From source file:org.jasig.resourceserver.utils.aggr.ResourcesElementsProviderImpl.java
@Override public Resources getResources(HttpServletRequest request, String skinXml) { final Included includedType = this.getIncludedType(request); final Resource skinResource = getResource(skinXml); final File skinFile; try {/*from w w w .j a va 2 s. co m*/ skinFile = skinResource.getFile(); } catch (IOException e) { throw new IllegalArgumentException("Failed to get File for skin XML path: " + skinXml, e); } switch (includedType) { case AGGREGATED: { final String aggregatedSkinXml = resourcesDao.getAggregatedSkinName(skinFile.getName()); final File aggregatedSkinFile = new File(skinFile.getParentFile(), aggregatedSkinXml); if (aggregatedSkinFile.exists()) { return resourcesDao.readResources(aggregatedSkinFile, includedType); } this.logger.warn("Could not find aggregated skin XML '" + aggregatedSkinFile + "' for '" + skinFile + "', falling back on unaggregated version."); } case PLAIN: { return resourcesDao.readResources(skinFile, includedType); } default: { throw new UnsupportedOperationException("Unkown Included type: " + includedType); } } }
From source file:org.jgrades.lic.api.crypto.encrypt.LicenceSaverTest.java
@Before public void setUp() throws Exception { Resource licResource = new ClassPathResource("encrypted.lic"); licenceBytes = FileUtils.readFileToByteArray(licResource.getFile()); Resource signResource = new ClassPathResource("encrypted.lic.sign"); signatureBytes = FileUtils.readFileToByteArray(signResource.getFile()); }
From source file:org.jgrades.rest.client.lic.LicenceManagerServiceClient.java
@Override public Licence uploadAndInstall(MultipartFile licence, MultipartFile signature) throws IOException { Resource licenceResource = getResource(licence); Resource signatureResource = getResource(signature); try {/*w w w .j ava 2s . c o m*/ String serviceUrl = backendBaseUrl + "/licence"; HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.MULTIPART_FORM_DATA); LinkedMultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); params.add("licence", licenceResource); params.add("signature", signatureResource); HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<>(params, headers); ResponseEntity<Licence> response = restTemplate.exchange(serviceUrl, HttpMethod.POST, requestEntity, Licence.class); return response.getBody(); } finally { FileUtils.deleteQuietly(licenceResource.getFile()); FileUtils.deleteQuietly(signatureResource.getFile()); } }
From source file:org.jspringbot.keyword.config.ConfigHelper.java
public void init() throws IOException { ResourceEditor editor = new ResourceEditor(); editor.setAsText("classpath:config/"); Resource configDirResource = (Resource) editor.getValue(); boolean hasConfigDirectory = true; boolean hasConfigProperties = true; if (configDirResource != null) { try {// ww w .java 2 s.c om File configDir = configDirResource.getFile(); if (configDir.isDirectory()) { File[] propertiesFiles = configDir.listFiles(new FileFilter() { @Override public boolean accept(File file) { return StringUtils.endsWith(file.getName(), ".properties") || StringUtils.endsWith(file.getName(), ".xml"); } }); for (File propFile : propertiesFiles) { String filename = propFile.getName(); String name = StringUtils.substring(filename, 0, StringUtils.indexOf(filename, ".")); addProperties(name, propFile); } } } catch (IOException e) { hasConfigDirectory = false; } } editor.setAsText("classpath:config.properties"); Resource configPropertiesResource = (Resource) editor.getValue(); if (configPropertiesResource != null) { try { File configPropertiesFile = configPropertiesResource.getFile(); if (configPropertiesFile.isFile()) { Properties configs = new Properties(); configs.load(new FileReader(configPropertiesFile)); for (Map.Entry entry : configs.entrySet()) { String name = (String) entry.getKey(); editor.setAsText(String.valueOf(entry.getValue())); try { Resource resource = (Resource) editor.getValue(); addProperties(name, resource.getFile()); } catch (Exception e) { throw new IOException(String.format("Unable to load config '%s'.", name), e); } } } } catch (IOException e) { hasConfigProperties = false; } } if (!hasConfigDirectory && !hasConfigProperties) { LOGGER.warn("No configuration found."); } }
From source file:org.kuali.rice.krad.datadictionary.DataDictionary.java
/** * Processes a given source for XML files to populate the dictionary with * * @param namespaceCode - namespace the beans loaded from the location should be associated with * @param sourceName - a file system or classpath resource locator * @throws IOException//from w w w .java 2s . c om */ protected void indexSource(String namespaceCode, String sourceName) throws IOException { if (sourceName == null) { throw new DataDictionaryException("Source Name given is null"); } if (!sourceName.endsWith(".xml")) { Resource resource = getFileResource(sourceName); if (resource.exists()) { try { indexSource(namespaceCode, resource.getFile()); } catch (IOException e) { // ignore resources that exist and cause an error here // they may be directories resident in jar files LOG.debug("Skipped existing resource without absolute file path"); } } else { LOG.warn("Could not find " + sourceName); throw new DataDictionaryException("DD Resource " + sourceName + " not found"); } } else { if (LOG.isDebugEnabled()) { LOG.debug("adding sourceName " + sourceName + " "); } Resource resource = getFileResource(sourceName); if (!resource.exists()) { throw new DataDictionaryException("DD Resource " + sourceName + " not found"); } addModuleDictionaryFile(namespaceCode, sourceName); } }