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:org.apache.lens.cube.parse.QueriedPhraseContext.java
public static Date getFactColumnEndTime(CandidateTable table, String factCol) { Date endTime = null;/* w w w . j a v a 2s. c o m*/ if (table instanceof CandidateFact) { for (String key : ((CandidateFact) table).fact.getProperties().keySet()) { if (key.contains(MetastoreConstants.FACT_COL_END_TIME_PFX)) { String propCol = StringUtils.substringAfter(key, MetastoreConstants.FACT_COL_END_TIME_PFX); if (factCol.equals(propCol)) { endTime = ((CandidateFact) table).fact.getDateFromProperty(key, false, true); } } } } return endTime; }
From source file:org.apache.lens.cube.parse.StorageCandidate.java
public Optional<Date> getColumnStartTime(String column) { Date startTime = null;/*from ww w . ja v a 2 s. com*/ for (String key : getTable().getProperties().keySet()) { if (key.contains(MetastoreConstants.FACT_COL_START_TIME_PFX)) { String propCol = StringUtils.substringAfter(key, MetastoreConstants.FACT_COL_START_TIME_PFX); if (column.equals(propCol)) { startTime = MetastoreUtil.getDateFromProperty(getTable().getProperties().get(key), false, true); } } } return Optional.ofNullable(startTime); }
From source file:org.apache.lens.cube.parse.StorageCandidate.java
@Override public Optional<Date> getColumnEndTime(String column) { Date endTime = null;// w w w . j a v a 2s .c om for (String key : getTable().getProperties().keySet()) { if (key.contains(MetastoreConstants.FACT_COL_END_TIME_PFX)) { String propCol = StringUtils.substringAfter(key, MetastoreConstants.FACT_COL_END_TIME_PFX); if (column.equals(propCol)) { endTime = MetastoreUtil.getDateFromProperty(getTable().getProperties().get(key), false, true); } } } return Optional.ofNullable(endTime); }
From source file:org.apache.maven.archetype.ui.generation.ArchetypeSelectorUtils.java
private static String extractArtifactIdFromFilter(String filter) { // if no : the full text is considered as artifactId content return StringUtils.contains(filter, ':') ? StringUtils.substringAfter(filter, ":") : filter; }
From source file:org.apache.maven.scm.provider.svn.svnexe.command.remoteinfo.SvnRemoteInfoCommand.java
@Override public RemoteInfoScmResult executeRemoteInfoCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException { String url = ((SvnScmProviderRepository) repository).getUrl(); // use a default svn layout, url is here http://svn.apache.org/repos/asf/maven/maven-3/trunk // so as we presume we have good users using standard svn layout, we calculate tags and branches url String baseUrl = StringUtils.endsWith(url, "/") ? StringUtils.substringAfter(StringUtils.removeEnd(url, "/"), "/") : StringUtils.substringBeforeLast(url, "/"); Commandline cl = SvnCommandLineUtils.getBaseSvnCommandLine(fileSet == null ? null : fileSet.getBasedir(), (SvnScmProviderRepository) repository); cl.createArg().setValue("ls"); cl.createArg().setValue(baseUrl + "/tags"); CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer(); LsConsumer consumer = new LsConsumer(getLogger(), baseUrl); int exitCode = 0; Map<String, String> tagsInfos = null; try {/* w w w . j av a 2 s . c om*/ exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger()); tagsInfos = consumer.infos; } catch (CommandLineException ex) { throw new ScmException("Error while executing svn command.", ex); } if (exitCode != 0) { return new RemoteInfoScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false); } cl = SvnCommandLineUtils.getBaseSvnCommandLine(fileSet == null ? null : fileSet.getBasedir(), (SvnScmProviderRepository) repository); cl.createArg().setValue("ls"); cl.createArg().setValue(baseUrl + "/tags"); stderr = new CommandLineUtils.StringStreamConsumer(); consumer = new LsConsumer(getLogger(), baseUrl); Map<String, String> branchesInfos = null; try { exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger()); branchesInfos = consumer.infos; } catch (CommandLineException ex) { throw new ScmException("Error while executing svn command.", ex); } if (exitCode != 0) { return new RemoteInfoScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false); } return new RemoteInfoScmResult(cl.toString(), branchesInfos, tagsInfos); }
From source file:org.apache.maven.scm.provider.svn.svnjava.command.remoteinfo.SvnJavaRemoteInfoCommand.java
@Override public RemoteInfoScmResult executeRemoteInfoCommand(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException { SvnJavaScmProviderRepository javaRepo = (SvnJavaScmProviderRepository) repository; String url = ((SvnScmProviderRepository) repository).getUrl(); // use a default svn layout, url is here http://svn.apache.org/repos/asf/maven/maven-3/trunk // so as we presume we have good users using standard svn layout, we calculate tags and branches url String baseUrl = StringUtils.endsWith(url, "/") ? StringUtils.substringAfter(StringUtils.removeEnd(url, "/"), "/") : StringUtils.substringBeforeLast(url, "/"); RemoteInfoScmResult remoteInfoScmResult = new RemoteInfoScmResult(null, null, null, true); try {//from ww w .j a v a 2s. co m DirEntryHandler dirEntryHandler = new DirEntryHandler(baseUrl); javaRepo.getClientManager().getLogClient().doList(SVNURL.parseURIEncoded(baseUrl + "/tags"), SVNRevision.HEAD, SVNRevision.HEAD, false, false, dirEntryHandler); remoteInfoScmResult.setTags(dirEntryHandler.infos); } catch (SVNException e) { return new RemoteInfoScmResult(null, e.getMessage(), null, false); } try { DirEntryHandler dirEntryHandler = new DirEntryHandler(baseUrl); javaRepo.getClientManager().getLogClient().doList(SVNURL.parseURIEncoded(baseUrl + "/branches"), SVNRevision.HEAD, SVNRevision.HEAD, false, false, dirEntryHandler); remoteInfoScmResult.setBranches(dirEntryHandler.infos); } catch (SVNException e) { return new RemoteInfoScmResult(null, e.getMessage(), null, false); } return remoteInfoScmResult; }
From source file:org.apache.nutch.crawl.SeedGenerator.java
public static void main(String[] args) throws Exception { String urlFormat = "http://oumen.com/detail.php?atid={{{1000,4460}}}"; String[] urlParts = urlFormat.split("\\{\\{\\{\\d+\\,\\d+\\}\\}\\}"); String[] placeholders = StringUtils.substringsBetween(urlFormat, "{{{", "}}}"); ArrayList<ArrayList<Integer>> ranges = Lists.newArrayList(); for (int i = 0; i < placeholders.length; ++i) { int min = Integer.parseInt(StringUtils.substringBefore(placeholders[i], ",")); int max = Integer.parseInt(StringUtils.substringAfter(placeholders[i], ",")); ranges.add(Lists.newArrayList(min, max)); }// w w w . j av a2 s .co m // we can support only one placeholder right now StringBuilder content = new StringBuilder(); for (int i = ranges.get(0).get(0); i <= ranges.get(0).get(1); ++i) { String url = urlParts[0] + i; if (urlParts.length > 1) { url += urlParts[1]; } content.append(url); content.append("\n"); } String tidyDomain = NetUtil.getTopLevelDomain(urlFormat); String file = StringUtils.substringBefore(tidyDomain, ".").toLowerCase().replaceAll("[^a-z]", "_"); file = "/tmp/" + file + ".txt"; FileUtils.writeStringToFile(new File(file), content.toString(), "utf-8"); System.out.println("url seed results are saved in : " + file); }
From source file:org.apache.ofbiz.shipment.thirdparty.usps.UspsServices.java
public static Map<String, Object> uspsPriorityMailInternationalLabel(DispatchContext dctx, Map<String, ? extends Object> context) { Delegator delegator = dctx.getDelegator(); LocalDispatcher dispatcher = dctx.getDispatcher(); String shipmentGatewayConfigId = (String) context.get("shipmentGatewayConfigId"); String resource = (String) context.get("configProps"); GenericValue shipmentRouteSegment = (GenericValue) context.get("shipmentRouteSegment"); Locale locale = (Locale) context.get("locale"); // Start the document Document requestDocument;//from w w w . ja v a 2 s .c om boolean certify = false; String test = getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "test", resource, "shipment.usps.test"); if (!"Y".equalsIgnoreCase(test)) { requestDocument = createUspsRequestDocument("PriorityMailIntlRequest", false, delegator, shipmentGatewayConfigId, resource); } else { requestDocument = createUspsRequestDocument("PriorityMailIntlCertifyRequest", false, delegator, shipmentGatewayConfigId, resource); certify = true; } Element rootElement = requestDocument.getDocumentElement(); // Retrieve from/to address and package details GenericValue originAddress = null; GenericValue originTelecomNumber = null; GenericValue destinationAddress = null; GenericValue destinationProvince = null; GenericValue destinationCountry = null; GenericValue destinationTelecomNumber = null; List<GenericValue> shipmentPackageRouteSegs = null; try { originAddress = shipmentRouteSegment.getRelatedOne("OriginPostalAddress", false); originTelecomNumber = shipmentRouteSegment.getRelatedOne("OriginTelecomNumber", false); destinationAddress = shipmentRouteSegment.getRelatedOne("DestPostalAddress", false); if (destinationAddress != null) { destinationProvince = destinationAddress.getRelatedOne("StateProvinceGeo", false); destinationCountry = destinationAddress.getRelatedOne("CountryGeo", false); } destinationTelecomNumber = shipmentRouteSegment.getRelatedOne("DestTelecomNumber", false); shipmentPackageRouteSegs = shipmentRouteSegment.getRelated("ShipmentPackageRouteSeg", null, null, false); } catch (GenericEntityException e) { Debug.logError(e, module); } if (originAddress == null || originTelecomNumber == null) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsPriorityMailLabelOriginAddressMissing", locale)); } // Origin Info // USPS wants a separate first name and last, best we can do is split the string on the white space, if that doesn't work then default to putting the attnName in both fields String fromAttnName = originAddress.getString("attnName"); String fromFirstName = StringUtils.defaultIfEmpty(StringUtils.substringBefore(fromAttnName, " "), fromAttnName); String fromLastName = StringUtils.defaultIfEmpty(StringUtils.substringAfter(fromAttnName, " "), fromAttnName); UtilXml.addChildElementValue(rootElement, "FromFirstName", fromFirstName, requestDocument); UtilXml.addChildElementValue(rootElement, "FromLastName", fromLastName, requestDocument); UtilXml.addChildElementValue(rootElement, "FromFirm", originAddress.getString("toName"), requestDocument); // The following 2 assignments are not typos - USPS address1 = OFBiz address2, USPS address2 = OFBiz address1 UtilXml.addChildElementValue(rootElement, "FromAddress1", originAddress.getString("address2"), requestDocument); UtilXml.addChildElementValue(rootElement, "FromAddress2", originAddress.getString("address1"), requestDocument); UtilXml.addChildElementValue(rootElement, "FromCity", originAddress.getString("city"), requestDocument); UtilXml.addChildElementValue(rootElement, "FromState", originAddress.getString("stateProvinceGeoId"), requestDocument); UtilXml.addChildElementValue(rootElement, "FromZip5", originAddress.getString("postalCode"), requestDocument); // USPS expects a phone number consisting of area code + contact number as a single numeric string String fromPhoneNumber = originTelecomNumber.getString("areaCode") + originTelecomNumber.getString("contactNumber"); fromPhoneNumber = StringUtil.removeNonNumeric(fromPhoneNumber); UtilXml.addChildElementValue(rootElement, "FromPhone", fromPhoneNumber, requestDocument); // Destination Info UtilXml.addChildElementValue(rootElement, "ToName", destinationAddress.getString("attnName"), requestDocument); UtilXml.addChildElementValue(rootElement, "ToFirm", destinationAddress.getString("toName"), requestDocument); UtilXml.addChildElementValue(rootElement, "ToAddress1", destinationAddress.getString("address1"), requestDocument); UtilXml.addChildElementValue(rootElement, "ToAddress2", destinationAddress.getString("address2"), requestDocument); UtilXml.addChildElementValue(rootElement, "ToCity", destinationAddress.getString("city"), requestDocument); UtilXml.addChildElementValue(rootElement, "ToProvince", destinationProvince.getString("geoName"), requestDocument); // TODO: Test these country names, I think we're going to need to maintain a list of USPS names UtilXml.addChildElementValue(rootElement, "ToCountry", destinationCountry.getString("geoName"), requestDocument); UtilXml.addChildElementValue(rootElement, "ToPostalCode", destinationAddress.getString("postalCode"), requestDocument); // TODO: Figure out how to answer this question accurately UtilXml.addChildElementValue(rootElement, "ToPOBoxFlag", "N", requestDocument); String toPhoneNumber = destinationTelecomNumber.getString("countryCode") + destinationTelecomNumber.getString("areaCode") + destinationTelecomNumber.getString("contactNumber"); UtilXml.addChildElementValue(rootElement, "ToPhone", toPhoneNumber, requestDocument); UtilXml.addChildElementValue(rootElement, "NonDeliveryOption", "RETURN", requestDocument); for (GenericValue shipmentPackageRouteSeg : shipmentPackageRouteSegs) { Document packageDocument = (Document) requestDocument.cloneNode(true); // This is our reference and can be whatever we want. For lack of a better alternative we'll use shipmentId:shipmentPackageSeqId:shipmentRouteSegmentId String fromCustomsReference = shipmentRouteSegment.getString("shipmentId") + ":" + shipmentRouteSegment.getString("shipmentRouteSegmentId"); fromCustomsReference = StringUtils.join(UtilMisc.toList(shipmentRouteSegment.get("shipmentId"), shipmentPackageRouteSeg.get("shipmentPackageSeqId"), shipmentRouteSegment.get("shipmentRouteSegementId")), ':'); UtilXml.addChildElementValue(rootElement, "FromCustomsReference", fromCustomsReference, packageDocument); // Determine the container type for this package String container = "VARIABLE"; String packageTypeCode = null; GenericValue shipmentPackage = null; List<GenericValue> shipmentPackageContents = null; try { shipmentPackage = shipmentPackageRouteSeg.getRelatedOne("ShipmentPackage", false); shipmentPackageContents = shipmentPackage.getRelated("ShipmentPackageContent", null, null, false); GenericValue shipmentBoxType = shipmentPackage.getRelatedOne("ShipmentBoxType", false); if (shipmentBoxType != null) { GenericValue carrierShipmentBoxType = EntityUtil.getFirst(shipmentBoxType .getRelated("CarrierShipmentBoxType", UtilMisc.toMap("partyId", "USPS"), null, false)); if (carrierShipmentBoxType != null) { packageTypeCode = carrierShipmentBoxType.getString("packageTypeCode"); // Supported type codes List<String> supportedPackageTypeCodes = UtilMisc.toList("LGFLATRATEBOX", "SMFLATRATEBOX", "FLATRATEBOX", "MDFLATRATEBOX", "FLATRATEENV"); if (supportedPackageTypeCodes.contains(packageTypeCode)) { container = packageTypeCode; } } } } catch (GenericEntityException e) { Debug.logError(e, module); } UtilXml.addChildElementValue(rootElement, "Container", container, packageDocument); // According to the docs sending an empty postage tag will cause the postage to be calculated UtilXml.addChildElementValue(rootElement, "Postage", "", packageDocument); BigDecimal packageWeight = shipmentPackage.getBigDecimal("weight"); String weightUomId = shipmentPackage.getString("weightUomId"); BigDecimal packageWeightPounds = UomWorker.convertUom(packageWeight, weightUomId, "WT_lb", dispatcher); Integer[] packagePoundsOunces = convertPoundsToPoundsOunces(packageWeightPounds); UtilXml.addChildElementValue(rootElement, "GrossPounds", packagePoundsOunces[0].toString(), packageDocument); UtilXml.addChildElementValue(rootElement, "GrossOunces", packagePoundsOunces[1].toString(), packageDocument); UtilXml.addChildElementValue(rootElement, "ContentType", "MERCHANDISE", packageDocument); UtilXml.addChildElementValue(rootElement, "Agreement", "N", packageDocument); UtilXml.addChildElementValue(rootElement, "ImageType", "PDF", packageDocument); // TODO: Try the different layouts UtilXml.addChildElementValue(rootElement, "ImageType", "ALLINONEFILE", packageDocument); UtilXml.addChildElementValue(rootElement, "CustomerRefNo", fromCustomsReference, packageDocument); // Add the shipping contents Element shippingContents = UtilXml.addChildElement(rootElement, "ShippingContents", packageDocument); for (GenericValue shipmentPackageContent : shipmentPackageContents) { Element itemDetail = UtilXml.addChildElement(shippingContents, "ItemDetail", packageDocument); GenericValue product = null; GenericValue originGeo = null; try { GenericValue shipmentItem = shipmentPackageContent.getRelatedOne("ShipmentItem", false); product = shipmentItem.getRelatedOne("Product", false); originGeo = product.getRelatedOne("OriginGeo", false); } catch (GenericEntityException e) { Debug.logInfo(e, module); } UtilXml.addChildElementValue(itemDetail, "Description", product.getString("productName"), packageDocument); UtilXml.addChildElementValue(itemDetail, "Quantity", shipmentPackageContent .getBigDecimal("quantity").setScale(0, BigDecimal.ROUND_CEILING).toPlainString(), packageDocument); String packageContentValue = ShipmentWorker.getShipmentPackageContentValue(shipmentPackageContent) .setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString(); UtilXml.addChildElementValue(itemDetail, "Value", packageContentValue, packageDocument); BigDecimal productWeight = ProductWorker.getProductWeight(product, "WT_lbs", delegator, dispatcher); Integer[] productPoundsOunces = convertPoundsToPoundsOunces(productWeight); UtilXml.addChildElementValue(itemDetail, "NetPounds", productPoundsOunces[0].toString(), packageDocument); UtilXml.addChildElementValue(itemDetail, "NetOunces", productPoundsOunces[1].toString(), packageDocument); UtilXml.addChildElementValue(itemDetail, "HSTariffNumber", "", packageDocument); UtilXml.addChildElementValue(itemDetail, "CountryOfOrigin", originGeo.getString("geoName"), packageDocument); } // Send the request Document responseDocument = null; String api = certify ? "PriorityMailIntlCertify" : "PriorityMailIntl"; try { responseDocument = sendUspsRequest(api, requestDocument, delegator, shipmentGatewayConfigId, resource, locale); } catch (UspsRequestException e) { Debug.logInfo(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsPriorityMailLabelSendingError", UtilMisc.toMap("errorString", e.getMessage()), locale)); } Element responseElement = responseDocument.getDocumentElement(); // TODO: No mention of error returns in the docs String labelImageString = UtilXml.childElementValue(responseElement, "LabelImage"); if (UtilValidate.isEmpty(labelImageString)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsPriorityMailLabelResponseIncompleteElementLabelImage", locale)); } shipmentPackageRouteSeg.setBytes("labelImage", Base64.base64Decode(labelImageString.getBytes())); String trackingCode = UtilXml.childElementValue(responseElement, "BarcodeNumber"); if (UtilValidate.isEmpty(trackingCode)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsPriorityMailLabelResponseIncompleteElementBarcodeNumber", locale)); } shipmentPackageRouteSeg.set("trackingCode", trackingCode); try { shipmentPackageRouteSeg.store(); } catch (GenericEntityException e) { Debug.logError(e, module); } } return ServiceUtil.returnSuccess(); }
From source file:org.apache.qpid.server.store.berkeleydb.HATestClusterCreator.java
/** * @param configKeySuffix "highAvailability.designatedPrimary", for example * @return "virtualhost.test.store.highAvailability.designatedPrimary", for example *//* w w w . j a v a 2 s.c o m*/ private String getConfigKey(String configKeySuffix) { final String configKey = StringUtils.substringAfter(_vhostStoreConfigKeyPrefix + configKeySuffix, "virtualhosts."); return configKey; }
From source file:org.apache.qpid.test.utils.QpidBrokerTestCase.java
/** * Set a configuration Property for this test run. * * This creates a new configuration based on the current configuration * with the specified property change.//from w w w. j a v a2 s. c o m * * Multiple calls to this method will result in multiple temporary * configuration files being created. * * @param property the configuration property to set * @param value the new value * * @throws ConfigurationException when loading the current config file */ public void setVirtualHostConfigurationProperty(String property, String value) throws ConfigurationException { // Choose which file to write the property to based on prefix. if (property.startsWith("virtualhosts")) { _testVirtualhosts.setProperty(StringUtils.substringAfter(property, "virtualhosts."), value); } else { throw new ConfigurationException("Cannot set broker configuration as property"); } }