Example usage for org.apache.commons.lang3 StringUtils substringBeforeLast

List of usage examples for org.apache.commons.lang3 StringUtils substringBeforeLast

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substringBeforeLast.

Prototype

public static String substringBeforeLast(final String str, final String separator) 

Source Link

Document

Gets the substring before the last occurrence of a separator.

Usage

From source file:cn.teamlab.wg.framework.struts2.json.PackageBasedActionConfigBuilder.java

/**
 * Note that we can't include the test for {@link #actionSuffix} here
 * because a class is included if its name ends in {@link #actionSuffix} OR
 * it implements {@link com.opensymphony.xwork2.Action}. Since the whole
 * goal is to avoid loading the class if we don't have to, the (actionSuffix
 * || implements Action) test will have to remain until later. See
 * {@link #getActionClassTest()} for the test performed on the loaded
 * {@link ClassInfo} structure.//from   w ww  .  j  av a  2  s .c o  m
 * 
 * @param className
 *            the name of the class to test
 * @return true if the specified class should be included in the
 *         package-based action scan
 */
protected boolean includeClassNameInActionScan(String className) {
    String classPackageName = StringUtils.substringBeforeLast(className, ".");
    return (checkActionPackages(classPackageName) || checkPackageLocators(classPackageName))
            && checkExcludePackages(classPackageName);
}

From source file:de.blizzy.documentr.page.PageStore.java

@Override
public List<String> listPageAttachments(String projectName, String branchName, String pagePath)
        throws IOException {

    Assert.hasLength(projectName);/*from w w  w .jav a2 s.  com*/
    Assert.hasLength(branchName);
    Assert.hasLength(pagePath);
    // check if page exists by trying to load it
    getPage(projectName, branchName, pagePath, false);

    ILockedRepository repo = null;
    try {
        repo = globalRepositoryManager.getProjectBranchRepository(projectName, branchName);
        File workingDir = RepositoryUtil.getWorkingDir(repo.r());
        File attachmentsDir = new File(workingDir, DocumentrConstants.ATTACHMENTS_DIR_NAME);
        File pageAttachmentsDir = Util.toFile(attachmentsDir, pagePath);
        List<String> names = Collections.emptyList();
        if (pageAttachmentsDir.isDirectory()) {
            FileFilter filter = new FileFilter() {
                @Override
                public boolean accept(File file) {
                    return file.isFile() && file.getName().endsWith(DocumentrConstants.META_SUFFIX);
                }
            };
            List<File> files = Lists.newArrayList(pageAttachmentsDir.listFiles(filter));
            Function<File, String> function = new Function<File, String>() {
                @Override
                public String apply(File file) {
                    return StringUtils.substringBeforeLast(file.getName(), DocumentrConstants.META_SUFFIX);
                }
            };
            names = Lists.newArrayList(Lists.transform(files, function));
            Collections.sort(names);
        }
        return names;
    } catch (GitAPIException e) {
        throw new IOException(e);
    } finally {
        Closeables.closeQuietly(repo);
    }
}

From source file:de.blizzy.documentr.access.UserStore.java

/**
 * Returns the user that has an OpenID whose real ID is equal to the specified OpenID.
 *
 * @throws UserNotFoundException when the user could not be found
 *//*from   w w w  .j a va  2  s .  c om*/
public User getUserByOpenId(String openId) throws IOException {
    ILockedRepository repo = null;
    try {
        repo = globalRepositoryManager.getProjectCentralRepository(REPOSITORY_NAME, false);
        File workingDir = RepositoryUtil.getWorkingDir(repo.r());
        FileFilter filter = new FileFilter() {
            @Override
            public boolean accept(File file) {
                return file.isFile() && file.getName().endsWith(USER_SUFFIX);
            }
        };
        for (File file : workingDir.listFiles(filter)) {
            String loginName = StringUtils.substringBeforeLast(file.getName(), USER_SUFFIX);
            String json = FileUtils.readFileToString(file, Charsets.UTF_8);
            User user = getUser(loginName, json);
            for (OpenId id : user.getOpenIds()) {
                if (id.getRealId().equals(openId)) {
                    return user;
                }
            }
        }

        throw new OpenIdNotFoundException(openId);
    } finally {
        Closeables.closeQuietly(repo);
    }
}

