List of usage examples for org.apache.commons.lang StringUtils strip
public static String strip(String str, String stripChars)
Strips any of a set of characters from the start and end of a String.
From source file:com.iflytek.edu.cloud.frame.doc.ServiceDocBuilder.java
public List<ClassDoc> buildDoc() { List<ClassDoc> classDocs = new ArrayList<ClassDoc>(); List<JavaClass> javaClasses = findRestServices(); for (JavaClass javaClass : javaClasses) { ClassDoc classDoc = new ClassDoc(); classDoc.setServiceDesc(javaClass.getComment()); classDoc.setServiceName(javaClass.getTagByName("serviceName").getValue()); List<JavaMethod> javaMethods = findMethods(javaClass); for (JavaMethod method : javaMethods) { //?// w w w .ja va 2 s.co m MethodDoc methodDoc = new MethodDoc(); Annotation[] annotations = method.getAnnotations(); for (Annotation ann : annotations) { if (ServiceMethod.class.getName().equals(ann.getType().getFullyQualifiedName())) { String name = (String) ann.getNamedParameter("value"); String version = (String) ann.getNamedParameter("version"); methodDoc.setName(StringUtils.strip(name.trim(), "\"")); methodDoc.setVersion(StringUtils.strip(version.trim(), "\"")); break; } } methodDoc.setDescription(method.getComment()); //? ReturnDoc returnDoc = new ReturnDoc(); returnDoc.setDataType(method.getReturnType().getFullyQualifiedName()); if ("java.util.List".equals(returnDoc.getDataType())) { Type type = method.getReturnType().getActualTypeArguments()[0]; if (!ClassUtils.isPrimitiveOrWrapper(type.getFullyQualifiedName())) { returnDoc.setBeanName(type.getFullyQualifiedName()); JavaBeanDoc beanDoc = getJavaBeanDoc(type.getFullyQualifiedName()); classDoc.getBeanDocs().add(beanDoc); } } if (method.getTagByName("return") == null) { throw new RuntimeException(" " + method.getName() + " return"); } //??? @return userid A2342312 $$ ID String returnDesc = method.getTagByName("return").getValue(); String[] desces = returnDesc.split("\\$\\$"); if (desces.length > 1) { returnDoc.setExampleData(desces[0]); returnDoc.setDescription(desces[1]); } else { returnDoc.setDescription(returnDesc); } returnDoc.setDimensions(method.getReturnType().getDimensions()); methodDoc.setReturnDoc(returnDoc); //?? JavaParameter[] parameters = method.getParameters(); DocletTag[] paramTags = method.getTagsByName("param"); for (int i = 0, len = parameters.length; i < len; i++) { JavaParameter parameter = parameters[i]; String type = parameter.getType().getFullyQualifiedName(); String paramName = parameter.getName(); ParamDoc paramDoc = new ParamDoc(); paramDoc.setName(paramName); paramDoc.setDataType(type); //????? @param userid A2342312 $$ ID String paramDesc = getParamDesc(paramName, paramTags); desces = paramDesc.split("\\$\\$"); if (desces.length > 1) { paramDoc.setExampleData(desces[0].trim()); paramDoc.setDescription(desces[1].trim()); } else { paramDoc.setDescription(paramDesc); } methodDoc.getParamDocs().add(paramDoc); //javax.servlet.* if (!ClassUtils.isPrimitiveOrWrapper(type) && !type.startsWith("javax.servlet")) { classDoc.getBeanDocs().add(getJavaBeanDoc(type)); } } classDoc.getMethodDocs().add(methodDoc); } boolean isNew = true; for (ClassDoc doc : classDocs) { if (doc.getServiceName().equals(classDoc.getServiceName())) { doc.getBeanDocs().addAll(classDoc.getBeanDocs()); doc.getMethodDocs().addAll(classDoc.getMethodDocs()); isNew = false; break; } } if (isNew) classDocs.add(classDoc); } return classDocs; }
From source file:easycare.web.patient.PhysicianConverter.java
protected String generatePhysicianAddressFromAddress(Address userAddressToGenerateFrom) { if (userAddressToGenerateFrom == null) { return ""; }/*from ww w .ja va 2s.c o m*/ String addressSeparator = ", "; String address = StringUtils.join(new String[] { userAddressToGenerateFrom.getCitySuburb(), userAddressToGenerateFrom.getState() == null ? null : userAddressToGenerateFrom.getState().getStateCode().toUpperCase(), userAddressToGenerateFrom.getPostcode() }, addressSeparator); return StringUtils.strip(address, addressSeparator); }
From source file:com.redhat.rhn.frontend.nav.NavTreeIndex.java
/** * Splits the given url string at the /. Returns the * parts in an array. For example, given "/network/users/details" * this method will return {"/network", "/users", "/details"} * @param urlIn url string to be split.//from w w w.j a va2s . c o m * @return the parts in an array. */ public static String[] splitUrlPrefixes(String urlIn) { String url = StringUtils.strip(urlIn, "/"); String[] splitPath = StringUtils.split(url, "/"); List pathPrefixes = new ArrayList(splitPath.length + 1); // loop through the path parts of URL, creating a new split // URL for each pass, starting with longest, going to shortest for (int i = splitPath.length - 1; i >= 0; i--) { StringBuilder sb = new StringBuilder("/"); for (int j = 0; j <= i; j++) { sb.append(splitPath[j]); sb.append("/"); } // strip off trailing / from last pass in loop sb.deleteCharAt(sb.length() - 1); pathPrefixes.add(sb.toString()); } pathPrefixes.add("/"); return (String[]) pathPrefixes.toArray(new String[] {}); }
From source file:ips1ap101.lib.core.db.util.DBUtils.java
public static String[] getConstraintMessageKeys(String message) { String trimmed = StringUtils/*from w ww .ja v a2 s . c o m*/ .trimToEmpty(StringUtils.substringAfter(StringUtils.substringBefore(message, WHERE), ERROR)); if (StringUtils.isNotBlank(trimmed)) { String[] tokens = StringUtils.split(trimmed, ';'); if (tokens != null && tokens.length > 1) { String key = tokens[0].trim(); if (key.matches("^[0-9]{1,3}$")) { int length = Integer.valueOf(key); if (length == tokens.length - 1) { String string; String[] keys = new String[length]; for (int i = 1; i < tokens.length; i++) { key = tokens[i].trim(); if (key.endsWith(SUFIJO) && StringUtils.indexOfAny(key, INFIJOS) > 0) { key = StringUtils.removeEnd(key, SUFIJO); string = BundleMensajes.getString(key); keys[i - 1] = isKey(string) ? string : "<" + key + ">"; } else { return null; } } return keys; } } } String key, string; String stripChars = BOMK + EOMK; List<String> list = new ArrayList<>(); Pattern pattern = Pattern.compile("\\" + BOMK + ".*\\" + EOMK); Matcher matcher = pattern.matcher(trimmed); while (matcher.find()) { key = StringUtils.strip(matcher.group(), stripChars); if (key.endsWith(SUFIJO) && StringUtils.indexOfAny(key, INFIJOS) > 0) { key = StringUtils.removeEnd(key, SUFIJO); string = BundleMensajes.getString(key); key = isKey(string) ? string : "<" + key + ">"; list.add(key); } } return (list.isEmpty()) ? null : list.toArray(new String[list.size()]); } return null; }
From source file:cn.vlabs.duckling.vwb.service.auth.policy.PolicyUtil.java
private static Principal parsePrincipal(AuthorizationTokenStream ats) throws AuthorizationSyntaxParseException, IOException { String principal = ats.nextUsefulToken(); String className = ats.nextUsefulToken(); String roleName = ats.nextUsefulToken(); if (principal == null || !principal.toLowerCase().equals("principal")) { throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", principal syntax error"); }/*from w w w . j a va 2s. c o m*/ if (className == null) { throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", className is null"); } if (roleName == null) { throw new AuthorizationSyntaxParseException("Line " + ats.getLineNum() + ", roleName is null"); } else { roleName = StringUtils.strip(roleName, "\""); roleName = roleName.replace("*", "All"); } try { Class<?> clazz = Class.forName(className); return ((Principal) clazz.getDeclaredConstructor(String.class).newInstance(roleName)); } catch (ClassNotFoundException e) { throw new AuthorizationSyntaxParseException( "Line " + ats.getLineNum() + ", ClassNotFoundException, " + e.getMessage()); } catch (Exception e) { throw new AuthorizationSyntaxParseException( "Line " + ats.getLineNum() + ", Exception happens, " + e.getMessage()); } }
From source file:com.hs.mail.imap.processor.fetch.EnvelopeBuilder.java
private Address buildAddress(Mailbox mailbox) { // Javamail raises exception when personal name is surrounded with // double quotation mark. String name = StringUtils.strip(mailbox.getName(), "\""); String domain = mailbox.getDomain(); DomainList route = mailbox.getRoute(); String atDomainList;//from w ww .ja va 2 s .c o m if (CollectionUtils.isEmpty(route)) { atDomainList = null; } else { atDomainList = route.toRouteString(); } String localPart = mailbox.getLocalPart(); return new Address(atDomainList, domain, localPart, name); }
From source file:com.openshift.internal.restclient.capability.resources.DockerRegistryImageStreamImportCapability.java
private Request createAuthRequest(HttpClient client, Map<String, String> authParams) { Request request = client.newRequest(StringUtils.strip(authParams.get(REALM), "\"")); for (Entry<String, String> e : authParams.entrySet()) { if (!REALM.equals(e.getKey())) { request.param(StringUtils.strip(e.getKey(), "\""), StringUtils.strip(e.getValue(), "\"")); }// w ww . ja va 2 s . c om } LOG.debug("Auth request uri: " + request.getURI()); return request; }
From source file:ie.deri.unlp.javaservices.topicextraction.topicextractor.gate.TopicExtractorGate.java
/** * // w w w. j a v a 2 s .c om * Extract a directory in a JAR on the classpath to an output folder. * * Note: User's responsibility to ensure that the files are actually in a JAR. * * @param classInJar A class in the JAR file which is on the classpath * @param resourceDirectory Path to resource directory in JAR * @param outputDirectory Directory to write to * @return String containing the path to the outputDirectory * @throws IOException */ private static String extractDirectoryFromClasspathJAR(Class<?> classInJar, String resourceDirectory, String outputDirectory) throws IOException { resourceDirectory = StringUtils.strip(resourceDirectory, "\\/") + File.separator; URL jar = classInJar.getProtectionDomain().getCodeSource().getLocation(); JarFile jarFile = new JarFile(new File(jar.getFile())); byte[] buf = new byte[1024]; Enumeration<JarEntry> jarEntries = jarFile.entries(); while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); if (jarEntry.isDirectory() || !jarEntry.getName().startsWith(resourceDirectory)) { continue; } String outputFileName = FilenameUtils.concat(outputDirectory, jarEntry.getName()); //Create directories if they don't exist new File(FilenameUtils.getFullPath(outputFileName)).mkdirs(); //Write file FileOutputStream fileOutputStream = new FileOutputStream(outputFileName); int n; InputStream is = jarFile.getInputStream(jarEntry); while ((n = is.read(buf, 0, 1024)) > -1) { fileOutputStream.write(buf, 0, n); } is.close(); fileOutputStream.close(); } jarFile.close(); String fullPath = FilenameUtils.concat(outputDirectory, resourceDirectory); return fullPath; }
From source file:com.googlesource.gerrit.plugins.supermanifest.JiriManifestParser.java
public static JiriProjects getProjects(GerritRemoteReader reader, String repoKey, String ref, String manifest) throws ConfigInvalidException, IOException { try (RepoMap<String, Repository> repoMap = new RepoMap<>()) { repoMap.put(repoKey, reader.openRepository(repoKey)); Queue<ManifestItem> q = new LinkedList<>(); q.add(new ManifestItem(repoKey, manifest, ref, "", false)); HashMap<String, HashSet<String>> processedRepoFiles = new HashMap<>(); HashMap<String, JiriProjects.Project> projectMap = new HashMap<>(); while (q.size() != 0) { ManifestItem mi = q.remove(); Repository repo = repoMap.get(mi.repoKey); if (repo == null) { repo = reader.openRepository(mi.repoKey); repoMap.put(mi.repoKey, repo); }//w w w . j a v a2s.co m HashSet<String> processedFiles = processedRepoFiles.get(mi.repoKey); if (processedFiles == null) { processedFiles = new HashSet<String>(); processedRepoFiles.put(mi.repoKey, processedFiles); } if (processedFiles.contains(mi.manifest)) { continue; } processedFiles.add(mi.manifest); JiriManifest m; try { m = parseManifest(repo, mi.ref, mi.manifest); } catch (JAXBException | XMLStreamException e) { throw new ConfigInvalidException("XML parse error", e); } for (JiriProjects.Project project : m.projects.getProjects()) { project.fillDefault(); if (mi.revisionPinned && project.Key().equals(mi.projectKey)) { project.setRevision(mi.ref); } if (projectMap.containsKey(project.Key())) { if (!projectMap.get(project.Key()).equals(project)) throw new ConfigInvalidException(String.format( "Duplicate conflicting project %s in manifest %s\n%s\n%s", project.Key(), mi.manifest, project.toString(), projectMap.get(project.Key()).toString())); } else { projectMap.put(project.Key(), project); } } URI parentURI; try { parentURI = new URI(mi.manifest); } catch (URISyntaxException e) { throw new ConfigInvalidException("Invalid parent URI", e); } for (JiriManifest.LocalImport l : m.imports.getLocalImports()) { ManifestItem tw = new ManifestItem(mi.repoKey, parentURI.resolve(l.getFile()).getPath(), mi.ref, mi.projectKey, mi.revisionPinned); q.add(tw); } for (JiriManifest.Import i : m.imports.getImports()) { i.fillDefault(); URI uri; try { uri = new URI(i.getRemote()); } catch (URISyntaxException e) { throw new ConfigInvalidException("Invalid URI", e); } String iRepoKey = new Project.NameKey(StringUtils.strip(uri.getPath(), "/")).toString(); String iRef = i.getRevision(); boolean revisionPinned = true; if (iRef.isEmpty()) { iRef = REFS_HEADS + i.getRemotebranch(); revisionPinned = false; } ManifestItem tmi = new ManifestItem(iRepoKey, i.getManifest(), iRef, i.Key(), revisionPinned); q.add(tmi); } } return new JiriProjects(projectMap.values().toArray(new JiriProjects.Project[0])); } }
From source file:com.htmlhifive.tools.rhino.comment.js.JSDocCommentNodeParser.java
private JSDocRoot resolveJsDoc() { // ?????(@~~) JSTag currentTag = JSTag.ROOT;/*from ww w.ja va2 s . c om*/ // ??Token? TokenType previousTokenType = TokenType.START; JSDocRoot root = new JSDocRoot(docType); // ?.?????. JSTagNode tempNode = root; int currentLineNum = 0; // ??StringBuilder StringBuilder currentDesc = new StringBuilder(); // JsDoc?. String desc = null; for (Token token : tokenList) { if (currentDesc.length() != 0 && !TokenUtil.isSymbolType(token.getType())) { if (token.getLineNum() != currentLineNum) { // ?????? currentDesc.append(Constants.LINE_SEPARATOR); currentLineNum = token.getLineNum(); } else { // ?????Token?. currentDesc.append(" "); } } switch (token.getType()) { case STRING_LITERAL: resolveStringLiteral(token, currentTag, previousTokenType, tempNode, currentDesc); break; case ANNOTATION: if (tempNode instanceof JSDocRoot) { // ??????desc?JSDoc????desc?? desc = currentDesc.toString(); } else if (tempNode instanceof JSSinglePartTagNode) { // ?????. ((JSSinglePartTagNode) tempNode).setValue(StringUtils.chomp(currentDesc.toString())); } if (tempNode != root) { root.addTagNode(tempNode); } currentDesc = new StringBuilder(); // ?????. JSTag temp = TokenUtil.resolveTagType(token); if (temp != null) { currentTag = temp; } // ?????. tempNode = resolveTagNode(currentTag); break; case TYPE: if (currentTag == null) { // ???????? currentDesc.append(token.getValue()); } if (tempNode instanceof JSTypePartNode) { // Type??????node? ((JSTypePartNode) tempNode).setType(StringUtils.strip(token.getValue(), "{}")); } break; case END: if (tempNode instanceof JSSinglePartTagNode) { // ?????. ((JSSinglePartTagNode) tempNode).setValue(currentDesc.toString()); } root.addTagNode(tempNode); break; case START: case SYMBOL: default: break; } previousTokenType = token.getType(); } // ?. root.setDescription(desc); return root; }