List of usage examples for java.lang StringBuilder charAt
char charAt(int index);
From source file:tr.edu.gsu.nerwip.retrieval.reader.wikipedia.WikipediaReader.java
/** * Retrieve the text located in /*from ww w .j a va 2s . c o m*/ * a list (UL or OL) HTML element. * * @param element * Element to be processed. * @param rawStr * Current raw text string. * @param linkedStr * Current text with hyperlinks. * @param ordered * Whether the list is numbered or not. */ private void processListElement(Element element, StringBuilder rawStr, StringBuilder linkedStr, boolean ordered) { // possibly remove the last new line character char c = rawStr.charAt(rawStr.length() - 1); if (c == '\n') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly remove preceeding space c = rawStr.charAt(rawStr.length() - 1); if (c == ' ') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly add a column c = rawStr.charAt(rawStr.length() - 1); if (c != '.' && c != ':' && c != ';') { rawStr.append(":"); linkedStr.append(":"); } // process each list element int count = 1; for (Element listElt : element.getElementsByTag(XmlNames.ELT_LI)) { // add leading space rawStr.append(" "); linkedStr.append(" "); // possibly add number if (ordered) { rawStr.append(count + ") "); linkedStr.append(count + ") "); } count++; // get text and links processTextElement(listElt, rawStr, linkedStr); // possibly remove the last new line character c = rawStr.charAt(rawStr.length() - 1); if (c == '\n') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // add final separator rawStr.append(";"); linkedStr.append(";"); } // possibly remove last separator c = rawStr.charAt(rawStr.length() - 1); if (c == ';') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); c = rawStr.charAt(rawStr.length() - 1); if (c != '.') { rawStr.append("."); linkedStr.append("."); } rawStr.append("\n"); linkedStr.append("\n"); } }
From source file:com.datos.vfs.impl.DefaultFileSystemManager.java
/** * Resolves a name, relative to the root. * * @param base the base filename/*from ww w .j a v a 2 s . com*/ * @param name the name * @param scope the {@link NameScope} * @return The FileName of the file. * @throws FileSystemException if an error occurs. */ @Override public FileName resolveName(final FileName base, final String name, final NameScope scope) throws FileSystemException { final FileName realBase; if (base != null && VFS.isUriStyle() && base.isFile()) { realBase = base.getParent(); } else { realBase = base; } final StringBuilder buffer = new StringBuilder(name); // Adjust separators UriParser.fixSeparators(buffer); String scheme = UriParser.extractScheme(buffer.toString()); // Determine whether to prepend the base path if (name.length() == 0 || (scheme == null && buffer.charAt(0) != FileName.SEPARATOR_CHAR)) { // Supplied path is not absolute if (!VFS.isUriStyle()) { // when using uris the parent already do have the trailing "/" buffer.insert(0, FileName.SEPARATOR_CHAR); } buffer.insert(0, realBase.getPath()); } // Normalise the path final FileType fileType = UriParser.normalisePath(buffer); // Check the name is ok final String resolvedPath = buffer.toString(); if (!AbstractFileName.checkName(realBase.getPath(), resolvedPath, scope)) { throw new FileSystemException("vfs.provider/invalid-descendent-name.error", name); } String fullPath; if (scheme != null) { fullPath = resolvedPath; } else { scheme = realBase.getScheme(); fullPath = realBase.getRootURI() + resolvedPath; } final FileProvider provider = providers.get(scheme); if (provider != null) { // TODO: extend the filename parser to be able to parse // only a pathname and take the missing informations from // the base. Then we can get rid of the string operation. // // String fullPath = base.getRootURI() + // resolvedPath.substring(1); return provider.parseUri(realBase, fullPath); } // An unknown scheme - hand it to the default provider - if possible if (scheme != null && defaultProvider != null) { return defaultProvider.parseUri(realBase, fullPath); } // TODO: avoid fallback to this point // this happens if we have a virtual filesystem (no provider for scheme) return ((AbstractFileName) realBase).createName(resolvedPath, fileType); }
From source file:tr.edu.gsu.nerwip.retrieval.reader.wikipedia.WikipediaReader.java
/** * Retrieve the text located in /*from w w w. ja v a 2s.c o m*/ * a description list (DL) HTML element. * * @param element * Element to be processed. * @param rawStr * Current raw text string. * @param linkedStr * Current text with hyperlinks. */ private void processDescriptionListElement(Element element, StringBuilder rawStr, StringBuilder linkedStr) { // possibly remove the last new line character char c = rawStr.charAt(rawStr.length() - 1); if (c == '\n') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly remove preceeding space c = rawStr.charAt(rawStr.length() - 1); if (c == ' ') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly add a column c = rawStr.charAt(rawStr.length() - 1); if (c != '.' && c != ':' && c != ';') { rawStr.append(":"); linkedStr.append(":"); } // process each list element Elements elements = element.children(); Iterator<Element> it = elements.iterator(); Element tempElt = null; if (it.hasNext()) tempElt = it.next(); while (tempElt != null) { // add leading space rawStr.append(" "); linkedStr.append(" "); // get term String tempName = tempElt.tagName(); if (tempName.equals(XmlNames.ELT_DT)) { // process term processTextElement(tempElt, rawStr, linkedStr); // possibly remove the last new line character c = rawStr.charAt(rawStr.length() - 1); if (c == '\n') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly remove preceeding space c = rawStr.charAt(rawStr.length() - 1); if (c == ' ') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly add a column and space c = rawStr.charAt(rawStr.length() - 1); if (c != '.' && c != ':' && c != ';') { rawStr.append(": "); linkedStr.append(": "); } // go to next element if (it.hasNext()) tempElt = it.next(); else tempElt = null; } // get definition // if(tempName.equals(XmlNames.ELT_DD)) if (tempElt != null) { // process term processTextElement(tempElt, rawStr, linkedStr); // possibly remove the last new line character c = rawStr.charAt(rawStr.length() - 1); if (c == '\n') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly remove preceeding space c = rawStr.charAt(rawStr.length() - 1); if (c == ' ') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); } // possibly add a semi-column c = rawStr.charAt(rawStr.length() - 1); if (c != '.' && c != ':' && c != ';') { rawStr.append(";"); linkedStr.append(";"); } // go to next element if (it.hasNext()) tempElt = it.next(); else tempElt = null; } } // possibly remove last separator c = rawStr.charAt(rawStr.length() - 1); if (c == ';') { rawStr.deleteCharAt(rawStr.length() - 1); linkedStr.deleteCharAt(linkedStr.length() - 1); c = rawStr.charAt(rawStr.length() - 1); if (c != '.') { rawStr.append("."); linkedStr.append("."); } rawStr.append("\n"); linkedStr.append("\n"); } }
From source file:org.eclipse.php.internal.core.typeinference.PHPModelUtils.java
/** * Concatenate FQN parameters into one string e.g. 'A\B' + 'C\D' = 'A\B\C\D' * /*from w w w. j a va2s.co m*/ * @param fqns * names to concat * @return concatenated names */ @NonNull public static String concatFullyQualifiedNames(String... fqns) { StringBuilder builder = new StringBuilder(); for (String fqn : fqns) { if (fqn != null) { if (builder.length() != 0 && builder.charAt(builder.length() - 1) != NamespaceReference.NAMESPACE_SEPARATOR && !fqn.isEmpty() && fqn.charAt(0) != NamespaceReference.NAMESPACE_SEPARATOR) { builder.append(NamespaceReference.NAMESPACE_SEPARATOR); } builder.append(fqn); } } return builder.toString(); }
From source file:github.daneren2005.dsub.util.Util.java
public static String getRestUrl(Context context, String method, SharedPreferences prefs, int instance, boolean allowAltAddress) { StringBuilder builder = new StringBuilder(); String serverUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_URL + instance, null); if (allowAltAddress && Util.isWifiConnected(context)) { String SSID = prefs.getString(Constants.PREFERENCES_KEY_SERVER_LOCAL_NETWORK_SSID + instance, ""); String currentSSID = Util.getSSID(context); String[] ssidParts = SSID.split(","); if ("".equals(SSID) || SSID.equals(currentSSID) || Arrays.asList(ssidParts).contains(currentSSID)) { String internalUrl = prefs.getString(Constants.PREFERENCES_KEY_SERVER_INTERNAL_URL + instance, null);//w ww.ja va 2 s. c o m if (internalUrl != null && !"".equals(internalUrl) && !"http://".equals(internalUrl)) { serverUrl = internalUrl; } } } String username = prefs.getString(Constants.PREFERENCES_KEY_USERNAME + instance, null); String password = prefs.getString(Constants.PREFERENCES_KEY_PASSWORD + instance, null); // Slightly obfuscate password password = "enc:" + Util.utf8HexEncode(password); builder.append(serverUrl); if (builder.charAt(builder.length() - 1) != '/') { builder.append("/"); } builder.append("rest/").append(method).append(".view"); builder.append("?u=").append(username); builder.append("&p=").append(password); builder.append("&v=").append(Constants.REST_PROTOCOL_VERSION); builder.append("&c=").append(Constants.REST_CLIENT_ID); return builder.toString(); }
From source file:jp.aegif.alfresco.online_webdav.WebDAVHelper.java
public String getURLForPath(HttpServletRequest request, String path, boolean isCollection, String userAgent) { String urlPathPrefix = getUrlPathPrefix(request); StringBuilder urlStr = new StringBuilder(urlPathPrefix); if (path.equals(WebDAV.RootPath) == false) { // split the path and URL encode each path element for (StringTokenizer t = new StringTokenizer(path, PathSeperator); t.hasMoreTokens(); /**/) { urlStr.append(WebDAVHelper.encodeURL(t.nextToken(), userAgent)); if (t.hasMoreTokens()) { urlStr.append(PathSeperator); }/* w ww. jav a2s. co m*/ } } // If the URL is to a collection add a trailing slash if (isCollection && urlStr.charAt(urlStr.length() - 1) != PathSeperatorChar) { urlStr.append(PathSeperator); } logger.debug("getURLForPath() path:" + path + " => url:" + urlStr); // Return the URL string return urlStr.toString(); }
From source file:org.georchestra.security.Proxy.java
private String concat(String target, StringBuilder builder) { if (target == null) { return null; }//from w ww . j a v a2 s .co m String target2 = target; if (target.endsWith("/")) { target2 = target.substring(0, target.length() - 1); } if (builder.charAt(0) != '/') { builder.insert(0, '/'); } return target2 + builder; }
From source file:org.ngrinder.perftest.service.PerfTestService.java
private void completeCustomData(Map<String, String> returnMap, String key, StringBuilder customData) { if (customData.charAt(customData.length() - 1) == ',') { customData.deleteCharAt(customData.length() - 1); }//from w w w. jav a2 s. co m returnMap.put(key, customData.append("]").toString()); }
From source file:com.heliosdecompiler.helios.tasks.DecompileTask.java
private List<String> generatePossibilities(ClassOrInterfaceType type) { List<String> possibilities = new ArrayList<>(); /*/*from ww w . j av a 2 s .c o m*/ * This is the ClassOrInterfaceType as the entire string. * Eg. java.lang.System or System */ String fullName = type.toString(); /* * This will only be one word. * Eg. System */ String simpleName = type.getName(); /* * If the fullName is something like Outer.Inner, asInnerClass will be Outer$Inner * * However, if the fullName is a FQN, then asInnerClass will not be valid * Eg, java$lang$System */ String asInnerClass = fullName.replace('.', '$'); for (ImportDeclaration importDeclaration : compilationUnit.getImports()) { if (importDeclaration.isAsterisk()) { String fullImport = importDeclaration.getName().toString(); String internalName = fullImport.replace('.', '/'); possibilities.add(internalName + "/" + asInnerClass + ".class"); } else if (importDeclaration.isStatic()) { } else { NameExpr importName = importDeclaration.getName(); if (importName.getName().equals(simpleName)) { String javaName = importDeclaration.getName().toString(); String internalName = javaName.replace('.', '/'); possibilities.add(internalName + ".class"); } } } /* * We must consider Fully Qualified Names * Therefore the string java.lang.System could be java$lang$System, java.lang$System, or java.lang.System */ String[] split = fullName.split("\\."); for (int i = 0; i < split.length; i++) { StringBuilder builder = new StringBuilder(); for (int start = 0; start < i; start++) { builder.append(split[start]).append("/"); } for (int start = i; start < split.length; start++) { builder.append(split[start]).append("$"); } if (builder.length() > 0 && (builder.charAt(builder.length() - 1) == '$' || builder.charAt(builder.length() - 1) == '/')) { builder.setLength(builder.length() - 1); } builder.append(".class"); possibilities.add(builder.toString()); } return possibilities; }
From source file:org.ngrinder.perftest.service.PerfTestService.java
/** * Get plugin monitor data and wrap the data as a string value like "[22,11,12,34,....]", which can be used directly * in JS as a vector.//w w w. j a va2s. c om * * @param testId test id * @param plugin plugin name * @param kind kind * @param interval interval value to get data. Interval value "2" means, get one record for every "2" records. * @return return the data in map */ public Map<String, Object> getReportPluginGraph(long testId, String plugin, String kind, int interval) { Map<String, Object> returnMap = Maps.newHashMap(); File pluginDataFile = getReportPluginDataFile(testId, plugin, kind); BufferedReader br = null; try { br = new BufferedReader(new FileReader(pluginDataFile)); String header = br.readLine(); StringBuilder headerSB = new StringBuilder("["); String[] headers = StringUtils.split(header, ","); String[] refinedHeaders = StringUtils.split(header, ","); List<StringBuilder> dataStringBuilders = new ArrayList<StringBuilder>(headers.length); for (int i = 0; i < headers.length; i++) { dataStringBuilders.add(new StringBuilder("[")); String refinedHead = headers[i].trim().replaceAll(" ", "_"); refinedHeaders[i] = refinedHead; headerSB.append("'").append(refinedHead).append("'").append(","); } String headerStringInJSONList = headerSB.deleteCharAt(headerSB.length() - 1).append("]").toString(); returnMap.put("header", headerStringInJSONList); String line = br.readLine(); int skipCount = interval; // to be compatible with previous version, check the length before adding while (StringUtils.isNotBlank(line)) { if (skipCount < interval) { skipCount++; } else { skipCount = 1; String[] records = StringUtils.split(line, ","); for (int i = 0; i < records.length; i++) { if ("null".equals(records[i]) || "undefined".equals(records[i])) { dataStringBuilders.get(i).append("null").append(","); } else { dataStringBuilders.get(i).append(records[i]).append(","); } } line = br.readLine(); } } for (int i = 0; i < refinedHeaders.length; i++) { StringBuilder dataSB = dataStringBuilders.get(i); if (dataSB.charAt(dataSB.length() - 1) == ',') { dataSB.deleteCharAt(dataSB.length() - 1); } dataSB.append("]"); returnMap.put(refinedHeaders[i], dataSB.toString()); } } catch (IOException e) { LOGGER.error("Error while getting monitor: {} data file:{}", plugin, pluginDataFile); LOGGER.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(br); } return returnMap; }