List of usage examples for org.apache.commons.lang StringUtils substringBeforeLast
public static String substringBeforeLast(String str, String separator)
Gets the substring before the last occurrence of a separator.
From source file:info.magnolia.cms.Aggregator.java
/** * Collect content from the pre configured repository and attach it to the HttpServletRequest. * @throws PathNotFoundException//w w w .j a v a 2s . co m * @throws RepositoryException */ public static boolean collect(HttpServletRequest request) throws PathNotFoundException, RepositoryException { String uri = StringUtils.substringBeforeLast(Path.getURI(request), "."); //$NON-NLS-1$ String extension = StringUtils.substringAfterLast(Path.getURI(request), "."); //$NON-NLS-1$ HierarchyManager hierarchyManager = MgnlContext.getHierarchyManager(ContentRepository.WEBSITE); Content requestedPage = null; NodeData requestedData = null; Template template = null; if (hierarchyManager.isPage(uri)) { requestedPage = hierarchyManager.getContent(uri); // ATOM // check if its a request for a versioned page if (request.getParameter(VERSION_NUMBER) != null) { // get versioned state try { requestedPage = requestedPage.getVersionedContent(request.getParameter(VERSION_NUMBER)); } catch (RepositoryException re) { log.debug(re.getMessage(), re); log.error("Unable to get versioned state, rendering current state of " + uri); } } String templateName = requestedPage.getMetaData().getTemplate(); if (StringUtils.isBlank(templateName)) { log.error("No template configured for page [{}].", requestedPage.getHandle()); //$NON-NLS-1$ } template = TemplateManager.getInstance().getInfo(templateName, extension); if (template == null) { log.error("Template [{}] for page [{}] not found.", //$NON-NLS-1$ templateName, requestedPage.getHandle()); } } else { if (hierarchyManager.isNodeData(uri)) { requestedData = hierarchyManager.getNodeData(uri); } else { // check again, resource might have different name int lastIndexOfSlash = uri.lastIndexOf("/"); //$NON-NLS-1$ if (lastIndexOfSlash > 0) { uri = StringUtils.substringBeforeLast(uri, "/"); //$NON-NLS-1$ try { requestedData = hierarchyManager.getNodeData(uri); } catch (PathNotFoundException e) { // no page available return false; } catch (RepositoryException e) { log.debug(e.getMessage(), e); return false; } } } if (requestedData != null) { String templateName = requestedData.getAttribute("nodeDataTemplate"); //$NON-NLS-1$ if (!StringUtils.isEmpty(templateName)) { template = TemplateManager.getInstance().getInfo(templateName, extension); } } else { return false; } } // Attach all collected information to the HttpServletRequest. if (requestedPage != null) { request.setAttribute(Aggregator.ACTPAGE, requestedPage); request.setAttribute(Aggregator.CURRENT_ACTPAGE, requestedPage); } if ((requestedData != null) && (requestedData.getType() == PropertyType.BINARY)) { File file = new File(); file.setProperties(requestedData); file.setNodeData(requestedData); request.setAttribute(Aggregator.FILE, file); } request.setAttribute(Aggregator.HANDLE, uri); request.setAttribute(Aggregator.EXTENSION, extension); request.setAttribute(Aggregator.HIERARCHY_MANAGER, hierarchyManager); request.setAttribute(Aggregator.TEMPLATE, template); return true; }
From source file:info.magnolia.commands.impl.DeleteCommand.java
@Override public boolean execute(Context ctx) throws Exception { log.debug("Going to remove node [{}].", getPath()); String parentPath = StringUtils.substringBeforeLast(getPath(), "/"); String label = StringUtils.substringAfterLast(getPath(), "/"); Node parentNode = MgnlContext.getJCRSession(this.getRepository()).getNode(parentPath); Node toRemove = parentNode.getNode(label); toRemove.remove();// w ww . j a v a 2s . co m parentNode.getSession().save(); return true; }
From source file:info.magnolia.importexport.BootstrapFilesComparator.java
private static String getName(File file) { String name = StringUtils.substringBeforeLast(file.getName(), "."); if (name.endsWith(DataTransporter.XML) || name.endsWith(DataTransporter.PROPERTIES)) { name = StringUtils.substringBeforeLast(file.getName(), "."); }//w w w . j a v a2 s .co m return name; }
From source file:com.github.fritaly.graphml4j.samples.GradleDependencies.java
/** * Computes and returns a label from the given value. * * @param value/*from www . j a va 2 s. c om*/ * a string identifying a dependency (group, artifact, version) * generated by the Gradle dependencies task. Can't be null. * @return a string corresponding to a shorter label to uniquely identify a * dependency. */ private static String computeLabel(String value) { // Examples of input values: // "org.springframework:spring-core:3.2.0.RELEASE (*)" => "spring-core:3.2.0.RELEASE" // "com.acme:acme-logging:1.16.0 -> 1.16.3 (*)" => "acme-logging:1.16.3" // "junit:junit:3.8.1 -> 4.8.1" => "junit:4.8.1" // "sun-jaxb:jaxb-impl:2.2" => "jaxb-impl:2.2" if (value.endsWith(" (*)")) { // Ex: "org.springframework:spring-core:3.2.0.RELEASE (*)" => "org.springframework:spring-core:3.2.0.RELEASE" value = value.replace(" (*)", ""); } if (value.contains(" -> ")) { // Ex: "junit:junit:3.8.1 -> 4.8.1" => "junit:junit:4.8.1" final String version = StringUtils.substringAfter(value, " -> "); value = StringUtils.substringBeforeLast(value, ":") + ":" + version; } // Ex: "sun-jaxb:jaxb-impl:2.2" => "jaxb-impl:2.2" value = StringUtils.substringAfter(value, ":"); return StringUtils.replace(value, ":", "\n"); }
From source file:com.google.gdt.eclipse.designer.hosted.tdt.Utils.java
private static String getUserJarFolder(IModuleDescription moduleDescription) { String userJarPath = getUserJarLocation(moduleDescription); if (userJarPath != null) { return StringUtils.substringBeforeLast(userJarPath, "/"); } else {// w w w. j a v a2s . c o m return null; } }
From source file:info.magnolia.module.delta.BootstrapSingleResourceAndOrderBefore.java
public BootstrapSingleResourceAndOrderBefore(String name, String description, String resource, String orderBeforeName) { super(name, description); // TODO : these values should be provided by the BootstrapUtil/Helper once MAGNOLIA-1806 is done. String filename = StringUtils.substringAfterLast(resource, "/"); String repository = StringUtils.substringBefore(filename, "."); String path = StringUtils.substringAfter(StringUtils.substringBeforeLast(filename, "."), "."); path = "/" + StringUtils.replace(path, ".", "/"); addTask(new BootstrapSingleResource(name, description, resource)); addTask(new OrderNodeBeforeTask(name, description, repository, path, orderBeforeName)); }
From source file:info.magnolia.module.workflow.commands.simple.DeleteCommand.java
private void deleteNode(Context context, String path) throws Exception { String parentPath = StringUtils.substringBeforeLast(path, "/"); String label = StringUtils.substringAfterLast(path, "/"); deleteNode(context, parentPath, label); }
From source file:info.magnolia.cms.util.PathUtil.java
/** * Removes the extension from a path if one exists. *///from ww w .j ava2 s.c o m public static String stripExtension(String path) { return StringUtils.substringBeforeLast(path, "."); }
From source file:i18nplugin.TranslationNode.java
/** * Create Tree//from w w w . j a va 2 s . co m * @param string Name of Tree-Node * @param file Jar-File with Properties */ public TranslationNode(String string, File file) { super(string); try { JarFile jarfile = new JarFile(file); Enumeration<JarEntry> entries = jarfile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.getName().endsWith(".properties")) { String name = entry.getName(); name = name.substring(0, name.length() - 11); if (name.indexOf('/') >= 0) { String dir = StringUtils.substringBeforeLast(name, "/"); if (dir.contains("/")) { dir = StringUtils.substringAfterLast(dir, "/"); } name = StringUtils.substringAfterLast(name, "/"); if (name.equals(dir)) { addEntry(jarfile, entry); } } } } } catch (IOException e) { e.printStackTrace(); } }
From source file:com.qualitesys.sonarqcr4pblplugin.pbl.PblFile.java
/** * @param unitTest whether it is a unit test file or a source file *///w ww . jav a2 s. co m public PblFile(String key, boolean unitTest) { super(); if (key != null && key.indexOf('$') >= 0) { throw new IllegalArgumentException("Pbl inner classes are not supported : " + key); } String realKey = StringUtils.trim(key); this.unitTest = unitTest; if (realKey.contains(".")) { this.filename = StringUtils.substringAfterLast(realKey, "."); this.packageKey = StringUtils.substringBeforeLast(realKey, "."); this.longName = realKey; } else { this.filename = realKey; this.longName = realKey; this.packageKey = PblPackage.DEFAULT_PACKAGE_NAME; realKey = new StringBuilder().append(PblPackage.DEFAULT_PACKAGE_NAME).append(".").append(realKey) .toString(); } setKey(realKey); }