List of usage examples for org.apache.commons.lang3 StringUtils substring
public static String substring(final String str, int start)
Gets a substring from the specified String avoiding exceptions.
A negative start position can be used to start n characters from the end of the String.
A null String will return null .
From source file:com.mirth.connect.plugins.datatypes.hl7v2.HL7v2ResponseValidator.java
private String getOriginalControlId(ConnectorMessage connectorMessage) throws Exception { String controlId = ""; String originalMessage = ""; if (responseValidationProperties.getOriginalMessageControlId() .equals(OriginalMessageControlId.Destination_Encoded)) { originalMessage = connectorMessage.getEncoded().getContent(); } else if (responseValidationProperties.getOriginalMessageControlId() .equals(OriginalMessageControlId.Map_Variable)) { String originalIdMapVariable = responseValidationProperties.getOriginalIdMapVariable(); if (StringUtils.isEmpty(originalIdMapVariable)) { throw new Exception("Map variable for original control Id not set."); }/*w ww . j a v a 2 s . co m*/ Object value = null; if (connectorMessage.getConnectorMap().containsKey(originalIdMapVariable)) { value = connectorMessage.getConnectorMap().get(originalIdMapVariable); } else { value = connectorMessage.getChannelMap().get(originalIdMapVariable); } if (value == null) { throw new Exception("Map variable for original control Id not set."); } controlId = value.toString(); return controlId; } if (originalMessage.startsWith("<")) { Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new InputSource(new CharArrayReader(originalMessage.toCharArray()))); controlId = XPathFactory.newInstance().newXPath().compile("//MSH.10.1/text()").evaluate(doc).trim(); } else { int index; if ((index = originalMessage.indexOf("MSH")) >= 0) { index += 4; char fieldSeparator = originalMessage.charAt(index - 1); int iteration = 2; int segmentDelimeterIndex = originalMessage.indexOf(serializationSegmentDelimiter, index); while (iteration < MESSAGE_CONTROL_ID_FIELD) { index = originalMessage.indexOf(fieldSeparator, index + 1); if ((segmentDelimeterIndex >= 0 && segmentDelimeterIndex < index) || index == -1) { return ""; } iteration++; } String tempSegment = StringUtils.substring(originalMessage, index + 1); index = StringUtils.indexOfAny(tempSegment, fieldSeparator + serializationSegmentDelimiter); if (index >= 0) { controlId = StringUtils.substring(tempSegment, 0, index); } else { controlId = StringUtils.substring(tempSegment, 0); } } } return controlId; }
From source file:com.mirth.connect.client.ui.components.MirthTree.java
/** * Construct a path for a specific node. * // w w w .j a va 2 s . c o m * @param parent * @param prefix * @param suffix * @return */ public static StringBuilder constructPath(TreeNode parent, String prefix, String suffix) { StringBuilder sb = new StringBuilder(); sb.insert(0, prefix); MirthTreeNode node = (MirthTreeNode) parent; SerializationType serializationType = node.getSerializationType(); // Get the parent if the leaf was actually passed in instead of the parent. if (node.isLeaf()) { node = (MirthTreeNode) node.getParent(); } /* * MIRTH-3196 - We now assign nodes types as we iterate from child to parent to add more * versatility to namespace drag and drop. The drag and drop can drag nodes, attribute or * namespace attributes so the user should be able to correctly do these now. If a node has * a namespace then will wildcard it. If an ancestor of the node has an implicit namespace * then we will also append a wildcard. The only exception to this is if the implicit * namespace is on the root node, we actually set this to the default namespace in * JavaScriptBuilder. */ LinkedList<PathNode> nodeQ = new LinkedList<PathNode>(); while (node != null && node.getParent() != null) { if (serializationType.equals(SerializationType.JSON) && node.isArrayElement()) { nodeQ.add(new PathNode(String.valueOf(node.getParent().getIndex(node) - 1), PathNode.NodeType.ARRAY_CHILD)); } else { PathNode.NodeType type = PathNode.NodeType.OTHER; if (serializationType.equals(SerializationType.XML)) { type = getXmlNodeType(node); } String nodeValue = node.getValue().replaceAll(" \\(.*\\)", ""); nodeQ.add(new PathNode(nodeValue, type)); if (serializationType.equals(SerializationType.XML)) { int parentIndexValue = getIndexOfNode(node); if (parentIndexValue != -1) { nodeQ.add(nodeQ.size() - 1, new PathNode(String.valueOf(parentIndexValue), PathNode.NodeType.ARRAY_CHILD)); } } } node = (MirthTreeNode) node.getParent(); } boolean foundImplicitNamespace = false; while (!nodeQ.isEmpty()) { PathNode nodeValue = nodeQ.removeLast(); //We start at the parent so if any implicit namespaces are reached then the rest of the nodes should wildcard the namespace boolean includeNamespace = false; PathNode.NodeType type = nodeValue.getType(); //We don't want to include a wildcard for attributes, ns definitions or array indices if (serializationType.equals(SerializationType.XML) && !Arrays .asList(PathNode.NodeType.XML_ATTRIBUTE, PathNode.NodeType.XMLNS_DEFINITION, PathNode.NodeType.XML_PREFIX_DEFINITION, PathNode.NodeType.ARRAY_CHILD) .contains(type)) { if (foundImplicitNamespace) { includeNamespace = true; } else if (type == PathNode.NodeType.XML_XMLNS_NODE) { foundImplicitNamespace = true; includeNamespace = true; } else if (type == PathNode.NodeType.XML_PREFIXED_NODE) { includeNamespace = true; } } if (includeNamespace) { int colonIndex = nodeValue.getValue().indexOf(':') + 1; sb.append(".*::['" + StringUtils.substring(nodeValue.getValue(), colonIndex) + "']"); } else if (serializationType.equals(SerializationType.XML) && type == PathNode.NodeType.XMLNS_DEFINITION) { sb.append(".namespace('')"); } else if (serializationType.equals(SerializationType.XML) && type == PathNode.NodeType.XML_PREFIX_DEFINITION) { sb.append(".namespace('" + StringUtils.substringAfter(nodeValue.getValue(), "@xmlns:") + "')"); } else if (type == PathNode.NodeType.XML_PREFIXED_ATTRIBUTE) { sb.append(".@*::['" + StringUtils.substringAfter(nodeValue.getValue(), ":") + "']"); } else if (type == PathNode.NodeType.ARRAY_CHILD) { sb.append("[" + nodeValue.getValue() + "]"); } else { sb.append("['" + nodeValue.getValue() + "']"); } } if (!serializationType.equals(SerializationType.JSON)) { sb.append(suffix); } return sb; }
From source file:com.sonicle.webtop.core.app.WebTopManager.java
public String internetNameToDomain(String internetName) { synchronized (lock0) { if (cacheInternetNameToDomain.size() == 1) { // If we have only one domain in cache, simply returns it... Map.Entry<String, String> entry = cacheInternetNameToDomain.entrySet().iterator().next(); return entry.getValue(); } else {//from w ww . j a v a 2s . co m for (int i = 2; i < 255; i++) { final int iOfNDot = StringUtils.lastOrdinalIndexOf(internetName, ".", i); final String key = StringUtils.substring(internetName, iOfNDot + 1); if (cacheInternetNameToDomain.containsKey(key)) { return cacheInternetNameToDomain.get(key); } } return null; } //return cacheInternetNameToDomain.get(internetName); } }
From source file:com.lzsoft.rules.core.RulesEngine.java
/** * ??ObjectList/*w w w . j a v a 2s.c om*/ * * @param conditionRuleResults * @param parameterElmt * @return * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException * @return ?Map */ private Map<String, List<Object>> groupingObjsByGroupvalue(List<Object> conditionRuleResults, ParameterElmt parameterElmt) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { String groupValue = parameterElmt.getValue(); String[] groupkeys = null; if (groupValue.startsWith("@")) { groupkeys = StringUtils.split(StringUtils.substring(groupValue, 2), ":"); } // rule-invoke Map<String, List<Object>> groupObjs = new HashMap<String, List<Object>>(); for (Object objs : conditionRuleResults) { combineObjsByGroupkey(groupkeys, groupObjs, objs, parameterElmt.getClazz()); } return groupObjs; }
From source file:fusion.FuseLinkServlet.java
private void metadataKeepConcatLeft(int idx) throws SQLException { Connection virt_conn = vSet.getConnection(); StringBuilder concat_str = new StringBuilder(); for (String s : fs.predsA) { String[] pres = StringUtils.split(s, ","); StringBuilder q = new StringBuilder(); q.append("sparql SELECT * "); String prev_s = "<" + nodeA + ">"; q.append(" WHERE {\n GRAPH <" + tGraph + "metadataA> {"); for (int i = 0; i < pres.length; i++) { q.append(prev_s + " <" + pres[i] + "> ?o" + i + " . "); prev_s = "?o" + i; }/* w w w.j av a 2s . com*/ q.append("} }"); //System.out.println(q.toString()); PreparedStatement stmt; stmt = virt_conn.prepareStatement(q.toString()); ResultSet rs = stmt.executeQuery(); while (rs.next()) { //for (int i = 0; i < pres.length; i++) { String o = rs.getString(pres.length); String simplified = StringUtils.substringAfter(pres[pres.length - 1], "#"); if (simplified.equals("")) { simplified = StringUtils.substring(pres[pres.length - 1], StringUtils.lastIndexOf(pres[pres.length - 1], "/") + 1); } //concat_str.append(simplified+":"+o+" "); concat_str.append(o + " "); //} } //System.out.println(q.toString()); } concat_str.setLength(concat_str.length() - 1); int lastIdx = StringUtils.lastIndexOf(fs.predsA.get(0), ","); String pred = fs.predsA.get(0).substring(0, lastIdx); String[] pres = StringUtils.split(pred, ","); StringBuilder q = new StringBuilder(); q.append("INSERT { GRAPH <" + tGraph + "> { "); String prev_s = "<" + nodeA + ">"; for (int i = 0; i < pres.length - 1; i++) { q.append(prev_s + " <" + pres[i] + "> ?o" + i + " . "); prev_s = "?o" + i; } q.append(prev_s + " ?o" + (pres.length - 1) + " \"" + concat_str + "\""); q.append("} } WHERE {\n GRAPH <" + tGraph + "metadataA> {"); prev_s = "<" + nodeA + ">"; for (int i = 0; i < pres.length; i++) { q.append(prev_s + " <" + pres[i] + "> ?o" + i + " . "); prev_s = "?o" + i; } q.append("} }"); //System.out.println(q.toString()); VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(q.toString(), vSet); vur.exec(); //System.out.println(concat_str); }
From source file:com.gp.cong.logisoft.lcl.report.LclAllBLPdfCreator.java
public void setLclBLPdfCreator(String documentName, LclBl lclbl, LclBooking lclBooking) throws Exception { this.printdocumentName = documentName; if (CommonFunctions.isNotNull(lclbl)) { List<LclOptions> optionsList = lclbl.getLclFileNumber().getLclOptionsList(); for (LclOptions options : optionsList) { if (!"CORRECTEDBL".equalsIgnoreCase(options.getOptionValue()) && !"ARRIVALDATE".equalsIgnoreCase(options.getOptionValue())) { if ("ALERT".equalsIgnoreCase(options.getOptionValue())) { headingAlert = options.getOptionKey(); }/*from w w w. j a va2s. c o m*/ if ("LADENSAILDATE".equalsIgnoreCase(options.getOptionValue())) { ladenSailDateOptKey = options.getOptionKey(); } if ("PROOF".equalsIgnoreCase(options.getOptionValue())) { LclAllBLPdfCreator.this.watermarkLabel = options.getOptionKey(); } if ("PRINTTERMSTYPE".equalsIgnoreCase(options.getOptionValue())) { printTermsTypeKey = options.getOptionKey(); } if ("PIER".equalsIgnoreCase(options.getOptionValue())) { printPierPol = options.getOptionKey(); } if ("HBLPOL".equalsIgnoreCase(options.getOptionValue())) { hblPolOverRideKey = options.getOptionKey(); } if ("HBLPIER".equalsIgnoreCase(options.getOptionValue())) { hblPierOverRideKey = options.getOptionKey(); } if ("DELIVERY".equalsIgnoreCase(options.getOptionValue())) { fdOverride = options.getOptionKey(); } if ("RECEIVE".equalsIgnoreCase(options.getOptionValue())) { receiveKeyValue = options.getOptionKey(); } if ("NCM".equalsIgnoreCase(options.getOptionValue())) { ncmKeyValue = options.getOptionKey(); } if ("AES".equalsIgnoreCase(options.getOptionValue())) { aesKeyValue = options.getOptionKey(); } if ("HS".equalsIgnoreCase(options.getOptionValue())) { hsKeyValue = options.getOptionKey(); } if ("MINI".equalsIgnoreCase(options.getOptionValue())) { miniKeyValue = options.getOptionKey(); } if ("IMP".equalsIgnoreCase(options.getOptionValue())) { impKeyValue = options.getOptionKey(); } if ("MET".equalsIgnoreCase(options.getOptionValue())) { metKeyValue = options.getOptionKey(); } if ("FP".equalsIgnoreCase(options.getOptionValue())) { altAgentKey = options.getOptionKey(); } if ("FPFEILD".equalsIgnoreCase(options.getOptionValue())) { altAgentValue = options.getOptionKey(); } if ("PORT".equalsIgnoreCase(options.getOptionValue())) { portKey = options.getOptionKey(); } if ("PORTFIELD".equalsIgnoreCase(options.getOptionValue())) { portKeyValue = options.getOptionKey(); } if ("PRINTHAZBEFORE".equalsIgnoreCase(options.getOptionValue())) { printHazBeforeKeyValue = options.getOptionKey(); } if ("PRINTPPDBLBOTH".equalsIgnoreCase(options.getOptionValue())) { printPpdBlBothKey = options.getOptionKey(); } if ("INSURANCE".equalsIgnoreCase(options.getOptionValue())) { printBlInsuranceKey = options.getOptionKey(); } } } engmet = new PortsDAO() .getEngmet(lclbl.getFinalDestination() != null ? lclbl.getFinalDestination().getUnLocationCode() : lclbl.getPortOfDestination().getUnLocationCode()); String printTermsValueBodyBl = null != lclbl.getTermsType1() ? lclbl.getTermsType1() : ""; if (!"".equalsIgnoreCase(printTermsValueBodyBl)) { termsType1 = "ER".equalsIgnoreCase(printTermsValueBodyBl) ? "\nExpress Release" : "OR".equalsIgnoreCase(printTermsValueBodyBl) ? "\nOriginals Required" : "ORD".equalsIgnoreCase(printTermsValueBodyBl) ? "\nOriginals Released At Destination" : "DER".equalsIgnoreCase(printTermsValueBodyBl) ? "\nDo Not Express Release" : "MBL".equalsIgnoreCase(printTermsValueBodyBl) ? "\nMEMO HOUSE BILL OF LADING" : ""; } lclBlPiecesList = lclbl.getLclFileNumber().getLclBlPieceList(); if (CommonFunctions.isNotNull(lclbl.getPortOfLoading())) { polValues = lclbl.getPortOfLoading().getUnLocationName(); } if (CommonFunctions.isNotNull(lclbl.getPortOfLoading()) && CommonFunctions.isNotNull(lclbl.getPortOfLoading().getStateId()) && CommonFunctions.isNotNull(lclbl.getPortOfLoading().getStateId().getCode())) { polValues += "," + lclbl.getPortOfLoading().getStateId().getCode(); } Integer PodId = 0; String FreightAcctNo = null; boolean freightFlag = false; if (lclBooking.getBookingType().equals("T")) { PodId = lclbl.getLclFileNumber().getLclBookingImport().getForeignPortOfDischarge().getId(); FreightAcctNo = lclbl.getLclFileNumber().getLclBookingImport().getExportAgentAcctNo() != null ? lclbl.getLclFileNumber().getLclBookingImport().getExportAgentAcctNo().getAccountno() : null; } else if (lclBooking.getAgentAcct() != null) { PodId = lclBooking.getPortOfDestination().getId(); FreightAcctNo = lclBooking.getAgentAcct().getAccountno(); } if (CommonUtils.isNotEmpty(FreightAcctNo)) { agencyInfo = new AgencyInfoDAO().getAgentPickAcctNo(PodId, FreightAcctNo); if (agencyInfo != null && CommonUtils.isNotEmpty(agencyInfo[1])) { freightFlag = true; UnLocation unLocation = new UnLocationDAO().getUnlocation( StringUtils.substring(agencyInfo[1], agencyInfo[1].length() - 6).replace(")", "")); if (unLocation != null && CommonFunctions.isNotNull(unLocation.getUnLocationName())) { podValues = unLocation.getUnLocationName(); } if (unLocation != null && CommonFunctions.isNotNull(unLocation.getCountryId()) && CommonFunctions.isNotNull(unLocation.getCountryId().getCodedesc())) { podValues += ", " + unLocation.getCountryId().getCodedesc(); } } } if (CommonFunctions.isNotNull(lclbl.getPortOfDestination()) && !freightFlag) { if (CommonFunctions.isNotNull(lclbl.getPortOfDestination().getUnLocationName())) { podValues = lclbl.getPortOfDestination().getUnLocationName(); } if (CommonFunctions.isNotNull(lclbl.getPortOfDestination().getCountryId()) && CommonFunctions.isNotNull(lclbl.getPortOfDestination().getCountryId().getCodedesc())) { podValues += ", " + lclbl.getPortOfDestination().getCountryId().getCodedesc(); } } ruleName = lclbl.getLclFileNumber().getBusinessUnit(); } boolean ipeHotCodeFlag = new LclBookingHotCodeDAO().isHotCodeValidate(lclBooking.getFileNumberId(), "IPE"); if (ipeHotCodeFlag) { Iterator bookingCommentsIterator = new GenericCodeDAO().getLclPrintComments(39, "ipeclass"); while (bookingCommentsIterator.hasNext()) { Object[] row = (Object[]) bookingCommentsIterator.next(); ipeHotCodeComments = (String) row[1]; } } }
From source file:com.feilong.core.lang.StringUtil.java
/** * [?](<code>beginIndex</code>),. * //from w w w.j a v a 2 s .c o m * <p> * <code>beginIndex</code>,??,?,? {@link #substringLast(String, int)} * </p> * * <pre class="code"> * StringUtil.substring(null, *) = null * StringUtil.substring("", *) = "" * StringUtil.substring("abc", 0) = "abc" * StringUtil.substring("abc", 2) = "c" * StringUtil.substring("abc", 4) = "" * StringUtil.substring("abc", -2) = "bc" * StringUtil.substring("abc", -4) = "abc" * StringUtil.substring("jinxin.feilong",6) =.feilong * </pre> * * @param text * the String to get the substring from, may be null * @param beginIndex * the position to start from,negative means count back from the end of the String by this many characters * @return <code>text</code> null, null<br> * An empty ("") String "".<br> * @see org.apache.commons.lang3.StringUtils#substring(String, int) * @see #substringLast(String, int) */ public static String substring(final String text, final int beginIndex) { return StringUtils.substring(text, beginIndex); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.dom.Node.java
/** * Allows the removal of event listeners on the event target. * @param type the event type to listen for (like "onclick") * @param listener the event listener// w w w .j a v a2 s .c om * @see <a href="http://msdn.microsoft.com/en-us/library/ms536411.aspx">MSDN documentation</a> */ @JsxFunction(@WebBrowser(IE)) public void detachEvent(final String type, final Function listener) { removeEventListener(StringUtils.substring(type, 2), listener, false); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.Node.java
/** * Allows the registration of event listeners on the event target. * @param type the event type to listen for (like "onclick") * @param listener the event listener//from w w w .java 2 s . c om * @return <code>true</code> if the listener has been added * @see <a href="http://msdn.microsoft.com/en-us/library/ms536343.aspx">MSDN documentation</a> * @see #addEventListener(String, Function, boolean) */ @JsxFunction(@WebBrowser(IE)) public boolean attachEvent(final String type, final Function listener) { return getEventListenersContainer().addEventListener(StringUtils.substring(type, 2), listener, false); }
From source file:com.ottogroup.bi.spqr.pipeline.MicroPipelineFactory.java
/** * Instantiates, initializes and returns the {@link DelayedResponseOperatorWaitStrategy} configured for the {@link DelayedResponseOperator} * whose {@link MicroPipelineComponentConfiguration configuration} is provided when calling this method. * @param delayedResponseOperatorCfg//from www .ja v a 2 s. co m * @return */ protected DelayedResponseOperatorWaitStrategy getResponseWaitStrategy( final MicroPipelineComponentConfiguration delayedResponseOperatorCfg) throws RequiredInputMissingException, UnknownWaitStrategyException { ///////////////////////////////////////////////////////////////////////////////////// // validate input if (delayedResponseOperatorCfg == null) throw new RequiredInputMissingException("Missing required delayed response operator configuration"); if (delayedResponseOperatorCfg.getSettings() == null) throw new RequiredInputMissingException("Missing required delayed response operator settings"); String strategyName = StringUtils.lowerCase(StringUtils.trim(delayedResponseOperatorCfg.getSettings() .getProperty(DelayedResponseOperator.CFG_WAIT_STRATEGY_NAME))); if (StringUtils.isBlank(strategyName)) throw new RequiredInputMissingException( "Missing required strategy name expected as part of operator settings ('" + DelayedResponseOperator.CFG_WAIT_STRATEGY_NAME + "')"); // ///////////////////////////////////////////////////////////////////////////////////// if (logger.isDebugEnabled()) logger.debug("Settings provided for strategy '" + strategyName + "'"); Properties strategyProperties = new Properties(); for (Enumeration<Object> keyEnumerator = delayedResponseOperatorCfg.getSettings().keys(); keyEnumerator .hasMoreElements();) { String key = (String) keyEnumerator.nextElement(); if (StringUtils.startsWith(key, DelayedResponseOperator.CFG_WAIT_STRATEGY_SETTINGS_PREFIX)) { String waitStrategyCfgKey = StringUtils.substring(key, StringUtils.lastIndexOf(key, ".") + 1); if (StringUtils.isNoneBlank(waitStrategyCfgKey)) { String waitStrategyCfgValue = delayedResponseOperatorCfg.getSettings().getProperty(key); strategyProperties.put(waitStrategyCfgKey, waitStrategyCfgValue); if (logger.isDebugEnabled()) logger.debug("\t" + waitStrategyCfgKey + ": " + waitStrategyCfgValue); } } } if (StringUtils.equalsIgnoreCase(strategyName, MessageCountResponseWaitStrategy.WAIT_STRATEGY_NAME)) { MessageCountResponseWaitStrategy strategy = new MessageCountResponseWaitStrategy(); strategy.initialize(strategyProperties); return strategy; } else if (StringUtils.equalsIgnoreCase(strategyName, TimerBasedResponseWaitStrategy.WAIT_STRATEGY_NAME)) { TimerBasedResponseWaitStrategy strategy = new TimerBasedResponseWaitStrategy(); strategy.initialize(strategyProperties); return strategy; } else if (StringUtils.equalsIgnoreCase(strategyName, OperatorTriggeredWaitStrategy.WAIT_STRATEGY_NAME)) { OperatorTriggeredWaitStrategy strategy = new OperatorTriggeredWaitStrategy(); strategy.initialize(strategyProperties); return strategy; } throw new UnknownWaitStrategyException("Unknown wait strategy '" + strategyName + "'"); }