Example usage for java.lang String replaceFirst

List of usage examples for java.lang String replaceFirst

Introduction

In this page you can find the example usage for java.lang String replaceFirst.

Prototype

public String replaceFirst(String regex, String replacement) 

Source Link

Document

Replaces the first substring of this string that matches the given regular expression with the given replacement.

Usage

From source file:se.trillian.goodies.stripes.ViewForwardResolution.java

protected String extractViewName(String uri, HttpServletRequest request) {
    String contextPath = request.getContextPath();
    uri = StringUtils.removeStart(uri, contextPath);
    return uri.replaceFirst(viewNameSuffixPattern, "");

}

From source file:ch.rgw.tools.StringTool.java

public static String flattenStrings(final Hashtable<Object, Object> h, final flattenFilter fil) {
    if (h == null) {
        return null;
    }//  w  w  w .j  av a2 s.  c  o  m
    Enumeration<Object> keys = h.keys();
    StringBuffer res = new StringBuffer(1000);
    res.append("FS1").append(flattenSeparator);
    while (keys.hasMoreElements()) {
        Object ko = (keys.nextElement());
        if (fil != null) {
            if (fil.accept(ko) == false) {
                continue;
            }
        }
        String v = ObjectToString(h.get(ko));
        String k = ObjectToString(ko);
        if ((k == null) || (v == null) || k.matches(".*=.*")) { // log.log("attempt
            // to
            // flatten
            // unsupported
            // object
            // type",Log.FATALS);
            return null;
        }
        res.append(k).append("=").append(v).append(flattenSeparator);
    }
    String r = res.toString();
    return r.replaceFirst(flattenSeparator + "$", "");
}

From source file:com.github.mjdetullio.jenkins.plugins.multibranch.AbstractMultiBranchProject.java

/**
 * Migrates <code>SyncBranchesTrigger</code> to {@link hudson.triggers.TimerTrigger} and copies the
 * template's {@link hudson.security.AuthorizationMatrixProperty} to the parent as a
 * {@link com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty}.
 *///from  www .j  a  va  2  s.  c  o  m
@SuppressWarnings(UNUSED)
@Initializer(before = InitMilestone.PLUGINS_STARTED)
public static void migrate() throws IOException {
    final String projectAmpStartTag = "<hudson.security.AuthorizationMatrixProperty>";

    final File projectsDir = new File(Jenkins.getActiveInstance().getRootDir(), "jobs");

    if (!projectsDir.getCanonicalFile().isDirectory()) {
        return;
    }

    Collection<File> configFiles = FileUtils.listFiles(projectsDir, new NameFileFilter("config.xml"),
            TrueFileFilter.TRUE);

    for (final File configFile : configFiles) {
        String xml = FileUtils.readFileToString(configFile);

        // Rename and wrap trigger open tag
        xml = xml.replaceFirst("(?m)^  <syncBranchesTrigger>(\r?\n)    <spec>",
                "  <triggers>\n    <hudson.triggers.TimerTrigger>\n      <spec>");

        // Rename and wrap trigger close tag
        xml = xml.replaceFirst("(?m)^  </syncBranchesTrigger>",
                "    </hudson.triggers.TimerTrigger>\n  </triggers>");

        // Copy AMP from template if parent does not have a properties tag
        if (!xml.matches("(?ms).+(\r?\n)  <properties.+")
                // Long line is long
                && xml.matches(
                        "(?ms).*<((freestyle|maven)-multi-branch-project|com\\.github\\.mjdetullio\\.jenkins\\.plugins\\.multibranch\\.(FreeStyle|Maven)MultiBranchProject)( plugin=\".*?\")?.+")) {

            File templateConfigFile = new File(new File(configFile.getParentFile(), TEMPLATE), "config.xml");

            if (templateConfigFile.isFile()) {
                String templateXml = FileUtils.readFileToString(templateConfigFile);

                int start = templateXml.indexOf(projectAmpStartTag);
                int end = templateXml.indexOf("</hudson.security.AuthorizationMatrixProperty>");

                if (start != -1 && end != -1) {
                    String ampSettings = templateXml.substring(start + projectAmpStartTag.length(), end);

                    xml = xml.replaceFirst("(?m)^  ", "  <properties>\n    "
                            + "<com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty>"
                            + ampSettings
                            + "</com.cloudbees.hudson.plugins.folder.properties.AuthorizationMatrixProperty>"
                            + "\n  </properties>\n  ");
                }
            }
        }

        FileUtils.writeStringToFile(configFile, xml);
    }
}

From source file:at.ac.univie.isc.asio.engine.DatasetResource.java

@GET
@Path("/meta/schema")
public Response redirectFromDeprecatedDefinitionUri(@Context final UriInfo uri) {
    final String requested = uri.getAbsolutePath().toString();
    final String redirect = requested.replaceFirst("/meta/schema/?$", "/schema");
    log.debug(Scope.REQUEST.marker(), "redirecting request to deprecated schema path {} to {}", requested,
            redirect);//from   www . j a  v  a  2 s .  co m
    assert requested.endsWith("/meta/schema")
            || requested.endsWith("/meta/schema/") : "check @Path annotation - unexpected request to "
                    + requested;
    return Response.status(Response.Status.MOVED_PERMANENTLY).location(URI.create(redirect)).build();
}

From source file:com.codepine.api.testrail.model.Result.java

/**
 * Add a custom field./*  w  ww.j a v  a  2  s .  c o  m*/
 *
 * @param key   the name of the custom field with or without "custom_" prefix
 * @param value the value of the custom field
 * @return result instance for chaining
 */
