List of usage examples for org.apache.commons.lang StringUtils substringBefore
public static String substringBefore(String str, String separator)
Gets the substring before the first occurrence of a separator.
From source file:org.beangle.struts2.action.EntityDrivenAction.java
/** * ?/*from ww w . j ava 2s. c o m*/ * * @return * @throws Exception */ public String export() throws Exception { String format = get("format"); String fileName = get("fileName"); String template = get("template"); if (StringUtils.isBlank(format)) { format = TransferFormats.XLS; } if (StringUtils.isEmpty(fileName)) { fileName = "exportResult"; } // ? Context context = new Context(); context.put("format", format); context.put("exportFile", fileName); context.put("template", template); String properties = get("properties"); if (null != properties) { String[] props = StringUtils.split(properties, ","); List<String> keys = CollectUtils.newArrayList(); List<String> titles = CollectUtils.newArrayList(); for (String prop : props) { keys.add(StringUtils.substringBefore(prop, ":")); titles.add(getTextInternal(StringUtils.substringAfter(prop, ":"))); } context.put(Context.KEYS, StrUtils.join(keys, ",")); context.put(Context.TITLES, StrUtils.join(titles, ",")); } else { context.put(Context.KEYS, get("keys")); context.put(Context.TITLES, get("titles")); } context.put(Context.EXTRACTOR, getPropertyExtractor()); HttpServletResponse response = ServletActionContext.getResponse(); Exporter exporter = buildExporter(context); exporter.getWriter().setOutputStream(response.getOutputStream()); configExporter(exporter, context); if (format.equals(TransferFormats.XLS)) { response.setContentType("application/vnd.ms-excel;charset=GBK"); } else { response.setContentType("application/x-msdownload"); } response.setHeader("Content-Disposition", "attachment;filename=" + encodeAttachName(ServletActionContext.getRequest(), fileName + "." + format)); // exporter.setContext(context); exporter.transfer(new TransferResult()); return null; }
From source file:org.beangle.struts2.convention.result.DefaultResultBuilder.java
public Result build(String resultCode, ActionConfig actionConfig, ActionContext context) { String path = null;/*from ww w. j ava2 s . c o m*/ ResultTypeConfig resultTypeConfig = null; logger.debug("result code:{} for actionConfig:{}", resultCode, actionConfig); if (null == resultTypeConfigs) { PackageConfig pc = configuration.getPackageConfig(actionConfig.getPackageName()); this.resultTypeConfigs = pc.getAllResultTypeConfigs(); } // prefix // TODO jsp,vm,ftl if (!StringUtils.contains(resultCode, ':')) { String className = context.getActionInvocation().getProxy().getAction().getClass().getName(); String methodName = context.getActionInvocation().getProxy().getMethod(); if (StringUtils.isEmpty(resultCode)) { resultCode = "index"; } StringBuilder buf = new StringBuilder(); buf.append(viewMapper.getViewPath(className, methodName, resultCode)); buf.append('.'); buf.append(profileService.getProfile(className).getViewExtension()); path = buf.toString(); resultTypeConfig = resultTypeConfigs.get("freemarker"); return buildResult(resultCode, resultTypeConfig, context, buildResultParams(path, resultTypeConfig)); } else { String prefix = StringUtils.substringBefore(resultCode, ":"); resultTypeConfig = (ResultTypeConfig) resultTypeConfigs.get(prefix); if (prefix.startsWith("chain")) { Action action = buildAction(StringUtils.substringAfter(resultCode, ":")); Map<String, String> params = buildResultParams(path, resultTypeConfig); addNamespaceAction(action, params); if (StringUtils.isNotEmpty(action.getMethod())) { params.put("method", action.getMethod()); } return buildResult(resultCode, resultTypeConfig, context, params); } else if (prefix.startsWith("redirect")) { String targetResource = StringUtils.substringAfter(resultCode, ":"); if (StringUtils.contains(targetResource, ':')) { return new ServletRedirectResult(targetResource); } Action action = buildAction(targetResource); // add special param and ajax tag for redirect HttpServletRequest request = ServletActionContext.getRequest(); String redirectParamStr = request.getParameter("params"); action.params(redirectParamStr); if (redirectParamStr != null && !"null".equals(redirectParamStr)) { action.param("params", redirectParamStr); } // x-requested-with->XMLHttpRequest if (null != request.getHeader("x-requested-with")) { action.param("x-requested-with", "1"); } Map<String, String> params = buildResultParams(path, resultTypeConfig); if (null != action.getParams().get("method")) { params.put("method", (String) action.getParams().get("method")); action.getParams().remove("method"); } if (StringUtils.isNotEmpty(action.getMethod())) { params.put("method", action.getMethod()); } addNamespaceAction(action, params); ServletRedirectResult result = (ServletRedirectResult) buildResult(resultCode, resultTypeConfig, context, params); for (Map.Entry<String, String> param : action.getParams().entrySet()) { String property = param.getKey(); result.addParameter(property, param.getValue()); } return result; } else { return buildResult(resultCode, resultTypeConfig, context, buildResultParams(path, resultTypeConfig)); } } }
From source file:org.beangle.struts2.convention.route.Action.java
public Action params(String paramStr) { if (StringUtils.isNotEmpty(paramStr)) { String[] paramPairs = StringUtils.split(paramStr, "&"); for (int i = 0; i < paramPairs.length; i++) { String key = StringUtils.substringBefore(paramPairs[i], "="); String value = StringUtils.substringAfter(paramPairs[i], "="); if (StringUtils.isNotEmpty(key) && StringUtils.isNotEmpty(value)) { params.put(key, value);/* w ww .j av a2 s .co m*/ } } } return this; }
From source file:org.beangle.struts2.view.component.Navmenu.java
/** * ???resource(action!method)/*from w w w. j ava 2 s . c o m*/ * * @param first * @param second * @return */ private boolean sameAction(String first) { StringBuilder firstSb = new StringBuilder(StringUtils.substringBefore(first, ".")); if (-1 == firstSb.lastIndexOf("!")) { firstSb.append("!index"); } return firstSb.toString().equals(uri); }
From source file:org.beangle.struts2.view.component.Select.java
public void setOption(String option) { if (null != option) { if (StringUtils.contains(option, ",")) { keyName = StringUtils.substringBefore(option, ","); valueName = StringUtils.substringAfter(option, ","); }//ww w.j a va 2s . com } }
From source file:org.beangle.web.agent.BrowserCategory.java
private BrowserCategory(String name, Engine renderEngine, String... versions) { this.name = name; this.engine = renderEngine; for (String version : versions) { String matcheTarget = version; String versionNum = ""; if (StringUtils.contains(version, "->")) { matcheTarget = StringUtils.substringBefore(version, "->"); versionNum = StringUtils.substringAfter(version, "->"); }//from w w w. j a va 2 s . com versionMap.put(Pattern.compile(matcheTarget), versionNum); } }
From source file:org.beangle.web.agent.OsCategory.java
private OsCategory(String name, String... versions) { this.name = name; for (String version : versions) { String matcheTarget = version; String versionNum = ""; if (StringUtils.contains(version, "->")) { matcheTarget = StringUtils.substringBefore(version, "->"); versionNum = StringUtils.substringAfter(version, "->"); }//from w w w.j av a2s. c o m versionMap.put(Pattern.compile(matcheTarget), versionNum); } }
From source file:org.betaconceptframework.astroboa.client.service.AbstractClientServiceWrapper.java
private void initialize(String serverHostNameAndorPortToConnect) { if (StringUtils.isBlank(serverHostNameAndorPortToConnect)) { //Set default URL if none provided serverHostNameAndorPortToConnect = AstroboaClient.INTERNAL_CONNECTION + ":" + DEFAULT_PORT; } else {/*from ww w . ja v a 2s . co m*/ //Set port if not provided if (!serverHostNameAndorPortToConnect.contains(":")) { serverHostNameAndorPortToConnect = serverHostNameAndorPortToConnect.concat(":" + DEFAULT_PORT); } else { if (StringUtils.isBlank(StringUtils.substringAfterLast(serverHostNameAndorPortToConnect, ":"))) { serverHostNameAndorPortToConnect = serverHostNameAndorPortToConnect.concat(DEFAULT_PORT); } } } resetService(); this.serverHostNameOrIpAndPortDelimitedWithSemiColon = serverHostNameAndorPortToConnect; this.serverHostNameOrIp = StringUtils.substringBefore(serverHostNameAndorPortToConnect, ":"); this.port = StringUtils.substringAfter(serverHostNameAndorPortToConnect, ":"); loadService(); }
From source file:org.betaconceptframework.astroboa.engine.definition.RepositoryEntityResolver.java
private byte[] getSchema(String systemId) { if (StringUtils.isBlank(systemId)) { return null; }/*from www . j a v a 2 s . co m*/ //We are only interested in content type name or path. String schemaFilename = systemId; //We expect URL of the form //http://<server>/resource-api/<repository-id>/model/multilingualStringPropertyType?output=xsd //Definition name is located after the last forward slash if (schemaFilename.contains(CmsConstants.FORWARD_SLASH)) { schemaFilename = StringUtils.substringAfterLast(schemaFilename, CmsConstants.FORWARD_SLASH); } if (schemaFilename.contains("?")) { schemaFilename = StringUtils.substringBefore(schemaFilename, "?"); } byte[] schema = contentDefinitionDao.getXMLSchemaFileForDefinition(schemaFilename); if (schema == null || schema.length == 0) { return null; } return schema; }
From source file:org.betaconceptframework.astroboa.util.PropertyPath.java
public PropertyPath(String propertyPath) { propertyNameWithIndex = getFirstPath(propertyPath); propertyName = StringUtils.substringBefore(propertyNameWithIndex, CmsConstants.LEFT_BRACKET); propertyIndex = extractIndexFromPath(propertyNameWithIndex); propertyDescendantPath = getPathAfterFirstLevel(propertyPath); fullPath = propertyPath;// w w w .j a va 2 s .com }