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

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

Introduction

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

Prototype

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

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:suonos.services.player.mplayer.MPlayerProcessInstance.java

private void processAnsTimePos(String line) {
    String val = StringUtils.substringAfter(line, "=");
    double v = Double.parseDouble(val);

    // Round up.// w  ww  . j a  va  2  s  . c  o  m
    //
    int timeInSecs = (int) (v + 0.5);

    callback.playerPosUpdate(timeInSecs);
}

From source file:tw.edu.chit.struts.action.secretary.ReportPrintAction.java

/**
 * ?/*from www.  ja v  a  2s.com*/
 * 
 * @param mapping org.apache.struts.action.ActionMapping object
 * @param form org.apache.struts.action.ActionForm object
 * @param request request javax.servlet.http.HttpServletRequest object
 * @param response response javax.servlet.http.HttpServletResponse object
 * @param sterm 
 */
private void printCalendarList(ActionMapping mapping, DynaActionForm form, HttpServletRequest request,
        HttpServletResponse response, String sterm) throws Exception {

    HttpSession session = request.getSession(false);
    AdminManager am = (AdminManager) getBean(IConstants.ADMIN_MANAGER_BEAN_NAME);
    DynaActionForm aForm = (DynaActionForm) form;
    ServletContext context = request.getSession().getServletContext();
    ActionMessages messages = new ActionMessages();

    Date from = null, to = null;
    if (StringUtils.isNotBlank(aForm.getString("licenseValidDateStart"))
            || StringUtils.isNotBlank(aForm.getString("licenseValidDateEnd"))) {
        from = StringUtils.isBlank(aForm.getString("licenseValidDateStart")) ? null
                : Toolket.parseNativeDate(aForm.getString("licenseValidDateStart"));
        // ???
        to = StringUtils.isBlank(aForm.getString("licenseValidDateEnd")) ? Calendar.getInstance().getTime()
                : Toolket.parseNativeDate(aForm.getString("licenseValidDateEnd"));
    }

    Calendar cal = Calendar.getInstance();
    cal.setTime(to);
    cal.add(Calendar.DAY_OF_MONTH, 1);

    try {
        IConstants.GOOGLE_SERVICES.setUserCredentials(IConstants.GOOGLE_EMAIL_USERNAME,
                IConstants.GOOGLE_EMAIL_PASSWORD);
    } catch (AuthenticationException ae) {
        log.error(ae.getMessage(), ae);
        messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("Course.errorN1",
                "??,??,,??!"));
        saveMessages(request, messages);
    }

    DateTime rangeFrom = Toolket.parseDateToGoogleDateTime(from);
    DateTime rangeTo = Toolket.parseDateToGoogleDateTime(cal.getTime());

    CalendarEventEntry[] entries = am.findCalendarEventBy(IConstants.GOOGLE_SERVICES, rangeFrom, rangeTo);

    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet("");
    sheet.setColumnWidth(0, 5000);
    sheet.setColumnWidth(1, 3000);
    sheet.setColumnWidth(2, 3000);
    sheet.setColumnWidth(3, 8000);
    sheet.setColumnWidth(4, 8000);
    sheet.setColumnWidth(5, 8000);
    sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));

    HSSFFont fontSize16 = workbook.createFont();
    fontSize16.setFontHeightInPoints((short) 16);
    fontSize16.setFontName("Arial Unicode MS");

    HSSFFont fontSize10 = workbook.createFont();
    fontSize10.setFontHeightInPoints((short) 10);
    fontSize10.setFontName("Arial Unicode MS");

    // Header
    Toolket.setCellValue(workbook, sheet, 0, 0, "", fontSize16, HSSFCellStyle.ALIGN_CENTER,
            false, 35.0F, null);

    // Column Header
    Toolket.setCellValue(workbook, sheet, 1, 0, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 1, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 2, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    Toolket.setCellValue(workbook, sheet, 1, 3, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
    Toolket.setCellValue(workbook, sheet, 1, 4, "", fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
    Toolket.setCellValue(workbook, sheet, 1, 5, "?", fontSize10, HSSFCellStyle.ALIGN_CENTER, true,
            null);
    int index = 2;

    List<ExtendedProperty> props = null;
    boolean flag = false;
    DateFormat dt = new SimpleDateFormat("kk:mm");
    DateTime d = null;
    Calendar c = null;

    if (entries.length != 0) {
        for (CalendarEventEntry entry : entries) {

            props = entry.getExtendedProperty();
            flag = false;
            for (ExtendedProperty prop : props) {
                if ("host".equalsIgnoreCase(prop.getName())) {
                    Toolket.setCellValue(workbook, sheet, index, 2, StringUtils.trimToEmpty(prop.getValue()),
                            fontSize10, HSSFCellStyle.ALIGN_CENTER, true, null);
                    flag = true;
                }
            }

            if (!flag)
                Toolket.setCellValue(workbook, sheet, index, 2, "", fontSize10, HSSFCellStyle.ALIGN_CENTER,
                        true, null);

            d = entry.getTimes().get(0).getStartTime();
            c = Calendar.getInstance();
            c.setTimeInMillis(d.getValue());
            Toolket.setCellValue(workbook, sheet, index, 0, Toolket.printNativeDate(c.getTime()), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 1, dt.format(c.getTime()), fontSize10,
                    HSSFCellStyle.ALIGN_CENTER, true, null);
            Toolket.setCellValue(workbook, sheet, index, 3, entry.getTitle().getPlainText(), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
            Toolket.setCellValue(workbook, sheet, index, 4,
                    StringUtils.defaultIfEmpty(entry.getLocations().get(0).getValueString(), ""), fontSize10,
                    HSSFCellStyle.ALIGN_LEFT, true, null);
            if (StringUtils.contains(entry.getPlainTextContent(), "?"))
                Toolket.setCellValue(workbook, sheet, index++, 5,
                        StringUtils.substringAfter(entry.getPlainTextContent().trim(), "\n"), fontSize10,
                        HSSFCellStyle.ALIGN_LEFT, true, null);
            else
                Toolket.setCellValue(workbook, sheet, index++, 5, entry.getPlainTextContent().trim(),
                        fontSize10, HSSFCellStyle.ALIGN_LEFT, true, null);

        }
    }

    File tempDir = new File(
            context.getRealPath("/WEB-INF/reports/temp/" + getUserCredential(session).getMember().getIdno()
                    + (new SimpleDateFormat("yyyyMMdd").format(new Date()))));
    if (!tempDir.exists())
        tempDir.mkdirs();

    File output = new File(tempDir, "CalendarList.xls");
    FileOutputStream fos = new FileOutputStream(output);
    workbook.write(fos);
    fos.close();

    JasperReportUtils.printXlsToFrontEnd(response, output);
    output.delete();
    tempDir.delete();
}

From source file:ua.utility.kfsdbupgrade.MaintainableXMLConversionServiceImpl.java

/**
 * Transforms the given <code>xml</code> that is in KFS3 format to KFS6
 * format./*from  w  ww  .j  a  v a2s .c  om*/
 * 
 * @param xml
 *            {@link String} of the XML to transform
 * @return {@link String} of the transformed XML
 * @throws Exception
 *             Any {@link Exception}s encountered will be rethrown
 */
public String transformMaintainableXML(String xml, String docid) throws Exception {
    /*
     * a handful of documents have unfriendly Unicode characters which the
     * XML processor (and the rest of KFS) can't handle. Pre-process to
     * replace with a friendly base ASCII characters.
     */
    xml = xml.replace("\u0001", "-");
    xml = xml.replace("\u001e", " ");
    xml = xml.replace("\u001d", " ");
    String beginning = StringUtils.substringBefore(xml, "<" + OLD_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">");
    String oldMaintainableObjectXML = StringUtils.substringBetween(xml,
            "<" + OLD_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">",
            "</" + OLD_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">");
    String newMaintainableObjectXML = StringUtils.substringBetween(xml,
            "<" + NEW_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">",
            "</" + NEW_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">");
    String ending = StringUtils.substringAfter(xml, "</" + NEW_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">");

    // quick hack to catch top-level class replacements
    for (String className : classNameRuleMap.keySet()) {
        if (beginning.contains("maintainableImplClass=\"" + className + "\"")) {
            LOGGER.trace("Replacing top-level maintainableImplClass attribute: " + className + " with: "
                    + classNameRuleMap.get(className));
            beginning = beginning.replace("maintainableImplClass=\"" + className + "\"",
                    "maintainableImplClass=\"" + classNameRuleMap.get(className) + "\"");
        }
    }
    String convertedOldMaintainableObjectXML = transformSection(oldMaintainableObjectXML, docid);
    String convertedNewMaintainableObjectXML = transformSection(newMaintainableObjectXML, docid);

    String convertedXML = beginning + "<" + OLD_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">"
            + convertedOldMaintainableObjectXML + "</" + OLD_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">" + "<"
            + NEW_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">" + convertedNewMaintainableObjectXML + "</"
            + NEW_MAINTAINABLE_OBJECT_ELEMENT_NAME + ">" + ending;
    return convertedXML;
}

From source file:ui.FtpDialog.java

private void loginBtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginBtActionPerformed

    String host = hostAddressField.getText();
    int port = (int) portNumberSp.getValue();
    String user = userNameField.getText();
    char[] password = passField.getPassword();
    String pass = new String(password);
    String hostIP = null;/*from w  w w . jav  a 2 s .  c om*/

    Trace.connectionFtp = true;

    InetAddress address = null;

    if (!connected) {
        try {
            address = InetAddress.getByName(host);
            ;
            hostIP = StringUtils.substringAfter(address.toString(), "/");
            if (hostIP == null || hostIP.equals("127.0.0.1")) {
                JOptionPane.showMessageDialog(rootFrame, "Host name not set", "Error",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }
            if (port == 0) {
                JOptionPane.showMessageDialog(rootFrame, "Invalid port number", "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
            if (Trace.connectionFtp) {
                Trace.trc("Host IP address: " + hostIP);
            }
        } catch (UnknownHostException e) {
            JOptionPane.showMessageDialog(rootFrame, "Cannot resolve host address", "Error",
                    JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
        }

        try {
            if (address != null && port != 0 && user != null && pass != null) {
                connected = ftpHandler.doConnect(hostIP, port, user, pass);
                Arrays.fill(password, '0');
                if (!connected) {
                    JOptionPane.showMessageDialog(rootFrame,
                            "Problem iniating connection to the FTP server, please check your login credentials",
                            "Error", JOptionPane.ERROR_MESSAGE);
                    return;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (connected) {
            try {
                if (Trace.connectionFtp) {
                    Trace.trc("Attempting to list the remote directory...");
                }
                String dirList = ftpHandler.list();
                lastKnownDir = ftpHandler.pwd();
                outputTextArea.setText(dirList);
                remoteSiteText.setText(ftpHandler.pwd());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } else {
        JOptionPane.showMessageDialog(rootFrame, "Already connected to a FTP server, cannot reconnect!",
                "Error", JOptionPane.ERROR_MESSAGE);
    }

}

From source file:uk.gov.hscic.common.util.DateFormatter.java

public static String combineDateTime(final Date date, final Date time) {
    final String dateAsString = toString(date);
    final String timeAsString = toString(time);

    if (dateAsString == null || timeAsString == null) {
        return null;
    }/*w  w w . j a  v a 2  s .  c om*/

    return StringUtils.substringBefore(dateAsString, "T") + "T" + StringUtils.substringAfter(timeAsString, "T");
}

From source file:unicon.matthews.security.AuthorizationUtils.java

private static String getSecretBasic(String authorizationHeader) {
    StringTokenizer st = new StringTokenizer(authorizationHeader);
    if (st.hasMoreTokens()) {
        String basic = st.nextToken();

        if (basic.equalsIgnoreCase("Basic") || basic.equalsIgnoreCase("Base64")) {

            try {
                String credentials = new String(Base64.decodeBase64(st.nextToken()), "UTF-8");
                return StringUtils.substringAfter(credentials, ":");
            } catch (UnsupportedEncodingException e) {
                throw new Error("Couldn't retrieve key", e);
            }//from w w  w .  j  av a 2s . c  om
        } else {
            throw new Error("Couldn't retrieve key from header: " + authorizationHeader);
        }
    } else {
        throw new Error("Couldn't retrieve key from header: " + authorizationHeader);
    }
}

From source file:v7db.auth.PasswordUtil.java

/**
 * Checks the password against the password digest (which can be in a number
 * of supported formats, they will all the checked in turn).
 * /*from  w w w. j a va  2 s  .c  o  m*/
 * @return true, if the password matches the digest
 */
public static boolean check(char[] password, Object digest) {
    if (digest instanceof String) {
        String str = (String) digest;
        // UNIX MD5 crypt
        if ((str.startsWith("$1$") || str.startsWith("$apr1$"))
                && MD5Crypt.verifyPassword(new String(password), str))
            return true;
        if ((str.startsWith("{CRYPT}") && check(password, StringUtils.substringAfter(str, "{CRYPT}"))))
            return true;
    }
    return false;
}