From source file:ching.icecreaming.action.ViewAction.java

@Action(value = "view", results = { @Result(name = "login", location = "edit.jsp"),
        @Result(name = "input", location = "view.jsp"), @Result(name = "success", location = "view.jsp"),
        @Result(name = "error", location = "error.jsp") })
public String execute() throws Exception {
    Enumeration enumerator = null;
    String[] array1 = null, array2 = null;
    int int1 = -1, int2 = -1, int3 = -1;
    InputStream inputStream1 = null;
    OutputStream outputStream1 = null;
    java.io.File file1 = null, file2 = null, dir1 = null;
    List<File> files = null;
    HttpHost httpHost1 = null;/*from  www  . j av  a2s  .c  o  m*/
    HttpGet httpGet1 = null, httpGet2 = null;
    HttpPut httpPut1 = null;
    URI uri1 = null;
    URL url1 = null;
    DefaultHttpClient httpClient1 = null;
    URIBuilder uriBuilder1 = null, uriBuilder2 = null;
    HttpResponse httpResponse1 = null, httpResponse2 = null;
    HttpEntity httpEntity1 = null, httpEntity2 = null;
    List<NameValuePair> nameValuePair1 = null;
    String string1 = null, string2 = null, string3 = null, string4 = null, return1 = LOGIN;
    XMLConfiguration xmlConfiguration = null;
    List<HierarchicalConfiguration> list1 = null, list2 = null;
    HierarchicalConfiguration hierarchicalConfiguration2 = null;
    DataModel1 dataModel1 = null;
    DataModel2 dataModel2 = null;
    List<DataModel1> listObject1 = null, listObject3 = null;
    org.joda.time.DateTime dateTime1 = null, dateTime2 = null;
    org.joda.time.Period period1 = null;
    PeriodFormatter periodFormatter1 = new PeriodFormatterBuilder().appendYears()
            .appendSuffix(String.format(" %s", getText("year")), String.format(" %s", getText("years")))
            .appendSeparator(" ").appendMonths()
            .appendSuffix(String.format(" %s", getText("month")), String.format(" %s", getText("months")))
            .appendSeparator(" ").appendWeeks()
            .appendSuffix(String.format(" %s", getText("week")), String.format(" %s", getText("weeks")))
            .appendSeparator(" ").appendDays()
            .appendSuffix(String.format(" %s", getText("day")), String.format(" %s", getText("days")))
            .appendSeparator(" ").appendHours()
            .appendSuffix(String.format(" %s", getText("hour")), String.format(" %s", getText("hours")))
            .appendSeparator(" ").appendMinutes()
            .appendSuffix(String.format(" %s", getText("minute")), String.format(" %s", getText("minutes")))
            .appendSeparator(" ").appendSeconds().minimumPrintedDigits(2)
            .appendSuffix(String.format(" %s", getText("second")), String.format(" %s", getText("seconds")))
            .printZeroNever().toFormatter();
    if (StringUtils.isBlank(urlString) || StringUtils.isBlank(wsType)) {
        urlString = portletPreferences.getValue("urlString", "/");
        wsType = portletPreferences.getValue("wsType", "folder");
    }
    Configuration propertiesConfiguration1 = new PropertiesConfiguration("system.properties");
    timeZone1 = portletPreferences.getValue("timeZone", TimeZone.getDefault().getID());
    enumerator = portletPreferences.getNames();
    if (enumerator.hasMoreElements()) {
        array1 = portletPreferences.getValues("server", null);
        if (array1 != null) {
            if (ArrayUtils.isNotEmpty(array1)) {
                for (int1 = 0; int1 < array1.length; int1++) {
                    switch (int1) {
                    case 0:
                        sid = array1[int1];
                        break;
                    case 1:
                        uid = array1[int1];
                        break;
                    case 2:
                        pid = array1[int1];
                        break;
                    case 3:
                        alias1 = array1[int1];
                        break;
                    default:
                        break;
                    }
                }
                sid = new String(Base64.decodeBase64(sid.getBytes()));
                uid = new String(Base64.decodeBase64(uid.getBytes()));
                pid = new String(Base64.decodeBase64(pid.getBytes()));
            }
            return1 = INPUT;
        } else {
            return1 = LOGIN;
        }
    } else {
        return1 = LOGIN;
    }

    if (StringUtils.equals(urlString, "/")) {

        if (listObject1 != null) {
            listObject1.clear();
        }
        if (session.containsKey("breadcrumbs")) {
            session.remove("breadcrumbs");
        }
    } else {
        array2 = StringUtils.split(urlString, "/");
        listObject1 = (session.containsKey("breadcrumbs")) ? (List<DataModel1>) session.get("breadcrumbs")
                : new ArrayList<DataModel1>();
        int2 = array2.length - listObject1.size();
        if (int2 > 0) {
            listObject1.add(new DataModel1(urlString, label1));
        } else {
            int2 += listObject1.size();
            for (int1 = listObject1.size() - 1; int1 >= int2; int1--) {
                listObject1.remove(int1);
            }
        }
        session.put("breadcrumbs", listObject1);
    }
    switch (wsType) {
    case "folder":
        break;
    case "reportUnit":
        try {
            dateTime1 = new org.joda.time.DateTime();
            return1 = INPUT;
            httpClient1 = new DefaultHttpClient();
            if (StringUtils.equals(button1, getText("Print"))) {
                nameValuePair1 = new ArrayList<NameValuePair>();
                if (listObject2 != null) {
                    if (listObject2.size() > 0) {
                        for (DataModel2 dataObject2 : listObject2) {
                            listObject3 = dataObject2.getOptions();
                            if (listObject3 == null) {
                                string2 = dataObject2.getValue1();
                                if (StringUtils.isNotBlank(string2))
                                    nameValuePair1.add(new BasicNameValuePair(dataObject2.getId(), string2));
                            } else {
                                for (int1 = listObject3.size() - 1; int1 >= 0; int1--) {
                                    dataModel1 = (DataModel1) listObject3.get(int1);
                                    string2 = dataModel1.getString2();
                                    if (StringUtils.isNotBlank(string2))
                                        nameValuePair1
                                                .add(new BasicNameValuePair(dataObject2.getId(), string2));
                                }
                            }
                        }
                    }
                }
                url1 = new URL(sid);
                uriBuilder1 = new URIBuilder(sid);
                uriBuilder1.setUserInfo(uid, pid);
                if (StringUtils.isBlank(format1))
                    format1 = "pdf";
                uriBuilder1.setPath(url1.getPath() + "/rest_v2/reports" + urlString + "." + format1);
                if (StringUtils.isNotBlank(locale2)) {
                    nameValuePair1.add(new BasicNameValuePair("userLocale", locale2));
                }
                if (StringUtils.isNotBlank(page1)) {
                    if (NumberUtils.isNumber(page1)) {
                        nameValuePair1.add(new BasicNameValuePair("page", page1));
                    }
                }
                if (nameValuePair1.size() > 0) {
                    uriBuilder1.setQuery(URLEncodedUtils.format(nameValuePair1, "UTF-8"));
                }
                uri1 = uriBuilder1.build();
                httpGet1 = new HttpGet(uri1);
                httpResponse1 = httpClient1.execute(httpGet1);
                int1 = httpResponse1.getStatusLine().getStatusCode();
                if (int1 == HttpStatus.SC_OK) {
                    string3 = System.getProperty("java.io.tmpdir") + File.separator
                            + httpServletRequest.getSession().getId();
                    dir1 = new File(string3);
                    if (!dir1.exists()) {
                        dir1.mkdir();
                    }
                    httpEntity1 = httpResponse1.getEntity();
                    file1 = new File(string3, StringUtils.substringAfterLast(urlString, "/") + "." + format1);
                    if (StringUtils.equalsIgnoreCase(format1, "html")) {
                        result1 = EntityUtils.toString(httpEntity1);
                        FileUtils.writeStringToFile(file1, result1);
                        array1 = StringUtils.substringsBetween(result1, "<img src=\"", "\"");
                        if (ArrayUtils.isNotEmpty(array1)) {
                            dir1 = new File(
                                    string3 + File.separator + FilenameUtils.getBaseName(file1.getName()));
                            if (dir1.exists()) {
                                FileUtils.deleteDirectory(dir1);
                            }
                            file2 = new File(FilenameUtils.getFullPath(file1.getAbsolutePath())
                                    + FilenameUtils.getBaseName(file1.getName()) + ".zip");
                            if (file2.exists()) {
                                if (FileUtils.deleteQuietly(file2)) {
                                }
                            }
                            for (int2 = 0; int2 < array1.length; int2++) {
                                try {
                                    string2 = url1.getPath() + "/rest_v2/reports" + urlString + "/"
                                            + StringUtils.substringAfter(array1[int2], "/");
                                    uriBuilder1.setPath(string2);
                                    uri1 = uriBuilder1.build();
                                    httpGet1 = new HttpGet(uri1);
                                    httpResponse1 = httpClient1.execute(httpGet1);
                                    int1 = httpResponse1.getStatusLine().getStatusCode();
                                } finally {
                                    if (int1 == HttpStatus.SC_OK) {
                                        try {
                                            string2 = StringUtils.substringBeforeLast(array1[int2], "/");
                                            dir1 = new File(string3 + File.separator + string2);
                                            if (!dir1.exists()) {
                                                dir1.mkdirs();
                                            }
                                            httpEntity1 = httpResponse1.getEntity();
                                            inputStream1 = httpEntity1.getContent();
                                        } finally {
                                            string1 = StringUtils.substringAfterLast(array1[int2], "/");
                                            file2 = new File(string3 + File.separator + string2, string1);
                                            outputStream1 = new FileOutputStream(file2);
                                            IOUtils.copy(inputStream1, outputStream1);
                                        }
                                    }
                                }
                            }
                            outputStream1 = new FileOutputStream(
                                    FilenameUtils.getFullPath(file1.getAbsolutePath())
                                            + FilenameUtils.getBaseName(file1.getName()) + ".zip");
                            ArchiveOutputStream archiveOutputStream1 = new ArchiveStreamFactory()
                                    .createArchiveOutputStream(ArchiveStreamFactory.ZIP, outputStream1);
                            archiveOutputStream1.putArchiveEntry(new ZipArchiveEntry(file1, file1.getName()));
                            IOUtils.copy(new FileInputStream(file1), archiveOutputStream1);
                            archiveOutputStream1.closeArchiveEntry();
                            dir1 = new File(FilenameUtils.getFullPath(file1.getAbsolutePath())
                                    + FilenameUtils.getBaseName(file1.getName()));
                            files = (List<File>) FileUtils.listFiles(dir1, TrueFileFilter.INSTANCE,
                                    TrueFileFilter.INSTANCE);
                            for (File file3 : files) {
                                archiveOutputStream1.putArchiveEntry(new ZipArchiveEntry(file3, StringUtils
                                        .substringAfter(file3.getCanonicalPath(), string3 + File.separator)));
                                IOUtils.copy(new FileInputStream(file3), archiveOutputStream1);
                                archiveOutputStream1.closeArchiveEntry();
                            }
                            archiveOutputStream1.close();
                        }
                        bugfixGateIn = propertiesConfiguration1.getBoolean("bugfixGateIn", false);
                        string4 = bugfixGateIn
                                ? String.format("<img src=\"%s/namespace1/file-link?sessionId=%s&fileName=",
                                        portletRequest.getContextPath(),
                                        httpServletRequest.getSession().getId())
                                : String.format("<img src=\"%s/namespace1/file-link?fileName=",
                                        portletRequest.getContextPath());
                        result1 = StringUtils.replace(result1, "<img src=\"", string4);
                    } else {
                        inputStream1 = httpEntity1.getContent();
                        outputStream1 = new FileOutputStream(file1);
                        IOUtils.copy(inputStream1, outputStream1);
                        result1 = file1.getAbsolutePath();
                    }
                    return1 = SUCCESS;
                } else {
                    addActionError(String.format("%s %d: %s", getText("Error"), int1,
                            getText(Integer.toString(int1))));
                }
                dateTime2 = new org.joda.time.DateTime();
                period1 = new Period(dateTime1, dateTime2.plusSeconds(1));
                message1 = getText("Execution.time") + ": " + periodFormatter1.print(period1);
            } else {
                url1 = new URL(sid);
                uriBuilder1 = new URIBuilder(sid);
                uriBuilder1.setUserInfo(uid, pid);
                uriBuilder1.setPath(url1.getPath() + "/rest_v2/reports" + urlString + "/inputControls");
                uri1 = uriBuilder1.build();
                httpGet1 = new HttpGet(uri1);
                httpResponse1 = httpClient1.execute(httpGet1);
                int1 = httpResponse1.getStatusLine().getStatusCode();
                switch (int1) {
                case HttpStatus.SC_NO_CONTENT:
                    break;
                case HttpStatus.SC_OK:
                    httpEntity1 = httpResponse1.getEntity();
                    if (httpEntity1 != null) {
                        inputStream1 = httpEntity1.getContent();
                        if (inputStream1 != null) {
                            xmlConfiguration = new XMLConfiguration();
                            xmlConfiguration.load(inputStream1);
                            list1 = xmlConfiguration.configurationsAt("inputControl");
                            if (list1.size() > 0) {
                                listObject2 = new ArrayList<DataModel2>();
                                for (HierarchicalConfiguration hierarchicalConfiguration1 : list1) {
                                    string2 = hierarchicalConfiguration1.getString("type");
                                    dataModel2 = new DataModel2();
                                    dataModel2.setId(hierarchicalConfiguration1.getString("id"));
                                    dataModel2.setLabel1(hierarchicalConfiguration1.getString("label"));
                                    dataModel2.setType1(string2);
                                    dataModel2.setMandatory(hierarchicalConfiguration1.getBoolean("mandatory"));
                                    dataModel2.setReadOnly(hierarchicalConfiguration1.getBoolean("readOnly"));
                                    dataModel2.setVisible(hierarchicalConfiguration1.getBoolean("visible"));
                                    switch (string2) {
                                    case "bool":
                                    case "singleValueText":
                                    case "singleValueNumber":
                                    case "singleValueDate":
                                    case "singleValueDatetime":
                                        hierarchicalConfiguration2 = hierarchicalConfiguration1
                                                .configurationAt("state");
                                        dataModel2.setValue1(hierarchicalConfiguration2.getString("value"));
                                        break;
                                    case "singleSelect":
                                    case "singleSelectRadio":
                                    case "multiSelect":
                                    case "multiSelectCheckbox":
                                        hierarchicalConfiguration2 = hierarchicalConfiguration1
                                                .configurationAt("state");
                                        list2 = hierarchicalConfiguration2.configurationsAt("options.option");
                                        if (list2.size() > 0) {
                                            listObject3 = new ArrayList<DataModel1>();
                                            for (HierarchicalConfiguration hierarchicalConfiguration3 : list2) {
                                                dataModel1 = new DataModel1(
                                                        hierarchicalConfiguration3.getString("label"),
                                                        hierarchicalConfiguration3.getString("value"));
                                                if (hierarchicalConfiguration3.getBoolean("selected")) {
                                                    dataModel2.setValue1(
                                                            hierarchicalConfiguration3.getString("value"));
                                                }
                                                listObject3.add(dataModel1);
                                            }
                                            dataModel2.setOptions(listObject3);
                                        }
                                        break;
                                    default:
                                        break;
                                    }
                                    listObject2.add(dataModel2);
                                }
                            }
                        }
                    }
                    break;
                default:
                    addActionError(String.format("%s %d: %s", getText("Error"), int1,
                            getText(Integer.toString(int1))));
                    break;
                }
                if (httpEntity1 != null) {
                    EntityUtils.consume(httpEntity1);
                }
                uriBuilder1.setPath(url1.getPath() + "/rest/resource" + urlString);
                uri1 = uriBuilder1.build();
                httpGet1 = new HttpGet(uri1);
                httpResponse1 = httpClient1.execute(httpGet1);
                int2 = httpResponse1.getStatusLine().getStatusCode();
                if (int2 == HttpStatus.SC_OK) {
                    httpEntity1 = httpResponse1.getEntity();
                    inputStream1 = httpEntity1.getContent();
                    xmlConfiguration = new XMLConfiguration();
                    xmlConfiguration.load(inputStream1);
                    list1 = xmlConfiguration.configurationsAt("resourceDescriptor");
                    for (HierarchicalConfiguration hierarchicalConfiguration4 : list1) {
                        if (StringUtils.equalsIgnoreCase(
                                StringUtils.trim(hierarchicalConfiguration4.getString("[@wsType]")), "prop")) {
                            if (map1 == null)
                                map1 = new HashMap<String, String>();
                            string2 = StringUtils.substringBetween(
                                    StringUtils.substringAfter(
                                            hierarchicalConfiguration4.getString("[@uriString]"), "_files/"),
                                    "_", ".properties");
                            map1.put(string2,
                                    StringUtils.isBlank(string2) ? getText("Default") : getText(string2));
                        }
                    }
                }
                if (httpEntity1 != null) {
                    EntityUtils.consume(httpEntity1);
                }
            }
        } catch (IOException | ConfigurationException | URISyntaxException exception1) {
            exception1.printStackTrace();
            addActionError(exception1.getLocalizedMessage());
            httpGet1.abort();
            return ERROR;
        } finally {
            httpClient1.getConnectionManager().shutdown();
            IOUtils.closeQuietly(inputStream1);
        }
        break;
    default:
        addActionError(getText("This.file.type.is.not.supported"));
        break;
    }
    if (return1 != LOGIN) {
        sid = new String(Base64.encodeBase64(sid.getBytes()));
        uid = new String(Base64.encodeBase64(uid.getBytes()));
        pid = new String(Base64.encodeBase64(pid.getBytes()));
    }
    return return1;
}

