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

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

Introduction

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

Prototype

public static String substringBetween(final String str, final String open, final String close) 

Source Link

Document

Gets the String that is nested in between two Strings.

Usage

From source file:org.pepstock.jem.junit.test.jppf.StopJppf.java

private void close(String type) throws IOException {
    System.out.println("====================================\nStop JPPF " + type
            + "\n====================================");
    File dir = new File("./jppf/" + type);
    File log = new File(dir, "jppf-" + type + ".log");

    List<String> rows = FileUtils.readLines(log);

    String toSearch = "starting " + type + " with PID=";

    for (String row : rows) {
        if (StringUtils.contains(row, toSearch)) {
            String pids = StringUtils.substringBetween(row, toSearch, ",");
            long pid = Long.parseLong(pids);
            platform.kill(pid, null, true, false);
            System.out.println("kill process " + type + ":" + pid);
            return;
        }// w  w w  .  j  a  v  a  2s.c o m
    }

}

From source file:org.springside.examples.oadata.service.ProjecgtRuleViewService.java

License:asdf

public boolean sysProjectDoc(ProjectData projectData) {
    boolean result = false;
    List<ProjectRuleView> projectRuleViews = projectRuleViewDao
            .queryProjectRuleView(projectData.getProjectId());

    ProjectRuleView projectRuleView = null;
    if (projectRuleViews != null && projectRuleViews.size() > 0) {

        projectRuleView = projectRuleViews.get(0);

        //?/*from   w  w  w  .jav  a2s  .  co m*/
        projectRuleView.setIsPack(projectData.getProjectPkgDatas().size() > 0 ? "1" : "0");
        if (projectData.getProjectPkgDatas().size() > 0) {

            for (ProjectRuleView projRView : projectRuleViews) {
                ProjectRulePkgView projectRulePkgView = new ProjectRulePkgView();
                try {
                    BeanUtils.copyProperties(projectRulePkgView, projRView);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
                projectRuleView.getPack().add(projectRulePkgView);
            }
        }

        //?
        List<ProjectDocView> projectDocViews = projectDocViewDao.queryProjectDocView(projectData.getProjectId(),
                "2");

        if (projectDocViews != null && projectDocViews.size() > 0) {//?
            List<String> purchaseDocUrls = new ArrayList<String>();
            for (ProjectDocView projectDocView : projectDocViews) {
                purchaseDocUrls
                        .add(projectDocView.getAttachmentPath() + "*" + projectDocView.getAttachmentName());
            }
            //?
            projectRuleView.setPurchaseDocUrl(StringUtils.join(purchaseDocUrls, ","));
        }

        //??
        StringWriter writer = new StringWriter();

        BodyXml<ProjectRuleView> bodyXml = new BodyXml<ProjectRuleView>();
        bodyXml.setProjectInfo(projectRuleView);
        ProjectRuleXml projectXml = new ProjectRuleXml();
        projectXml.setBody(bodyXml);
        HeadXml header = new HeadXml(projectData.getDepartmentId(), projectData.getCreator());
        projectXml.setHeader(header);

        try {
            marshaller.marshal(projectXml, writer);
        } catch (JAXBException e) {
            logger.error("{}|{}XML?:" + e.getStackTrace(),
                    projectData.getId(), projectData.getProjectName());
        }
        try {

            HttpPost httpPost = new HttpPost(propertiesLoader.getProperty("syn.synProjectRuleUrl"));
            // ??/  
            List<NameValuePair> parameters = new ArrayList<NameValuePair>();

            parameters.add(new BasicNameValuePair("xmlContent", writer.toString()));
            // UrlEncodedFormEntity  
            UrlEncodedFormEntity formEntiry = new UrlEncodedFormEntity(parameters, "UTF-8");
            httpPost.setEntity(formEntiry);

            // ?connection poolclient
            CloseableHttpResponse closeableHttpResponse = httpClient.execute(httpPost);
            closeableHttpResponse.getEntity().getContent();
            String xmlContentresp = IOUtils.toString(closeableHttpResponse.getEntity().getContent());
            if (xmlContentresp.contains("operTag")) {
                String operTag = StringUtils.substringBetween(xmlContentresp, "<operTag>", "</operTag>");
                if ("Y".equals(operTag)) {//?   
                    //?? 
                    projectData.setSynStatus(ProjectData.SYNSTATUS_DOC_SUCCESS);
                    projectDataDao.save(projectData);
                    result = true;
                } else {
                    logger.error("?{}|{}??", projectData.getId(),
                            projectData.getProjectName());
                }
            }
            closeableHttpResponse.close();
        } catch (IOException e) {
            e.printStackTrace();
            logger.error("?{}|{}??:" + e.getStackTrace(),
                    projectData.getId(), projectData.getProjectName());
        }
    }
    return result;
}

From source file:org.springside.examples.oadata.service.TenderViewService.java

public Result synTenderProccess(TenderView tenderView) {

    boolean result = false;
    //??//ww w .  j ava  2 s. co m
    StringWriter writer = new StringWriter();

    BodyXml<TenderView> bodyXml = new BodyXml<TenderView>();
    bodyXml.setProjectInfo(tenderView);
    ;
    SupplierXml supplierXml = new SupplierXml();
    supplierXml.setBody(bodyXml);
    try {
        marshaller.marshal(supplierXml, writer);
    } catch (JAXBException e) {
        logger.error("{}|{}XML?:" + e.getStackTrace(), tenderView.getTenderId(),
                tenderView.getTenderName());
    }
    try {
        HttpPost httpPost = new HttpPost(propertiesLoader.getProperty("syn.synSupplierUrl"));
        // ??/  
        List<NameValuePair> parameters = new ArrayList<NameValuePair>();

        String xmlContent = writer.toString();

        parameters.add(new BasicNameValuePair("xmlContent", xmlContent));
        // UrlEncodedFormEntity  
        UrlEncodedFormEntity formEntiry = new UrlEncodedFormEntity(parameters, "UTF-8");
        httpPost.setEntity(formEntiry);

        // ?connection poolclient
        CloseableHttpResponse closeableHttpResponse = httpClient.execute(httpPost);
        closeableHttpResponse.getEntity().getContent();
        String xmlContentresp = IOUtils.toString(closeableHttpResponse.getEntity().getContent());
        if (xmlContentresp.contains("operTag")) {
            String operTag = StringUtils.substringBetween(xmlContentresp, "<operTag>", "</operTag>");
            String operDesc = StringUtils.substringBetween(xmlContentresp, "<operDesc>", "</operDesc>");
            if ("Y".equals(operTag)) {//?   
                result = true;
            } else {
                logger.error("?{}|{}??{}", tenderView.getTenderId(),
                        tenderView.getTenderName(), operDesc);
            }
        }
        closeableHttpResponse.close();
    } catch (IOException e) {
        e.printStackTrace();
        logger.error("?{}|{}??:" + e.getStackTrace(),
                tenderView.getTenderId(), tenderView.getTenderName());
    }
    return new Result(result, null);
}

From source file:org.springside.examples.quickstart.service.BulletinDataService.java

/**
 * ????//w  ww  .ja  va  2 s.  c  o m
 * @param ids
 */
public boolean synBulletin(Long[] ids) {
    //
    boolean result = false;
    List<Long> idls = new ArrayList<Long>();
    CollectionUtils.addAll(idls, ids);
    Iterable<BulletinData> bulletinDatas = bulletinDataDao.findAll(idls);
    for (BulletinData bulletinData : bulletinDatas) {

        //bulletinData
        //         bulletinData.setBulletinUrl("http://gxoa.cc/attachmentDownload.do?filePath="+bulletinData.getAttachmentPath()+"&amp;fileName="+bulletinData.getAttachmentId());

        //??
        StringWriter writer = new StringWriter();

        BodyXml<BulletinData> bodyXml = new BodyXml<BulletinData>();
        bodyXml.setProjectInfo(bulletinData);
        BulletinXml bulletinXml = new BulletinXml();
        bulletinXml.setBody(bodyXml);

        try {
            marshaller.marshal(bulletinXml, writer);
        } catch (JAXBException e) {
            logger.error("{}|{}XML?:" + e.getStackTrace(), bulletinData.getId(),
                    bulletinData.getAnnouncementDate());
        }
        try {

            HttpPost httpPost = new HttpPost(propertiesLoader.getProperty("syn.synBulletinUrl"));
            // ??/  
            List<NameValuePair> parameters = new ArrayList<NameValuePair>();

            parameters.add(new BasicNameValuePair("xmlContent", writer.toString()));
            // UrlEncodedFormEntity  
            UrlEncodedFormEntity formEntiry = new UrlEncodedFormEntity(parameters, "UTF-8");
            httpPost.setEntity(formEntiry);

            // ?connection poolclient
            CloseableHttpResponse closeableHttpResponse = httpClient.execute(httpPost);
            closeableHttpResponse.getEntity().getContent();
            String xmlContentresp = IOUtils.toString(closeableHttpResponse.getEntity().getContent());
            if (xmlContentresp.contains("operTag")) {
                String operTag = StringUtils.substringBetween(xmlContentresp, "<operTag>", "</operTag>");
                if ("Y".equals(operTag)) {//?   
                    //?? 
                    bulletinData.setSynStatus(BuyerData.SYNSTATUS_SUCCESS);
                    bulletinDataDao.save(bulletinData);
                    result = true;
                } else {

                    logger.error("?{}|{}??", bulletinData.getId(),
                            bulletinData.getAnnouncementDate());
                }
            }
            //httpClient.close();
        } catch (IOException e) {
            e.printStackTrace();
            logger.error("?{}|{}??:" + e.getStackTrace(),
                    bulletinData.getId(), bulletinData.getAnnouncementDate());
        }
    }
    return result;
}

From source file:org.springside.examples.quickstart.service.BulletinDataService.java

public boolean sysBulletinProccess(ProjectData projectData) {
    boolean result = false;

    BulletinData bulletinData = projectData.getBulletinDataSelected();

    //bulletinData 
    //bulletinData.setBulletinUrl("http://gxoa.cc/attachmentDownload.do?filePath="+bulletinData.getAttachmentPath()+"&amp;fileName="+bulletinData.getAttachmentName());

    //??//from  w w w.ja v  a 2  s . c  om
    StringWriter writer = new StringWriter();

    BodyXml<BulletinData> bodyXml = new BodyXml<BulletinData>();
    bodyXml.setProjectInfo(bulletinData);
    BulletinXml bulletinXml = new BulletinXml();
    bulletinXml.setBody(bodyXml);

    try {
        marshaller.marshal(bulletinXml, writer);
    } catch (JAXBException e) {
        logger.error("{}|{}XML?:" + e.getStackTrace(), bulletinData.getId(),
                bulletinData.getAnnouncementDate());
    }
    try {

        HttpPost httpPost = new HttpPost(propertiesLoader.getProperty("syn.synBulletinUrl"));
        // ??/  
        List<NameValuePair> parameters = new ArrayList<NameValuePair>();

        parameters.add(new BasicNameValuePair("xmlContent", writer.toString()));
        // UrlEncodedFormEntity  
        UrlEncodedFormEntity formEntiry = new UrlEncodedFormEntity(parameters, "UTF-8");
        httpPost.setEntity(formEntiry);

        // ?connection poolclient
        CloseableHttpResponse closeableHttpResponse = httpClient.execute(httpPost);
        closeableHttpResponse.getEntity().getContent();
        String xmlContentresp = IOUtils.toString(closeableHttpResponse.getEntity().getContent());
        if (xmlContentresp.contains("operTag")) {
            String operTag = StringUtils.substringBetween(xmlContentresp, "<operTag>", "</operTag>");
            if ("Y".equals(operTag)) {//?   
                //?? 
                bulletinData.setSynStatus(BulletinData.SYNSTATUS_SUCCESS);
                bulletinDataDao.save(bulletinData);
                //???
                projectData.setSynStatus(ProjectData.SYNSTATUS_BULLETIN_SUCCESS);
                projectDataDao.save(projectData);
                result = true;
            } else {
                logger.error("?{}|{}??", bulletinData.getId(),
                        bulletinData.getAnnouncementDate());
            }
        }
        closeableHttpResponse.close();
        //httpClient.close();
    } catch (IOException e) {
        e.printStackTrace();
        logger.error("?{}|{}??:" + e.getStackTrace(),
                bulletinData.getId(), bulletinData.getAnnouncementDate());
    }
    return result;
}

From source file:org.usc.wechat.mp.sdk.util.platform.MediaUtil.java

private static String getFileNameFromContentDisposition(HttpResponse response) {
    Header header = ObjectUtils.firstNonNull(response.getFirstHeader("Content-disposition"),
            response.getFirstHeader("Content-Disposition"));
    if (header == null) {
        return null;
    }/*from   w  w w  .j a v a2  s.  c om*/

    return StringUtils.substringBetween(header.getValue(), "filename=\"", "\"");
}

From source file:org.wso2.carbon.apimgt.hybrid.gateway.configurator.Configurator.java

/**
 * Retrieve Gateway port based on the configured port offset
 *
 * @param carbonFilePath String//from www . j  a  v a  2  s.  c o m
 * @return port int
 */
protected static int getGatewayPort(String carbonFilePath) {
    int port = 0;
    try {
        File file = new File(carbonFilePath);
        String carbonXMLContent = FileUtils.readFileToString(file);
        String offsetStr = StringUtils.substringBetween(carbonXMLContent, ConfigConstants.START_OFFSET_TAG,
                ConfigConstants.END_OFFSET_TAG);
        port = ConfigConstants.GATEWAY_DEFAULT_PORT + Integer.parseInt(offsetStr);
    } catch (IOException e) {
        log.error("Error occurred while reading the carbon XML.", e);
        Runtime.getRuntime().exit(1);
    }
    return port;
}

From source file:org.wso2.carbon.business.rules.core.util.TemplateManagerHelper.java

/**
 * Replaces elements templated within characters '${' and '}', with provided replacement values
 *
 * @param templateString//from w w w  . j a v  a 2 s  .co m
 * @param replacementValues
 * @return
 * @throws TemplateManagerHelperException
 */
public static String replaceTemplateString(String templateString, Map<String, String> replacementValues)
        throws TemplateManagerHelperException {
    StrSubstitutor substitutor = new StrSubstitutor(replacementValues);
    String replacedString = substitutor.replace(templateString);
    // If any templated value has no replacements
    if (replacedString.contains(TemplateManagerConstants.TEMPLATED_ELEMENT_PATTERN_PREFIX)) {
        throw new TemplateManagerHelperException(
                "No matching replacement found for the value - " + StringUtils.substringBetween(replacedString,
                        TemplateManagerConstants.TEMPLATED_ELEMENT_PATTERN_PREFIX,
                        TemplateManagerConstants.TEMPLATED_ELEMENT_PATTERN_SUFFIX));
    }
    return replacedString;
}

From source file:org.xlrnet.metadict.engines.leo.LeoEngine.java

/**
 * Extracts the domain information from a given representation string.
 * <p>//  w  ww . j av a2s .  c o  m
 * Example:
 * If the input is "drive-in restaurant [cook.]", then the domain is "cook."
 *
 * @param representation
 *         The input string.
 * @return the domain string or null if none could be found
 */
@Nullable
private String extractAbbreviationString(String representation) {
    String substring = StringUtils.substringBetween(representation, "[abbr.:", "]");
    if (substring != null)
        return StringUtils.strip(substring, " \u00A0\n\t\r");
    return null;
}

From source file:org.xlrnet.metadict.engines.leo.LeoEngine.java

private void processAdditionalForms(EntryType entryType, DictionaryObjectBuilder dictionaryObjectBuilder,
        Language language, String representation) {
    // Try to extract verb tenses in english  and german dictionary:
    if (entryType == EntryType.VERB
            && (Language.ENGLISH.equals(language) || Language.GERMAN.equals(language))) {
        String tensesString = StringUtils.substringBetween(representation, "|", "|");
        if (tensesString != null) {
            String[] tensesArray = StringUtils.split(tensesString, ",");
            if (tensesArray.length != 2) {
                LOGGER.warn("Tenses array {} has unexpected length {} instead of 2", tensesArray,
                        tensesArray.length);
            }/*  w  w w. j a va2 s .c o  m*/
            dictionaryObjectBuilder.setAdditionalForm(GrammaticalTense.PAST_TENSE,
                    StringUtils.strip(tensesArray[0], " \u00A0\n\t\r"));
            dictionaryObjectBuilder.setAdditionalForm(GrammaticalTense.PAST_PERFECT,
                    StringUtils.strip(tensesArray[1], " \u00A0\n\t\r"));
        }
    }
}