List of usage examples for java.lang StringBuffer lastIndexOf
@Override public int lastIndexOf(String str)
From source file:org.eclipse.dirigible.ide.db.export.DataExportServiceHandler.java
/** * Generate the download URL// w w w . jav a 2 s. c o m * * @param tableName * @return the URL */ public static String getUrl(String tableName) { ServiceManager manager = RWT.getServiceManager(); String rootURL = manager.getServiceHandlerUrl(DataExportServiceHandler_SERVICE_HANDLER_ID); StringBuffer url = new StringBuffer(); url.append(rootURL); url.append(AMP); url.append(FILENAME_PARAM).append(EQ).append(tableName.toLowerCase()).append(DSV_EXTENSION); int relativeIndex = url.lastIndexOf(SLASH); if (relativeIndex > -1) { url.delete(0, relativeIndex + 1); } return RWT.getResponse().encodeURL(url.toString()); }
From source file:hydrograph.ui.perspective.dialog.PreStartActivity.java
/** * Checks whether given JDK-PATH is valid or not. * /* w ww . j a v a 2 s.co m*/ * @param javaHome * input jdk path * @param showPopUp * true if user wants to show pop for invalid path. * @return * true if input string is valid JDK path. */ public static boolean isValidJDKPath(String javaHome, boolean showPopUp) { try { if (javaHome != null && isValidDirectory(javaHome, showPopUp)) { if (StringUtils.endsWith(javaHome, SLASH_BIN)) { javaHome = StringUtils.replace(javaHome, SLASH_BIN, ""); } if (StringUtils.isNotBlank(javaHome)) { StringBuffer jdkPath = new StringBuffer(javaHome); jdkPath = jdkPath.delete(0, jdkPath.lastIndexOf("\\") + 1); return checkJDKVersion(jdkPath.toString(), showPopUp); } } } catch (Exception exception) { logger.warn("Exception occurred while validating javaHome path", exception); } return false; }
From source file:ch.entwine.weblounge.common.url.PathUtils.java
/** * Concatenates the path elements with respect to leading and trailing * slashes. The path will always end with a trailing slash. * /* w w w .j av a2s .co m*/ * @param pathElements * the path elements * @return the concatenated url of the two arguments * @throws IllegalArgumentException * if less than two path elements are provided */ public static String concat(String... pathElements) throws IllegalArgumentException { if (pathElements == null || pathElements.length < 1) throw new IllegalArgumentException("Prefix cannot be null or empty"); if (pathElements.length < 2) throw new IllegalArgumentException("Suffix cannot be null or empty"); StringBuffer b = new StringBuffer(); for (String s : pathElements) { if (StringUtils.isBlank(s)) throw new IllegalArgumentException("Path element cannot be null"); String element = adjustSeparator(s); element = removeDoubleSeparator(element); element = cleanSpecializedCharacter(element); if (b.length() == 0) { b.append(element); } else if (b.lastIndexOf(File.separator) < b.length() - 1 && !element.startsWith(File.separator)) { b.append(File.separator).append(element); } else if (b.lastIndexOf(File.separator) == b.length() - 1 && element.startsWith(File.separator)) { b.append(element.substring(1)); } else { b.append(element); } } return b.toString(); }
From source file:com.android.providers.downloads.OmaDownload.java
/** * This method parses an xml file into a provided component. @param ddUrl the URL of the download descriptor file @param file the file containing the XML to be parsed @param component the component to which the parsed xml data should be added @return the status code (success or other error code) *///from ww w. j a v a 2 s . c o m protected static int parseXml(URL ddUrl, File file, OmaDescription component) { BufferedReader sReader = null; //Initialize the status code in the component component.setStatusCode(OmaStatusHandler.SUCCESS); if (file == null || ddUrl == null) { component.setStatusCode(OmaStatusHandler.INVALID_DESCRIPTOR); } else { try { sReader = new BufferedReader(new FileReader(file)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block Log.e("@M_" + Constants.LOG_OMA_DL, e.toString()); } try { Xml.parse(sReader, OMADL_INSTANCE.new DDHandler(ddUrl, component)); } catch (IOException e) { // TODO Auto-generated catch block Log.e("@M_" + Constants.LOG_OMA_DL, e.toString()); } catch (SAXException e) { // TODO Auto-generated catch block Log.e("@M_" + Constants.LOG_OMA_DL, e.toString()); component.setStatusCode(OmaStatusHandler.INVALID_DESCRIPTOR); //parse install notify url String strLine; try { sReader = new BufferedReader(new FileReader(file)); while ((strLine = sReader.readLine()) != null) { strLine = strLine.trim(); StringBuffer strBuffer = new StringBuffer(strLine); String startTag = "<installNotifyURI>"; String endTag = "</installNotifyURI>"; int startTagPos = strBuffer.lastIndexOf(startTag); int endTagPos = strBuffer.lastIndexOf(endTag); if (startTagPos != -1 && endTagPos != -1) { strLine = strLine.substring(startTagPos + startTag.length(), endTagPos); Log.d("@M_" + Constants.LOG_OMA_DL, "install notify URI: " + strLine); URL url = new URL(strLine); component.setInstallNotifyUrl(url); break; } } } catch (IOException e1) { // TODO Auto-generated catch block Log.e("@M_" + Constants.LOG_OMA_DL, e1.toString()); } } } return component.getStatusCode(); }
From source file:org.bibsonomy.plugin.jabref.util.JabRefModelConverter.java
public static void copyTags(final BibtexEntry entry, final Post<? extends Resource> post) { /*/*from w w w .j ava2 s .c o m*/ * concatenate tags using the JabRef keyword separator */ final Set<Tag> tags = post.getTags(); final StringBuffer tagsBuffer = new StringBuffer(); for (final Tag tag : tags) { tagsBuffer.append(tag.getName() + jabRefKeywordSeparator); } /* * remove last separator */ if (!tags.isEmpty()) { tagsBuffer.delete(tagsBuffer.lastIndexOf(jabRefKeywordSeparator), tagsBuffer.length()); } final String tagsBufferString = tagsBuffer.toString(); if (present(tagsBufferString)) entry.setField("keywords", tagsBufferString); }
From source file:ch.entwine.weblounge.common.url.UrlUtils.java
/** * Concatenates the url elements with respect to leading and trailing slashes. * The path will always end with a trailing slash. * //from w ww . jav a 2s . c o m * @param urlElements * the path elements * @return the concatenated url of the two arguments * @throws IllegalArgumentException * if less than two path elements are provided */ public static String concat(String... urlElements) throws IllegalArgumentException { if (urlElements == null || urlElements.length < 1) throw new IllegalArgumentException("Prefix cannot be null or empty"); if (urlElements.length < 2) throw new IllegalArgumentException("Suffix cannot be null or empty"); StringBuffer b = new StringBuffer(); for (String s : urlElements) { if (StringUtils.isBlank(s)) throw new IllegalArgumentException("Path element cannot be null"); String element = checkSeparator(s); element = removeDoubleSeparator(element); if (b.length() == 0) { b.append(element); } else if (b.lastIndexOf("/") < b.length() - 1 && !element.startsWith("/")) { b.append("/").append(element); } else if (b.lastIndexOf("/") == b.length() - 1 && element.startsWith("/")) { b.append(element.substring(1)); } else { b.append(element); } } return b.toString(); }
From source file:org.wso2.andes.configuration.AndesConfigurationManager.java
private static String getKey(Stack<String> nameStack) { StringBuffer key = new StringBuffer(); for (int i = 0; i < nameStack.size(); i++) { String name = nameStack.elementAt(i); key.append(name).append("."); }//from w ww. j a va2 s .c om key.deleteCharAt(key.lastIndexOf(".")); return key.toString(); }
From source file:org.bibsonomy.layout.util.JabRefModelConverter.java
/** * Converts a BibSonomy post into a JabRef BibtexEntry * //from w ww . jav a2 s. c o m * @param post * @param urlGen * - the URLGenerator to create the biburl-field * @return */ public static BibtexEntry convertPost(final Post<? extends Resource> post, URLGenerator urlGen) { try { /* * what we have */ final BibTex bibtex = (BibTex) post.getResource(); /* * what we want */ final BibtexEntry entry = new BibtexEntry(); /* * each entry needs an ID (otherwise we get a NPE) ... let JabRef * generate it */ /* * we use introspection to get all fields ... */ final BeanInfo info = Introspector.getBeanInfo(bibtex.getClass()); final PropertyDescriptor[] descriptors = info.getPropertyDescriptors(); /* * iterate over all properties */ for (final PropertyDescriptor pd : descriptors) { final Method getter = pd.getReadMethod(); // loop over all String attributes final Object o = getter.invoke(bibtex, (Object[]) null); if (String.class.equals(pd.getPropertyType()) && (o != null) && !JabRefModelConverter.EXCLUDE_FIELDS.contains(pd.getName())) { final String value = ((String) o); if (present(value)) entry.setField(pd.getName().toLowerCase(), value); } } /* * convert entry type (Is never null but getType() returns null for * unknown types and JabRef knows less types than we.) * * FIXME: a nicer solution would be to implement the corresponding * classes for the missing entrytypes. */ final BibtexEntryType entryType = BibtexEntryType.getType(bibtex.getEntrytype()); entry.setType(entryType == null ? BibtexEntryType.OTHER : entryType); if (present(bibtex.getMisc()) || present(bibtex.getMiscFields())) { // parse the misc fields and loop over them bibtex.parseMiscField(); if (bibtex.getMiscFields() != null) for (final String key : bibtex.getMiscFields().keySet()) { if ("id".equals(key)) { // id is used by jabref entry.setField("misc_id", bibtex.getMiscField(key)); continue; } if (key.startsWith("__")) // ignore fields starting with // __ - jabref uses them for // control continue; entry.setField(key, bibtex.getMiscField(key)); } } final String month = bibtex.getMonth(); if (present(month)) { /* * try to convert the month abbrev like JabRef does it */ final String longMonth = Globals.MONTH_STRINGS.get(month); if (present(longMonth)) { entry.setField("month", longMonth); } else { entry.setField("month", month); } } final String bibAbstract = bibtex.getAbstract(); if (present(bibAbstract)) entry.setField("abstract", bibAbstract); /* * concatenate tags using the JabRef keyword separator */ final Set<Tag> tags = post.getTags(); final StringBuffer tagsBuffer = new StringBuffer(); for (final Tag tag : tags) { tagsBuffer.append(tag.getName() + jabRefKeywordSeparator); } /* * remove last separator */ if (!tags.isEmpty()) { tagsBuffer.delete(tagsBuffer.lastIndexOf(jabRefKeywordSeparator), tagsBuffer.length()); } final String tagsBufferString = tagsBuffer.toString(); if (present(tagsBufferString)) entry.setField(BibTexUtils.ADDITIONAL_MISC_FIELD_KEYWORDS, tagsBufferString); // set groups - will be used in jabref when exporting to bibsonomy if (present(post.getGroups())) { final Set<Group> groups = post.getGroups(); final StringBuffer groupsBuffer = new StringBuffer(); for (final Group group : groups) groupsBuffer.append(group.getName() + " "); final String groupsBufferString = groupsBuffer.toString().trim(); if (present(groupsBufferString)) entry.setField("groups", groupsBufferString); } // set comment + description final String description = post.getDescription(); if (present(description)) { entry.setField(BibTexUtils.ADDITIONAL_MISC_FIELD_DESCRIPTION, post.getDescription()); entry.setField("comment", post.getDescription()); } if (present(post.getDate())) { entry.setField("added-at", sdf.format(post.getDate())); } if (present(post.getChangeDate())) { entry.setField("timestamp", sdf.format(post.getChangeDate())); } if (present(post.getUser())) entry.setField("username", post.getUser().getName()); // set URL to bibtex version of this entry (bibrecord = ...) entry.setField(BibTexUtils.ADDITIONAL_MISC_FIELD_BIBURL, urlGen.getPublicationUrl(bibtex, post.getUser()).toString()); return entry; } catch (final Exception e) { log.error("Could not convert BibSonomy post into a JabRef BibTeX entry.", e); } return null; }
From source file:ch.entwine.weblounge.maven.S3DeployMojo.java
/** * Concatenates the url elements with respect to leading and trailing slashes. * The path will always end with a trailing slash. * //ww w. ja v a2s .c o m * @param urlElements * the path elements * @return the concatenated url of the two arguments * @throws IllegalArgumentException * if less than two path elements are provided */ private static String concat(String... urlElements) throws IllegalArgumentException { if (urlElements == null || urlElements.length < 1) throw new IllegalArgumentException("Prefix cannot be null or empty"); if (urlElements.length < 2) throw new IllegalArgumentException("Suffix cannot be null or empty"); StringBuffer b = new StringBuffer(); for (String s : urlElements) { if (StringUtils.isBlank(s)) throw new IllegalArgumentException("Path element cannot be null"); String element = checkSeparator(s); element = removeDoubleSeparator(element); if (b.length() == 0) { b.append(element); } else if (b.lastIndexOf("/") < b.length() - 1 && !element.startsWith("/")) { b.append("/").append(element); } else if (b.lastIndexOf("/") == b.length() - 1 && element.startsWith("/")) { b.append(element.substring(1)); } else { b.append(element); } } return b.toString(); }
From source file:org.eclipse.jubula.tools.internal.utils.StringParsing.java
/** * Checks <code>str</code> for a sequence number, based on the * <code>sequencePrefix</code>. If a sequence number is found, it is * incremented, and the incremented string is returned. If no sequence is * found, a new sequence is started, and the string with the newly started * sequence is returned. Only positive integers are recognized as a * valid sequence./*from w w w . ja v a 2s .c o m*/ * * <pre> * StringParsing.incrementSequence("abc", "_") = "abc_1" * StringParsing.incrementSequence("abc_5", "_") = "abc_6" * StringParsing.incrementSequence("_2", "_") = "_3" * StringParsing.incrementSequence("1", "_") = "1_1" * StringParsing.incrementSequence("abc_-1", "_") = "abc_-1_1" * StringParsing.incrementSequence("abc_0", "_") = "abc_0_1" * StringParsing.incrementSequence("abc_1_1", "_") = "abc_1_2" * </pre> * * @param str The string for which the sequence should be incremented. * Must not be empty (<code>null</code> or empty string). * @param sequencePrefix The string that precedes the sequence. Must not be * empty (<code>null</code> or empty string). * @return a string that represents the given string <code>str</code> with * the sequence number incremented. */ public static String incrementSequence(String str, String sequencePrefix) { Validate.notEmpty(str); Validate.notEmpty(sequencePrefix); StringBuffer builder = new StringBuffer(str); String suffix = StringUtils.substringAfterLast(str, "_"); //$NON-NLS-1$ // parse suffix to integer and increment if possible. // if we can't parse it, then we just start a new sequence. int sequence = -1; try { sequence = Integer.parseInt(suffix); if (sequence > 0) { sequence++; } } catch (NumberFormatException nfe) { // Could not parse the suffix to an integer. // The sequence will remain at its initialized value. } if (sequence > 0) { builder.replace(builder.lastIndexOf(suffix), builder.length(), String.valueOf(sequence)); } else { builder.append(sequencePrefix).append(1); } return builder.toString(); }