From source file:com.xpn.xwiki.objects.classes.PropertyClass.java

/**
 * Get a short name identifying this type of property. This is derived from the java class name, lowercasing the
 * part before {@code Class}./*from w  w  w.j a  v  a2 s  .  co  m*/
 * 
 * @return a string, for example {@code string}, {@code dblist}, {@code number}
 */
private String getTypeName() {
    return StringUtils.substringBeforeLast(this.getClass().getSimpleName(), "Class").toLowerCase();
}

From source file:fusion.Fusion.java

private static void parseINAData() throws FileNotFoundException, IOException {
    try (Scanner scanner = new Scanner(new File("dataINA/dataset_novideoperson.ttl"))
            .useDelimiter(Pattern.compile("^\\s*$", Pattern.MULTILINE))) {
        // On parcourt le fichier avec les donnees
        while (scanner.hasNext()) {
            String token = scanner.next();
            String propName = "";
            String propValue = "";
            token = new String(token.trim().getBytes(), Charset.forName("UTF-8"));

            // for (Integer name: distinctURLs.keySet()){
            // String value = new String(distinctURLs.get(name).getBytes(),
            // Charset.forName("UTF-8"));
            for (URI name : instances.keySet()) {
                Instance inst = instances.get(name); // Moins optimise que
                // de parcourir les
                // distinctURLs ?
                URI value = inst.getUri();
                if (token.contains(value.toString())) { // le scanner lit l'URL
                    try (Scanner scannerToken = new Scanner(token)) {
                        while (scannerToken.hasNextLine()) {
                            String line = scannerToken.nextLine();
                            line = line.trim();
                            // properties start with "notice:"
                            if (line.startsWith("notice")) {
                                if (line.contains(" ")) {
                                    propName = line.substring(7, line.indexOf(" "));
                                    propValue = line.substring(line.indexOf(" ")).trim().replaceAll("\\s+",
                                            " ");

                                    // Instance inst = instances.get(value);

                                    // add property in map if it doesn't
                                    // exist
                                    Property prop;
                                    if (!inst.containsProperty(propName)) {
                                        prop = new Property(propName);
                                        inst.addToProperties(prop);
                                    } else
                                        prop = inst.getProperty(propName);

                                    // get datatype values
                                    if (propValue.startsWith("\"")) {
                                        propValue = StringUtils.removeStart(propValue, "\"");
                                        propValue = StringUtils.substringBeforeLast(propValue, "\"");
                                        Value val = new Value(propValue);
                                        if (value.toString().contains("dbpedia")) {
                                            val.setSource(sources.get("fr.dbpedia.org"));
                                        } else {
                                            val.setSource(sources.get("www.ina.fr"));
                                        }

                                        if (!prop.containsValue(propValue)) //
                                            prop.addToValues(val);

                                    }/*from  w  w w .j  ava2s .c  om*/
                                }

                                //   System.out.println("=== "+line);
                            } // LineStarts(notice)
                              // System.out.println("*** "+line);
                        }
                    }
                }
            }
        }
    }
}

