List of usage examples for org.apache.commons.lang StringUtils startsWith
public static boolean startsWith(String str, String prefix)
Check if a String starts with a specified prefix.
From source file:org.jahia.services.usermanager.ldap.JahiaLDAPConfig.java
@SuppressWarnings("unchecked") private String computeProviderKey(Dictionary<String, ?> dictionary) { String provideKey = (String) dictionary.get(LDAP_PROVIDER_KEY_PROP); if (provideKey != null) { return provideKey; }/*from w w w. j a va 2 s . co m*/ String filename = (String) dictionary.get("felix.fileinstall.filename"); String factoryPid = (String) dictionary.get(ConfigurationAdmin.SERVICE_FACTORYPID); String confId; if (StringUtils.isBlank(filename)) { confId = (String) dictionary.get(Constants.SERVICE_PID); if (StringUtils.startsWith(confId, factoryPid + ".")) { confId = StringUtils.substringAfter(confId, factoryPid + "."); } } else { confId = StringUtils.removeEnd(StringUtils.substringAfter(filename, factoryPid + "-"), ".cfg"); } return (StringUtils.isBlank(confId) || "config".equals(confId)) ? "ldap" : ("ldap." + confId); }
From source file:org.jahia.services.usermanager.mongo.JahiaMongoConfig.java
/** * * @param dictionary// w w w . ja v a 2s. c om * @return */ private String computeProviderKey(final Dictionary<String, ?> dictionary) { final String provideKey = (String) dictionary.get(MONGO_PROVIDER_KEY); if (provideKey != null) { return provideKey; } final String filename = (String) dictionary.get("felix.fileinstall.filename"); final String factoryPid = (String) dictionary.get(ConfigurationAdmin.SERVICE_FACTORYPID); String confId; if (StringUtils.isBlank(filename)) { confId = (String) dictionary.get(Constants.SERVICE_PID); if (StringUtils.startsWith(confId, factoryPid + ".")) { confId = StringUtils.substringAfter(confId, factoryPid + "."); } } else { confId = StringUtils.removeEnd(StringUtils.substringAfter(filename, factoryPid + "-"), ".cfg"); } return (StringUtils.isBlank(confId) || "config".equals(confId)) ? "mongo" : ("mongo." + confId); }
From source file:org.jahia.utils.maven.plugin.contentgenerator.bo.PageBO.java
private void buildPageElement() { pageElement = new Element(getName()); pageElement.addNamespaceDeclaration(ContentGeneratorCst.NS_JCR); pageElement.addNamespaceDeclaration(ContentGeneratorCst.NS_NT); pageElement.addNamespaceDeclaration(ContentGeneratorCst.NS_JNT); pageElement.addNamespaceDeclaration(ContentGeneratorCst.NS_TEST); pageElement.addNamespaceDeclaration(ContentGeneratorCst.NS_SV); pageElement.addNamespaceDeclaration(ContentGeneratorCst.NS_JMIX); pageElement.addNamespaceDeclaration(ContentGeneratorCst.NS_J); pageElement.addNamespaceDeclaration(ContentGeneratorCst.NS_SV); pageElement.addNamespaceDeclaration(ContentGeneratorCst.NS_REP); pageElement.addNamespaceDeclaration(ContentGeneratorCst.NS_WEM); pageElement.setAttribute("changefreq", "monthly"); pageElement.setAttribute("templateName", pageTemplate, ContentGeneratorCst.NS_J); pageElement.setAttribute("primaryType", "jnt:page", ContentGeneratorCst.NS_JCR); pageElement.setAttribute("priority", "0.5"); String mixinTypes = "jmix:sitemap"; if (hasVanity) { mixinTypes = mixinTypes + " jmix:vanityUrlMapped"; }//from w w w. j a va2 s .co m pageElement.setAttribute("mixinTypes", mixinTypes, ContentGeneratorCst.NS_JCR); if (idCategory != null) { pageElement.setAttribute("jcategorized", StringUtils.EMPTY, ContentGeneratorCst.NS_JMIX); pageElement.setAttribute("defaultCategory", "/sites/systemsite/categories/category" + idCategory, ContentGeneratorCst.NS_J); } if (idTag != null) { pageElement.setAttribute("tags", "/sites/" + siteKey + "/tags/tag" + idTag, ContentGeneratorCst.NS_J); } // articles for (Map.Entry<String, ArticleBO> entry : articles.entrySet()) { Element translationNode = new Element("translation_" + entry.getKey(), ContentGeneratorCst.NS_J); translationNode.setAttribute("language", entry.getKey(), ContentGeneratorCst.NS_JCR); translationNode.setAttribute("mixinTypes", "mix:title", ContentGeneratorCst.NS_JCR); translationNode.setAttribute("primaryType", "jnt:translation", ContentGeneratorCst.NS_JCR); translationNode.setAttribute("title", entry.getValue().getTitle(), ContentGeneratorCst.NS_JCR); if (StringUtils.isNotEmpty(description)) { translationNode.setAttribute("description", description, ContentGeneratorCst.NS_JCR); } pageElement.addContent(translationNode); } if (!acls.isEmpty()) { Element aclNode = new Element("acl", ContentGeneratorCst.NS_J); aclNode.setAttribute("inherit", "true", ContentGeneratorCst.NS_J); aclNode.setAttribute("primaryType", "jnt:acl", ContentGeneratorCst.NS_JCR); for (Map.Entry<String, List<String>> entry : acls.entrySet()) { String roles = ""; for (String s : entry.getValue()) { roles += s + " "; } Element aceNode = new Element("GRANT_" + entry.getKey().replace(":", "_")); aceNode.setAttribute("aceType", "GRANT", ContentGeneratorCst.NS_J); aceNode.setAttribute("principal", entry.getKey(), ContentGeneratorCst.NS_J); aceNode.setAttribute("protected", "false", ContentGeneratorCst.NS_J); aceNode.setAttribute("roles", roles.trim(), ContentGeneratorCst.NS_J); aceNode.setAttribute("primaryType", "jnt:ace", ContentGeneratorCst.NS_JCR); aclNode.addContent(aceNode); } pageElement.addContent(aclNode); } // begin content list Element listNode = new Element("listA"); listNode.setAttribute("primaryType", "jnt:contentList", ContentGeneratorCst.NS_JCR); LinkedList<Element> personalizableElements = new LinkedList<Element>(); if (pageTemplate.equals(ContentGeneratorCst.PAGE_TPL_QALIST)) { List<String> languages = new ArrayList<String>(); for (Map.Entry<String, ArticleBO> entry : articles.entrySet()) { languages.add(entry.getKey()); } for (int i = 1; i <= ContentGeneratorCst.NB_NEWS_IN_QALIST; i++) { Element newsNode = new NewsBO(namePrefix + "-" + "news" + i, languages).getElement(); listNode.addContent(newsNode); if (i <= ContentGeneratorCst.NB_NEWS_PER_PAGE_IN_QALIST) { // News are split to multiple pages by Jahia at runtime, so only personalize items present on the first page. personalizableElements.add(newsNode); } } } else if (pageTemplate.equals(ContentGeneratorCst.PAGE_TPL_DEFAULT)) { for (int i = 1; i <= numberBigText.intValue(); i++) { Element bigTextNode = new Element("bigText_" + i); bigTextNode.setAttribute("primaryType", "jnt:bigText", ContentGeneratorCst.NS_JCR); bigTextNode.setAttribute("mixinTypes", "jmix:renderable", ContentGeneratorCst.NS_JCR); for (Map.Entry<String, ArticleBO> entry : articles.entrySet()) { Element translationNode = new Element("translation_" + entry.getKey(), ContentGeneratorCst.NS_J); translationNode.setAttribute("language", entry.getKey(), ContentGeneratorCst.NS_JCR); translationNode.setAttribute("primaryType", "jnt:translation", ContentGeneratorCst.NS_JCR); translationNode.setAttribute("text", entry.getValue().getContent()); bigTextNode.addContent(translationNode); } listNode.addContent(bigTextNode); personalizableElements.add(bigTextNode); } } // for pages with external/internal file reference, we check the page name if (StringUtils.startsWith(namePrefix, ContentGeneratorCst.PAGE_TPL_QAEXTERNAL)) { for (int i = 0; i < externalFilePaths.size(); i++) { String externalFilePath = externalFilePaths.get(i); Element externalFileReference = new Element("external-file-reference-" + i); externalFileReference.setAttribute("node", "/mounts/" + ContentGeneratorCst.CMIS_MOUNT_POINT_NAME + "/Sites/" + cmisSite + externalFilePath, ContentGeneratorCst.NS_J); externalFileReference.setAttribute("primaryType", "jnt:fileReference", ContentGeneratorCst.NS_JCR); listNode.addContent(externalFileReference); personalizableElements.add(externalFileReference); } } if (StringUtils.startsWith(namePrefix, ContentGeneratorCst.PAGE_TPL_QAINTERNAL) && fileName != null) { Element randomFileNode = new Element("rand-file"); randomFileNode.setAttribute("primaryType", "jnt:fileReference", ContentGeneratorCst.NS_JCR); Element fileTranslationNode = new Element("translation_en", ContentGeneratorCst.NS_J); fileTranslationNode.setAttribute("language", "en", ContentGeneratorCst.NS_JCR); fileTranslationNode.setAttribute("primaryType", "jnt:translation", ContentGeneratorCst.NS_JCR); fileTranslationNode.setAttribute("title", "My file", ContentGeneratorCst.NS_JCR); randomFileNode.addContent(fileTranslationNode); Element publicationNode = new Element("publication"); publicationNode.setAttribute("primaryType", "jnt:publication", ContentGeneratorCst.NS_JCR); Element publicationTranslationNode = new Element("translation_en", ContentGeneratorCst.NS_J); publicationTranslationNode.setAttribute("author", "Jahia Content Generator"); publicationTranslationNode.setAttribute("body", "<p> Random publication</p>"); publicationTranslationNode.setAttribute("title", "Random publication", ContentGeneratorCst.NS_JCR); publicationTranslationNode.setAttribute("file", "/sites/" + siteKey + "/files/contributed/" + org.apache.jackrabbit.util.ISO9075.encode(fileName)); publicationTranslationNode.setAttribute("language", "en", ContentGeneratorCst.NS_JCR); publicationTranslationNode.setAttribute("primaryType", "jnt:translation", ContentGeneratorCst.NS_JCR); publicationTranslationNode.setAttribute("source", "Jahia"); publicationNode.addContent(publicationTranslationNode); listNode.addContent(publicationNode); } if (personalized) { if (personalizableElements.isEmpty()) { personalized = false; pageElement.setName(getName()); // Re-set the root element name: it must change according to page personalization change. } else { Element element = personalizableElements .get(ThreadLocalRandom.current().nextInt(personalizableElements.size())); int elementIndex = listNode.indexOf(element); listNode.removeContent(element); element = getPersonalizedElement(element); listNode.addContent(elementIndex, element); } } // end content list pageElement.addContent(listNode); if (hasVanity) { Element vanityNode = new Element("vanityUrlMapping"); vanityNode.setAttribute("primaryType", "jnt:vanityUrls", ContentGeneratorCst.NS_JCR); Element vanitySubNode = new Element(namePrefix); vanitySubNode.setAttribute("active", "true", ContentGeneratorCst.NS_J); vanitySubNode.setAttribute("default", "true", ContentGeneratorCst.NS_J); vanitySubNode.setAttribute("url", "/" + namePrefix, ContentGeneratorCst.NS_J); vanitySubNode.setAttribute("language", "en", ContentGeneratorCst.NS_JCR); vanitySubNode.setAttribute("primaryType", "jnt:vanityUrl", ContentGeneratorCst.NS_JCR); vanityNode.addContent(vanitySubNode); pageElement.addContent(vanityNode); } if (visibilityEnabled) { Element visibilityNode = new Element("conditionalVisibility", ContentGeneratorCst.NS_J); visibilityNode.setAttribute("conditionalVisibility", null, ContentGeneratorCst.NS_J); visibilityNode.setAttribute("forceMatchAllConditions", "true", ContentGeneratorCst.NS_J); visibilityNode.setAttribute("primaryType", "jnt:conditionalVisibility", ContentGeneratorCst.NS_JCR); Element visibilityConditionNode = new Element("startEndDateCondition0", ContentGeneratorCst.NS_JNT); visibilityConditionNode.setAttribute("primaryType", "jnt:startEndDateCondition", ContentGeneratorCst.NS_JCR); visibilityConditionNode.setAttribute("start", visibilityStartDate); visibilityConditionNode.setAttribute("end", visibilityEndDate); visibilityNode.addContent(visibilityConditionNode); pageElement.addContent(visibilityNode); } if (null != subPages) { for (Iterator<PageBO> iterator = subPages.iterator(); iterator.hasNext();) { PageBO subPage = iterator.next(); pageElement.addContent(subPage.getElement()); } } }
From source file:org.jahia.utils.PomUtils.java
public static File extractPomFromJar(JarFile jar, String groupId, String artifactId) throws IOException { // deploy artifacts to Maven distribution server Enumeration<JarEntry> jarEntries = jar.entries(); JarEntry jarEntry = null;/* w w w . jav a 2s .com*/ boolean found = false; while (jarEntries.hasMoreElements()) { jarEntry = jarEntries.nextElement(); String name = jarEntry.getName(); if (StringUtils.startsWith(name, groupId != null ? ("META-INF/maven/" + groupId + "/") : "META-INF/maven/") && StringUtils.endsWith(name, artifactId + "/pom.xml")) { found = true; break; } } if (!found) { throw new IOException("unable to find pom.xml file within while looking for " + artifactId); } InputStream is = jar.getInputStream(jarEntry); File pomFile = File.createTempFile("pom", ".xml"); FileUtils.copyInputStreamToFile(is, pomFile); return pomFile; }
From source file:org.jamwiki.servlets.JAMWikiServlet.java
/** * Build a map of links and the corresponding link text to be used as the user * menu links for the WikiPageInfo object. *///from www.j a v a 2 s .c o m private LinkedHashMap buildUserMenu(WikiPageInfo pageInfo) { LinkedHashMap<String, WikiMessage> links = new LinkedHashMap<String, WikiMessage>(); WikiUserDetails userDetails = ServletUtil.currentUserDetails(); if (userDetails.hasRole(RoleImpl.ROLE_ANONYMOUS) && !userDetails.hasRole(RoleImpl.ROLE_EMBEDDED)) { // include the current page in the login link String loginLink = "Special:Login"; if (!StringUtils.startsWith(pageInfo.getTopicName(), "Special:Login")) { loginLink += LinkUtil.appendQueryParam("", PARAM_LOGIN_SUCCESS_TARGET, pageInfo.getTopicName()); } links.put(loginLink, new WikiMessage("common.login")); links.put("Special:Account", new WikiMessage("usermenu.register")); } if (!userDetails.hasRole(RoleImpl.ROLE_ANONYMOUS)) { WikiUser user = ServletUtil.currentWikiUser(); String userPage = NamespaceHandler.NAMESPACE_USER + NamespaceHandler.NAMESPACE_SEPARATOR + user.getUsername(); String userCommentsPage = NamespaceHandler.NAMESPACE_USER_COMMENTS + NamespaceHandler.NAMESPACE_SEPARATOR + user.getUsername(); String username = user.getUsername(); if (!StringUtils.isBlank(user.getDisplayName())) { username = user.getDisplayName(); } // user name will be escaped by the jamwiki:link tag WikiMessage userMenuMessage = new WikiMessage("usermenu.user"); userMenuMessage.setParamsWithoutEscaping(new String[] { username }); links.put(userPage, userMenuMessage); links.put(userCommentsPage, new WikiMessage("usermenu.usercomments")); links.put("Special:Watchlist", new WikiMessage("usermenu.watchlist")); } if (!userDetails.hasRole(RoleImpl.ROLE_ANONYMOUS) && !userDetails.hasRole(RoleImpl.ROLE_NO_ACCOUNT)) { links.put("Special:Account", new WikiMessage("usermenu.account")); } if (!userDetails.hasRole(RoleImpl.ROLE_ANONYMOUS) && !userDetails.hasRole(RoleImpl.ROLE_EMBEDDED)) { links.put("Special:Logout", new WikiMessage("common.logout")); } if (userDetails.hasRole(RoleImpl.ROLE_SYSADMIN)) { links.put("Special:Admin", new WikiMessage("usermenu.admin")); } else if (userDetails.hasRole(RoleImpl.ROLE_TRANSLATE)) { links.put("Special:Translation", new WikiMessage("tab.admin.translations")); } return links; }
From source file:org.jamwiki.utils.WikiUtil.java
/** * Utility method for determining if a topic name is valid for use on the Wiki, * meaning that it is not empty and does not contain any invalid characters. * * @param name The topic name to validate. * @throws WikiException Thrown if the user name is invalid. *//*from ww w .jav a 2 s. c o m*/ public static void validateTopicName(String name) throws WikiException { if (StringUtils.isBlank(name)) { throw new WikiException(new WikiMessage("common.exception.notopic")); } if (PseudoTopicHandler.isPseudoTopic(name)) { throw new WikiException(new WikiMessage("common.exception.pseudotopic", name)); } WikiLink wikiLink = LinkUtil.parseWikiLink(name); String namespace = StringUtils.trimToNull(wikiLink.getNamespace()); String article = StringUtils.trimToNull(wikiLink.getArticle()); if (StringUtils.startsWith(namespace, "/") || StringUtils.startsWith(article, "/")) { throw new WikiException(new WikiMessage("common.exception.name", name)); } if (namespace != null && namespace.toLowerCase().equals(NamespaceHandler.NAMESPACE_SPECIAL.toLowerCase())) { throw new WikiException(new WikiMessage("common.exception.name", name)); } Matcher m = WikiUtil.INVALID_TOPIC_NAME_PATTERN.matcher(name); if (m.find()) { throw new WikiException(new WikiMessage("common.exception.name", name)); } }
From source file:org.jboss.as.test.integration.security.loginmodules.negotiation.PropagateIdentityServlet.java
/** * Retrieves a {@link GSSCredential} from {@link DelegationCredentialContext#getDelegCredential()}. If it's null error 401 * (SC_UNAUTHORIZED) is returned, otherwise {@link GSSTestClient} is used retrieve name of propagated identity from * {@link GSSTestServer}.//from w w w . j ava 2 s .c om * * @param req * @param resp * @throws ServletException * @throws IOException * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { LOGGER.debug("New request coming."); final GSSCredential credential = DelegationCredentialContext.getDelegCredential(); if (credential == null) { resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "GSSCredential not found"); } else { resp.setContentType("text/plain"); final PrintWriter writer = resp.getWriter(); final GSSTestClient client = new GSSTestClient(StringUtils.strip(req.getServerName(), "[]"), GSSTestConstants.PORT, GSSTestConstants.PRINCIPAL); LOGGER.trace("Client for identity propagation created: " + client); try { writer.print(client.getName(credential)); } catch (GSSException e) { if (StringUtils.startsWith(SystemUtils.JAVA_VENDOR, "IBM") && e.getMessage().contains("message: Incorrect net address")) { writer.print("jduke@JBOSS.ORG"); } else { throw new ServletException("Propagation failed.", e); } } } }
From source file:org.jboss.tools.openshift.internal.ui.webhooks.WebHooksComponent.java
private static boolean isGitHub(String gitUrl) { return StringUtils.startsWith(gitUrl, "https://github.com/"); }
From source file:org.jboss.windup.decorator.archive.PomVersionDecorator.java
@Override public void processMeta(XmlMetadata file) { if (!isActive(file)) { return;//from w w w. j a va2 s . com } Document doc = file.getParsedDocument(); try { String groupId = extractStringValue(groupIdXPath, doc); if (StringUtils.isBlank(groupId) || StringUtils.startsWith(groupId, "${")) { LOG.debug("GroupId not found for file: " + file.getFilePointer().getAbsolutePath() + "; trying parent groupId..."); // then check for parent... groupId = extractStringValue(parentGroupIdXPath, doc); if (StringUtils.isBlank(groupId)) { LOG.debug("Parent groupId not found for file: " + file.getFilePointer().getAbsolutePath() + "; skipping."); return; } } String version = extractStringValue(versionXPath, doc); if (StringUtils.isBlank(version) || StringUtils.startsWith(version, "${")) { LOG.debug("Version not found for file: " + file.getFilePointer().getAbsolutePath() + "; trying parent version..."); // then check the parent... version = extractStringValue(parentVersionXPath, doc); if (StringUtils.isBlank(version)) { LOG.debug("Parent version not found for file: " + file.getFilePointer().getAbsolutePath() + "; skipping."); return; } } String artifactId = extractStringValue(artifactIdXPath, doc); if (StringUtils.isBlank(artifactId)) { LOG.debug("ArtifactId not found for file: " + file.getFilePointer().getAbsolutePath()); return; } String name = extractStringValue(nameXPath, doc); createVersionResult(file, groupId, artifactId, version, name); } catch (XPathExpressionException e) { LOG.error("Exception running xpath expression.", e); } }
From source file:org.jboss.windup.decorator.java.JavaASTVariableResolvingVisitor.java
@Override public boolean visit(ImportDeclaration node) { String name = node.getName().toString(); if (!node.isOnDemand()) { String clzName = StringUtils.substringAfterLast(name, "."); classNameToFullyQualified.put(clzName, name); processInterest(node.getName().toString(), cu.getLineNumber(node.getStartPosition()), "Import of", SourceType.IMPORT);/*www. j av a2 s. c o m*/ } else { if (lineContainsPackageBlacklist(name)) { for (String knownClz : classNameToFullyQualified.values()) { if (StringUtils.startsWith(knownClz, name)) { processInterest(knownClz, cu.getLineNumber(node.getStartPosition()), "Leads to import of", SourceType.IMPORT); } } } } return true; }