Example usage for org.apache.commons.lang StringUtils substringAfterLast

List of usage examples for org.apache.commons.lang StringUtils substringAfterLast

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils substringAfterLast.

Prototype

public static String substringAfterLast(String str, String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:org.apache.torque.generator.source.stream.SourceToXmlTest.java

@Test
public void testSourceToXml() throws Exception {
    File xmlFile = new File("src/test/resources/org/apache/torque/generator/source/xml/source.xml");
    FileSource fileSource = new FileSource(new XmlSourceFormat(), xmlFile, controllerState);
    SourceElement rootElement = fileSource.getRootElement();

    String result = new SourceToXml().toXml(rootElement, true);
    String expected = FileUtils.readFileToString(
            new File("src/test/resources/org/apache/torque/generator/source/xml/sourceToXmlResult.xml"));
    // remove license from expected file
    expected = StringUtils.substringAfterLast(expected, "-->\n\n");
    assertEquals(expected, result);//from   w w w.ja  va  2 s  . c  om
}

From source file:org.apache.torque.generator.source.stream.SourceToXmlTest.java

@Test
public void testSourceToXmlWithReferences() throws Exception {
    File xmlFile = new File("src/test/resources/org/apache/torque/generator/source/xml/source.xml");
    FileSource fileSource = new FileSource(new XmlSourceFormat(), xmlFile, controllerState);
    SourceElement rootElement = fileSource.getRootElement();
    rootElement.getChildren().get(2).getChildren().add(rootElement.getChildren().get(0).getChildren().get(0));

    String result = new SourceToXml().toXml(rootElement, true);
    String expected = FileUtils.readFileToString(new File(
            "src/test/resources/org/apache/torque/generator/source/xml/sourceToXmlWithReferenceResult.xml"));
    // remove license from expected file
    expected = StringUtils.substringAfterLast(expected, "-->\n\n");
    assertEquals(expected, result);/*from   w w w. j ava2s  .c o m*/
}

From source file:org.apache.usergrid.management.EmailFlowIT.java

private String getTokenFromMessage(Message msg) throws IOException, MessagingException {
    String body = ((MimeMultipart) msg.getContent()).getBodyPart(0).getContent().toString();
    // TODO better token extraction
    // this is going to get the wrong string if the first part is not
    // text/plain and the url isn't the last character in the email
    return StringUtils.substringAfterLast(body, "token=");
}

From source file:org.apache.usergrid.rest.management.RegistrationIT.java

public String getTokenFromMessage(Message msg) throws IOException, MessagingException {
    String body = ((MimeMultipart) msg.getContent()).getBodyPart(0).getContent().toString();
    String token = StringUtils.substringAfterLast(body, "token=");
    // TODO better token extraction
    // this is going to get the wrong string if the first part is not
    // text/plain and the url isn't the last character in the email
    return token;
}

From source file:org.apache.usergrid.rest.management.users.MUUserResourceIT.java

private String getTokenFromMessage(Message msg) throws IOException, MessagingException {
    String body = ((MimeMultipart) msg.getContent()).getBodyPart(0).getContent().toString();
    return StringUtils.substringAfterLast(body, "token=");
}

From source file:org.b3log.latke.cron.Cron.java

/**
 * Parses the specified schedule into {@link #period execution period}.
 * /*from ww  w  .  j  ava  2 s. c  o  m*/
 * @param schedule the specified schedule
 */
private void parse(final String schedule) {
    final int num = Integer.valueOf(StringUtils.substringBetween(schedule, " ", " "));
    final String timeUnit = StringUtils.substringAfterLast(schedule, " ");

    LOGGER.log(Level.FINEST, "Parsed cron job[schedule={0}]: [num={1}, timeUnit={2}]",
            new Object[] { schedule, num, timeUnit });

    if ("hours".equals(timeUnit)) {
        period = num * SIXTY * SIXTY * THOUSAND;
    } else if ("minutes".equals(timeUnit)) {
        period = num * SIXTY * THOUSAND;
    }
}

From source file:org.b3log.solo.processor.ArticleProcessor.java

/**
 * Gets the request page number from the specified request URI.
 * //from w ww . j  av a  2s .  com
 * @param requestURI the specified request URI
 * @return page number
 */
private static int getTagArticlesPagedCurrentPageNum(final String requestURI) {
    return Requests.getCurrentPageNum(StringUtils.substringAfterLast(requestURI, "/"));
}

From source file:org.b3log.solo.processor.ArticleProcessor.java

/**
 * Gets the request page number from the specified request URI.
 * //w ww  .  ja  va 2  s  .c o  m
 * @param requestURI the specified request URI
 * @return page number
 */
private static int getArchivesArticlesPagedCurrentPageNum(final String requestURI) {
    return Requests.getCurrentPageNum(StringUtils.substringAfterLast(requestURI, "/"));
}

From source file:org.b3log.solo.processor.ErrorProcessor.java

/**
 * Shows the user template page./*  ww w  . java 2s .  co  m*/
 * 
 * @param context the specified context
 * @param request the specified HTTP servlet request
 * @param response the specified HTTP servlet response
 * @throws IOException io exception 
 */
@RequestProcessing(value = "/error/*.html", method = HTTPRequestMethod.GET)
public void showErrorPage(final HTTPRequestContext context, final HttpServletRequest request,
        final HttpServletResponse response) throws IOException {
    final String requestURI = request.getRequestURI();
    String templateName = StringUtils.substringAfterLast(requestURI, "/");
    templateName = StringUtils.substringBefore(templateName, ".") + ".ftl";
    LOGGER.log(Level.FINE, "Shows error page[requestURI={0}, templateName={1}]",
            new Object[] { requestURI, templateName });

    final ConsoleRenderer renderer = new ConsoleRenderer();
    context.setRenderer(renderer);
    renderer.setTemplateName("error" + File.separatorChar + templateName);

    final Map<String, Object> dataModel = renderer.getDataModel();

    try {
        final Map<String, String> langs = langPropsService.getAll(Locales.getLocale(request));
        dataModel.putAll(langs);
        final JSONObject preference = preferenceQueryService.getPreference();

        filler.fillBlogHeader(request, dataModel, preference);
        filler.fillBlogFooter(dataModel, preference);

        dataModel.put(Common.LOGIN_URL, userService.createLoginURL(Common.ADMIN_INDEX_URI));
    } catch (final Exception e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);

        try {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        } catch (final IOException ex) {
            LOGGER.severe(ex.getMessage());
        }
    }
}

