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:org.gradle.util.TemporaryFolder.java
private String determinePrefix() { StackTraceElement[] stackTrace = new RuntimeException().getStackTrace(); for (StackTraceElement element : stackTrace) { if (element.getClassName().endsWith("Test")) { return StringUtils.substringAfterLast(element.getClassName(), ".") + "/unknown-test"; }/*from w ww . ja v a2 s . c o m*/ } return "unknown-test-class"; }
From source file:org.hippoecm.frontend.plugins.console.menu.rename.RenameDialog.java
@Override protected void onOk() { try {// ww w. ja va 2 s . co m JcrNodeModel nodeModel = (JcrNodeModel) modelReference.getModel(); if (nodeModel.getParentModel() != null) { JcrNodeModel parentModel = nodeModel.getParentModel(); Node parentNode = parentModel.getNode(); //This will be used to position the renamed node exactly where it was before the rename String nextSiblingPath = parentNode.getPrimaryNodeType().hasOrderableChildNodes() ? findNextSiblingPath(nodeModel.getNode()) : null; //The actual JCR move String oldPath = nodeModel.getNode().getPath(); String newPath = parentNode.getPath(); if (!newPath.endsWith("/")) { newPath += "/"; } newPath += getName(); Session jcrSession = UserSession.get().getJcrSession(); jcrSession.move(oldPath, newPath); JcrNodeModel newNodeModel = new JcrNodeModel(parentModel.getNode().getNode(getName())); //Re-order (because the rename action also positioned the renamed node last) if (nextSiblingPath != null) { String nextSiblingRelPath = StringUtils.substringAfterLast(nextSiblingPath, "/"); try { parentNode.orderBefore(getName(), nextSiblingRelPath); } catch (RepositoryException e) { log.error(e.getMessage(), e); } } modelReference.setModel(newNodeModel); } } catch (RepositoryException ex) { error(ex.getMessage()); } }
From source file:org.hippoecm.frontend.plugins.gallery.processor.ScalingGalleryProcessorPlugin.java
protected ScalingGalleryProcessor createScalingGalleryProcessor(IPluginConfig config) { final ScalingGalleryProcessor processor = new ScalingGalleryProcessor(); for (IPluginConfig scaleConfig : config.getPluginConfigSet()) { final String nodeName = StringUtils.substringAfterLast(scaleConfig.getName(), "."); if (!StringUtils.isEmpty(nodeName)) { final int width = scaleConfig.getAsInteger(CONFIG_PARAM_WIDTH, DEFAULT_WIDTH); final int height = scaleConfig.getAsInteger(CONFIG_PARAM_HEIGHT, DEFAULT_HEIGHT); final boolean upscaling = scaleConfig.getAsBoolean(CONFIG_PARAM_UPSCALING, DEFAULT_UPSCALING); final float compressionQuality = (float) scaleConfig.getAsDouble(CONFIG_PARAM_COMPRESSION, DEFAULT_COMPRESSION); final String strategyName = scaleConfig.getString(CONFIG_PARAM_OPTIMIZE, DEFAULT_OPTIMIZE); ImageUtils.ScalingStrategy strategy = SCALING_STRATEGY_MAP.get(strategyName); if (strategy == null) { log.warn(/*from ww w.jav a2 s. com*/ "Image variant '{}' specifies an unknown scaling optimization strategy '{}'. Possible values are {}. Falling back to '{}' instead.", nodeName, strategyName, SCALING_STRATEGY_MAP.keySet(), DEFAULT_OPTIMIZE); strategy = SCALING_STRATEGY_MAP.get(DEFAULT_OPTIMIZE); } final ScalingParameters parameters = new ScalingParameters(width, height, upscaling, strategy, compressionQuality); log.debug("Scaling parameters for {}: {}", nodeName, parameters); processor.addScalingParameters(nodeName, parameters); } } return processor; }
From source file:org.hippoecm.frontend.plugins.richtext.jcr.RichTextImageURLProvider.java
public String getURL(String link) throws RichTextException { final String facetName = StringUtils.substringBefore(link, "/"); final String type = StringUtils.substringAfterLast(link, "/"); final Node node = this.nodeModel.getObject(); final String uuid = RichTextFacetHelper.getChildDocBaseOrNull(node, facetName); if (uuid != null && linkFactory.getLinkUuids().contains(uuid)) { RichTextImage rti = imageFactory.loadImageItem(uuid, type); return rti.getUrl(); }// w w w .j av a 2 s. c om return link; }
From source file:org.hippoecm.frontend.plugins.standards.sort.NodeSortAction.java
public boolean moveUp() { if (moveUp) { //failsafe try {//from www .j av a 2 s . com Node node = nodeModel.getNode(); Node parentNode = node.getParent(); NodeIterator siblings = parentNode.getNodes(); long position = -1; while (siblings.hasNext()) { Node sibling = siblings.nextNode(); if (sibling != null && sibling.isSame(node)) { position = siblings.getPosition(); break; } } Node placedBefore = null; siblings = parentNode.getNodes(); for (int i = 0; i < position - 1; i++) { placedBefore = siblings.nextNode(); } String srcChildRelPath = StringUtils.substringAfterLast(node.getPath(), "/"); String destChildRelPath = placedBefore == null ? null : StringUtils.substringAfterLast(placedBefore.getPath(), "/"); parentNode.orderBefore(srcChildRelPath, destChildRelPath); moveUp = position > 2; moveDown = true; return true; } catch (RepositoryException e) { log.error(e.getMessage(), e); } } return false; }
From source file:org.hippoecm.frontend.plugins.standards.sort.NodeSortAction.java
public boolean moveDown() { if (moveDown) { //failsafe try {//from ww w. j av a2 s . co m Node node = nodeModel.getNode(); Node parentNode = node.getParent(); NodeIterator siblings = parentNode.getNodes(); Node placedBefore = null; while (siblings.hasNext()) { Node sibling = siblings.nextNode(); if (sibling.isSame(node)) { siblings.nextNode(); if (siblings.hasNext()) { placedBefore = siblings.nextNode(); } else { placedBefore = null; } break; } } String srcChildRelPath = StringUtils.substringAfterLast(node.getPath(), "/"); String destChildRelPath = placedBefore == null ? null : StringUtils.substringAfterLast(placedBefore.getPath(), "/"); parentNode.orderBefore(srcChildRelPath, destChildRelPath); moveUp = true; moveDown = placedBefore != null; return true; } catch (RepositoryException e) { log.error(e.getMessage(), e); } } return false; }
From source file:org.jahia.ajax.gwt.helper.NodeHelper.java
GWTJahiaNode getGWTJahiaNode(JCRNodeWrapper node, List<String> fields, Locale uiLocale) { if (fields == null) { fields = Collections.emptyList(); }/*from w ww. jav a 2 s . c om*/ GWTJahiaNode n = new GWTJahiaNode(); // get uuid try { n.setUUID(node.getIdentifier()); } catch (RepositoryException e) { logger.debug("Unable to get uuid for node " + node.getName(), e); } populateNames(n, node, uiLocale); populateDescription(n, node); n.setPath(node.getPath()); n.setUrl(node.getUrl()); populateNodeTypes(n, node); JCRStoreProvider provider = node.getProvider(); if (provider.isDynamicallyMounted()) { n.setProviderKey(StringUtils.substringAfterLast(provider.getMountPoint(), "/")); } else { n.setProviderKey(provider.getKey()); } if (fields.contains(GWTJahiaNode.PERMISSIONS)) { populatePermissions(n, node); } if (fields.contains(GWTJahiaNode.LOCKS_INFO) && !provider.isSlowConnection()) { populateLocksInfo(n, node); } if (fields.contains(GWTJahiaNode.VISIBILITY_INFO)) { populateVisibilityInfo(n, node); } n.setVersioned(node.isVersioned()); n.setLanguageCode(node.getLanguage()); populateSiteInfo(n, node); if (node.isFile()) { n.setSize(node.getFileContent().getContentLength()); } n.setFile(node.isFile()); n.setIsShared(false); try { if (node.isNodeType("mix:shareable") && node.getSharedSet().getSize() > 1) { n.setIsShared(true); } } catch (RepositoryException e) { logger.error("Error when getting shares", e); } try { n.setReference(node.isNodeType("jmix:nodeReference")); } catch (RepositoryException e1) { logger.error("Error checking node type", e1); } if (fields.contains(GWTJahiaNode.CHILDREN_INFO)) { populateChildrenInfo(n, node); } if (fields.contains(GWTJahiaNode.TAGS)) { populateTags(n, node); } // icons if (fields.contains(GWTJahiaNode.ICON)) { populateIcon(n, node); } populateThumbnails(n, node); // count if (fields.contains(GWTJahiaNode.COUNT)) { populateCount(n, node); } populateStatusInfo(n, node); if (supportsWorkspaceManagement(node)) { if (fields.contains(GWTJahiaNode.PUBLICATION_INFO)) { populatePublicationInfo(n, node); } if (fields.contains(GWTJahiaNode.QUICK_PUBLICATION_INFO)) { populateQuickPublicationInfo(n, node); } if (fields.contains(GWTJahiaNode.PUBLICATION_INFOS)) { populatePublicationInfos(n, node); } n.set("supportsPublication", supportsPublication(node)); } if (fields.contains(GWTJahiaNode.WORKFLOW_INFO) || fields.contains(GWTJahiaNode.PUBLICATION_INFO)) { populateWorkflowInfo(n, node, uiLocale); } if (fields.contains(GWTJahiaNode.WORKFLOW_INFOS)) { populateWorkflowInfos(n, node, uiLocale); } if (fields.contains(GWTJahiaNode.AVAILABLE_WORKKFLOWS)) { populateAvailableWorkflows(n, node); } if (fields.contains(GWTJahiaNode.PRIMARY_TYPE_LABEL)) { populatePrimaryTypeLabel(n, node); } JCRStoreProvider p = JCRSessionFactory.getInstance().getMountPoints().get(n.getPath()); if (p != null && p.isDynamicallyMounted()) { n.set("j:isDynamicMountPoint", Boolean.TRUE); } if (n.isFile() && (n.isNodeType("jmix:image") || n.isNodeType("jmix:size"))) { // handle width and height try { if (node.hasProperty("j:height")) { n.set("j:height", node.getProperty("j:height").getString()); } } catch (RepositoryException e) { logger.error("Cannot get property j:height on node {}", node.getPath()); } try { if (node.hasProperty("j:width")) { n.set("j:width", node.getProperty("j:width").getString()); } } catch (RepositoryException e) { logger.error("Cannot get property j:width on node {}", node.getPath()); } } if (fields.contains("j:view") && n.isNodeType("jmix:renderable")) { try { if (node.hasProperty("j:view")) { n.set("j:view", node.getProperty("j:view").getString()); } } catch (RepositoryException e) { logger.error("Cannot get property j:view on node {}", node.getPath()); } } if (fields.contains(GWTJahiaNode.SITE_LANGUAGES)) { populateSiteLanguages(n, node); } if ((node instanceof JCRSiteNode) && fields.contains("j:resolvedDependencies")) { populateDependencies(n, node); } if (fields.contains(GWTJahiaNode.SUBNODES_CONSTRAINTS_INFO)) { populateSubnodesConstraintsInfo(n, node); } if (fields.contains(GWTJahiaNode.DEFAULT_LANGUAGE)) { populateDefaultLanguage(n, node); } if ((node instanceof JCRSiteNode) && fields.contains(GWTJahiaNode.HOMEPAGE_PATH)) { populateHomePage(n, node); } Boolean isModuleNode = null; final JahiaTemplateManagerService templateManagerService = ServicesRegistry.getInstance() .getJahiaTemplateManagerService(); try { if (fields.contains("j:versionInfo")) { isModuleNode = node.isNodeType("jnt:module"); if (isModuleNode) { populateVersionInfoForModule(n, node); } } } catch (RepositoryException e) { logger.error("Cannot get property module version"); } // properties for (String field : fields) { if (!GWTJahiaNode.RESERVED_FIELDS.contains(field)) { try { if (field.startsWith("fields-")) { String type = field.substring("fields-".length()); PropertyIterator pi = node.getProperties(); while (pi.hasNext()) { JCRPropertyWrapper property = (JCRPropertyWrapper) pi.next(); if (((ExtendedPropertyDefinition) property.getDefinition()).getItemType() .equals(type)) { setPropertyValue(n, property, node.getSession()); } } } else if (node.hasProperty(field)) { final JCRPropertyWrapper property = node.getProperty(field); setPropertyValue(n, property, node.getSession()); } else if (isModuleNode != null ? isModuleNode.booleanValue() : (isModuleNode = node.isNodeType("jnt:module"))) { JahiaTemplatesPackage templatePackageByFileName = templateManagerService .getTemplatePackageById(node.getName()); if (templatePackageByFileName != null) { JCRNodeWrapper versionNode = node .getNode(templatePackageByFileName.getVersion().toString()); if (versionNode.hasProperty(field)) { final JCRPropertyWrapper property = versionNode.getProperty(field); setPropertyValue(n, property, node.getSession()); } } } } catch (RepositoryException e) { logger.error("Cannot get property {} on node {}", field, node.getPath()); } } } // versions if (fields.contains(GWTJahiaNode.VERSIONS) && node.isVersioned()) { populateVersions(n, node); } // resource bundle if (fields.contains(GWTJahiaNode.RESOURCE_BUNDLE)) { GWTResourceBundle b = GWTResourceBundleUtils.load(node, uiLocale); if (b != null) { n.set(GWTJahiaNode.RESOURCE_BUNDLE, b); } } populateReference(n, node, fields, uiLocale); populateOrdering(n, node); populateChildConstraints(n, node); populateWCAG(n, node); populateInvalidLanguages(n, node); List<String> installedModules = (List<String>) n.get("j:installedModules"); if (installedModules != null) { List<JahiaTemplatesPackage> s = new ArrayList<>(); LinkedHashMap<JahiaTemplatesPackage, List<JahiaTemplatesPackage>> deps = new LinkedHashMap<>(); for (String packId : installedModules) { JahiaTemplatesPackage pack = templateManagerService.getTemplatePackageById(packId); if (pack != null) { deps.put(pack, new ArrayList<JahiaTemplatesPackage>()); } } installedModules.clear(); for (Map.Entry<JahiaTemplatesPackage, List<JahiaTemplatesPackage>> entry : deps.entrySet()) { List<JahiaTemplatesPackage> allDeps = entry.getKey().getDependencies(); for (JahiaTemplatesPackage dep : allDeps) { if (deps.keySet().contains(dep)) { entry.getValue().add(dep); } } if (entry.getValue().isEmpty()) { s.add(entry.getKey()); } } while (!s.isEmpty()) { JahiaTemplatesPackage pack = s.remove(0); installedModules.add(pack.getId()); for (Map.Entry<JahiaTemplatesPackage, List<JahiaTemplatesPackage>> entry : deps.entrySet()) { if (entry.getValue().contains(pack)) { entry.getValue().remove(pack); if (entry.getValue().isEmpty()) { s.add(entry.getKey()); } } } } } return n; }
From source file:org.jahia.ajax.gwt.helper.SchedulerHelper.java
private List<GWTJahiaJobDetail> convertToGWTJobs(List<JobDetail> jobDetails) { List<GWTJahiaJobDetail> jobs = new ArrayList<GWTJahiaJobDetail>(); for (JobDetail jobDetail : jobDetails) { JobDataMap jobDataMap = jobDetail.getJobDataMap(); Date created = (Date) jobDataMap.get(BackgroundJob.JOB_CREATED); final String status = jobDataMap.getString(BackgroundJob.JOB_STATUS); final String user = StringUtils.substringAfterLast(jobDataMap.getString(BackgroundJob.JOB_USERKEY), "/"); final String message = jobDataMap.getString(BackgroundJob.JOB_MESSAGE); final Long beginTime = getLong(jobDataMap, BackgroundJob.JOB_BEGIN); final Long endTime = getLong(jobDataMap, BackgroundJob.JOB_END); final String site = jobDataMap.getString(BackgroundJob.JOB_SITEKEY); if (created == null && beginTime != null) { // this can happen for cron scheduler jobs. created = new Date(beginTime); }/*from w w w .ja v a2 s. c o m*/ Long duration = getLong(jobDataMap, BackgroundJob.JOB_DURATION); if ((duration == null) && (beginTime != null) && (endTime == null) && BackgroundJob.STATUS_EXECUTING.equals(status)) { // here we have a currently running job, let's calculate the duration until now. duration = System.currentTimeMillis() - beginTime.longValue(); } final String jobLocale = jobDataMap.getString(BackgroundJob.JOB_CURRENT_LOCALE); String targetNodeIdentifier = null; String targetAction = null; String targetWorkspace = null; // if ((jahiaUser != null) && (!jahiaUser.getUserKey().equals(user))) { // we must check whether the user has the permission to view other users's jobs // if (!jahiaUser.isPermitted(new PermissionIdentity("view-all-jobs"))) { // // he doesn't we skip this entry. // continue; // } // } String description = jobDetail.getDescription(); final List<String> targetPaths = new ArrayList<String>(); String fileName = jobDataMap.getString(ImportJob.FILENAME); if (BackgroundJob.getGroupName(PublicationJob.class).equals(jobDetail.getGroup())) { @SuppressWarnings("unchecked") List<GWTJahiaNodeProperty> publicationInfos = (List<GWTJahiaNodeProperty>) jobDataMap .get(PublicationJob.PUBLICATION_PROPERTIES); if (publicationInfos != null && publicationInfos.size() > 0) { description += " " + publicationInfos.get(0).getValues(); } List<String> publicationPathsFromJob = (List<String>) jobDataMap .get(PublicationJob.PUBLICATION_PATHS); // get target paths from job if specified, if not, use uuids to get the nodes if (publicationPathsFromJob != null && publicationPathsFromJob.size() > 0) { targetPaths.addAll(publicationPathsFromJob); } else { final List<String> uuids = (List<String>) jobDataMap.get("publicationInfos"); try { JCRTemplate.getInstance().doExecuteWithSystemSession(new JCRCallback<Object>() { @Override public Object doInJCR(JCRSessionWrapper session) throws RepositoryException { for (String uuid : uuids) { try { targetPaths.add(session.getNodeByIdentifier(uuid).getPath()); } catch (ItemNotFoundException e) { logger.debug("Cannot get item " + uuid, e); } } return null; } }); } catch (RepositoryException e) { logger.error("Cannot get publication details", e); } } } else if (BackgroundJob.getGroupName(ImportJob.class).equals(jobDetail.getGroup())) { String uri = (String) jobDataMap.get(ImportJob.URI); if (uri != null) { targetPaths.add(uri); description += " " + uri; } else { String destinationParentPath = jobDataMap.getString(ImportJob.DESTINATION_PARENT_PATH); targetPaths.add(destinationParentPath); } } else if (BackgroundJob.getGroupName(ActionJob.class).equals(jobDetail.getGroup())) { String actionToExecute = jobDataMap.getString(ActionJob.JOB_ACTION_TO_EXECUTE); targetAction = actionToExecute; String nodeUUID = jobDataMap.getString(ActionJob.JOB_NODE_UUID); targetNodeIdentifier = nodeUUID; } else if (BackgroundJob.getGroupName(RuleJob.class).equals(jobDetail.getGroup())) { String ruleToExecute = jobDataMap.getString(RuleJob.JOB_RULE_TO_EXECUTE); targetAction = ruleToExecute; String nodeUUID = jobDataMap.getString(RuleJob.JOB_NODE_UUID); targetNodeIdentifier = nodeUUID; String workspace = jobDataMap.getString(RuleJob.JOB_WORKSPACE); targetWorkspace = workspace; } else if (BackgroundJob.getGroupName(TextExtractorJob.class).equals(jobDetail.getGroup())) { String path = jobDataMap.getString(TextExtractorJob.JOB_PATH); String extractNodePath = jobDataMap.getString(TextExtractorJob.JOB_EXTRACTNODE_PATH); targetPaths.add(path); targetPaths.add(extractNodePath); } GWTJahiaJobDetail job = new GWTJahiaJobDetail(jobDetail.getName(), created, user, site, description, status, message, targetPaths, jobDetail.getGroup(), jobDetail.getJobClass().getName(), beginTime, endTime, duration, jobLocale, fileName, targetNodeIdentifier, targetAction, targetWorkspace); job.setLabelKey("label." + jobDetail.getGroup() + ".task"); jobs.add(job); } return jobs; }
From source file:org.jahia.ajax.gwt.helper.StubHelper.java
/** * Returns a map of code snippets.// w w w.ja v a 2 s . c om * * @param fileType * the type of the file to lookup snippets for, e.g. "jsp" * @param snippetType * the snippet type to lookup code snippets for, e.g. "conditionals", "loops" etc. * @param nodeTypeName * null or the node type associated with the file * @return a map of code snippets */ private Map<String, String> getCodeSnippets(String fileType, String snippetType, String nodeTypeName) { Map<String, String> stub = new LinkedHashMap<String, String>(); InputStream is = null; try { ServletContext servletContext = JahiaContextLoaderListener.getServletContext(); @SuppressWarnings("unchecked") Set<String> resources = servletContext .getResourcePaths("/WEB-INF/etc/snippets/" + fileType + "/" + snippetType + "/"); ExtendedNodeType n = null; if (resources != null) { for (String resource : resources) { String resourceName = StringUtils.substringAfterLast(resource, "/"); String viewNodeType = getResourceViewNodeType(resourceName); if (nodeTypeName != null && viewNodeType != null) { // check if the view node type matches the requested one if (null == n) { try { n = NodeTypeRegistry.getInstance().getNodeType(nodeTypeName); } catch (NoSuchNodeTypeException e) { // node type not found, do nothing } } if (n != null && !n.isNodeType(viewNodeType)) { // we skip that stub as it's node type does not match the requested one continue; } } is = servletContext.getResourceAsStream(resource); try { stub.put(viewNodeType != null ? (resourceName + "/" + viewNodeType) : resourceName, StringUtils.join(IOUtils.readLines(is), "\n")); } finally { IOUtils.closeQuietly(is); } } } } catch (IOException e) { logger.error("Failed to read code snippets from " + fileType + "/" + snippetType, e); } return stub; }
From source file:org.jahia.ajax.gwt.helper.WorkflowHelper.java
private String getUsername(String userPath) { return StringUtils.substringAfterLast(userPath, "/"); }