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

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

Introduction

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

Prototype

public static String substringAfter(String str, String separator) 

Source Link

Document

Gets the substring after the first occurrence of a separator.

Usage

From source file:net.ymate.platform.webmvc.support.RequestMappingParser.java

/**
 * @param partStr ?//from w w  w . ja va  2 s. c  o  m
 * @return '/'
 */
private String __doFixMappingPart(String partStr) {
    partStr = StringUtils.trimToEmpty(partStr);
    if (StringUtils.startsWith(partStr, "/")) {
        partStr = StringUtils.substringAfter(partStr, "/");
    }
    if (StringUtils.endsWith(partStr, "/")) {
        partStr = StringUtils.substringBeforeLast(partStr, "/");
    }
    return partStr;
}

From source file:net.ymate.platform.webmvc.support.RequestMappingParser.java

/**
 * @param context /*from w ww .  ja v  a2 s.  c om*/
 * @return ?????????WebContextPathVariable?
 */
public RequestMeta doParse(IRequestContext context) {
    RequestMeta _meta = null;
    Map<String, RequestMeta> _mappingMap = null;
    switch (context.getHttpMethod()) {
    case POST:
        _mappingMap = __MAPPING_META_FOR_POST;
        break;
    case DELETE:
        _mappingMap = __MAPPING_META_FOR_DELETE;
        break;
    case PUT:
        _mappingMap = __MAPPING_META_FOR_PUT;
        break;
    case OPTIONS:
        _mappingMap = __MAPPING_META_FOR_OPTIONS;
        break;
    case HEAD:
        _mappingMap = __MAPPING_META_FOR_HEAD;
        break;
    case TRACE:
        _mappingMap = __MAPPING_META_FOR_TRACE;
        break;
    default:
        _mappingMap = __MAPPING_META_FOR_GET;
    }
    _meta = _mappingMap.get(context.getRequestMapping());
    if (_meta == null) {
        String _requestMapping = this.__doFixMappingPart(context.getRequestMapping());
        // ??PairObject<Mapping[??], ??>
        Set<PairObject<String[], Integer>> _filteredMapping = new HashSet<PairObject<String[], Integer>>();
        for (String _key : _mappingMap.keySet()) {
            if (_key.contains("{")) {
                String _mappingKey = StringUtils.substringBefore(_key, "{");
                String _fixedMappingKey = this.__doFixMappingPart(_mappingKey);
                if (StringUtils.startsWithIgnoreCase(_requestMapping, _fixedMappingKey)) {
                    // ?????
                    String _paramKey = _key.substring(_key.indexOf('{'));
                    _filteredMapping.add(new PairObject<String[], Integer>(
                            new String[] { _key, _mappingKey, _fixedMappingKey, _paramKey },
                            StringUtils.split(_paramKey, "/").length));
                }
            }
        }
        // ?????
        PairObject<String[], Integer> _result = null;
        String _mappingParamPart = null;
        for (PairObject<String[], Integer> _item : _filteredMapping) {
            // ?????
            _mappingParamPart = StringUtils.substringAfter(_requestMapping, _item.getKey()[2]);
            // ???
            int _paramPartCount = StringUtils.split(_mappingParamPart, "/").length;
            // ?????
            if (_paramPartCount == _item.getValue()) {
                _result = _item;
                break;
            }
        }
        if (_result != null) {
            Map<String, String> _params = this.__doParserMappingParams(_mappingParamPart, _result.getKey()[3]);
            // ???WebContextPathVariable?
            for (Map.Entry<String, String> _entry : _params.entrySet()) {
                context.addAttribute(_entry.getKey(), _entry.getValue());
            }
            _meta = _mappingMap.get(_result.getKey()[0]);
        }
    }
    return _meta;
}

From source file:net.ymate.platform.webmvc.view.impl.BinaryView.java

/**
 * ?Range????/* w w w.j a va2  s  .  co  m*/
 *
 * @param length ??
 * @return ?null
 */
