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.szl.common.utils.Struts2Utils.java
/** * ?contentTypeheaders.//from www . j a va 2s . c om */ private static HttpServletResponse initResponseHeader(final String contentType, final String... headers) { //?headers? String encoding = DEFAULT_ENCODING; boolean noCache = DEFAULT_NOCACHE; for (String header : headers) { String headerName = StringUtils.substringBefore(header, ":"); String headerValue = StringUtils.substringAfter(header, ":"); if (StringUtils.equalsIgnoreCase(headerName, HEADER_ENCODING)) { encoding = headerValue; } else if (StringUtils.equalsIgnoreCase(headerName, HEADER_NOCACHE)) { noCache = Boolean.parseBoolean(headerValue); } else { throw new IllegalArgumentException(headerName + "??header"); } } HttpServletResponse response = ServletActionContext.getResponse(); //headers? String fullContentType = contentType + ";charset=" + encoding; response.setContentType(fullContentType); if (noCache) { ServletUtils.setNoCacheHeader(response); } return response; }
From source file:mitm.common.util.DomainUtils.java
/** * Returns the upper level domain. //from w w w. j a v a 2s . c o m * * Example: sub.example.com returns example.com */ public static String getUpperLevelDomain(String domain) { return StringUtils.substringAfter(StringUtils.trimToEmpty(domain), "."); }
From source file:com.ewcms.web.pubsub.PubsubServlet.java
private PubsubSenderable createPubsubSender(String path) { String name = null;// w ww . j a v a 2s.co m if (StringUtils.indexOf(path, '/') == -1) { name = pathSender.get(path); } else { String root = StringUtils.substringBeforeLast(path, "/"); name = pathSender.get(root); if (name == null) { String middle = StringUtils.substringAfter(root, "/"); name = pathSender.get(middle); } } if (StringUtils.isNotBlank(name)) { try { Class<?> clazz = Class.forName(name); Class<?>[] argsClass = new Class<?>[] { String.class, ServletContext.class }; Constructor<?> cons = clazz.getConstructor(argsClass); return (PubsubSenderable) cons.newInstance(new Object[] { path, this.getServletContext() }); } catch (Exception e) { logger.error("PubsubSender create error:{}", e.toString()); } } return new NoneSender(); }
From source file:com.baidu.cc.common.SysUtils.java
/** * authCheck??projectId./* w ww . ja v a 2 s . co m*/ * * @param authCheck * authCheck * @return userId */ public static Long getProjectIdFromAuthcheck(String authCheck) { String value = Security.DESDecrypt(authCheck, AUTHCHECK_DES_KEY); return NumberUtils.toLong(StringUtils.substringAfter(value, "projectId=")); }
From source file:com.widen.valet.Route53Driver.java
private ZoneChangeStatus parseChangeResourceRecordSetsResponse(String zoneId, XMLTag xml) { try {/* ww w .ja v a2 s . c o m*/ XMLTag changeInfo = xml.gotoChild("ChangeInfo"); String changeId = StringUtils.substringAfter(changeInfo.getText("Id"), "/change/"); ZoneChangeStatus.Status status = ZoneChangeStatus.Status.valueOf(changeInfo.getText("Status")); Date date = null; try { date = parseDate("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", changeInfo.getText("SubmittedAt")); } catch (ParseException e) { try { date = parseDate("yyyy-MM-dd'T'HH:mm:ss'Z'", changeInfo.getText("SubmittedAt")); } catch (ParseException e2) { throw new RuntimeException(e2); } } return new ZoneChangeStatus(zoneId, changeId, status, date); } catch (XMLDocumentException e) { // Document has no child 'ChangeInfo' return new ZoneChangeStatus(zoneId, null, null, null); } }
From source file:com.prowidesoftware.swift.model.field.SwiftParseUtils.java
/** * Split components of a line using the parameter separator and returns the second token found or <code>null</code> if * second component is missing. Two adjacent separators are NOT treated as one. The second component is assumed as the * last one so its content may have additional separators if present.<br /> * Examples with slash as separator:<ul> * <li>for the literal "abc//def/ghi" will return null.</li> * <li>for the literal "abc/foo" will return "foo".</li> * <li>for the literal "abc/foo/def/ghi" will return "foo/def/ghi".</li> * </ul>//from w w w. ja v a2 s . c o m * * @param line * @param separator * @return s */ public static String getTokenSecondLast(final String line, final String separator) { String result = StringUtils.substringAfter(line, separator); if (StringUtils.isBlank(result)) { result = null; } return result; }
From source file:com.amalto.core.storage.record.XmlDOMDataRecordReader.java
private void _read(MetadataRepository repository, DataRecord dataRecord, ComplexTypeMetadata type, Element element) {/*from ww w .j a va 2 s . c om*/ // TODO Don't use getChildNodes() but getNextSibling() calls (but cause regressions -> see TMDM-5410). String tagName = element.getTagName(); NodeList children = element.getChildNodes(); NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); if (!type.hasField(attribute.getNodeName())) { continue; } FieldMetadata field = type.getField(attribute.getNodeName()); dataRecord.set(field, StorageMetadataUtils.convert(attribute.getNodeValue(), field)); } for (int i = 0; i < children.getLength(); i++) { Node currentChild = children.item(i); if (currentChild instanceof Element) { Element child = (Element) currentChild; if (METADATA_NAMESPACE.equals(child.getNamespaceURI())) { DataRecordMetadataHelper.setMetadataValue(dataRecord.getRecordMetadata(), child.getLocalName(), child.getTextContent()); } else { if (!type.hasField(child.getTagName())) { continue; } FieldMetadata field = type.getField(child.getTagName()); if (field.getType() instanceof ContainedComplexTypeMetadata) { ComplexTypeMetadata containedType = (ComplexTypeMetadata) field.getType(); String xsiType = child.getAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type"); //$NON-NLS-1$ if (xsiType.startsWith("java:")) { //$NON-NLS-1$ // Special format for 'java:' type names (used in Castor XML to indicate actual class name) xsiType = ClassRepository.format(StringUtils .substringAfterLast(StringUtils.substringAfter(xsiType, "java:"), ".")); //$NON-NLS-1$ //$NON-NLS-2$ } if (!xsiType.isEmpty()) { for (ComplexTypeMetadata subType : containedType.getSubTypes()) { if (subType.getName().equals(xsiType)) { containedType = subType; break; } } } DataRecord containedRecord = new DataRecord(containedType, UnsupportedDataRecordMetadata.INSTANCE); dataRecord.set(field, containedRecord); _read(repository, containedRecord, containedType, child); } else if (ClassRepository.EMBEDDED_XML.equals(field.getType().getName())) { try { dataRecord.set(field, Util.nodeToString(element)); } catch (TransformerException e) { throw new RuntimeException(e); } } else { _read(repository, dataRecord, type, child); } } } else if (currentChild instanceof Text) { StringBuilder builder = new StringBuilder(); for (int j = 0; j < element.getChildNodes().getLength(); j++) { String nodeValue = element.getChildNodes().item(j).getNodeValue(); if (nodeValue != null) { builder.append(nodeValue.trim()); } } String textContent = builder.toString(); if (!textContent.isEmpty()) { FieldMetadata field = type.getField(tagName); if (field instanceof ReferenceFieldMetadata) { ComplexTypeMetadata actualType = ((ReferenceFieldMetadata) field).getReferencedType(); String mdmType = element.getAttributeNS(SkipAttributeDocumentBuilder.TALEND_NAMESPACE, "type"); //$NON-NLS-1$ if (!mdmType.isEmpty()) { actualType = repository.getComplexType(mdmType); } if (actualType == null) { throw new IllegalArgumentException("Type '" + mdmType + "' does not exist."); } dataRecord.set(field, StorageMetadataUtils.convert(textContent, field, actualType)); } else { dataRecord.set(field, StorageMetadataUtils.convert(textContent, field, type)); } } } } }
From source file:cool.pandora.modeller.ui.handlers.common.NodeMap.java
/** * getLineIdMap.// w w w . j a v a 2 s. co m * * @param hocr hOCRData * @param areaIdList List * @return Map */ public static Map<String, List<String>> getLineIdMap(final hOCRData hocr, final List<String> areaIdList) { final Map<String, List<String>> nodemap = new HashMap<>(); List<String> lineIdList; for (String areaId : areaIdList) { lineIdList = getLineIdListforArea(hocr, areaId); for (int i = 0; i < lineIdList.size(); i++) { final String lineId = StringUtils.substringAfter(lineIdList.get(i), "_"); lineIdList.set(i, lineId); } areaId = StringUtils.substringAfter(areaId, "_"); nodemap.put(areaId, lineIdList); } return nodemap; }
From source file:info.magnolia.cms.module.ModuleUtil.java
public static void bootstrap(String[] resourceNames) throws IOException, RegisterException { HierarchyManager hm = MgnlContext.getHierarchyManager(ContentRepository.CONFIG); // sort by length --> import parent node first List list = new ArrayList(Arrays.asList(resourceNames)); Collections.sort(list, new Comparator() { public int compare(Object name1, Object name2) { return ((String) name1).length() - ((String) name2).length(); }// www . jav a2s . com }); for (Iterator iter = list.iterator(); iter.hasNext();) { String resourceName = (String) iter.next(); // windows again resourceName = StringUtils.replace(resourceName, "\\", "/"); String name = StringUtils.removeEnd(StringUtils.substringAfterLast(resourceName, "/"), ".xml"); String repository = StringUtils.substringBefore(name, "."); String pathName = StringUtils.substringAfter(StringUtils.substringBeforeLast(name, "."), "."); //$NON-NLS-1$ String nodeName = StringUtils.substringAfterLast(name, "."); String fullPath; if (StringUtils.isEmpty(pathName)) { pathName = "/"; fullPath = "/" + nodeName; } else { pathName = "/" + StringUtils.replace(pathName, ".", "/"); fullPath = pathName + "/" + nodeName; } // if the path already exists --> delete it try { if (hm.isExist(fullPath)) { hm.delete(fullPath); if (log.isDebugEnabled()) log.debug("already existing node [{}] deleted", fullPath); } // if the parent path not exists just create it if (!pathName.equals("/")) { ContentUtil.createPath(hm, pathName, ItemType.CONTENT); } } catch (Exception e) { throw new RegisterException("can't register bootstrap file: [" + name + "]", e); } InputStream stream = ModuleUtil.class.getResourceAsStream(resourceName); DataTransporter.executeImport(pathName, repository, stream, name, false, ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING, true, true); } }
From source file:com.sa.npopa.samples.hbase.RowCounter.java
/** * Sets up the actual job.// w ww. j av a 2s . c o m * * @param conf The current configuration. * @param args The command line parameters. * @return The newly created job. * @throws IOException When setting up the job fails. */ public static Job createSubmittableJob(Configuration conf, String[] args) throws IOException { String tableName = args[0]; String startKey = null; String endKey = null; long startTime = 0; long endTime = 0; StringBuilder sb = new StringBuilder(); final String rangeSwitch = "--range="; final String startTimeArgKey = "--starttime="; final String endTimeArgKey = "--endtime="; final String expectedCountArg = "--expected-count="; // First argument is table name, starting from second for (int i = 1; i < args.length; i++) { if (args[i].startsWith(rangeSwitch)) { String[] startEnd = args[i].substring(rangeSwitch.length()).split(",", 2); if (startEnd.length != 2 || startEnd[1].contains(",")) { printUsage("Please specify range in such format as \"--range=a,b\" " + "or, with only one boundary, \"--range=,b\" or \"--range=a,\""); return null; } startKey = startEnd[0]; endKey = startEnd[1]; continue; } if (args[i].startsWith(startTimeArgKey)) { startTime = Long.parseLong(args[i].substring(startTimeArgKey.length())); continue; } if (args[i].startsWith(endTimeArgKey)) { endTime = Long.parseLong(args[i].substring(endTimeArgKey.length())); continue; } if (args[i].startsWith(expectedCountArg)) { conf.setLong(EXPECTED_COUNT_KEY, Long.parseLong(args[i].substring(expectedCountArg.length()))); continue; } // if no switch, assume column names sb.append(args[i]); sb.append(" "); } if (endTime < startTime) { printUsage("--endtime=" + endTime + " needs to be greater than --starttime=" + startTime); return null; } Job job = Job.getInstance(conf, conf.get(JOB_NAME_CONF_KEY, NAME + "_" + tableName)); job.setJarByClass(RowCounter.class); Scan scan = new Scan(); scan.setCacheBlocks(false); if (startKey != null && !startKey.equals("")) { scan.setStartRow(Bytes.toBytes(startKey)); } if (endKey != null && !endKey.equals("")) { scan.setStopRow(Bytes.toBytes(endKey)); } if (sb.length() > 0) { for (String columnName : sb.toString().trim().split(" ")) { String family = StringUtils.substringBefore(columnName, ":"); String qualifier = StringUtils.substringAfter(columnName, ":"); if (StringUtils.isBlank(qualifier)) { scan.addFamily(Bytes.toBytes(family)); } else { scan.addColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier)); } } } scan.setFilter(new FirstKeyOnlyFilter()); scan.setTimeRange(startTime, endTime == 0 ? HConstants.LATEST_TIMESTAMP : endTime); job.setOutputFormatClass(NullOutputFormat.class); TableMapReduceUtil.initTableMapperJob(tableName, scan, RowCounterMapper.class, ImmutableBytesWritable.class, Result.class, job); job.setNumReduceTasks(0); return job; }