List of usage examples for org.apache.commons.lang StringUtils substringAfterLast
public static String substringAfterLast(String str, String separator)
Gets the substring after the last occurrence of a separator.
From source file:info.magnolia.jcr.util.PropertiesImportExport.java
/** * Each property or node in the stream has to be separated by the \n. *//* www . j a v a2s .com*/ public void createNodes(Node root, InputStream propertiesStream) throws IOException, RepositoryException { Properties properties = new OrderedProperties(); properties.load(propertiesStream); properties = keysToInnerFormat(properties); for (Object o : properties.keySet()) { String key = (String) o; String valueStr = properties.getProperty(key); String propertyName = StringUtils.substringAfterLast(key, "."); String path = StringUtils.substringBeforeLast(key, "."); String type = null; if (propertyName.equals("@type")) { type = valueStr; } else if (properties.containsKey(path + ".@type")) { type = properties.getProperty(path + ".@type"); } type = StringUtils.defaultIfEmpty(type, NodeTypes.ContentNode.NAME); Node c = NodeUtil.createPath(root, path, type); populateNode(c, propertyName, valueStr); } }
From source file:net.poemerchant.scraper.ShopScraper.java
private String scrapeShopId() { this.shopId = StringUtils.substringAfterLast(url, "/"); this.shopId = StringUtils.substringBefore(shopId, "."); return shopId; }
From source file:com.abiquo.api.spring.security.URLAuthenticator.java
private static String parse(final StringBuffer url, final String baseUri) { return StringUtils.substringAfterLast(url.toString(), baseUri); }
From source file:com.github.trask.sandbox.sshj.SshSession.java
public void scp(String resource) throws IOException, NoSuchAlgorithmException { logger.debug("scp(\"{}\")", resource); InputStream in = SshSession.class.getClassLoader().getResourceAsStream(resource); if (in == null) { File file = new File(resource); if (file.exists()) { client.newSCPFileTransfer().upload(file.getPath(), file.getName()); } else {/*from ww w .j a va 2s .c om*/ throw new IllegalArgumentException("could not find resource '" + resource + "'"); } } else { File tempFile = File.createTempFile("scp", ".tmp"); IOUtils.copy(in, new FileOutputStream(tempFile)); String fileName = resource; if (fileName.contains("/")) { fileName = StringUtils.substringAfterLast(fileName, "/"); } client.newSCPFileTransfer().upload(tempFile.getPath(), fileName); } }
From source file:info.magnolia.filesystembrowser.app.action.DuplicateFileAction.java
private File createFileCopy(File file) { String extension = StringUtils.substringAfterLast(file.getPath(), "."); extension = StringUtils.isEmpty(extension) ? "" : "." + extension; String newName = file.getPath().replace(extension, "") + " copy"; File copyFile = new File(newName + extension); int idx = 0;// w w w. java2s . co m while (copyFile.exists()) { copyFile = new File(newName + ++idx + extension); } return copyFile; }
From source file:biz.netcentric.cq.tools.actool.helper.InitialContentHelper.java
private static boolean createPathWithInitialContent(final Session session, String path, String initialContent, AcInstallationHistoryPojo history) throws RepositoryException, PathNotFoundException, ItemExistsException, ConstraintViolationException, VersionException, InvalidSerializedDataException, LockException, AccessDeniedException { String parentPath = StringUtils.substringBeforeLast(path, "/"); try {//from w w w. j a v a2 s. co m session.getNode(parentPath); } catch (PathNotFoundException e) { history.addWarning("Skipped installing initial content for path " + path + " since parent " + parentPath + " does not exist"); return false; } String rootElementStr = "<jcr:root "; if (!initialContent.contains(rootElementStr)) { throw new IllegalStateException("Invalid initial content for path " + path + ": " + rootElementStr + " must be provided as root element in XML"); } String initialContentAdjusted = initialContent; if (!initialContentAdjusted.contains("xmlns:cq")) { initialContentAdjusted = initialContentAdjusted.replace(rootElementStr, rootElementStr + " xmlns:cq=\"http://www.day.com/jcr/cq/1.0\" "); } if (!initialContentAdjusted.contains("xmlns:jcr")) { initialContentAdjusted = initialContentAdjusted.replace(rootElementStr, rootElementStr + " xmlns:jcr=\"http://www.jcp.org/jcr/1.0\" "); } if (!initialContentAdjusted.contains("xmlns:sling")) { initialContentAdjusted = initialContentAdjusted.replace(rootElementStr, rootElementStr + " xmlns:sling=\"http://sling.apache.org/jcr/sling/1.0\" "); } String nodeName = StringUtils.substringAfterLast(path, "/"); initialContentAdjusted = initialContentAdjusted.replace("jcr:root", nodeName); history.addVerboseMessage("Adding initial content for path " + path + "\n" + initialContentAdjusted); try { session.importXML(parentPath, new ByteArrayInputStream(initialContentAdjusted.getBytes()), ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); history.addMessage("Created initial content for path " + path); } catch (IOException e) { history.addWarning("Failed creating initial content for path " + path + ": " + e); return false; } return true; }
From source file:com.hangum.tadpole.engine.sql.util.sqlscripts.scripts.MySqlDDLScript.java
@Override public String getFunctionScript(ProcedureFunctionDAO functionDAO) throws Exception { SqlMapClient client = TadpoleSQLManager.getInstance(userDB); StringBuilder result = new StringBuilder(""); Map srcList = (HashMap) client.queryForObject("getFunctionScript", functionDAO.getName()); String strSource = "" + srcList.get("Create Function"); strSource = StringUtils.substringAfterLast(strSource, "FUNCTION"); return "CREATE FUNCTION " + strSource; }
From source file:com.mediaworx.intellij.opencmsplugin.opencms.OpenCmsModule.java
/** * Initializes the module with the given configuration data (from the module's configuration dialog) * @param moduleConfig the module's configuration data *//* w ww . j a va2s .c om*/ public void init(OpenCmsModuleConfigurationData moduleConfig) { this.moduleConfig = moduleConfig; if (moduleConfig.isUseProjectDefaultModuleNameEnabled()) { String moduleNamingScheme = pluginConfig.getModuleNamingScheme(); String moduleFolderName = StringUtils.substringAfterLast(this.moduleBasePath, "/"); if (moduleNamingScheme != null && moduleNamingScheme.length() > 0) { moduleName = moduleNamingScheme.replaceAll(Pattern.quote("${modulename}"), moduleFolderName); } else { moduleName = moduleFolderName; } } else { moduleName = moduleConfig.getModuleName(); } exportPoints = openCmsConfig.getExportPointsForModule(moduleName); moduleResources = openCmsConfig.getModuleResourcesForModule(moduleName); String relativeVfsRoot; if (moduleConfig.isUseProjectDefaultVfsRootEnabled()) { relativeVfsRoot = pluginConfig.getDefaultLocalVfsRoot(); } else { relativeVfsRoot = moduleConfig.getLocalVfsRoot(); } localVfsRoot = this.moduleBasePath + "/" + relativeVfsRoot; }
From source file:com.scit.sling.test.MockResourceFactory.java
/** * Build a {@link MockResourceResolver} with all {@link MockResource} and {@link MockValueMap}.<br> * The format of the JSON input is compatible with the Apache Sling json representations of the JCR, i.e. * <blockquote>curl -s -u admin:admin http://localhost:8080/content/path/to/node.infinity.json</blockquote> * //from w w w . ja v a 2 s . co m * @param basePath the parent path of this node (blank if it's meant to be the root) * @param in the input stream to load the JSON representation * * @return * @throws JsonParseException * @throws IOException */ public static ResourceNode loadRepositoryFromJson(String basePath, InputStream in) throws JsonParseException, IOException { JsonFactory jsonFactory = new JsonFactory(); JsonParser jp = jsonFactory.createJsonParser(in); ResourceNode root = new ResourceNode(StringUtils.substringBeforeLast(basePath, "/"), StringUtils.substringAfterLast(basePath, "/")); JsonToken token = jp.nextToken(); if (token == JsonToken.START_OBJECT) { parseJsonObject(root, jp); } return root; }
From source file:adalid.util.i18n.Mapper.java
private String base(File bundle) { String name = bundle.getName(); String base = _project + FILE_SEPARATOR; base += StringUtils.substringAfterLast(bundle.getParent(), join(_project)); if (name.contains("_")) { base = base + FILE_SEPARATOR + StringUtils.substringBefore(name, "_"); } else {// ww w.java 2s . c o m base = base + FILE_SEPARATOR + StringUtils.substringBeforeLast(name, "."); } return base; }