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.importexport.DataTransporter.java
/** * @param file// w w w .ja va 2 s.c o m * @return XSL stream for Xml file or <code>null</code> */ protected static InputStream getXslStreamForXmlFile(File file) { InputStream xslStream = null; String xlsFilename = StringUtils.substringBeforeLast(file.getAbsolutePath(), ".") + ".xsl"; File xslFile = new File(xlsFilename); if (xslFile.exists()) { try { xslStream = new FileInputStream(xslFile); log.info("XSL file for [" + file.getName() + "] found (" + xslFile.getName() + ")"); } catch (FileNotFoundException e) { // should never happen (xslFile.exists()) e.printStackTrace(); } } return xslStream; }
From source file:com.wwinsoft.modules.orm.hibernate.HibernateDao.java
private String getRealPropertyName(String propertyName, ResolveAlias ra) { if (propertyName.indexOf(".") == -1) { //?/*w w w . j a v a 2s . c o m*/ return propertyName; } else { //? String association = StringUtils.substringBeforeLast(propertyName, "."); String property = StringUtils.substringAfterLast(propertyName, "."); String aliasName = ra.createAlias(association); return aliasName + "." + property; } }
From source file:com.rsmart.kuali.kfs.sys.batch.service.impl.BatchFeedHelperServiceImpl.java
/** * @see com.rsmart.kuali.kfs.sys.batch.service.BatchFeedHelperService#removeDoneFile(java.lang.String) *///from w w w.j a v a2 s . c o m public void removeDoneFile(String dataFileName) { File doneFile = new File(StringUtils.substringBeforeLast(dataFileName, ".") + ".done"); if (doneFile.exists()) { doneFile.delete(); } }
From source file:com.iorga.webappwatcher.EventLogManager.java
public static ObjectInputStream readLog(InputStream inputStream, String fileName) throws FileNotFoundException, IOException { if (fileName.endsWith(".gz")) { inputStream = new GZIPInputStream(inputStream); fileName = StringUtils.substringBeforeLast(fileName, ".gz"); } else if (fileName.endsWith(".xz")) { inputStream = new XZInputStream(inputStream); fileName = StringUtils.substringBeforeLast(fileName, ".xz"); }//from w w w .j ava2 s .c om if (fileName.endsWith(".ser")) { return new DecompressibleObjectInputStream(inputStream); } else { throw new IllegalArgumentException("Filename must end with .ser, .ser.gz or .ser.xz"); } }
From source file:com.adobe.acs.commons.mcp.impl.processes.renovator.Renovator.java
private void buildMoveTree(Resource r, int level, MovingNode root, AtomicInteger visitedSourceNodes) throws RepositoryException { if (level > 0) { Actions.setCurrentItem(r.getPath()); Optional<MovingNode> node = buildMoveNode(r); if (node.isPresent()) { MovingNode childNode = node.get(); String parentPath = StringUtils.substringBeforeLast(r.getPath(), "/"); MovingNode parent = root.findByPath(parentPath).orElseThrow( () -> new RepositoryException("Unable to find data structure for node " + parentPath)); parent.addChild(childNode);//from www. j ava 2 s . c o m if (detailedReport) { note(childNode.getSourcePath(), Report.target, childNode.getDestinationPath()); } visitedSourceNodes.addAndGet(1); } } }
From source file:info.magnolia.module.admininterface.AdminTreeMVCHandler.java
public String renameNode(String newLabel) throws AccessDeniedException, ExchangeException, PathNotFoundException, RepositoryException { String returnValue;//from w w w. ja va 2 s.c om String parentPath = StringUtils.substringBeforeLast(this.getPath(), "/"); //$NON-NLS-1$ newLabel = Path.getValidatedLabel(newLabel); // don't rename if it uses the same name as the current if (this.getPath().endsWith("/" + newLabel)) { return newLabel; } String dest = parentPath + "/" + newLabel; //$NON-NLS-1$ if (getHierarchyManager().isExist(dest)) { newLabel = Path.getUniqueLabel(getHierarchyManager(), parentPath, newLabel); dest = parentPath + "/" + newLabel; //$NON-NLS-1$ } this.deActivateNode(this.getPath()); if (log.isInfoEnabled()) { log.info("Moving node from " + this.getPath() + " to " + dest); //$NON-NLS-1$ //$NON-NLS-2$ } if (getHierarchyManager().isNodeData(this.getPath())) { Content parentPage = getHierarchyManager().getContent(parentPath); NodeData newNodeData = parentPage.createNodeData(newLabel); NodeData existingNodeData = getHierarchyManager().getNodeData(this.getPath()); newNodeData.setValue(existingNodeData.getString()); existingNodeData.delete(); dest = parentPath; } else { // we can't rename a node. we must move // we must place the node at the same position Content current = getHierarchyManager().getContent(this.getPath()); Content parent = current.getParent(); String placedBefore = null; for (Iterator iter = parent.getChildren(current.getNodeTypeName()).iterator(); iter.hasNext();) { Content child = (Content) iter.next(); if (child.getHandle().equals(this.getPath())) { if (iter.hasNext()) { child = (Content) iter.next(); placedBefore = child.getName(); } } } getHierarchyManager().moveTo(this.getPath(), dest); // now set at the same place as before if (placedBefore != null) { parent.orderBefore(newLabel, placedBefore); } } Content newPage = getHierarchyManager().getContent(dest); returnValue = newLabel; newPage.updateMetaData(); newPage.save(); return returnValue; }
From source file:com.tesora.dve.mysqlapi.repl.MyReplicationSlaveService.java
private String stripPort(String address) { if (address == null) return null; return StringUtils.substringBeforeLast(address, ":"); }
From source file:info.magnolia.cms.module.ModuleUtil.java
/** * Register a repository/* ww w . j a va2 s. c o m*/ * @param repositoryName * @param nodeTypeFile * @return <code>true</code> if a repository is registered or <code>false</code> if it was already existing * @throws RegisterException */ public static boolean registerRepository(String repositoryName, String nodeTypeFile) throws RegisterException { Document doc; try { doc = getRepositoryDefinitionDocument(); } catch (JDOMException e) { throw new RegisterException("Failed to read magnolia repositories config file", e); } catch (IOException e) { throw new RegisterException("Failed to read magnolia repositories config file", e); } // check if there try { Element node = (Element) XPath.selectSingleNode(doc, "/JCR/Repository[@name='" + repositoryName + "']"); if (node == null) { // create node = new Element("Repository"); String provider = ((Element) XPath.selectSingleNode(doc, "/JCR/Repository[@name='magnolia']")) .getAttributeValue("provider"); String configFile = ((Element) XPath.selectSingleNode(doc, "/JCR/Repository[@name='magnolia']/param[@name='configFile']")).getAttributeValue("value"); String repositoryHome = ((Element) XPath.selectSingleNode(doc, "/JCR/Repository[@name='magnolia']/param[@name='repositoryHome']")) .getAttributeValue("value"); repositoryHome = StringUtils.substringBeforeLast(repositoryHome, "/") + "/" + repositoryName; String contextFactoryClass = ((Element) XPath.selectSingleNode(doc, "/JCR/Repository[@name='magnolia']/param[@name='contextFactoryClass']")) .getAttributeValue("value"); String providerURL = ((Element) XPath.selectSingleNode(doc, "/JCR/Repository[@name='magnolia']/param[@name='providerURL']")).getAttributeValue("value"); String bindName = ((Element) XPath.selectSingleNode(doc, "/JCR/Repository[@name='magnolia']/param[@name='bindName']")).getAttributeValue("value"); bindName = StringUtils.replace(bindName, "magnolia", repositoryName); node.setAttribute("name", repositoryName); node.setAttribute("id", repositoryName); node.setAttribute("loadOnStartup", "true"); node.setAttribute("provider", provider); node.addContent( new Element("param").setAttribute("name", "configFile").setAttribute("value", configFile)); node.addContent(new Element("param").setAttribute("name", "repositoryHome").setAttribute("value", repositoryHome)); node.addContent(new Element("param").setAttribute("name", "contextFactoryClass") .setAttribute("value", contextFactoryClass)); node.addContent(new Element("param").setAttribute("name", "providerURL").setAttribute("value", providerURL)); node.addContent( new Element("param").setAttribute("name", "bindName").setAttribute("value", bindName)); if (StringUtils.isNotEmpty(nodeTypeFile)) { node.addContent(new Element("param").setAttribute("name", "customNodeTypes") .setAttribute("value", nodeTypeFile)); } // add a workspace node.addContent(new Element("workspace").setAttribute("name", repositoryName)); doc.getRootElement().addContent(node); // make the mapping node = new Element("Map"); node.setAttribute("name", repositoryName).setAttribute("repositoryName", repositoryName); // add it doc.getRootElement().getChild("RepositoryMapping").addContent(node); // save it XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(doc, new FileWriter(getRepositoryDefinitionFile())); return true; } else if (nodeTypeFile != null) { // this never requires a restart ModuleUtil.registerNodetypes(repositoryName, nodeTypeFile); return false; } } catch (IOException e) { log.error("Can't register repository. Unable to write modified file.", e); throw new RegisterException("Can't register repository. Unable to write modified file.", e); } catch (JDOMException e) { log.error("can't register repository", e); throw new RegisterException("can't register repository", e); } return false; }
From source file:com.adobe.acs.tools.csv_asset_importer.impl.CsvAssetImporterServlet.java
/** * Gets an existing Asset to update or creates a new Asset. * * @param resourceResolver the resource resolver * @param params the CSV Asset Importer params * @param columns the Columns of the CSV * @param row a row in the CSV * @return the Asset//from w w w . ja va 2s .c o m * @throws FileNotFoundException * @throws RepositoryException * @throws CsvAssetImportException */ private Asset getOrCreateAsset(final ResourceResolver resourceResolver, final Parameters params, final Map<String, Column> columns, final String[] row) throws FileNotFoundException, RepositoryException, CsvAssetImportException { final AssetManager assetManager = resourceResolver.adaptTo(AssetManager.class); String uniqueId = null; if (StringUtils.isNotBlank(params.getUniqueProperty())) { uniqueId = row[columns.get(params.getUniqueProperty()).getIndex()]; } String srcPath = null; // SrcPath is optional; If blank then process as an update properties strategy if (StringUtils.isNotBlank(params.getFileLocation()) && !StringUtils.equals("/dev/null", params.getFileLocation()) && StringUtils.isNotBlank(params.getRelSrcPathProperty()) && StringUtils.isNotBlank(row[columns.get(params.getRelSrcPathProperty()).getIndex()])) { srcPath = params.getFileLocation() + "/" + row[columns.get(params.getRelSrcPathProperty()).getIndex()]; log.debug("Row points to a file to import [ {} ]", srcPath); } final String mimeType = this.getMimeType(params, columns, row); final String absTargetPath = row[columns.get(params.getAbsTargetPathProperty()).getIndex()]; if (StringUtils.endsWith(absTargetPath, "/")) { throw new CsvAssetImportException( "Absolute path [ " + absTargetPath + " ] is to a folder, not a file. Skipping"); } // Resolve the absolute target path Asset Asset asset = null; // If a uniqueProperty is specified, ensure the value matches if (StringUtils.isNotBlank(params.getUniqueProperty()) && StringUtils.isNotBlank(uniqueId)) { // Check for existing Assets asset = this.findExistingAsset(resourceResolver, row[columns.get(params.getAbsTargetPathProperty()).getIndex()], params.getUniqueProperty(), uniqueId); } else { final Resource assetResource = resourceResolver.getResource(absTargetPath); if (assetResource != null) { asset = DamUtil.resolveToAsset(assetResource); } } FileInputStream fileInputStream = null; if (srcPath != null) { fileInputStream = new FileInputStream(srcPath); } // Determine if a Asset Creation or Update is needed if (asset == null) { if (fileInputStream == null) { log.warn("Existing asset could not be found for [ {} ] and no src file can found to import", absTargetPath); } else { log.info("Existing asset could not be found for [ {} ], creating from [ {} ]", absTargetPath, srcPath); asset = this.createAsset(assetManager, absTargetPath, fileInputStream, mimeType); } } else { // Asset exists if (Parameters.ImportStrategy.DELTA.equals(params.getImportStrategy())) { if (!StringUtils.equals(asset.getPath(), absTargetPath)) { // If is metadata only then moving the existing asset final Session session = resourceResolver.adaptTo(Session.class); if (!session.nodeExists(absTargetPath)) { JcrUtils.getOrCreateByPath(StringUtils.substringBeforeLast(absTargetPath, "/"), "sling:OrderedFolder", session); } session.move(asset.getPath(), absTargetPath); log.info("Moved asset from [ {} ~> {} ]", asset.getPath(), absTargetPath); asset = DamUtil.resolveToAsset(resourceResolver.getResource(absTargetPath)); } // Partial Import, check if the original rendition should be updated if (params.isUpdateBinary()) { if (fileInputStream != null) { asset = this.updateAssetOriginal(asset, fileInputStream, mimeType); } else { log.info( "Delta import strategy with 'Update Binary' specified but no src was specified. Skipping updating of binary for [ {} ].", absTargetPath); } } } else if (Parameters.ImportStrategy.FULL.equals(params.getImportStrategy())) { // Remove existing asset so it can be recreated if (fileInputStream != null) { asset.adaptTo(Resource.class).adaptTo(Node.class).remove(); log.info("Removed existing asset so it can be re-created"); asset = this.createAsset(assetManager, absTargetPath, fileInputStream, mimeType); } else { log.info( "Full import strategy specified but no src was specified. Skipping re-creation of binary for [ {} ].", absTargetPath); } } } return asset; }
From source file:adalid.util.velocity.BaseBuilder.java
private void createTextFilePropertiesFile(String source, String target) { boolean java = StringUtils.endsWithIgnoreCase(source, ".java"); boolean bundle = StringUtils.endsWithIgnoreCase(source, ".properties"); File sourceFile = new File(source); String sourceFileName = sourceFile.getName(); String sourceFileSimpleName = StringUtils.substringBeforeLast(sourceFileName, "."); String sourceFolderName = sourceFile.getParentFile().getName(); String sourceFolderSimpleName = StringUtils.substringBeforeLast(sourceFolderName, "."); String sourceEntityName = getOptionalEntityName(sourceFileSimpleName, sourceFolderSimpleName); String properties = source.replace(projectFolderPath, velocityPlatformsTargetFolderPath) + ".properties"; String folder = StringUtils.substringBeforeLast(properties, FS); String template = StringUtils.substringAfter(target, velocityFolderPath + FS).replace(FS, "/"); String path = StringUtils.substringBeforeLast(StringUtils.substringAfter(source, projectFolderPath), FS) .replace(FS, "/").replace(project, PROJECT_ALIAS).replace("eclipse.settings", ".settings"); path = replaceAliasWithRootFolderName(path); String pack = null;//w w w . ja v a2 s . c o m if (java || bundle) { String s1 = StringUtils.substringAfter(path, SRC); if (StringUtils.contains(s1, PROJECT_ALIAS)) { String s2 = StringUtils.substringBefore(s1, PROJECT_ALIAS); String s3 = SRC + s2; String s4 = StringUtils.substringBefore(path, s3) + s3; String s5 = StringUtils.substringAfter(s1, PROJECT_ALIAS).replace("/", "."); path = StringUtils.removeEnd(s4, "/"); pack = ROOT_PACKAGE_NAME + s5; } } path = finalisePath(path); String file = StringUtils.substringAfterLast(source, FS).replace(project, PROJECT_ALIAS) .replace("eclipse.project", ".project"); List<String> lines = new ArrayList<>(); lines.add("template = " + template); // lines.add("template-type = velocity"); lines.add("path = " + path); if (StringUtils.isNotBlank(pack)) { lines.add("package = " + pack); } lines.add("file = " + file); if (sourceFileSimpleName.equals("eclipse") || sourceFolderSimpleName.equals("eclipse") || sourceFolderSimpleName.equals("nbproject")) { lines.add("disabled = true"); } else if (sourceEntityName != null) { lines.add("disabled-when-missing = " + sourceEntityName); } if (source.endsWith(".css") || source.endsWith(".jrtx")) { lines.add("preserve = true"); } else if (ArrayUtils.contains(preservableFiles, sourceFileName)) { lines.add("preserve = true"); } lines.add("dollar.string = $"); lines.add("pound.string = #"); lines.add("backslash.string = \\\\"); FilUtils.mkdirs(folder); if (write(properties, lines, WINDOWS_CHARSET)) { propertiesFilesCreated++; } }