From source file:com.myjeeva.digitalocean.impl.DigitalOceanClient.java

private String appendRateLimitValues(String response, HttpResponse httpResponse) {
    if (StringUtils.isEmpty(response)) {
        return "";
    }/*from   w  w w  .j  a  v  a2s.c  om*/

    String rateLimitData = String.format(RATE_LIMIT_JSON_STRUCT,
            httpResponse.getFirstHeader("RateLimit-Limit").getValue(),
            httpResponse.getFirstHeader("RateLimit-Remaining").getValue(),
            getDateString(httpResponse.getFirstHeader("RateLimit-Reset").getValue(), DATE_FORMAT));

    return StringUtils.substringBeforeLast(response, "}") + ", " + rateLimitData + "}";
}

From source file:net.turnbig.pandora.web.Servlets.java

/**
 * http://domain:port/context/related-path
 * // ww  w. j  ava2 s.com
 * @param request
 * @return http://domain:port/context
 */
public static String getBasePath(HttpServletRequest request) {
    String requestURL = request.getRequestURL().toString(); // whole URL
    String requestURI = request.getRequestURI(); // context-path + path
    String host = StringUtils.substringBeforeLast(requestURL, requestURI);
    String contextPath = request.getContextPath();
    return StringUtils.removeEnd(host + contextPath, "/");
}

