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.link.LinkUtil.java
/** * Make a absolute path relative. It adds ../ until the root is reached * @param absolutePath absolute path/*from ww w . j av a2 s .c o m*/ * @param url page to be relative to * @return relative path */ public static String makePathRelative(String url, String absolutePath) { String fromPath = StringUtils.substringBeforeLast(url, "/"); String toPath = StringUtils.substringBeforeLast(absolutePath, "/"); // reference to parent folder if (StringUtils.equals(fromPath, toPath) && StringUtils.endsWith(absolutePath, "/")) { return "."; } String[] fromDirectories = StringUtils.split(fromPath, "/"); String[] toDirectories = StringUtils.split(toPath, "/"); int pos = 0; while (pos < fromDirectories.length && pos < toDirectories.length && fromDirectories[pos].equals(toDirectories[pos])) { pos++; } StringBuilder rel = new StringBuilder(); for (int i = pos; i < fromDirectories.length; i++) { rel.append("../"); } for (int i = pos; i < toDirectories.length; i++) { rel.append(toDirectories[i] + "/"); } rel.append(StringUtils.substringAfterLast(absolutePath, "/")); return rel.toString(); }
From source file:com.htmlhifive.tools.codeassist.core.proposal.checker.AbstractSuffixProposalChecker.java
/** * ??????????.<br>/*from www . ja v a 2 s. c om*/ * ?????????true?.<br> * ???false. * * @return ?????????. */ private boolean checkParentObjController() { String addedObjectName = null; Pattern suffixPattern = getBean().getRegExPattern(); if (suffixPattern.matcher(this.getCodeAssistStr()).matches()) { addedObjectName = this.getCodeAssistStr(); } else { addedObjectName = StringUtils.substringBeforeLast(this.getCodeAssistStr().toString(), "."); } this.addDummyCodeInfoList(new DelegateDummyCodeInfo(memberAccess.sourceEnd() + 1, addedObjectName, CodeBuilderType.REFERENCE_OBJ)); // } return true; }
From source file:edu.cornell.kfs.vnd.batch.service.impl.VendorBatchServiceImpl.java
/** * Clears out associated .done files for the processed data files. * //ww w. j av a 2 s.c om * @param dataFileNames */ protected void removeDoneFiles(List<String> dataFileNames) { for (String dataFileName : dataFileNames) { File doneFile = new File(StringUtils.substringBeforeLast(dataFileName, ".") + ".done"); if (doneFile.exists()) { doneFile.delete(); } } }
From source file:acromusashi.stream.tools.ConfigPutTool.java
/** * Put file to remote server./* w ww. j ava2 s . com*/ * * @param connection Ssh Connection * @param srcPath src Path * @param dstPath dst Path * @throws IOException Put failed */ private void putFile(Connection connection, String srcPath, String dstPath) throws IOException { SCPClient client = new SCPClient(connection); File srcFile = new File(srcPath); String dstFileDir = StringUtils.substringBeforeLast(dstPath, PATH_DELIMETER); String dstFileName = StringUtils.substringAfterLast(dstPath, PATH_DELIMETER); try (BufferedInputStream in = new BufferedInputStream(new FileInputStream(srcFile)); SCPOutputStream out = client.put(dstFileName, srcFile.length(), dstFileDir, "0664");) { IOUtils.copy(in, out); } catch (IOException ex) { throw ex; } }
From source file:eionet.cr.dao.virtuoso.VirtuosoFolderDAO.java
@Override public boolean fileOrFolderExists(String folderUri) throws DAOException { // Make sure we have valid inputs. if (StringUtils.isBlank(folderUri)) { throw new IllegalArgumentException("Folder URI must not be blank!"); }//from ww w . j a v a 2 s . c o m String parentFolderUri = StringUtils.substringBeforeLast(folderUri, "/"); Bindings bindings = new Bindings(); bindings.setURI("parentFolder", parentFolderUri); bindings.setURI("folderUri", folderUri); bindings.setURI("crFolder", Subjects.CR_FOLDER); bindings.setURI("crHasFolder", Predicates.CR_HAS_FOLDER); bindings.setURI("crHasFile", Predicates.CR_HAS_FILE); StringBuilder sb = new StringBuilder(); sb.append(SPARQLQueryUtil.getCrInferenceDefinitionStr()); sb.append("select count(*) where { "); sb.append("?parentFolder ?p ?o . "); sb.append("filter (?p IN (?crHasFolder, ?crHasFile)) . "); sb.append("filter (?o = ?folderUri) } "); String result = executeUniqueResultSPARQL(sb.toString(), bindings, new SingleObjectReader<String>()); if (Integer.parseInt(result) > 0) { return true; } return false; }
From source file:com.google.gdt.eclipse.designer.core.GTestUtils.java
/** * Creates new GWT module.//from w ww. j a v a 2s . co m * * @param moduleId * the id of module, such as <code>com.mycompany.project.ImageViewer</code>. * * @return the module {@link IFile}. */ public static IFile createModule(TestProject testProject, String moduleId) throws Exception { IProject project = testProject.getProject(); Assert.isTrue(moduleId.contains("."), "Given module name '%s' is not fully qualifed.", moduleId); String packageName = StringUtils.substringBeforeLast(moduleId, "."); String shortModuleName = StringUtils.substringAfterLast(moduleId, "."); String publicFolderPath = WebUtils.getWebFolderName(project) + "/"; IPackageFragment modulePackage = testProject.getPackage(packageName); // *.gwt.xml IFile moduleFile; { String entryPointTypeName = packageName + ".client." + shortModuleName; String source = DesignerTestCase .getDoubleQuotes2(new String[] { "<module>", " <inherits name='com.google.gwt.user.User'/>", //" <inherits name='com.google.gwt.user.theme.standard.Standard'/>", " <entry-point class='" + entryPointTypeName + "'/>", "</module>" }); moduleFile = testProject.createFile(modulePackage, shortModuleName + ".gwt.xml", source); } // "client" package { IPackageFragment clientPackage = testProject.getPackage(packageName + ".client"); testProject.createUnit(clientPackage, shortModuleName + ".java", DesignerTestCase.getSourceDQ("package " + clientPackage.getElementName() + ";", "import com.google.gwt.core.client.EntryPoint;", "import com.google.gwt.user.client.ui.RootPanel;", "public class " + shortModuleName + " implements EntryPoint {", " public void onModuleLoad() {", " RootPanel rootPanel = RootPanel.get();", " }", "}")); } // "public" resources { // HTML { String docType = ""; if (Utils.getVersion(project).isHigherOrSame(Utils.GWT_2_0)) { docType += "<!doctype html>"; } // String html = DesignerTestCase.getSourceDQ(docType, "<html>", " <head>", " <title>Wrapper HTML for GWT module</title>", " <meta name='gwt:module' content='" + moduleId + "'/>", " <link type='text/css' rel='stylesheet' href='" + shortModuleName + ".css'/>", " </head>", " <body>", " <script language='javascript' src='" + moduleId + ".nocache.js'></script>", " <iframe id='__gwt_historyFrame' style='width:0;height:0;border:0'></iframe>", " </body>", "</html>"); setFileContent(project, publicFolderPath + "/" + shortModuleName + ".html", html); } // CSS { String css = DesignerTestCase.getSourceDQ("body {", " background-color: white;", " font: 18px Arial;", "}", ".gwt-Button {", " overflow: visible;", "}", "td {", " font: 18px Arial;", " padding: 0px;", "}", "a {", " color: darkblue;", "}", ".gwt-TabLayoutPanelTab {", " float: left;", " border: 1px solid #87b3ff;", " padding: 2px;", " cursor: hand;", "}", ".gwt-TabLayoutPanelTab-selected {", " font-weight: bold;", " background-color: #e8eef7;", " cursor: default;", "}"); setFileContent(project, publicFolderPath + "/" + shortModuleName + ".css", css); } // images { TestUtils.createImagePNG(testProject, publicFolderPath + "/1.png", 16, 16); TestUtils.createImagePNG(testProject, publicFolderPath + "/2.png", 16, 16); } } // web.xml { String content = DesignerTestCase.getSourceDQ(new String[] { "<?xml version='1.0' encoding='UTF-8'?>", "<!DOCTYPE web-app", " PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'", " 'http://java.sun.com/dtd/web-app_2_3.dtd'>", "", "<web-app>", "", " <!-- Default page to serve -->", " <welcome-file-list>", " <welcome-file>" + shortModuleName + ".html</welcome-file>", " </welcome-file-list>", "", "</web-app>" }); setFileContent(project, publicFolderPath + "/WEB-INF/web.xml", content); } // "server" package testProject.getPackage(packageName + ".server"); // done return moduleFile; }
From source file:info.magnolia.cms.core.HierarchyManager.java
/** * Like getContent() but creates the node if not yet existing. Attention save is not called! * @param path the path of the node/*from w w w . j av a 2 s. com*/ * @param create true if the node should get created * @param type the node type of the created node * @return the node * @throws AccessDeniedException * @throws RepositoryException */ public Content getContent(String path, boolean create, ItemType type) throws AccessDeniedException, RepositoryException { Content node; try { node = getContent(path); } catch (PathNotFoundException e) { if (create) { node = this.createContent(StringUtils.substringBeforeLast(path, "/"), StringUtils.substringAfterLast(path, "/"), type.toString()); } else { throw e; } } return node; }
From source file:it.latraccia.dss.util.builder.SignatureBuilder.java
/** * Suggest the target file name./* w w w . java 2s. c o m*/ * Original code in {@link eu.europa.ec.markt.dss.applet.wizard.signature.SaveStep#prepareTargetFileName(java.io.File, * eu.europa.ec.markt.dss.signature.SignaturePackaging, String)} * * @param file The selected file to sign * @param signaturePackaging The selected packaging * @param signatureFormat The complete signature format (e.g. "CAdES") * @return The suggested target File */ private File prepareTargetFileName(final File file, final SignaturePackaging signaturePackaging, final String signatureFormat) { final File parentDir = file.getParentFile(); final String originalName = StringUtils.substringBeforeLast(file.getName(), "."); final String originalExtension = "." + StringUtils.substringAfterLast(file.getName(), "."); final String format = signatureFormat.toUpperCase(); if ((SignaturePackaging.ENVELOPING == signaturePackaging || SignaturePackaging.DETACHED == signaturePackaging) && format.startsWith("XADES")) { return new File(parentDir, originalName + "-signed" + ".xml"); } if (format.startsWith("CADES") && !originalExtension.toLowerCase().equals(".p7m")) { return new File(parentDir, originalName + originalExtension + ".p7m"); } if (format.startsWith("ASIC")) { return new File(parentDir, originalName + originalExtension + ".asics"); } return new File(parentDir, originalName + "-signed" + originalExtension); }
From source file:com.adobe.acs.commons.mcp.impl.processes.renovator.RenovatorTest.java
private ResourceResolver getEnhancedMockResolver() throws RepositoryException, LoginException, PersistenceException { rr = getFreshMockResolver();/*w w w . j a v a 2 s .c o m*/ for (Map.Entry<String, String> entry : testNodes.entrySet()) { String path = entry.getKey(); String type = entry.getValue(); AbstractResourceImpl mockFolder = new AbstractResourceImpl(path, type, "", new ResourceMetadata()); mockFolder.getResourceMetadata().put(JCR_PRIMARYTYPE, type); when(rr.resolve(path)).thenReturn(mockFolder); when(rr.getResource(path)).thenReturn(mockFolder); } for (Map.Entry<String, String> entry : testNodes.entrySet()) { String parentPath = StringUtils.substringBeforeLast(entry.getKey(), "/"); if (rr.getResource(parentPath) != null) { AbstractResourceImpl parent = ((AbstractResourceImpl) rr.getResource(parentPath)); AbstractResourceImpl node = (AbstractResourceImpl) rr.getResource(entry.getKey()); parent.addChild(node); } } Session ses = mock(Session.class); when(ses.nodeExists(any())).thenReturn(true); // Needed to prevent MovingFolder.createFolder from going berserk when(rr.adaptTo(Session.class)).thenReturn(ses); Workspace wk = mock(Workspace.class); ObservationManager om = mock(ObservationManager.class); when(ses.getWorkspace()).thenReturn(wk); when(wk.getObservationManager()).thenReturn(om); AccessControlManager acm = mock(AccessControlManager.class); when(ses.getAccessControlManager()).thenReturn(acm); when(acm.privilegeFromName(any())).thenReturn(mock(Privilege.class)); return rr; }
From source file:mitm.common.mail.EmailAddressUtils.java
/** * Returns the local part of an email address ie. everything before the @. If there is no @ the complete string is * returned. The email address is not normalized or validated. It's up to the caller to validate the email address. * If there is no local part null is returned. *///from w w w . j a va 2 s .co m public static String getLocalPart(String email) { String local = StringUtils.substringBeforeLast(email, "@"); if (StringUtils.isEmpty(local)) { local = null; } return local; }