List of usage examples for org.apache.commons.lang StringUtils endsWith
public static boolean endsWith(String str, String suffix)
Check if a String ends with a specified suffix.
From source file:org.jahia.modules.jahiaoauth.impl.cache.ClusteredCacheImpl.java
@Override public void updateCacheEntry(String originalSessionId, String newSessionId) { for (Object key : hazelcastInstance.getMap(JahiaOAuthConstants.JAHIA_OAUTH_USER_CACHE).keySet()) { String keyAsString = (String) key; if (StringUtils.endsWith(keyAsString, originalSessionId)) { String newKey = StringUtils.substringBefore(keyAsString, originalSessionId) + newSessionId; HashMap<String, Object> mapperResult = (HashMap<String, Object>) hazelcastInstance .getMap(JahiaOAuthConstants.JAHIA_OAUTH_USER_CACHE).get(key); hazelcastInstance.getMap(JahiaOAuthConstants.JAHIA_OAUTH_USER_CACHE).remove(key); hazelcastInstance.getMap(JahiaOAuthConstants.JAHIA_OAUTH_USER_CACHE).set(newKey, mapperResult); }/*from w w w . j a va 2s . c o m*/ } }
From source file:org.jahia.modules.jahiaoauth.impl.cache.EHCacheManagerImpl.java
@Override public void updateCacheEntry(String originalSessionId, String newSessionId) { for (String key : (List<String>) userCache.getKeys()) { if (StringUtils.endsWith(key, originalSessionId)) { String newKey = StringUtils.substringBefore(key, originalSessionId) + newSessionId; HashMap<String, Object> mapperResults = getMapperResultsCacheEntry(key); if (mapperResults != null) { cacheMapperResults(newKey, mapperResults); }//www. java 2 s .co m } } }
From source file:org.jahia.osgi.JahiaBundleTemplatesPackageHandler.java
private static boolean hasResourceBundle(Bundle bundle, String resourceBundleName) { boolean found = false; // check if there is a resource bundle file in the resources folder Enumeration<String> paths = bundle.getEntryPaths("/resources/"); while (paths != null && paths.hasMoreElements()) { String path = paths.nextElement(); if (StringUtils.startsWith(path, "resources/" + resourceBundleName) && StringUtils.endsWith(path, ".properties")) { return true; }/*from w ww . j a va 2 s .c o m*/ } return false; }
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;//from w w w.j a va 2s .c om 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.jasig.schedassist.impl.oraclecalendar.AbstractOracleCalendarDao.java
/** * This function encapsulates the processing of the output from Oracle Calendar * by iCal4j.//from ww w .j av a2 s .c om * * This method currently inspects the end of the agenda argument for the presence * of the complete string "END:VCALENDAR" (a known bug with the Oracle Calendar APIs presents * itself in this fashion) and attempts to repair the agenda before sending to iCal4J. * * {@link CalendarBuilder#build(java.io.Reader)} can throw an {@link IOException}; this method wraps the call * in try-catch and throws any caught {@link IOException}s wrapped in a {@link ParseException} instead. * * @param agenda * @return * @throws ParserException */ protected Calendar parseAgenda(String agenda) throws ParserException { final String chomped = StringUtils.chomp(agenda); if (!StringUtils.endsWith(chomped, "END:VCALENDAR")) { // Oracle for an unknown reason sometimes does not properly end the iCalendar LOG.warn("agenda does not end in END:VCALENDAR"); // find out how much is missing from the end int indexOfLastNewline = StringUtils.lastIndexOf(chomped, CRLF); if (indexOfLastNewline == -1) { throw new ParserException("oracle calendar data is malformed ", -1); } String agendaWithoutLastLine = agenda.substring(0, indexOfLastNewline); StringBuilder agendaBuilder = new StringBuilder(); agendaBuilder.append(agendaWithoutLastLine); agendaBuilder.append(CRLF); agendaBuilder.append("END:VCALENDAR"); agenda = agendaBuilder.toString(); } StringReader reader = new StringReader(agenda); CalendarBuilder builder = new CalendarBuilder(); try { Calendar result = builder.build(reader); if (LOG.isTraceEnabled()) { LOG.trace(result.toString()); } return result; } catch (IOException e) { LOG.error("ical4j threw IOException attempting to build Calendar; rethrowing as ParserException", e); throw new ParserException(e.getMessage(), -1, e); } }
From source file:org.jboss.windup.decorator.archive.ClassesProvidedDecorator.java
protected void recursivelyCollectRequiredProvided(ZipMetadata meta, Map<String, GraphableClz> provided) { try {// ww w .j av a 2 s .com ZipEntry entry; Enumeration<?> e = meta.getZipFile().entries(); // locate a random class entry... while (e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); if (StringUtils.endsWith(entry.getName(), ".class")) { String className = extractClassName(entry.getName()); Set<String> required = extractImports(meta.getZipFile(), entry); ApplicationClz cg = new ApplicationClz(meta, className, required); provided.put(className, cg); } } } catch (Exception e) { LOG.error("Exception getting JDK version.", e); } for (ArchiveMetadata child : meta.getNestedArchives()) { ZipMetadata cast = (ZipMetadata) child; this.recursivelyCollectRequiredProvided(cast, provided); } }
From source file:org.jboss.windup.decorator.archive.JVMVersionDecorator.java
@Override public void processMeta(ZipMetadata meta) { try {//from w ww .jav a 2 s . c o m ZipEntry entry; Enumeration<?> e = meta.getZipFile().entries(); // locate a random class entry... while (e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); if (StringUtils.endsWith(entry.getName(), ".class")) { String version = null; DataInputStream in = null; try { in = new DataInputStream(meta.getZipFile().getInputStream(entry)); // ignore Java "magic" number. in.readInt(); int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); switch (major) { case ClassFile.JAVA_1: version = "1.1"; break; case ClassFile.JAVA_2: version = "1.2"; break; case ClassFile.JAVA_3: version = "1.3"; break; case ClassFile.JAVA_4: version = "1.4"; break; case ClassFile.JAVA_5: version = "5.0"; break; case ClassFile.JAVA_6: version = "6.0"; break; case ClassFile.JAVA_7: version = "7.0"; break; default: LOG.warn("No version mapping for: " + version); } version = version + "." + minor; } finally { in.close(); } JVMBuildVersionResult vr = new JVMBuildVersionResult(); vr.setJdkBuildVersion(version); meta.getDecorations().add(vr); if (LOG.isDebugEnabled()) { LOG.debug("Built with: " + version); } break; } } } catch (Exception e) { LOG.error("Exception getting JDK version.", e); } }
From source file:org.jboss.windup.decorator.archive.ManifestVersionDecorator.java
private String extractNameFromArchiveName(String archiveName) { String name = archiveName;//from w w w.j ava 2 s. c om name = StringUtils.substringBefore(name, "."); // now, if there are numbers... strip the numbers from the end. StringBuilder nameBuilder = new StringBuilder(); String[] nameArray = StringUtils.split(name, "-"); for (String nameFrag : nameArray) { if (StringUtils.isNotBlank(nameFrag)) { // check to see if the fragment starts with alpha. if (!StringUtils.isNumeric(StringUtils.substring(nameFrag, 0, 1))) { nameBuilder.append(nameFrag).append("-"); } } } name = nameBuilder.toString(); if (StringUtils.endsWith(name, "-")) { name = StringUtils.substringBeforeLast(name, "-"); } return name; }
From source file:org.jboss.windup.decorator.java.JavaASTVariableResolvingVisitor.java
private List<String> methodParameterGuesser(List arguements) { List<String> resolvedParams = new ArrayList<String>(arguements.size()); for (Object o : arguements) { if (o instanceof SimpleName) { String name = nameInstance.get(o.toString()); if (name != null) { resolvedParams.add(name); } else { resolvedParams.add("Undefined"); }//from ww w.j a v a2s. c om } else if (o instanceof StringLiteral) { resolvedParams.add("java.lang.String"); } else if (o instanceof FieldAccess) { String field = ((FieldAccess) o).getName().toString(); if (names.contains(field)) { resolvedParams.add(nameInstance.get(field)); } else { resolvedParams.add("Undefined"); } } else if (o instanceof CastExpression) { String type = ((CastExpression) o).getType().toString(); type = qualifyType(type); resolvedParams.add(type); } else if (o instanceof MethodInvocation) { String on = ((MethodInvocation) o).getName().toString(); if (StringUtils.equals(on, "toString")) { if (((MethodInvocation) o).arguments().size() == 0) { resolvedParams.add("java.lang.String"); } } else { resolvedParams.add("Undefined"); } } else if (o instanceof NumberLiteral) { if (StringUtils.endsWith(o.toString(), "L")) { resolvedParams.add("long"); } else if (StringUtils.endsWith(o.toString(), "f")) { resolvedParams.add("float"); } else if (StringUtils.endsWith(o.toString(), "d")) { resolvedParams.add("double"); } else { resolvedParams.add("int"); } } else if (o instanceof BooleanLiteral) { resolvedParams.add("boolean"); } else if (o instanceof ClassInstanceCreation) { String nodeType = ((ClassInstanceCreation) o).getType().toString(); if (classNameToFullyQualified.containsKey(nodeType)) { nodeType = classNameToFullyQualified.get(nodeType.toString()); } resolvedParams.add(nodeType); } else if (o instanceof org.eclipse.jdt.core.dom.CharacterLiteral) { resolvedParams.add("char"); } else if (o instanceof InfixExpression) { String expression = o.toString(); if (StringUtils.contains(expression, "\"")) { resolvedParams.add("java.lang.String"); } else { resolvedParams.add("Undefined"); } } else { LOG.debug("Unable to determine type: " + o.getClass() + ReflectionToStringBuilder.toString(o)); resolvedParams.add("Undefined"); } } return resolvedParams; }
From source file:org.jboss.windup.interrogator.impl.ExtensionInterrogator.java
protected Set<Pattern> compilePatternSet(Set<String> patternStringSet) { if (patternStringSet == null) return null; Set<Pattern> target = new HashSet<Pattern>(patternStringSet.size()); for (String patternString : patternStringSet) { if (!StringUtils.endsWith(patternString, "$")) { patternString = patternString + "$"; }//ww w .j a v a 2 s. c o m target.add(Pattern.compile(patternString)); } return target; }