List of usage examples for org.apache.commons.lang3 StringUtils trim
public static String trim(final String str)
Removes control characters (char <= 32) from both ends of this String, handling null by returning null .
The String is trimmed using String#trim() .
From source file:de.micromata.genome.tpsb.CommonTestBuilder.java
protected T failImpl(AssertionFailedException ex) { ex.setTestBuilder(this); StackTraceElement el = AssertUtils.getStackAbove(this.getClass()); if (el != null) { String line = StringUtils.trim(AssertUtils.getCodeLine(el)); ex.setClassName(el.getClassName()); ex.setMethodName(el.getMethodName()); ex.setLineNo(el.getLineNumber()); ex.setCodeLine(line);// ww w . ja va 2 s. co m } throw ex; }
From source file:com.intuit.karate.Script.java
private static void assign(AssignType type, String name, String exp, ScriptContext context) { name = StringUtils.trim(name); if (!isValidVariableName(name)) { throw new RuntimeException("invalid variable name: " + name); }/* w ww.ja v a 2 s .c om*/ if ("request".equals(name) || "url".equals(name)) { throw new RuntimeException( "'" + name + "' is not a variable, use the form '* " + name + " " + exp + "' instead"); } ScriptValue sv; switch (type) { case TEXT: exp = exp.replace("\n", "\\n"); if (!isQuoted(exp)) { exp = "'" + exp + "'"; } sv = evalInNashorn(exp, context); break; case YAML: DocumentContext doc = JsonUtils.fromYaml(exp); evalJsonEmbeddedExpressions(doc, context); sv = new ScriptValue(doc); break; default: // AUTO sv = eval(exp, context); } logger.trace("assigning {} = {} evaluated to {}", name, exp, sv); context.vars.put(name, sv); }
From source file:com.mgmtp.jfunk.core.scripting.ScriptContext.java
/** * Prompts for closure-line input. the input is stored in the configuration under the specified * key.//w ww. j av a 2 s . c o m * * @param configKey * the key for storing the input in the configuration * @param message * the prompt message * @return the input */ @Cmd public String prompt(final String configKey, final String message) { System.out.print(resolveProperty(message) + " "); //NOSONAR BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); try { String value = StringUtils.trim(in.readLine()); config.put(configKey, value); return value; // Stream nicht schliessen } catch (IOException ex) { throw new IllegalStateException(ex); } }
From source file:com.ottogroup.bi.asap.pipeline.MicroPipeline.java
/** * Unsubscribes the referenced subscriber from the referenced publisher * @param subscriberId//from ww w . j a v a2 s. c om * @param publisherId * @throws RequiredInputMissingException */ public void unsubscribe(final String subscriberId, final String publisherId) throws RequiredInputMissingException, UnknownComponentException { /////////////////////////////////////////////////////////////////// // validate input if (StringUtils.isBlank(subscriberId)) throw new RequiredInputMissingException("Missing required input for 'subscriberId'"); if (StringUtils.isBlank(publisherId)) throw new RequiredInputMissingException("Missing required input for 'publisherId'"); // /////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////// // String pid = StringUtils.lowerCase(StringUtils.trim(publisherId)); if (this.sourceExecutors.containsKey(pid)) { SourceExecutor publisher = this.sourceExecutors.get(pid); if (publisher == null) throw new UnknownComponentException( "Unknown component referenced by publisherId '" + publisherId + "'"); publisher.unsubscribe(subscriberId); } else if (this.operatorExecutors.containsKey(pid)) { OperatorExecutor publisher = this.operatorExecutors.get(pid); if (publisher == null) throw new UnknownComponentException( "Unknown component referenced by publisherId '" + publisherId + "'"); publisher.unsubscribe(subscriberId); } else { throw new UnknownComponentException( "Unknown component referenced by publisherId '" + publisherId + "'"); } // /////////////////////////////////////////////////////////////////// if (logger.isDebugEnabled()) logger.debug("unsubscription [subscriberId=" + subscriberId + ", publisherId=" + publisherId + "]"); }
From source file:de.micromata.genome.tpsb.CommonTestBuilder.java
protected T failImpl(Exception ex) { AssertionFailedException nex = new AssertionFailedException(ex); nex.setTestBuilder(this); StackTraceElement el = AssertUtils.getStackAbove(this.getClass()); if (el != null) { String line = StringUtils.trim(AssertUtils.getCodeLine(el)); nex.setClassName(el.getClassName()); nex.setMethodName(el.getMethodName()); nex.setLineNo(el.getLineNumber()); nex.setCodeLine(line);//w ww. j a v a 2 s . co m } throw nex; }
From source file:com.jlhood.metrics.CloudWatchReporter.java
private String appendGlobalDimensions(String metric) { if (StringUtils.isBlank(StringUtils.trim(dimensions))) { return metric; } else {/*from w w w . j av a 2 s. com*/ return metric + Constants.NAME_TOKEN_DELIMITER + dimensions; } }
From source file:com.hubrick.vertx.s3.client.S3Client.java
private PutObjectRequest mapAdaptiveUploadRequestToPutObjectRequest(Buffer buffer, AdaptiveUploadRequest autoUploadRequest) { final PutObjectRequest putObjectRequest = new PutObjectRequest(buffer); putObjectRequest.withCacheControl(autoUploadRequest.getCacheControl()); putObjectRequest.withContentDisposition(autoUploadRequest.getContentDisposition()); putObjectRequest.withContentEncoding(autoUploadRequest.getContentEncoding()); putObjectRequest.withContentMD5(autoUploadRequest.getContentMD5()); putObjectRequest.withContentType(autoUploadRequest.getContentType()); putObjectRequest.withExpires(autoUploadRequest.getExpires()); for (Map.Entry<String, String> meta : autoUploadRequest.getAmzMeta()) { putObjectRequest.withAmzMeta(meta.getKey(), StringUtils.trim(meta.getValue())); }//w w w . java2 s .c o m putObjectRequest.withAmzStorageClass(autoUploadRequest.getAmzStorageClass()); putObjectRequest.withAmzTagging(autoUploadRequest.getAmzTagging()); putObjectRequest.withAmzWebsiteRedirectLocation(autoUploadRequest.getAmzWebsiteRedirectLocation()); putObjectRequest.withAmzAcl(autoUploadRequest.getAmzAcl()); putObjectRequest.withAmzGrantRead(autoUploadRequest.getAmzGrantRead()); putObjectRequest.withAmzGrantWrite(autoUploadRequest.getAmzGrantWrite()); putObjectRequest.withAmzGrantWriteAcp(autoUploadRequest.getAmzGrantWriteAcp()); putObjectRequest.withAmzGrantRead(autoUploadRequest.getAmzGrantRead()); putObjectRequest.withAmzGrantReadAcp(autoUploadRequest.getAmzGrantReadAcp()); putObjectRequest.withAmzGrantFullControl(autoUploadRequest.getAmzGrantFullControl()); return putObjectRequest; }
From source file:gtu._work.ui.DirectoryCompareUI.java
/** * TODO//from ww w .jav a 2 s . c o m */ private void compareStart() { try { String leftStr = leftDirText.getText(); String rightStr = rightDirText.getText(); Validate.notBlank(leftStr, "??"); Validate.notBlank(rightStr, "???"); initComponents(); File leftFile = new File(StringUtils.trim(leftStr)); File rightFile = new File(StringUtils.trim(rightStr)); if (!leftFile.exists()) { leftFile = File.createTempFile("left_", ".txt"); if (leftFile.exists()) { leftFile.delete(); } FileUtils.write(leftFile, leftStr, "utf8"); } if (!rightFile.exists()) { rightFile = File.createTempFile("right_", ".txt"); if (rightFile.exists()) { rightFile.delete(); } FileUtils.write(rightFile, rightStr, "utf8"); } File mainFile = leftFile; File compareFile = rightFile; modelOrignList.clear(); compareSearch = new MainCompareSearch(mainFile, compareFile) { @Override void compareFileNotExists(FileZ mainFile, FileZ compareToFile, boolean mainFileIsLeft) { modelOrignList .add(getCreateRow(mainFile, compareToFile, mainFileIsLeft, DiffMergeStatus.NOT_EXISTS)); } @Override void sameFile(FileZ mainFile, FileZ compareToFile, boolean mainFileIsLeft) { modelOrignList.add(getCreateRow(mainFile, compareToFile, mainFileIsLeft, DiffMergeStatus.SAME)); } @Override void differentFile(FileZ mainFile, FileZ compareToFile, boolean mainFileIsLeft) { modelOrignList .add(getCreateRow(mainFile, compareToFile, mainFileIsLeft, DiffMergeStatus.DIFFERENT)); } @Override void complete() { DefaultTableModel dirCompareModel = getDefaultTableModel(); DefaultComboBoxModel extensionModel = new DefaultComboBoxModel(); Set<String> extensionSet = new TreeSet<String>(); for (Object[] rows : modelOrignList) { dirCompareModel.addRow(rows); InfoObj infoObj = (InfoObj) rows[0]; // ??? checkExtensionName(infoObj, extensionSet); } extensionModel.addElement(EXTENSION_ALL); extensionModel.addElement(EXTENSION_CUSTOM); for (String name : extensionSet) { extensionModel.addElement(name); } while (extensionNameComboBox.getModel().getSize() != extensionModel.getSize()) { extensionNameComboBox.setModel(extensionModel); System.out.println("reset extensionNameComboBox"); } while (dirCompareTable.getModel().getRowCount() != dirCompareModel.getRowCount()) { dirCompareTable.setModel(dirCompareModel); System.out.println("reset dirCompareTable"); } System.out.println( "extensionNameComboBox = " + (extensionNameComboBox.getModel() == extensionModel)); System.out.println("dirCompareTable = " + (dirCompareTable.getModel() == dirCompareModel)); System.out.println("extensionNameComboBox = " + extensionNameComboBox.getModel().getSize()); System.out.println("dirCompareTable = " + dirCompareTable.getModel().getRowCount()); setTitle(":" + mainFileCount + "/?:" + compareToFileCount + ", :" + completeTime); JCommonUtil._jOptionPane_showMessageDialog_info(// "???" + // "\n?:" + this.countSameFile + // "\n??:" + this.countDifferentFile + // "\n?:" + this.countNotExists + // "\n:" + completeTime + // "\n?merge:" + modelOrignList.size()); } }; if (leftFile.isDirectory() && rightFile.isDirectory()) { if (StringUtils.equals(FINDFUNCTION_ABS, String.valueOf(compareStyleComboBox.getSelectedItem()))) { compareSearch.executeSameDirectory(); } else if (StringUtils.equals(FINDFUNCTION_REL, String.valueOf(compareStyleComboBox.getSelectedItem()))) { List<File> mainFileList = new ArrayList<File>(); List<File> compareFileList = new ArrayList<File>(); FileUtil.searchFilefind(mainFile, ".*", mainFileList); FileUtil.searchFilefind(compareFile, ".*", compareFileList); compareSearch.executeTwoDirectoryButNotSame(mainFileList, compareFileList); } else { Validate.isTrue(false, "??!"); } } else if (leftFile.isFile() && rightFile.isFile()) { compareSearch.executeTwoFile(); } else if (leftFile.isDirectory() && rightFile.isFile()) { List<File> mainFileList = new ArrayList<File>(); List<File> compareFileList = new ArrayList<File>(); FileUtil.searchFilefind(mainFile, ".*", mainFileList); compareFileList.add(compareFile); compareSearch.executeTwoDirectoryButNotSame(mainFileList, compareFileList); compareStyleComboBox.setSelectedItem(FINDFUNCTION_REL); } else if (leftFile.isFile() && rightFile.isDirectory()) { List<File> mainFileList = new ArrayList<File>(); List<File> compareFileList = new ArrayList<File>(); mainFileList.add(mainFile); FileUtil.searchFilefind(compareFile, ".*", compareFileList); compareSearch.executeTwoDirectoryButNotSame(mainFileList, compareFileList); compareStyleComboBox.setSelectedItem(FINDFUNCTION_REL); } else { Validate.isTrue(false, "???!"); } } catch (Exception ex) { JCommonUtil.handleException(ex, false); } }
From source file:com.intuit.karate.Script.java
public static AssertionResult matchNamed(MatchType matchType, String name, String path, String expected, ScriptContext context) {/* w ww . java 2 s.co m*/ name = StringUtils.trim(name); if (isJsonPath(name) || isXmlPath(name)) { // short-cut for operating on response path = name; name = ScriptValueMap.VAR_RESPONSE; } path = StringUtils.trimToNull(path); if (path == null) { Pair<String, String> pair = parseVariableAndPath(name); name = pair.getLeft(); path = pair.getRight(); } expected = StringUtils.trim(expected); if ("header".equals(name)) { // convenience shortcut for asserting against response header return matchNamed(matchType, ScriptValueMap.VAR_RESPONSE_HEADERS, "$['" + path + "'][0]", expected, context); } else { ScriptValue actual = context.vars.get(name); switch (actual.getType()) { case STRING: case INPUT_STREAM: return matchString(matchType, actual, expected, path, context); case XML: if ("$".equals(path)) { path = "/"; // whole document, also edge case where variable name was 'response' } if (!isJsonPath(path)) { return matchXmlPath(matchType, actual, path, expected, context); } // break; // fall through to JSON. yes, dot notation can be used on XML !! default: return matchJsonPath(matchType, actual, path, expected, context); } } }
From source file:com.offbynull.portmapper.upnpigd.UpnpIgdController.java
private Map<String, String> parseResponseXml(String expectedTagName, byte[] data) { try {/*from w w w.ja v a 2 s. c om*/ MessageFactory factory = MessageFactory.newInstance(); SOAPMessage soapMessage = factory.createMessage(new MimeHeaders(), new ByteArrayInputStream(data)); if (soapMessage.getSOAPBody().hasFault()) { StringWriter writer = new StringWriter(); try { Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform(new DOMSource(soapMessage.getSOAPPart()), new StreamResult(writer)); } catch (IllegalArgumentException | TransformerException | TransformerFactoryConfigurationError e) { writer.append("Failed to dump fault: " + e); } throw new ResponseException(writer.toString()); } Iterator<SOAPBodyElement> responseBlockIt = soapMessage.getSOAPBody() .getChildElements(new QName(serviceType, expectedTagName)); if (!responseBlockIt.hasNext()) { throw new ResponseException(expectedTagName + " tag missing"); } Map<String, String> ret = new HashMap<>(); SOAPBodyElement responseNode = responseBlockIt.next(); Iterator<SOAPBodyElement> responseChildrenIt = responseNode.getChildElements(); while (responseChildrenIt.hasNext()) { SOAPBodyElement param = responseChildrenIt.next(); String name = StringUtils.trim(param.getLocalName().trim()); String value = StringUtils.trim(param.getValue().trim()); ret.put(name, value); } return ret; } catch (IllegalArgumentException | IOException | SOAPException | DOMException e) { throw new IllegalStateException(e); // should never happen } }