From source file:nl.gertontenham.magnolia.templating.utils.HandlebarsPrecompileHelper.java

@Override
public CharSequence applyWithCurrentTemplate(final String path, final Options options) {
    notEmpty(path, "found: '%s', expected 'template path'", path);
    String wrapperName = options.hash("wrapper", "anonymous");
    final JsWrapper wrapper = JsWrapper.wrapper(wrapperName);
    notNull(wrapper, "found '%s', expected: '%s'", wrapperName,
            StringUtils.join(JsWrapper.values(), ", ").toLowerCase());

    Handlebars handlebars = options.handlebars;
    String name = StringUtils.substringBeforeLast(path, ".");
    if (name.startsWith("/")) {
        name = name.substring(1);/*from   w  w  w .  j  a v  a2 s  . co  m*/
    }
    if (wrapper == JsWrapper.AMD) {
        name += handlebars.getLoader().getSuffix();
    }
    Template template = options.fn;
    String precompiled = template.toJavaScript();
    return new Handlebars.SafeString(wrapper.wrap(name, precompiled));
}

From source file:org.aliuge.crawler.extractor.selector.action.string.StringBeforeLastAction.java

License:asdf

/**
 * ??separator?/* ww  w .jav  a 2 s.c  o m*/
 */
@Override
public String doAction(String content) {
    if (StringUtils.isNotBlank(content)) {
        return StringUtils.substringBeforeLast(content, separator);
    }
    return "";
}