List of usage examples for org.apache.commons.lang3 StringUtils replaceOnce
public static String replaceOnce(final String text, final String searchString, final String replacement)
Replaces a String with another String inside a larger String, once.
A null reference passed to this method is a no-op.
StringUtils.replaceOnce(null, *, *) = null StringUtils.replaceOnce("", *, *) = "" StringUtils.replaceOnce("any", null, *) = "any" StringUtils.replaceOnce("any", *, null) = "any" StringUtils.replaceOnce("any", "", *) = "any" StringUtils.replaceOnce("aba", "a", null) = "aba" StringUtils.replaceOnce("aba", "a", "") = "ba" StringUtils.replaceOnce("aba", "a", "z") = "zba"
From source file:org.kalypso.ui.rrm.internal.conversion.to12_02.FixDotDotTimeseriesVisitor.java
private String fixFoldername(final String href) { if (href.startsWith("Niederschlag/")) //$NON-NLS-1$ return StringUtils.replaceOnce(href, "Niederschlag/", RrmSimulation.FOLDER_NIEDERSCHLAG + '/'); //$NON-NLS-1$ //$NON-NLS-2$ if (href.startsWith("Precipitation/")) //$NON-NLS-1$ return StringUtils.replaceOnce(href, "Precipitation/", RrmSimulation.FOLDER_NIEDERSCHLAG + '/'); //$NON-NLS-1$ //$NON-NLS-2$ if (href.startsWith("Klima/")) //$NON-NLS-1$ return StringUtils.replaceOnce(href, "Klima/", RrmSimulation.FOLDER_KLIMA + '/'); //$NON-NLS-1$ //$NON-NLS-2$ if (href.startsWith("Climate/")) //$NON-NLS-1$ return StringUtils.replaceOnce(href, "Climate/", RrmSimulation.FOLDER_KLIMA + '/'); //$NON-NLS-1$ //$NON-NLS-2$ if (href.startsWith("Pegel/")) //$NON-NLS-1$ return StringUtils.replaceOnce(href, "Pegel/", RrmSimulation.FOLDER_PEGEL + '/'); //$NON-NLS-1$ //$NON-NLS-2$ if (href.startsWith("Gauges/")) //$NON-NLS-1$ return StringUtils.replaceOnce(href, "Gauges/", RrmSimulation.FOLDER_PEGEL + '/'); //$NON-NLS-1$ //$NON-NLS-2$ if (href.startsWith("Zufluss/")) //$NON-NLS-1$ return StringUtils.replaceOnce(href, "Zufluss/", RrmSimulation.FOLDER_ZUFLUSS + '/'); //$NON-NLS-1$ //$NON-NLS-2$ if (href.startsWith("Tributary/")) //$NON-NLS-1$ return StringUtils.replaceOnce(href, "Tributary/", RrmSimulation.FOLDER_ZUFLUSS + '/'); //$NON-NLS-1$ //$NON-NLS-2$ return href;// w w w . j a v a 2 s.c o m }
From source file:org.spdx.rdfparser.license.ListedLicenses.java
/** * @param uri - URI of the actual resource * @param base - base for any fragments present in the license model * @return/* w ww. ja va 2 s . c om*/ * @throws NoListedLicenseRdfModel */ private Model getLicenseModel(String uri, String base) throws NoListedLicenseRdfModel { Model retval = ModelFactory.createDefaultModel(); InputStream in = null; try { try { if (!(onlyUseLocalLicenses && uri.startsWith(LISTED_LICENSE_URI_PREFIX))) { //Accessing the old HTTP urls produces 301. String actualUrl = StringUtils.replaceOnce(uri, "http://", "https://"); in = FileManager.get().open(actualUrl); try { readRdfaIntoModel(retval, in, base); Property p = retval.getProperty(SpdxRdfConstants.SPDX_NAMESPACE, SpdxRdfConstants.PROP_LICENSE_ID); if (retval.isEmpty() || !retval.contains(null, p)) { try { in.close(); } catch (IOException e) { logger.warn("Error closing listed license input"); } in = null; } } catch (Exception ex) { if (in != null) { in.close(); in = null; } } } } catch (Exception ex) { in = null; logger.warn( "Unable to open SPDX listed license model. Using local file copy for SPDX listed licenses"); } if (in == null) { // need to fetch from the local file system String id = uri.substring(LISTED_LICENSE_URI_PREFIX.length()); String fileName = LISTED_LICENSE_RDF_LOCAL_DIR + "/" + id; in = LicenseInfoFactory.class.getResourceAsStream("/" + fileName); if (in == null) { throw (new NoListedLicenseRdfModel("SPDX listed license " + uri + " could not be read.")); } try (InputStreamReader reader = new InputStreamReader(in, Charset.forName("UTF-8"))) { readRdfaIntoModel(retval, in, uri); } catch (Exception ex) { throw (new NoListedLicenseRdfModel("Error reading the spdx listed licenses: " + ex.getMessage(), ex)); } } return retval; } finally { if (in != null) { try { in.close(); } catch (IOException e) { logger.warn("Unable to close model input stream"); } } } }
From source file:org.thelq.stackexchange.api.queries.methods.VectorQueryMethod.java
public String getFinal() { String methodFinal = raw;//from w w w .j a v a2 s.co m if (vectorSingle != null) { String[] subsitutions = new String[vectorSingle.length]; Arrays.fill(subsitutions, "{}"); methodFinal = StringUtils.replaceEach(raw, subsitutions, vectorSingle); } else if (vectorCollection != null) { if (StringUtils.countMatches(raw, "{}") != 1) throw new RuntimeException("No more vectors to replace! Raw: " + raw + " | Final: " + methodFinal); //Verify vector if it is required Iterator<?> vectorItr = vectorCollection.iterator(); if (!vectorItr.hasNext()) throw new RuntimeException("Vector cannot be empty"); //Do the replace methodFinal = StringUtils.replaceOnce(raw, "{}", QueryUtils.PARAMETER_JOINER.join(vectorItr)); //Make sure we didn't miss anything if (methodFinal.contains("{}")) throw new RuntimeException("Still contains vector: " + methodFinal); } else throw new RuntimeException("No vector to replace! " + raw); return methodFinal; }