From source file:org.b3log.solo.processor.FileUploadProcessor.java

@Override
public void doPost(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    if (QN_ENABLED) {
        return;//from   w ww . jav a  2 s.  c om
    }

    final MultipartRequestInputStream multipartRequestInputStream = new MultipartRequestInputStream(
            req.getInputStream());
    multipartRequestInputStream.readBoundary();
    multipartRequestInputStream.readDataHeader("UTF-8");

    String fileName = multipartRequestInputStream.getLastHeader().getFileName();

    String suffix = StringUtils.substringAfterLast(fileName, ".");
    if (StringUtils.isBlank(suffix)) {
        final String mimeType = multipartRequestInputStream.getLastHeader().getContentType();
        String[] exts = MimeTypes.findExtensionsByMimeTypes(mimeType, false);

        if (null != exts && 0 < exts.length) {
            suffix = exts[0];
        } else {
            suffix = StringUtils.substringAfter(mimeType, "/");
        }
    }

    final String name = StringUtils.substringBeforeLast(fileName, ".");
    final String processName = name.replaceAll("\\W", "");
    final String uuid = UUID.randomUUID().toString().replaceAll("-", "");

    if (StringUtils.isBlank(processName)) {
        fileName = uuid + "." + suffix;
    } else {
        fileName = uuid + '_' + processName + "." + suffix;
    }

    final OutputStream output = new FileOutputStream(UPLOAD_DIR + fileName);
    IOUtils.copy(multipartRequestInputStream, output);

    IOUtils.closeQuietly(multipartRequestInputStream);
    IOUtils.closeQuietly(output);

    final JSONObject data = new JSONObject();
    data.put("key", Latkes.getServePath() + "/upload/" + fileName);
    data.put("name", fileName);

    resp.setContentType("application/json");

    final PrintWriter writer = resp.getWriter();
    writer.append(data.toString());
    writer.flush();
    writer.close();
}