List of usage examples for org.apache.commons.lang StringUtils strip
public static String strip(String str, String stripChars)
Strips any of a set of characters from the start and end of a String.
From source file:pt.webdetails.cdf.dd.CdeSettings.java
/** * @deprecated/* w w w. j a v a2 s . co m*/ */ public static IReadAccess[] getComponentLocations() { ArrayList<IReadAccess> componentAccesses = new ArrayList<IReadAccess>(); CdfDDSettings settings = getSettings(); for (Element element : settings.getComponentLocationElements()) { String path = element.getText(); if (path != null) { path = StringUtils.strip(path, "/"); //ex: <path>system/pentaho-cdf-dd/resources/custom/components</path>, <path>system/cdc/cdeComponents</path> if (path.startsWith(CdeEnvironment.getSystemDir() + "/")) { path = path.replaceFirst(CdeEnvironment.getSystemDir() + "/", ""); // ex: <path>system/pentaho-cdf-dd/resources/custom/components</path> if (path.startsWith(CdeEnvironment.getPluginId() + "/")) { path = path.replaceFirst(CdeEnvironment.getPluginId() + "/", ""); if (CdeEnvironment.getPluginSystemReader().fileExists(path) && CdeEnvironment.getPluginSystemReader().fetchFile(path).isDirectory()) { componentAccesses.add(CdeEnvironment.getPluginSystemReader(path)); } } else { //XXX this isn't supposed to happen // ex: <path>system/cdc/cdeComponents</path> String pluginId = path.substring(0, path.indexOf("/")); path = path.replaceFirst(pluginId + "/", ""); if (CdeEnvironment.getOtherPluginSystemReader(pluginId).fileExists(path) && CdeEnvironment .getOtherPluginSystemReader(pluginId).fetchFile(path).isDirectory()) { componentAccesses.add(CdeEnvironment.getOtherPluginSystemReader(pluginId, path)); } } } else if (path.startsWith(CdeEnvironment.getPluginRepositoryDir() + "/")) { // ex: <path>cde/components</path> path = path.replaceFirst(CdeEnvironment.getPluginRepositoryDir() + "/", ""); if (CdeEnvironment.getPluginSystemReader().fileExists(path) && CdeEnvironment.getPluginSystemReader().fetchFile(path).isDirectory()) { componentAccesses.add(CdeEnvironment.getPluginRepositoryReader(path)); } } else { logger.warn("Components directory '" + element.getText() + "' was not found."); } } } return componentAccesses.toArray(new IReadAccess[componentAccesses.size()]); }
From source file:pt.webdetails.cdf.dd.reader.factory.ResourceLoaderFactory.java
protected boolean isSystem(String path) { if (path.isEmpty()) { return false; }/*w w w . java2s . c o m*/ ICdeEnvironment env = getCdeEnvironment(); IContentAccessFactory factory = getContentAccessFactory(env); path = StringUtils.strip(path.toLowerCase(), "/"); if (path.startsWith(getSystemDir(env))) { return true; } else if (path.startsWith(getPluginRepositoryDir(env))) { return false; } else { if (isSystemStaticResource(factory, path)) { return true; } else if (isRepositoryStaticResource(factory, path)) { return false; } } return false; }
From source file:pt.webdetails.cdf.dd.util.Utils.java
public static IReadAccess getAppropriateReadAccess(String resource, String basePath, ICdeEnvironment environment) {//from w w w . j a v a 2s . c o m if (StringUtils.isEmpty(resource)) { return null; } IContentAccessFactory factory = environment.getContentAccessFactory(); String systemDir = environment.getSystemDir() + "/"; String repoDir = environment.getPluginRepositoryDir() + "/"; resource = StringUtils.strip(resource, "/"); if (resource.regionMatches(true, 0, systemDir, 0, systemDir.length())) { resource = resource.replaceFirst(systemDir, ""); String pluginId = environment.getPluginId() + "/"; // system dir - this plugin if (resource.regionMatches(true, 0, pluginId, 0, pluginId.length())) { return factory.getPluginSystemReader(basePath); } else { // system dir - other plugin pluginId = resource.substring(0, resource.indexOf("/")); return factory.getOtherPluginSystemReader(pluginId, basePath); } } else if (resource.regionMatches(true, 0, repoDir, 0, repoDir.length())) { // plugin repository dir return factory.getPluginRepositoryReader(basePath); } else { // one of two: already trimmed system resource (ex: 'resources/templates/1-empty-structure.cdfde') // or a user solution resource (ex: 'plugin-samples/pentaho-cdf-dd/styles/my-style.css') if (factory.getPluginSystemReader(basePath).fileExists(resource)) { return factory.getPluginSystemReader(basePath); } else { // user solution dir return factory.getUserContentAccess(basePath); } } }
From source file:pt.webdetails.cdf.dd.util.Utils.java
public static IRWAccess getAppropriateWriteAccess(String resource, String basePath, ICdeEnvironment environment) {/*from www . j a va2s.c o m*/ if (StringUtils.isEmpty(resource)) { return null; } IContentAccessFactory factory = environment.getContentAccessFactory(); String systemDir = environment.getSystemDir() + "/"; String repoDir = environment.getPluginRepositoryDir() + "/"; resource = StringUtils.strip(resource, "/"); if (resource.regionMatches(true, 0, systemDir, 0, systemDir.length())) { resource = resource.replaceFirst(systemDir, ""); String pluginId = environment.getPluginId() + "/"; // system dir - this plugin if (resource.regionMatches(true, 0, pluginId, 0, pluginId.length())) { return factory.getPluginSystemWriter(basePath); } else { // system dir - other plugin pluginId = resource.substring(0, resource.indexOf("/")); return factory.getOtherPluginSystemWriter(pluginId, basePath); } } else if (resource.regionMatches(true, 0, repoDir, 0, repoDir.length())) { // plugin repository dir return factory.getPluginRepositoryWriter(basePath); } else { // one of two: already trimmed system resource (ex: 'resources/templates/1-empty-structure.cdfde') // or a user solution resource (ex: 'plugin-samples/pentaho-cdf-dd/styles/my-style.css') if (factory.getPluginSystemReader(basePath).fileExists(resource)) { return factory.getPluginSystemWriter(basePath); } else { // user solution dir return factory.getUserContentAccess(basePath); } } }
From source file:pt.webdetails.cdf.dd.util.Utils.java
public static IBasicFile getFileViaAppropriateReadAccess(String resource, String basePath, ICdeEnvironment environment) {/*www . j a v a2 s .c o m*/ if (StringUtils.isEmpty(resource)) { return null; } IContentAccessFactory factory = environment.getContentAccessFactory(); String systemDir = environment.getSystemDir() + "/"; String repoDir = environment.getPluginRepositoryDir() + "/"; resource = StringUtils.strip(resource, "/"); if (resource.regionMatches(true, 0, systemDir, 0, systemDir.length())) { resource = resource.replaceFirst(systemDir, ""); String pluginId = environment.getPluginId() + "/"; // system dir - this plugin if (resource.regionMatches(true, 0, pluginId, 0, pluginId.length())) { resource = resource.replaceFirst(pluginId, ""); return factory.getPluginSystemReader(basePath).fetchFile(resource); } else { // system dir - other plugin pluginId = resource.substring(0, resource.indexOf("/")); resource = resource.replaceFirst(pluginId, ""); return factory.getOtherPluginSystemReader(pluginId, basePath).fetchFile(resource); } } else if (resource.regionMatches(true, 0, repoDir, 0, repoDir.length())) { // plugin repository dir resource = resource.replaceFirst(repoDir, ""); return factory.getPluginRepositoryReader(basePath).fetchFile(resource); } else { // one of two: already trimmed system resource (ex: 'resources/templates/1-empty-structure.cdfde') // or a user solution resource (ex: 'plugin-samples/pentaho-cdf-dd/styles/my-style.css') if (factory.getPluginSystemReader(basePath).fileExists(resource)) { return factory.getPluginSystemReader(basePath).fetchFile(resource); } else if (factory.getUserContentAccess(basePath).fileExists(resource)) { // user solution dir return factory.getUserContentAccess(basePath).fetchFile(resource); } } return null; }
From source file:pt.webdetails.cpf.Util.java
/** * Helper method that given a path of a resource, allows us to infer on the appropriate IReadAccess object for it * * @param resourcePath the path to a resource * @param factory the IReadAccess factory * @param pluginId the plugin's id * @param pluginSystemDir the plugin's base system directory * @param pluginRepoDir the plugin's base repository directory * @return appropriate IReadAccess object for the given resource *//* w ww . j ava2 s . c om*/ public static IReadAccess getAppropriateReadAccess(final String resourcePath, final IContentAccessFactory factory, final String pluginId, final String pluginSystemDir, final String pluginRepoDir) { if (StringUtils.isEmpty(resourcePath) || StringUtils.isEmpty(pluginId) || StringUtils.isEmpty(pluginSystemDir) || StringUtils.isEmpty(pluginRepoDir) || factory == null) { return null; } String id = pluginId.endsWith(SEPARATOR) ? pluginId : pluginId + SEPARATOR; String repoDir = pluginRepoDir.endsWith(SEPARATOR) ? pluginRepoDir : pluginRepoDir + SEPARATOR; String systemDir = pluginSystemDir.endsWith(SEPARATOR) ? pluginSystemDir : pluginSystemDir + SEPARATOR; // remove leading and trailing SEPARATOR *and* also performs String.trim() String resource = StringUtils.strip(resourcePath, SEPARATOR); if (resource.regionMatches(true, 0, systemDir, 0, systemDir.length())) { resource = resource.replaceFirst(systemDir, ""); // trim the 'system' if (resource.regionMatches(true, 0, id, 0, id.length())) { // system dir - this plugin id return factory.getPluginSystemReader(null); } else { // system dir - some other plugin id; lets find out which one String otherPluginId = resource.substring(0, resource.indexOf(SEPARATOR)); return factory.getOtherPluginSystemReader(otherPluginId, null); } } else if (resource.regionMatches(true, 0, repoDir, 0, repoDir.length())) { // plugin repository dir return factory.getPluginRepositoryReader(null); } else { // one of two: // A - already trimmed system resource (ex: 'resources/templates/1-empty-structure.cdfde') for the pluginId // B - user solution resource (ex: 'public/plugin-samples/pentaho-cdf-dd/styles/my-style.css') if (factory.getPluginSystemReader(null).fileExists(resourcePath)) { return factory.getPluginSystemReader(null); } else if (factory.getUserContentAccess(null).fileExists(resourcePath)) { // user solution dir return factory.getUserContentAccess(null); } } return null; // reaching this point, there's not much more left to be done, and null is returned }