List of usage examples for org.apache.commons.lang StringUtils substringAfter
public static String substringAfter(String str, String separator)
Gets the substring after the first occurrence of a separator.
From source file:net.ymate.platform.mvc.web.support.DispatchHelper.java
/** * /*from w ww . j a v a2 s. c o m*/ * * @param config */ public DispatchHelper(FilterConfig config) { prefix = StringUtils.defaultIfEmpty(config.getInitParameter("prefix"), ""); methodParam = StringUtils.defaultIfEmpty(config.getInitParameter("methodParam"), DEFAULT_METHOD_PARAM); baseViewFilePath = RuntimeUtils.getRootPath() + StringUtils.substringAfter(TemplateHelper.getRootViewPath(), "/WEB-INF/"); }
From source file:net.ymate.platform.mvc.web.support.DispatchHelper.java
/** * /*from ww w . j a v a 2 s . co m*/ * * @param config */ public DispatchHelper(ServletConfig config) { prefix = StringUtils.defaultIfEmpty(config.getInitParameter("prefix"), ""); methodParam = StringUtils.defaultIfEmpty(config.getInitParameter("methodParam"), DEFAULT_METHOD_PARAM); baseViewFilePath = RuntimeUtils.getRootPath() + StringUtils.substringAfter(TemplateHelper.getRootViewPath(), "/WEB-INF/"); }
From source file:net.ymate.platform.mvc.web.support.HttpRequestExecutor.java
protected IView processMethodResultToView(Object result) throws Exception { IView _view = null;// ww w. j ava 2s. com if (result == null) { _view = new JspView(); } else if (result instanceof String) { String _viewStr = StringUtils.trimToEmpty((String) result).toLowerCase(); if (StringUtils.startsWith(_viewStr, IWebView.VIEW_REDIRECT)) { _view = new RedirectView(StringUtils.substringAfter(_viewStr, IWebView.VIEW_REDIRECT)); } else if (StringUtils.startsWith(_viewStr, IWebView.VIEW_FORWARD)) { _view = new ForwardView(StringUtils.substringAfter(_viewStr, IWebView.VIEW_FORWARD)); } else if (StringUtils.startsWith(_viewStr, IWebView.VIEW_HTTP_STATUS)) { String[] _statusContent = StringUtils .split(StringUtils.substringAfter(_viewStr, IWebView.VIEW_HTTP_STATUS), ","); _view = new HttpStatusView(Integer.parseInt(_statusContent[0]), _statusContent.length >= 2 ? _statusContent[1] : null); } else if (StringUtils.startsWith(_viewStr, IWebView.VIEW_JSON)) { _view = new JsonView(StringUtils.substringAfter(_viewStr, IWebView.VIEW_JSON)); } else if (StringUtils.startsWith(_viewStr, IWebView.VIEW_JSP)) { _view = new JspView(StringUtils.substringAfter(_viewStr, IWebView.VIEW_JSP)); } else if (StringUtils.startsWith(_viewStr, IWebView.VIEW_FTL)) { _view = new FreeMarkerView(StringUtils.substringAfter(_viewStr, IWebView.VIEW_FTL)); } else if (StringUtils.startsWith(_viewStr, IWebView.VIEW_INLINE_FILE)) { _view = BinaryView.loadFromFile(StringUtils.substringAfter(_viewStr, IWebView.VIEW_INLINE_FILE), false); } else if (StringUtils.startsWith(_viewStr, IWebView.VIEW_FILE)) { _view = BinaryView.loadFromFile(StringUtils.substringAfter(_viewStr, IWebView.VIEW_FILE), true); } else { _view = new TextView(_viewStr); } } else if (result instanceof IView) { _view = (IView) result; } return _view; }
From source file:net.ymate.platform.mvc.web.support.RequestMappingParser.java
/** * @param partStr ?/*from ww w. ja v a 2 s. c o m*/ * @return '/' */ protected String fixMappingPart(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.mvc.web.support.RequestMappingParser.java
/** * @param context /*from ww w . jav a 2 s . co m*/ * @param mappingSet ???'$'? * @return ?????????WebContextPathVariable? */ public String doParser(IRequestContext context, Set<String> mappingSet) { String _requestMapping = this.fixMappingPart(context.getRequestMapping()); // ??PairObject<Mapping[??], ??> Set<PairObject<String[], Integer>> _filteredMapping = new HashSet<PairObject<String[], Integer>>(); for (String _key : mappingSet) { if (_key.contains("{")) { String _mappingKey = StringUtils.substringBefore(_key, "{"); String _fixedMappingKey = this.fixMappingPart(_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.parserMappingParams(_mappingParamPart, _result.getKey()[3]); if (WebContext.getContext() != null) { // ???WebContextPathVariable? for (String _key : _params.keySet()) { WebContext.getContext().put(_key, _params.get(_key)); } } return _result.getKey()[0]; } return null; }
From source file:net.ymate.platform.mvc.web.support.TemplateHelper.java
/** * @return ?Freemarker??, ?()/*from w ww . j ava 2 s . c om*/ */ public static Configuration getFreemarkerConfiguration() { if (__FREEMARKER_CONFIG == null) { synchronized (__LOCKER) { __FREEMARKER_CONFIG = new Configuration(); __FREEMARKER_CONFIG.setDefaultEncoding("UTF-8"); __FREEMARKER_CONFIG.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER); // List<TemplateLoader> _tmpLoaders = new ArrayList<TemplateLoader>(); try { _tmpLoaders.add(new FileTemplateLoader(new File(RuntimeUtils.getRootPath(), StringUtils.substringAfter(getRootViewPath(), "/WEB-INF/")))); // _tmpLoaders.add(new FileTemplateLoader(new File(RuntimeUtils.getRootPath(), StringUtils.substringAfter(getPluginViewPath(), "/WEB-INF/")))); // _tmpLoaders.add(new FileTemplateLoader((new File(WebMVC.getConfig().getPluginHome())))); } catch (IOException e) { throw new Error(RuntimeUtils.unwrapThrow(e)); } __FREEMARKER_CONFIG .setTemplateLoader(new MultiTemplateLoader(_tmpLoaders.toArray(new TemplateLoader[0]))); } } return __FREEMARKER_CONFIG; }
From source file:net.ymate.platform.mvc.web.view.impl.BinaryView.java
/** * ?Range????/* w ww .ja v a 2s. c o m*/ * * @param maxLength ?? * @return ?null */ private PairObject<Long, Long> __doParseRange(long maxLength) { 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; } try { // bytes=-100 if (_range.startsWith("-")) { long _end = Long.parseLong(_range); long _start = maxLength + _end; if (_start < 0) { return null; } _returnValue = new PairObject<Long, Long>(_start, maxLength); break; } // bytes=1024- if (_range.endsWith("-")) { long _start = Long.parseLong(StringUtils.substringBefore(_range, "-")); if (_start < 0) { return null; } _returnValue = new PairObject<Long, Long>(_start, maxLength); 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); } } catch (Throwable e) { return null; } } } return _returnValue; }
From source file:net.ymate.platform.mvc.web.view.impl.FreeMarkerView.java
protected Configuration processPath() { if (StringUtils.isNotBlank(getContentType())) { WebContext.getResponse().setContentType(getContentType()); }//from w ww . j a v a2 s . c om for (Entry<String, Object> entry : getAttributes().entrySet()) { WebContext.getRequest().setAttribute(entry.getKey(), entry.getValue()); } if (StringUtils.isBlank(this.path)) { String _mapping = WebContext.getWebRequestContext().getRequestMapping(); if (_mapping.endsWith("/")) { _mapping.substring(0, _mapping.length() - 1); } this.path = _mapping + ".ftl"; } else { if (this.path.startsWith(this.getBaseViewPath())) { this.path = StringUtils.substringAfter(this.path, this.getBaseViewPath()); } if (!this.path.endsWith(".ftl")) { this.path += ".ftl"; } } return TemplateHelper.getFreemarkerConfiguration(); }
From source file:net.ymate.platform.persistence.jdbc.query.OrderBy.java
public OrderBy orderBy(OrderBy orderBy) { String _orderBy = StringUtils.substringAfter(orderBy.toSQL(), "ORDER BY "); if (StringUtils.isNotBlank(_orderBy)) { if (__orderBySB.length() > 0) { __orderBySB.append(", "); }/*from w w w.jav a 2s . com*/ __orderBySB.append(_orderBy); } return this; }
From source file:net.ymate.platform.webmvc.impl.DefaultRequestContext.java
public DefaultRequestContext(HttpServletRequest request, String prefix) { this.requestMapping = this.originalUrl = StringUtils.defaultIfBlank(request.getPathInfo(), request.getServletPath());//from ww w . j a v a2s .c o m if (StringUtils.isNotBlank(prefix)) { this.requestMapping = StringUtils.substringAfter(this.requestMapping, prefix); this.prefix = prefix; } int _pos = 0; if (!this.requestMapping.endsWith("/")) { _pos = this.requestMapping.lastIndexOf('.'); if (_pos < this.requestMapping.lastIndexOf('/')) { _pos = -1; } } else { // (:'/'?'/'?) this.requestMapping = this.requestMapping.substring(0, this.requestMapping.length() - 1); } if (_pos > 0) { this.suffix = this.requestMapping.substring(_pos + 1); this.requestMapping = this.requestMapping.substring(0, _pos); } else { this.suffix = ""; } __httpMethod = Type.HttpMethod.valueOf(request.getMethod()); // __attributes = new HashMap<String, Object>(); }