/** * This method is used to back up existing Files. * * @param registry registry instance. * @param path path of the rxt. * @param fileName file name of backed up rxt files. * @throws RegistryException */ public static void backUpFiles(Registry registry, String path, String fileName) throws RegistryException { Resource resource = registry.get(path); try { contentToFile(resource.getContentStream(), fileName); } catch (FileNotFoundException e) { System.out.println("Could not read file content"); } }
/** * Creates and returns an InputStream from the file path / http location given. * * @throws DataServiceFault * @see InputStream */ public static InputStream getInputStreamFromPath(String path) throws IOException, DataServiceFault { InputStream ins; if (path.startsWith("http://")) { /* This is a url file path */ URL url = new URL(path); ins = url.openStream(); } else if (isRegistryPath(path)) { try { RegistryService registryService = DataServicesDSComponent.getRegistryService(); if (registryService == null) { throw new DataServiceFault( "DBUtils.getInputStreamFromPath(): Registry service is not available"); } Registry registry; if (path.startsWith(DBConstants.CONF_REGISTRY_PATH_PREFIX)) { if (path.length() > DBConstants.CONF_REGISTRY_PATH_PREFIX.length()) { path = path.substring(DBConstants.CONF_REGISTRY_PATH_PREFIX.length()); registry = registryService.getConfigSystemRegistry(getCurrentTenantId()); } else { throw new DataServiceFault("Empty configuration registry path given"); } } else { if (path.length() > DBConstants.GOV_REGISTRY_PATH_PREFIX.length()) { path = path.substring(DBConstants.GOV_REGISTRY_PATH_PREFIX.length()); registry = registryService.getGovernanceSystemRegistry(getCurrentTenantId()); } else { throw new DataServiceFault("Empty governance registry path given"); } } if (registry.resourceExists(path)) { Resource serviceResource = registry.get(path); ins = serviceResource.getContentStream(); } else { throw new DataServiceFault( "The given XSLT resource path at '" + path + "' does not exist"); } } catch (RegistryException e) { String msg = "Error in retrieving the resource: " + path; log.error(msg, e); throw new DataServiceFault(e, msg); } } else { File csvFile = new File(path); if (path.startsWith("." + File.separator) || path.startsWith(".." + File.separator)) { /* this is a relative path */ path = csvFile.getAbsolutePath(); } /* local file */ ins = new FileInputStream(path); } return ins; }