public Result addCustomField(String key, Object value) {
    if (customFields == null) {
        customFields = new HashMap<>();
    }
    customFields.put(key.replaceFirst(CUSTOM_FIELD_KEY_PREFIX, ""), value);
    return this;
}

From source file:org.apache.taverna.tavlang.tools.convert.ToJson.java

public void convert(File in, File out) throws ReaderException, IOException, WriterException {
    String filename = in.getName();
    filename = filename.replaceFirst("\\..*", ".json");
    File workflowFile = new File(out.getAbsolutePath(), filename);

    WorkflowBundle wfBundle = io.readBundle(in, null);
    io.writeBundle(wfBundle, workflowFile, "application/ld+json");
    //      System.out.println(workflowFile);

}

From source file:jp.co.opentone.bsol.linkbinder.dto.AbstractDto.java

/**
 * ???????ID??.//  w w  w .  ja va2 s . c  om
 * @param str
 *            ??
 * @return ID??
 */
private String removeObjectId(String str) {
    return str.replaceFirst("@(\\d|\\w)+\\[", "[");
}

From source file:net.erdfelt.android.sdkfido.local.JarListing.java

/**
 * Convert all of the classlist entries to *.java source file listings instead.
 * //w w w .  jav a  2 s  .  c o m
 * @return the list of java source files.
 */
public Set<String> getJavaSourceListing() {
    Set<String> javasrcs = new TreeSet<String>();

    String javasrc;
    for (String classname : classlist) {
        if (classname.contains("$")) {
            continue; // skip (inner classes don't have a direct 1::1 java source file
        }

        javasrc = classname.replaceFirst("\\.class$", ".java");
        javasrcs.add(javasrc);
    }

    return javasrcs;
}

From source file:com.surevine.ldap2alfresco.ProfileUpdater.java

/**
 * Return a list of profile fields from the properties file.
 * @param properties Properties to look in
 * @param fieldPrefix Prefix for all properties which represent a profile field
 * @return List of profile field converters
 * @throws PropertyException if profile fields are not defined correctly in the properties file
 *///  w w w  .  ja  v  a  2  s .c om
private Collection<ProfileFieldConverter> getProfileFields(final PropertyWrapper properties,
        final String fieldPrefix) throws PropertyException {

    final String typeLabel = "type";
    final String multipleLabel = "multiple";
    final String ldapNameLabel = "ldapName";
    final String alfrescoNameLabel = "alfrescoName";

    Collection<ProfileFieldConverter> fields = new LinkedList<ProfileFieldConverter>();

    // looking for e.g. syncField.type.something
    Collection<String> keys = properties.getKeys("^" + fieldPrefix + "\\." + typeLabel + "\\..+");

    Iterator<String> iter = keys.iterator();

    while (iter.hasNext()) {
        String typeKey = iter.next();
        String attributeName = typeKey.replaceFirst("^" + fieldPrefix + "\\." + typeLabel + "\\.", "");

        String type = properties.getProperty(typeKey);

        boolean multiple = properties.getProperty(fieldPrefix + "." + multipleLabel + "." + attributeName)
                .equalsIgnoreCase("yes");

        String ldapName = properties.getProperty(fieldPrefix + "." + ldapNameLabel + "." + attributeName);

        String alfrescoName = properties
                .getProperty(fieldPrefix + "." + alfrescoNameLabel + "." + attributeName);

        LOGGER.info("Loading profile field converter: " + ldapName + " -> " + alfrescoName);

        if (type.equalsIgnoreCase("text")) {
            fields.add(new ProfileFieldTextConverter(ldapName, alfrescoName, multiple));
        } else if (type.equalsIgnoreCase("telephone")) {
            fields.add(new ProfileFieldTelephoneConverter(ldapName, alfrescoName, multiple));
        } else {
            LOGGER.log(Level.ERROR, "Unrecognised profile field type: " + type);
        }
    }

    return fields;
}

From source file:net.sourceforge.subsonic.backend.controller.RedirectionController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {

    String redirectFrom = getRedirectFrom(request);
    if (RESERVED_REDIRECTS.containsKey(redirectFrom)) {
        LOG.info("Reserved redirection: " + redirectFrom);
        return new ModelAndView(new RedirectView(RESERVED_REDIRECTS.get(redirectFrom)));
    }/*from   ww w .j  a v  a  2  s.c  o  m*/

    Redirection redirection = redirectFrom == null ? null : redirectionDao.getRedirection(redirectFrom);

    if (redirection == null) {
        LOG.info("No redirection found: " + redirectFrom);
        return new ModelAndView(new RedirectView("http://subsonic.org/pages"));
    }

    redirection.setLastRead(new Date());
    redirection.setReadCount(redirection.getReadCount() + 1);
    redirectionDao.updateRedirection(redirection);

    // Check for trial expiration (unless called from REST client for which the Subsonic server manages trial expiry).
    if (isTrialExpired(redirection) && !isREST(request)) {
        LOG.info("Expired redirection: " + redirectFrom);
        return new ModelAndView(new RedirectView("http://subsonic.org/pages/redirect-expired.jsp?redirectFrom="
                + redirectFrom + "&expired=" + redirection.getTrialExpires().getTime()));
    }

    String requestUrl = getFullRequestURL(request);
    String to = StringUtils.removeEnd(getRedirectTo(request, redirection), "/");
    String redirectTo = requestUrl.replaceFirst("http://" + redirectFrom + "\\.subsonic\\.org", to);
    LOG.info("Redirecting from " + requestUrl + " to " + redirectTo);

    return new ModelAndView(new RedirectView(redirectTo));
}