private PairObject<Long, Long> __doParseRange(long length) {
    PairObject<Long, Long> _returnValue = null;
    // Range??
    String _rangeStr = WebContext.getRequest().getHeader("Range");
    if (_rangeStr != null && _rangeStr.startsWith("bytes=") && _rangeStr.length() >= 7) {
        _rangeStr = StringUtils.substringAfter(_rangeStr, "bytes=");
        String[] _ranges = StringUtils.split(_rangeStr, ",");
        // ?Range??...
        for (String _range : _ranges) {
            if (StringUtils.isBlank(_range)) {
                return null;
            }
            // bytes=-100
            if (_range.startsWith("-")) {
                long _end = Long.parseLong(_range);
                long _start = length + _end;
                if (_start < 0) {
                    return null;
                }
                _returnValue = new PairObject<Long, Long>(_start, length);
                break;
            }
            // bytes=1024-
            if (_range.endsWith("-")) {
                long _start = Long.parseLong(StringUtils.substringBefore(_range, "-"));
                if (_start < 0) {
                    return null;
                }
                _returnValue = new PairObject<Long, Long>(_start, length);
                break;
            }
            // bytes=10-1024
            if (_range.contains("-")) {
                String[] _tmp = _range.split("-");
                long _start = Long.parseLong(_tmp[0]);
                long _end = Long.parseLong(_tmp[1]);
                if (_start > _end) {
                    return null;
                }
                _returnValue = new PairObject<Long, Long>(_start, _end + 1);
            }
        }
    }
    return _returnValue;
}

From source file:net.ymate.platform.webmvc.view.impl.FreemarkerView.java

@Override
protected void __doViewInit(IWebMvc owner) {
    super.__doViewInit(owner);
    // ?Freemarker??
    if (__freemarkerConfig == null) {
        __freemarkerConfig = new Configuration(Configuration.VERSION_2_3_22);
        __freemarkerConfig.setDefaultEncoding(owner.getModuleCfg().getDefaultCharsetEncoding());
        __freemarkerConfig.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
        ////from  w  w  w .jav a  2  s  .  co  m
        List<TemplateLoader> _tmpLoaders = new ArrayList<TemplateLoader>();
        try {
            if (__baseViewPath.startsWith("/WEB-INF")) {
                _tmpLoaders.add(new FileTemplateLoader(new File(RuntimeUtils.getRootPath(),
                        StringUtils.substringAfter(__baseViewPath, "/WEB-INF/"))));
            } else {
                _tmpLoaders.add(new FileTemplateLoader(new File(__baseViewPath)));
            }
            //
            __freemarkerConfig.setTemplateLoader(
                    new MultiTemplateLoader(_tmpLoaders.toArray(new TemplateLoader[_tmpLoaders.size()])));
        } catch (IOException e) {
            throw new Error(RuntimeUtils.unwrapThrow(e));
        }
    }
}

From source file:net.ymate.platform.webmvc.view.impl.FreemarkerView.java

protected void __doProcessPath() {
    if (StringUtils.isNotBlank(__contentType)) {
        WebContext.getResponse().setContentType(__contentType);
    }/*from  w w w.j  a  v  a  2 s.  co  m*/
    if (StringUtils.isBlank(__path)) {
        String _mapping = WebContext.getRequestContext().getRequestMapping();
        if (_mapping.endsWith("/")) {
            _mapping = _mapping.substring(0, _mapping.length() - 1);
        }
        __path = _mapping + ".ftl";
    } else {
        if (__path.startsWith(__baseViewPath)) {
            __path = StringUtils.substringAfter(__path, __baseViewPath);
        }
        if (!__path.endsWith(".ftl")) {
            __path += ".ftl";
        }
    }
}

From source file:net.ymate.platform.webmvc.view.impl.VelocityView.java

@Override
protected void __doViewInit(IWebMvc owner) {
    super.__doViewInit(owner);
    // ?Velocity??
    if (!__inited) {
        __velocityConfig.setProperty(Velocity.ENCODING_DEFAULT,
                owner.getModuleCfg().getDefaultCharsetEncoding());
        __velocityConfig.setProperty(Velocity.INPUT_ENCODING, owner.getModuleCfg().getDefaultCharsetEncoding());
        __velocityConfig.setProperty(Velocity.OUTPUT_ENCODING,
                owner.getModuleCfg().getDefaultCharsetEncoding());
        ////  w  w w. j a  va  2s .  co m
        if (__baseViewPath.startsWith("/WEB-INF")) {
            __velocityConfig.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH,
                    new File(RuntimeUtils.getRootPath(),
                            StringUtils.substringAfter(__baseViewPath, "/WEB-INF/")).getPath());
        } else {
            __velocityConfig.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, __baseViewPath);
        }
        //
        Velocity.init(__velocityConfig);
        //
        __inited = true;
    }
}

