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:foam.nanos.blob.FileService.java

@Override
protected void download(X x) {
    OutputStream os = null;// ww  w.  jav a2 s. c  o  m
    HttpServletRequest req = x.get(HttpServletRequest.class);
    HttpServletResponse resp = x.get(HttpServletResponse.class);

    try {
        String path = req.getRequestURI();
        String id = path.replaceFirst("/service/" + nspec_.getName() + "/", "");

        // find file from file dao
        File file = (File) fileDAO_.find_(x, id);
        if (file == null || file.getData() == null) {
            resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }

        // check to see if current user has access to file owner
        if (userDAO_.find_(x, file.getOwner()) == null) {
            resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
            return;
        }

        // get blob and blob size
        // TODO: figure out why delegate is not being set for IdentifiedBlob
        String blobId = ((IdentifiedBlob) file.getData()).getId();
        Blob blob = getDelegate().find_(x, blobId);
        long size = blob.getSize();

        // set response status, content type, content length
        resp.setStatus(HttpServletResponse.SC_OK);
        resp.setContentType(file.getMimeType());
        resp.setHeader("Content-Length", Long.toString(size, 10));
        resp.setHeader("Cache-Control", "public");

        // output data to response
        os = resp.getOutputStream();
        blob.read(os, 0, size);
        os.close();
    } catch (Throwable t) {
        t.printStackTrace();
        throw new RuntimeException(t);
    } finally {
        IOUtils.closeQuietly(os);
    }
}

From source file:com.oakley.fon.util.RemoveHttpsRedirectHandler.java

@Override
public URI getLocationURI(HttpResponse response, HttpContext context) throws ProtocolException {
    String uri = super.getLocationURI(response, context).toString();
    if (uri.startsWith("https")) {
        uri = uri.replaceFirst("https", "http");
        Log.d(TAG, "Removing https from redirect:" + uri);
    }// ww w.ja  v  a2  s  . co m
    URI notSafeUri = null;
    try {
        notSafeUri = new URI(uri);
    } catch (URISyntaxException e) {
        Log.e(TAG, "error change URI", e);
    }
    return notSafeUri;
}

From source file:com.seedboxer.seedboxer.mule.processor.FileReceiver.java

@Override
public void process(Exchange exchange) throws Exception {
    Message msg = exchange.getIn();//  ww  w  .  j a  v a 2  s. c o m

    Matcher m = pattern.matcher((String) msg.getHeader(Exchange.FILE_NAME));
    if (m.matches()) {
        String username = m.group(1);
        String filepath = (String) msg.getHeader(Exchange.FILE_PATH);
        User user = usersController.getUser(username);

        for (String path : getLines(filepath)) {
            String realPath = path.replaceFirst("file://", ""); // Removes prefix of Flexget
            LOGGER.info("File added to queue. USER_ID={}, FILE={}", user.getId(), realPath);
            queueManager.push(user, realPath);
        }
    } else {
        throw new Exception("The file doesn't compile with the pattern");
    }
}

From source file:com.rover12421.shaka.apktool.AspjectJ.apktool_cli.MultiLanguageAj.java

public static String covertLocaleInfo(String str) {
    if (str == null || str.length() < MINLEN)
        return str;
    MultiLanguageSupport languageSupport = MultiLanguageSupport.getInstance();
    //        if (languageSupport.getLocale().equals(Locale.US)) return str;
    //        int len = str.length();
    for (int i = 0; i < langStr.length; i++) {
        String key = langStr[i];/*from  w w  w.j  av  a  2  s. c o  m*/
        //            if (len < key.length()) continue;
        String val = languageSupport.get(i, langStr[i]);
        if (key.equals(val))
            continue;
        str = str.replace(key, val);
    }

    for (int i = 0; i < langRpStr.length; i++) {
        try {
            String key = langRpStr[i];
            //                if (len < key.length()) continue;
            String val = languageSupport.get("r" + i, langRpStrDef[i]);
            if (key.equals(val))
                continue;
            str = str.replaceFirst(key, val);
        } catch (Exception e) {
        }
    }

    return str;
}

From source file:net.sf.maltcms.chromaui.charts.renderer.XYPlotRendererListCellRenderer.java

@Override
public Component getListCellRendererComponent(JList list, Object value, int i, boolean isSelected,
        boolean hasFocus) {
    //Get the selected index. (The index param isn't
    //always valid, so just use the value.)
    //        int selectedIndex = ((Integer)value).intValue();

    if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    } else {//from ww  w.  j  ava2s. co m
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }

    if (value instanceof XYItemRenderer) {
        String className = ((XYItemRenderer) value).getClass().getSimpleName();
        className = className.replaceFirst("XY", "");
        className = className.replaceFirst("Renderer", "");
        setText(className);
    }

    return this;
}

From source file:com.cognifide.qa.bb.aem.ui.AemContentTree.java

private String getPathWithoutRootNode(String path) {
    return path.replaceFirst(getRootNodeContent().getText(), StringUtils.EMPTY);
}

From source file:com.stratio.cassandra.lucene.schema.mapping.BigDecimalMapper.java

private void validateIntegerPart(String name, Object value, String[] parts) {
    String integerPart = parts[0];
    if (integerPart.replaceFirst("-", "").length() > integerDigits) {
        throw new IndexException("Field '%s' with value '%s' has more than %d integer digits", name, value,
                integerDigits);// w  w  w . java2s.c o  m
    }
}

From source file:org.fcrepo.auth.oauth.integration.api.ContainerWrapper.java

public void setConfigLocation(final String configLocation) {
    this.configLocation = configLocation.replaceFirst("^classpath:", "/");
}

From source file:com.norconex.collector.http.robot.impl.DefaultRobotsTxtProvider.java

private String getBaseURL(String url) {
    String baseURL = url.replaceFirst("(.*?://.*?/)(.*)", "$1");
    if (baseURL.endsWith("/")) {
        baseURL = StringUtils.removeEnd(baseURL, "/");
    }/*from  ww w .jav a 2  s. c om*/
    return baseURL;
}

From source file:org.alfresco.bm.event.producer.AbstractEventProducer.java

@Override
public void setBeanName(String beanName) {
    String eventName = beanName.replaceFirst(EventProducer.PRODUCER_NAME_PREFIX, "");
    setEventName(eventName);/*from  w w w.j ava2  s  . co  m*/
}