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.test.mock.jcr.MockSession.java
@Override public Property getProperty(String absPath) throws RepositoryException { Node node = getNode(StringUtils.substringBeforeLast(absPath, "/")); return node.getProperty(StringUtils.substringAfterLast(absPath, "/")); }
From source file:info.magnolia.importexport.BootstrapUtil.java
/** * I.e. given a resource path like <code>/mgnl-bootstrap/foo/config.server.i18n.xml</code> it will return <code>/server</code>. *///from w w w. j a v a 2s. co m public static String getPathnameFromResource(final String resourcePath) { String resourceName = StringUtils.replace(resourcePath, "\\", "/"); String name = getFilenameFromResource(resourceName, ".xml"); String fullPath = DataTransporter.revertExportPath(name); String pathName = StringUtils.substringAfter(StringUtils.substringBeforeLast(fullPath, "/"), "/"); if (!pathName.startsWith("/")) { pathName = "/" + pathName; } return pathName; }
From source file:com.nfl.dm.clubsites.cms.articles.subapp.articleeditor.ArticleEditorSubApp.java
@Override public ArticleEditorSubAppView start(Location location) { DetailLocation detailLocation = DetailLocation.wrap(location); super.start(detailLocation); String nodePath = detailLocation.getNodePath(); try {//from w w w.jav a 2 s .com Session session = MgnlContext.getJCRSession("articles"); if (session.nodeExists(nodePath) && session.getNode(nodePath).getPrimaryNodeType().getName() .equals(NFLNodeTypes.NFLArticle.NAME)) { Node node = SessionUtil.getNode("articles", nodePath); articleItem = new JcrNodeAdapter(node); } else { String parentPath = StringUtils.substringBeforeLast(nodePath, "/"); parentPath = parentPath.isEmpty() ? "/" : parentPath; Node parent = session.getNode(parentPath); Node articleNode = NodeUtil.createPath(parent, detailLocation.getNodePath(), NFLNodeTypes.NFLArticle.NAME); articleNode.setProperty(NodeTypes.Renderable.TEMPLATE, "cs-articles-module:pages/cs-articles-module"); articleNode.getSession().save(); articleItem = new JcrNodeAdapter(articleNode); } } catch (RepositoryException e) { throw new RuntimeException(e); } HeaderView headerView = headerPresenter.start(articleItem); subAppView.setHeader(headerView); NavigationView navigationView = navigationPresenter.start(); subAppView.setNavigator(navigationView); articleEditorViews.put(ViewType.LayoutEditor, layoutEditorPresenter.start(articleItem)); articleEditorViews.put(ViewType.Promote, promotionPresenter.start(articleItem)); articleEditorViews.put(ViewType.Summary, umbrellaContentPresenter.start(articleItem)); articleEditorViews.put(ViewType.Tags, taggingPresenter.start(articleItem)); articleEditorViews.put(ViewType.BodyEditor, bodyEditorPresenter.start(articleItem)); subAppView.setCurrentView(articleEditorViews.get(ViewType.BodyEditor)); ((NavigationViewImpl) navigationView).getComponent(2).addStyleName("selected"); return subAppView; }
From source file:info.magnolia.cms.gui.control.Tree.java
/** * Sets which path will be selected (and opened - overwrites pathOpen). * @param s//from w w w . ja va2 s . co m */ public void setPathSelected(String s) { if (StringUtils.isNotEmpty(s)) { if (StringUtils.isEmpty(this.getPathOpen())) { this.setPathOpen(StringUtils.substringBeforeLast(s, "/")); //$NON-NLS-1$ } } this.pathSelected = s; }
From source file:info.magnolia.cms.filters.AggregatorFilter.java
/** * Collect content from the pre configured repository and attach it to the HttpServletRequest. * @throws PathNotFoundException/* ww w. j av a 2 s. c om*/ * @throws RepositoryException */ protected boolean collect() throws RepositoryException { final AggregationState aggregationState = MgnlContext.getAggregationState(); final String handle = aggregationState.getHandle(); final String repository = aggregationState.getRepository(); final HierarchyManager hierarchyManager = MgnlContext.getHierarchyManager(repository); Content requestedPage = null; NodeData requestedData = null; String templateName; if (!isJcrPathValid(handle)) { // avoid calling isExist if the path can't be valid return false; } if (hierarchyManager.isExist(handle) && !hierarchyManager.isNodeData(handle)) { requestedPage = hierarchyManager.getContent(handle); // check if its a request for a versioned page if (MgnlContext.getAttribute(VERSION_NUMBER) != null) { // get versioned state try { requestedPage = requestedPage .getVersionedContent((String) MgnlContext.getAttribute(VERSION_NUMBER)); } catch (RepositoryException re) { log.debug(re.getMessage(), re); log.error("Unable to get versioned state, rendering current state of {}", handle); } } try { templateName = NodeTypes.Renderable.getTemplate(requestedPage.getJCRNode()); } catch (RepositoryException e) { templateName = null; } if (StringUtils.isBlank(templateName)) { log.error("No template configured for page [{}].", requestedPage.getHandle()); } } else { if (hierarchyManager.isNodeData(handle)) { requestedData = hierarchyManager.getNodeData(handle); } else { // check again, resource might have different name int lastIndexOfSlash = handle.lastIndexOf("/"); if (lastIndexOfSlash > 0) { final String handleToUse = StringUtils.substringBeforeLast(handle, "/"); try { requestedData = hierarchyManager.getNodeData(handleToUse); aggregationState.setHandle(handleToUse); // this is needed for binary nodedata, e.g. images are found using the path: // /features/integration/headerImage instead of /features/integration/headerImage/header30_2 } catch (PathNotFoundException e) { // no page available return false; } catch (RepositoryException e) { log.debug(e.getMessage(), e); return false; } } } if (requestedData != null) { templateName = requestedData.getAttribute(FileProperties.PROPERTY_TEMPLATE); } else { return false; } } // Attach all collected information to the HttpServletRequest. if (requestedPage != null) { aggregationState.setMainContent(requestedPage); aggregationState.setCurrentContent(requestedPage); } if ((requestedData != null) && (requestedData.getType() == PropertyType.BINARY)) { File file = new File(requestedData); aggregationState.setFile(file); } aggregationState.setTemplateName(templateName); return true; }
From source file:info.magnolia.importexport.DataTransporter.java
/** * @param xmlFile/*from w ww.ja va 2 s. co m*/ * @param repositoryName * @throws IOException */ public static void executeBootstrapImport(File xmlFile, String repositoryName) throws IOException { String filenameWithoutExt = StringUtils.substringBeforeLast(xmlFile.getName(), DOT); if (filenameWithoutExt.endsWith(XML)) { // if file ends in .xml.gz or .xml.zip // need to keep the .xml to be able to view it after decompression filenameWithoutExt = StringUtils.substringBeforeLast(xmlFile.getName(), DOT); } String pathName = StringUtils.substringAfter(StringUtils.substringBeforeLast(filenameWithoutExt, DOT), DOT); pathName = decodePath(pathName, UTF8); String basepath = SLASH + StringUtils.replace(pathName, DOT, SLASH); if (xmlFile.getName().endsWith(PROPERTIES)) { Properties properties = new Properties(); FileInputStream stream = new FileInputStream(xmlFile); properties.load(stream); stream.close(); importProperties(properties, repositoryName); } else { DataTransporter.importFile(xmlFile, repositoryName, basepath, false, BOOTSTRAP_IMPORT_MODE, true, true); } }
From source file:eu.annocultor.data.destinations.SolrServer.java
@Override public void writeTriple(Triple triple) throws Exception { if (subjectChanged(triple)) { lastWrittenUri = triple.getSubject(); if (isPreamptiveFlushNeeded()) { flush();//from w w w .j a va 2s. co m } log.info("Starting document " + lastWrittenUri); documents.add(new SolrInputDocument()); } String property = extractSolrProperty(triple); // if (Concepts.ANNOCULTOR.PERIOD_BEGIN.getUri().equals(property)) { // property = "enrichment_time_begin"; // } // if (Concepts.ANNOCULTOR.PERIOD_END.getUri().equals(property)) { // property = "enrichment_time_end"; // } // FieldDefinition fieldDefinition = fieldDefinitions.get(property); if (fieldDefinition == null) { System.out.println("Field " + property + " does not have exact match. Trying wildcards assuming that they have form blabla.*"); String wildcarded = StringUtils.substringBeforeLast(property, ".") + ".*"; fieldDefinition = fieldDefinitions.get(wildcarded); } if (fieldDefinition == null) { System.out.println("Skipped " + property + " because it is not defined"); // throw new Exception("Field " + triple.getProperty() + " is not defined in schema.xml"); } else { // if (fieldDefinition.dataType) System.out.println("Add " + property + "-" + triple.getValue().getValue() + " of type " + fieldDefinition.dataType); Object value = triple.getValue().getValue(); if (fieldDefinition.dataType.equals("tdate")) { System.out.println("Recognized type tdate"); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); format.setTimeZone(TimeZone.getTimeZone("UTC")); value = format.parse(triple.getValue().getValue()); } if (fieldDefinition.isMultiValued()) { documents.peek().addField(property, value); } else { documents.peek().setField(property, value); } } }
From source file:gov.nih.nci.caarray.dataStorage.fileSystem.FilesystemDataStorage.java
private URI handleFromFile(File file) { final String fileName = file.getName(); if (fileName.endsWith(".comp")) { return makeHandle(StringUtils.substringBeforeLast(fileName, ".comp")); } else if (fileName.endsWith(".unc")) { return makeHandle(StringUtils.substringBeforeLast(fileName, ".unc")); } else {/*from w w w. j a v a 2 s . c o m*/ throw new IllegalArgumentException("File not managed by filestorage engine: " + fileName); } }
From source file:gobblin.data.management.retention.sql.SqlBasedRetentionPoc.java
private void insertDailyPartition(Path dailyPartitionPath) throws Exception { String datasetPath = StringUtils.substringBeforeLast(dailyPartitionPath.toString(), Path.SEPARATOR + "daily"); DateTime partition = DateTimeFormat.forPattern(DAILY_PARTITION_PATTERN) .parseDateTime(StringUtils.substringAfter(dailyPartitionPath.toString(), "daily" + Path.SEPARATOR)); PreparedStatement insert = connection.prepareStatement("INSERT INTO Daily_Partitions VALUES (?, ?, ?)"); insert.setString(1, datasetPath);// w w w . j av a2 s. c om insert.setString(2, dailyPartitionPath.toString()); insert.setTimestamp(3, new Timestamp(partition.getMillis())); insert.executeUpdate(); }
From source file:de.pdark.dsmp.RequestHandler.java
public File getPatchFile(URL url) { File dir = config.getPatchesDirectory(); File f = getCacheFile(url, dir); if (!f.exists()) { String ext = StringUtils.substringAfterLast(url.getPath(), ".").toLowerCase(); if ("md5".equals(ext) || "sha1".equals(ext)) { File source = new File(StringUtils.substringBeforeLast(f.getAbsolutePath(), ".")); if (source.exists()) { generateChecksum(source, f, ext); }//from w w w. jav a2s .c o m } } return f; }