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:com.enonic.cms.core.search.ElasticSearchIndexedFieldsTranslator.java
public List<ContentIndexedFields> generateContentIndexFieldSet(ContentKey contentKey, Map<String, GetField> fields) { if (fields.isEmpty()) { return Collections.emptyList(); }//from ww w .jav a2 s. c o m final CategoryKey categoryKey = new CategoryKey((String) fields.get(CATEGORY_KEY_FIELDNAME).getValue()); final ContentIndexFieldSet indexFieldSet = new ContentIndexFieldSet(); indexFieldSet.setCategoryKey(categoryKey); indexFieldSet.setKey(contentKey); final String statusFieldName = STATUS_FIELDNAME + INDEX_FIELD_TYPE_SEPARATOR + NUMBER_FIELD_POSTFIX; indexFieldSet.setStatus(getFieldAsInt(fields.get(statusFieldName))); final String ctypeFieldName = CONTENTTYPE_KEY_FIELDNAME + INDEX_FIELD_TYPE_SEPARATOR + NUMBER_FIELD_POSTFIX; indexFieldSet.setContentTypeKey(new ContentTypeKey(getFieldAsInt(fields.get(ctypeFieldName)))); for (final String name : fields.keySet()) { if (skipField(name)) { continue; } if (name.startsWith(CONTENTDATA_PREFIX) && (!name.contains(INDEX_FIELD_TYPE_SEPARATOR))) { final GetField field = fields.get(name); final String value = StringUtils.join(field.getValues(), ','); if (StringUtils.isNotEmpty(value)) { final String customFieldName = StringUtils.substringAfter(name, CONTENTDATA_PREFIX); indexFieldSet.addFieldWithStringValue("data#" + customFieldName, value); } } else if ((!name.startsWith(CONTENTDATA_PREFIX)) && (!name.contains(INDEX_FIELD_TYPE_SEPARATOR))) { addIndexEntityField(indexFieldSet, name, fields); } } return indexFieldSet.getEntitites(); }
From source file:eu.annocultor.converters.europeana.EuropeanaLabelExtractor.java
boolean extractDfgCoverage(List<String> extracted, String label) { if (precheckisDfgCoverage(label)) { if (StringUtils.capitalize(label).equals(label)) { String countryAbbreviated = StringUtils.substringBefore(label, " "); extracted.add(countryAbbreviated); String countrySpelled = StringUtils.substringAfter(label, " "); if (!StringUtils.isEmpty(countrySpelled)) { extracted.add(countrySpelled); return true; }//from w w w . j a v a 2 s.co m } } return false; }
From source file:net.scriptability.core.url.DefaultURLResolver.java
/** * Resolves a URL and returns an input stream to its resource. * * @param url url to resolve//from ww w . j ava2 s .com * @return input stream to the resource addressed by the received URL * @throws URLResolutionException if the URL cannot be resolved */ @Override public InputStream resolve(final String url) throws URLResolutionException { Preconditions.checkArgument(StringUtils.isNotBlank(url), "URL cannot be blank."); LOG.debug("Resolving URL: [{}].", url); final InputStream urlInputStream; if (url.startsWith(CLASSPATH_URL_PREFIX)) { urlInputStream = ResourceLoader .getResourceAsStream(StringUtils.substringAfter(url, CLASSPATH_URL_PREFIX)); if (urlInputStream == null) { throw new URLResolutionException("Resource does not exist: [" + url + "]."); } } else { try { urlInputStream = openURLStream(new URL(url)); } catch (final MalformedURLException malformedUrlEx) { throw new URLResolutionException("URL is malformed: [" + malformedUrlEx + "].", malformedUrlEx); } } return urlInputStream; }
From source file:com.netflix.spinnaker.clouddriver.ecs.view.EcsInstanceProvider.java
@Override public EcsTask getInstance(String account, String region, String id) { if (!isValidId(id, region)) return null; EcsTask ecsInstance = null;/*from ww w . j a v a2 s . co m*/ String key = Keys.getTaskKey(account, region, id); Task task = taskCacheClient.get(key); if (task == null) { return null; } key = Keys.getContainerInstanceKey(account, region, task.getContainerInstanceArn()); ContainerInstance containerInstance = containerInstanceCacheClient.get(key); if (containerInstance != null) { String serviceName = StringUtils.substringAfter(task.getGroup(), "service:"); Long launchTime = task.getStartedAt(); List<Map<String, String>> healthStatus = containerInformationService.getHealthStatus(id, serviceName, account, region); String address = containerInformationService.getTaskPrivateAddress(account, region, task); ecsInstance = new EcsTask(id, launchTime, task.getLastStatus(), task.getDesiredStatus(), containerInstance.getAvailabilityZone(), healthStatus, address); } return ecsInstance; }
From source file:cool.pandora.modeller.ui.handlers.text.CreateAreasHandler.java
@Override public void execute() { final String message = ApplicationContextUtil.getMessage("bag.message.areacreated"); final DefaultBag bag = bagView.getBag(); final Map<String, BagInfoField> map = bag.getInfo().getFieldMap(); final String url = bag.gethOCRResource(); List<String> areaIdList = null; try {//from w w w . j a va 2s. c om final hOCRData hocr = DocManifestBuilder.gethOCRProjectionFromURL(url); areaIdList = getAreaIdList(hocr); } catch (final IOException e) { e.printStackTrace(); } assert areaIdList != null; for (String resourceID : areaIdList) { resourceID = StringUtils.substringAfter(resourceID, "_"); final URI areaObjectURI = TextObjectURI.getAreaObjectURI(map, resourceID); try { ModellerClient.doPut(areaObjectURI); ApplicationContextUtil.addConsoleMessage(message + " " + areaObjectURI); } catch (final ModellerClientFailedException e) { ApplicationContextUtil.addConsoleMessage(getMessage(e)); } } bagView.getControl().invalidate(); }
From source file:cool.pandora.modeller.ui.handlers.text.CreateLinesHandler.java
@Override public void execute() { final String message = ApplicationContextUtil.getMessage("bag.message.linecreated"); final DefaultBag bag = bagView.getBag(); final Map<String, BagInfoField> map = bag.getInfo().getFieldMap(); final String url = bag.gethOCRResource(); List<String> lineIdList = null; try {/*from w w w .ja v a2s. co m*/ final hOCRData hocr = DocManifestBuilder.gethOCRProjectionFromURL(url); lineIdList = getLineIdList(hocr); } catch (final IOException e) { e.printStackTrace(); } assert lineIdList != null; for (String resourceID : lineIdList) { resourceID = StringUtils.substringAfter(resourceID, "_"); final URI lineObjectURI = TextObjectURI.getLineObjectURI(map, resourceID); try { ModellerClient.doPut(lineObjectURI); ApplicationContextUtil.addConsoleMessage(message + " " + lineObjectURI); } catch (final ModellerClientFailedException e) { ApplicationContextUtil.addConsoleMessage(getMessage(e)); } } bagView.getControl().invalidate(); }
From source file:cool.pandora.modeller.ui.handlers.text.CreatePagesHandler.java
@Override public void execute() { final String message = ApplicationContextUtil.getMessage("bag.message.pagecreated"); final DefaultBag bag = bagView.getBag(); final Map<String, BagInfoField> map = bag.getInfo().getFieldMap(); final String url = bag.gethOCRResource(); List<String> pageIdList = null; try {/* w w w. j a va2 s .co m*/ final hOCRData hocr = DocManifestBuilder.gethOCRProjectionFromURL(url); pageIdList = getPageIdList(hocr); } catch (final IOException e) { e.printStackTrace(); } assert pageIdList != null; for (String resourceID : pageIdList) { resourceID = StringUtils.substringAfter(resourceID, "_"); final URI pageObjectURI = TextObjectURI.getPageObjectURI(map, resourceID); try { ModellerClient.doPut(pageObjectURI); ApplicationContextUtil.addConsoleMessage(message + " " + pageObjectURI); } catch (final ModellerClientFailedException e) { ApplicationContextUtil.addConsoleMessage(getMessage(e)); } } bagView.getControl().invalidate(); }
From source file:com.delmar.core.web.filter.ExportDelegate.java
/** * Actually writes exported data. Extracts content from the Map stored in request with the * <code>TableTag.FILTER_CONTENT_OVERRIDE_BODY</code> key. * @param wrapper BufferedResponseWrapper implementation * @param response HttpServletResponse/*from w w w . java 2s. c om*/ * @param request ServletRequest * @throws java.io.IOException exception thrown by response writer/outputStream */ public static void writeExport(HttpServletResponse response, ServletRequest request, BufferedResponseWrapper wrapper) throws IOException { if (wrapper.isOutRequested()) { // data already written log.debug("Filter operating in unbuffered mode. Everything done, exiting"); return; } // if you reach this point the PARAMETER_EXPORTING has been found, but the special header has never been set in // response (this is the signal from table tag that it is going to write exported data) log.debug("Filter operating in buffered mode. "); Map bean = (Map) request.getAttribute(TableTag.FILTER_CONTENT_OVERRIDE_BODY); if (log.isDebugEnabled()) { log.debug(bean); } Object pageContent = bean.get(TableTagParameters.BEAN_BODY); if (pageContent == null) { if (log.isDebugEnabled()) { log.debug("Filter is enabled but exported content has not been found. Maybe an error occurred?"); } response.setContentType(wrapper.getContentType()); PrintWriter out = response.getWriter(); out.write(wrapper.getContentAsString()); out.flush(); return; } // clear headers if (!response.isCommitted()) { response.reset(); } String filename = (String) bean.get(TableTagParameters.BEAN_FILENAME); String contentType = (String) bean.get(TableTagParameters.BEAN_CONTENTTYPE); if (StringUtils.isNotBlank(filename)) { response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); } String characterEncoding = wrapper.getCharacterEncoding(); String wrappedContentType = wrapper.getContentType(); if (wrappedContentType != null && wrappedContentType.indexOf("charset") > -1) { // charset is already specified (see #921811) characterEncoding = StringUtils.substringAfter(wrappedContentType, "charset="); } if (characterEncoding != null && contentType.indexOf("charset") == -1) //$NON-NLS-1$ { contentType += "; charset=" + characterEncoding; //$NON-NLS-1$ } response.setContentType(contentType); if (pageContent instanceof String) { // text content if (characterEncoding != null) { response.setContentLength(((String) pageContent).getBytes(characterEncoding).length); } else { //FIXME Reliance on default encoding // Found a call to a method which will perform a byte to String (or String to byte) conversion, // and will assume that the default platform encoding is suitable. // This will cause the application behaviour to vary between platforms. // Use an alternative API and specify a charset name or Charset object explicitly. response.setContentLength(((String) pageContent).getBytes().length); } PrintWriter out = response.getWriter(); out.write((String) pageContent); out.flush(); } else { // dealing with binary content byte[] content = (byte[]) pageContent; response.setContentLength(content.length); OutputStream out = response.getOutputStream(); out.write(content); out.flush(); } }
From source file:com.zb.app.biz.service.WeixinTest.java
public void login() { httpClient = new HttpClient(); PostMethod post = new PostMethod(loginUrl); post.addParameter(new NameValuePair("username", account)); post.addParameter(new NameValuePair("pwd", DigestUtils.md5Hex(password))); post.addParameter(new NameValuePair("imgcode", "")); post.addParameter(new NameValuePair("f", "json")); post.setRequestHeader("Host", "mp.weixin.qq.com"); post.setRequestHeader("Referer", "https://mp.weixin.qq.com/cgi-bin/loginpage?t=wxm2-login&lang=zh_CN"); try {//from w w w . java 2 s . c o m int code = httpClient.executeMethod(post); if (HttpStatus.SC_OK == code) { String res = post.getResponseBodyAsString(); JSONParser parser = new JSONParser(); JSONObject obj = (JSONObject) parser.parse(res); JSONObject _obj = (JSONObject) obj.get("base_resp"); @SuppressWarnings("unused") String msg = (String) _obj.get("err_msg"); String redirect_url = (String) obj.get("redirect_url"); Long errCode = (Long) _obj.get("ret"); if (0 == errCode) { isLogin = true; token = StringUtils.substringAfter(redirect_url, "token="); if (null == token) { token = StringUtils.substringBetween(redirect_url, "token=", "&"); } StringBuffer cookie = new StringBuffer(); for (Cookie c : httpClient.getState().getCookies()) { cookie.append(c.getName()).append("=").append(c.getValue()).append(";"); } this.cookiestr = cookie.toString(); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.blue.ssh.core.orm.PropertyFilter.java
/** * @param filterName//from w w w. jav a 2 s .c o m * ,???. eg. LIKES_NAME_OR_LOGIN_NAME * @param value * . */ public PropertyFilter(final String filterName, final String value) { String firstPart = StringUtils.substringBefore(filterName, "_"); String matchTypeCode = StringUtils.substring(firstPart, 0, firstPart.length() - 1); String propertyTypeCode = StringUtils.substring(firstPart, firstPart.length() - 1, firstPart.length()); try { matchType = Enum.valueOf(MatchType.class, matchTypeCode); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } try { propertyClass = Enum.valueOf(PropertyType.class, propertyTypeCode).getValue(); } catch (RuntimeException e) { throw new IllegalArgumentException( "filter??" + filterName + ",.", e); } String propertyNameStr = StringUtils.substringAfter(filterName, "_"); Assert.isTrue(StringUtils.isNotBlank(propertyNameStr), "filter??" + filterName + ",??."); propertyNames = StringUtils.splitByWholeSeparator(propertyNameStr, PropertyFilter.OR_SEPARATOR); this.matchValue = ConvertUtils.convertStringToObject(value, propertyClass); }