From source file:net.ymate.platform.webmvc.view.impl.VelocityView.java

protected void __doProcessPath() {
    if (StringUtils.isNotBlank(__contentType)) {
        WebContext.getResponse().setContentType(__contentType);
    }//from w w  w. j  a va2  s.  com
    __velocityContext = new VelocityContext();
    for (Map.Entry<String, Object> _entry : __attributes.entrySet()) {
        __velocityContext.put(_entry.getKey(), _entry.getValue());
    }
    if (StringUtils.isBlank(__path)) {
        String _mapping = WebContext.getRequestContext().getRequestMapping();
        if (_mapping.endsWith("/")) {
            _mapping = _mapping.substring(0, _mapping.length() - 1);
        }
        __path = _mapping + ".vm";
    } else {
        if (__path.startsWith(__baseViewPath)) {
            __path = StringUtils.substringAfter(__path, __baseViewPath);
        }
        if (!__path.endsWith(".vm")) {
            __path += ".vm";
        }
    }
}

From source file:nl.nn.adapterframework.extensions.svn.SvnUtils.java

public static String getLogReport(String urlString) throws DomBuilderException, XPathExpressionException,
        ConfigurationException, SenderException, TimeOutException {
    String head = getHeadHtml(urlString);
    String etag = XmlUtils.evaluateXPathNodeSetFirstElement(head, "headers/header[lower-case(@name)='etag']");
    if (etag != null) {
        if (StringUtils.countMatches(etag, "\"") >= 2) {
            String s = StringUtils.substringAfter(etag, "\"");
            String s2 = StringUtils.substringBefore(s, "\"");
            String s3 = StringUtils.substringBefore(s2, "/");
            String s4 = StringUtils.substringAfter(s2, "/");
            return getReportHtml(urlString, s3, s4);
        }/* www.  j  av  a2s.c o  m*/
    }
    return null;
}

From source file:nl.nn.adapterframework.http.HttpUtils.java

public static String getExtendedCommandIssuedBy(HttpServletRequest request, List<String> secLogParamNames,
        String message) {/*from   w  w w . java2  s.co m*/
    String contextPath = request.getContextPath();
    String requestUri = request.getRequestURI();
    String reqUri = StringUtils.substringAfter(requestUri, contextPath);
    if (StringUtils.isEmpty(reqUri)) {
        reqUri = requestUri;
    }
    return ("requestUri [" + reqUri + "] params [" + getParametersAsString(request, secLogParamNames)
            + "] method [" + request.getMethod() + "]" + getCommandIssuedBy(request))
            + (message == null ? "" : System.getProperty("line.separator") + message);
}

From source file:nl.nn.adapterframework.pipes.CreateRestViewPipe.java

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    HttpServletRequest httpServletRequest = (HttpServletRequest) session.get("restListenerServletRequest");
    String requestURL = httpServletRequest.getRequestURL().toString();
    String servletPath = httpServletRequest.getServletPath();
    String uri = StringUtils.substringAfter(requestURL, servletPath);
    int countSrcPrefix = StringUtils.countMatches(uri, "/");
    String srcPrefix = StringUtils.repeat("../", countSrcPrefix);
    session.put(SRCPREFIX, srcPrefix);//from  w  ww  .ja  v a2s . c om
    log.debug(getLogPrefix(session) + "stored [" + srcPrefix + "] in pipeLineSession under key [" + SRCPREFIX
            + "]");

    PipeRunResult prr = super.doPipe(input, session);
    String result = (String) prr.getResult();

    log.debug("transforming page [" + result + "] to view");

    String newResult = null;
    ServletContext servletContext = (ServletContext) session.get("restListenerServletContext");
    try {
        Map parameters = retrieveParameters(httpServletRequest, servletContext, srcPrefix);
        newResult = XmlUtils.getAdapterSite(result, parameters);
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on transforming page to view", e);
    }

    session.put(CONTENTTYPE, getContentType());
    log.debug(getLogPrefix(session) + "stored [" + getContentType() + "] in pipeLineSession under key ["
            + CONTENTTYPE + "]");

    return new PipeRunResult(getForward(), newResult);
}