List of usage examples for java.lang String concat
public String concat(String str)
From source file:com.github.cereda.arara.langchecker.LanguageUtils.java
/** * Prints the report for every language report. * @param languages The list of language reports. *//*from w w w . j a v a2 s . com*/ public static void printReport(List<LanguageReport> languages) { // print header System.out.println(StringUtils.center(" Language coverage report ", 60, "-").concat("\n")); // let's sort our list of reports according to // each language coverage Collections.sort(languages, new Comparator<LanguageReport>() { @Override public int compare(LanguageReport t1, LanguageReport t2) { // get values of each language float a1 = t1.getCoverage(); float a2 = t2.getCoverage(); // they are equal, do nothing if (a1 == a2) { return 0; } else { // we want to sort in reverse order, // so return a negative value here if (a1 > a2) { return -1; } else { // return a positive value, since // the first statement was false return 1; } } } }); // list of languages to be fixed List<LanguageReport> fix = new ArrayList<>(); // for each report, print // the corresponding entry for (LanguageReport language : languages) { // if there are problematic lines, // add the current language report if (!language.getLines().isEmpty()) { fix.add(language); } // build the beginning of the line String line = String.format("- %s ", language.getReference().getName()); // build the coverage information String coverage = String.format(" %2.2f%%", language.getCoverage()); // generate the line by concatenating // the beginning and coverage line = line.concat(StringUtils.repeat(".", 60 - line.length() - coverage.length())).concat(coverage); // print the line System.out.println(line); } // we have some fixes to do if (!fix.isEmpty()) { // print header System.out.println(); System.out.println(StringUtils.center(" Lines to fix ", 60, "-").concat("\n")); // print legend for a simple message System.out.println(StringUtils.center("S: Simple message, single quotes should not be doubled", 60)); // print legend for a parametrized System.out.println( StringUtils.center("P: Parametrized message, single quotes must be doubled", 60).concat("\n")); // print a line separator System.out.println(StringUtils.repeat("-", 60)); // print each language and its // corresponding lines for (LanguageReport report : fix) { // build the beginning of the line String line = String.format("- %s ", report.getReference().getName()); // build the first batch String batch = pump(report.getLines(), 2); // generate the line by concatenating // the beginning and batch line = line.concat(StringUtils.repeat(" ", 60 - line.length() - batch.length())).concat(batch); // print the line System.out.println(line); // get the next batch, if any batch = pump(report.getLines(), 2); // repeat while there // are other batches while (!batch.isEmpty()) { // print current line System.out.println(StringUtils.leftPad(batch, 60)); // get the next batch and let // the condition handle it batch = pump(report.getLines(), 2); } // print a line separator System.out.println(StringUtils.repeat("-", 60)); } } }
From source file:com.intuit.tank.harness.functions.StringFunctions.java
/** * Generates a string that is a concatenation of the strings, 0-n, passed in. Evaluates strings for variables and * will concat the variable value, not name, to string. * /* ww w .j a v a 2 s .c om*/ * @param values * List of Strings to concat starting at index 3 in array * @return Concatenation of strings */ static private String concat(String[] values, Variables variables) { String generatedStr = ""; for (int str = 3; str < values.length; str++) { String strToAdd = values[str]; if (strToAdd != null) { // check if string is variable if (ValidationUtil.isVariable(strToAdd)) { strToAdd = variables.getVariable(strToAdd); } generatedStr = generatedStr.concat(strToAdd); } } return generatedStr; }
From source file:utils.APIExporter.java
/** *write API documents in to the zip file * @param uuid APIId//from w w w . j av a 2 s . c o m * @param documentaionSummary resultant string from the getAPIDocuments *@param accessToken token with scope apim:api_view */ private static void exportAPIDocumentation(String uuid, String documentaionSummary, String accessToken, String archivePath) { System.out.println(" access token " + accessToken); OutputStream outputStream = null; ApiImportExportConfiguration config = ApiImportExportConfiguration.getInstance(); //create directory to hold API documents String documentFolderPath = archivePath.concat(File.separator + "docs"); ImportExportUtils.createDirectory(documentFolderPath); try { //writing API documents to the zip folder Object json = mapper.readValue(documentaionSummary, Object.class); String formattedJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json); writeFile(documentFolderPath + File.separator + "docs.json", formattedJson); //convert documentation summary to json object JSONObject jsonObj = (JSONObject) parser.parse(documentaionSummary); if (jsonObj.containsKey("list")) { org.json.simple.JSONArray arr = (org.json.simple.JSONArray) jsonObj .get(ImportExportConstants.DOC_LIST); // traverse through each document for (Object anArr : arr) { JSONObject document = (JSONObject) anArr; //getting document source type (inline/url/file) String sourceType = (String) document.get(ImportExportConstants.SOURCE_TYPE); if (ImportExportConstants.FILE_DOC_TYPE.equalsIgnoreCase(sourceType) || ImportExportConstants.INLINE_DOC_TYPE.equalsIgnoreCase(sourceType)) { //getting documentId String documentId = (String) document.get(ImportExportConstants.DOC_ID); //REST API call to get document contents String url = config.getPublisherUrl() + "apis/" + uuid + "/documents/" + documentId + "/content"; CloseableHttpClient client = HttpClientGenerator .getHttpClient(config.getCheckSSLCertificate()); HttpGet request = new HttpGet(url); request.setHeader(HttpHeaders.AUTHORIZATION, ImportExportConstants.CONSUMER_KEY_SEGMENT + " " + accessToken); HttpResponse response = client.execute(request); HttpEntity entity = response.getEntity(); if (ImportExportConstants.FILE_DOC_TYPE.equalsIgnoreCase(sourceType)) { //creating directory to hold FILE type content String filetypeFolderPath = documentFolderPath .concat(File.separator + ImportExportConstants.FILE_DOCUMENT_DIRECTORY); ImportExportUtils.createDirectory(filetypeFolderPath); //writing file type content in to the zip folder String localFilePath = filetypeFolderPath + File.separator + document.get(ImportExportConstants.DOC_NAME); try { outputStream = new FileOutputStream(localFilePath); entity.writeTo(outputStream); } finally { try { assert outputStream != null; outputStream.close(); } catch (IOException e) { log.warn("Error occurred while closing the streams"); } } } else { //create directory to hold inline contents String inlineFolderPath = documentFolderPath .concat(File.separator + ImportExportConstants.INLINE_DOCUMENT_DIRECTORY); ImportExportUtils.createDirectory(inlineFolderPath); //writing inline content in to the zip folder InputStream inlineStream = null; try { String localFilePath = inlineFolderPath + File.separator + document.get(ImportExportConstants.DOC_NAME); outputStream = new FileOutputStream(localFilePath); entity.writeTo(outputStream); } finally { try { if (inlineStream != null) { inlineStream.close(); } if (outputStream != null) { outputStream.close(); } } catch (IOException e) { log.warn("Error occure while closing the streams"); } } } } } } } catch (ParseException e) { log.error("Error occurred while getting API documents"); } catch (IOException e) { log.error("Error occured while writing getting API documents"); } }
From source file:com.liferay.cucumber.util.StringUtil.java
public static boolean contains(String s, String text, String delimiter) { if ((s == null) || (text == null) || (delimiter == null)) { return false; }/*from w w w.j a va 2s.c om*/ if (!s.endsWith(delimiter)) { s = s.concat(delimiter); } String dtd = delimiter.concat(text).concat(delimiter); int pos = s.indexOf(dtd); if (pos == -1) { String td = text.concat(delimiter); if (s.startsWith(td)) { return true; } return false; } return true; }
From source file:com.mg.framework.utils.StringUtils.java
/** * ? ? ? ? /*from w w w . j a va 2s. c om*/ * * @param string ?? ? * @param length ? * @param padChar ? ? ? * @param cut ??? ? ? ? <code>length</code>, ? * <code>true</code> ? , ? * ? * @return ?? ? */ public static String padRight(String string, int length, char padChar, boolean cut) { if (string == null) return null; if (string.length() > length) return cut ? string.substring(0, length) : string; else { char[] chars = new char[length - string.length()]; Arrays.fill(chars, padChar); return string.concat(new String(chars)); } }
From source file:com.microfocus.application.automation.tools.srf.run.RunFromSrfBuilder.java
public static JSONObject getSrfConnectionData(AbstractBuild<?, ?> build, PrintStream logger) { try {/*from ww w . j a v a 2 s. c om*/ CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); // Create all-trusting host name verifier HostnameVerifier allHostsValid = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); String path = build.getProject().getParent().getRootDir().toString(); path = path.concat( "/com.microfocus.application.automation.tools.srf.settings.SrfServerSettingsBuilder.xml"); File file = new File(path); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(file); // This also shows how you can consult the global configuration of the builder JSONObject connectionData = new JSONObject(); String credentialsId = document.getElementsByTagName("credentialsId").item(0).getTextContent(); UsernamePasswordCredentials credentials = CredentialsProvider.findCredentialById(credentialsId, StandardUsernamePasswordCredentials.class, build, URIRequirementBuilder.create().build()); String app = credentials.getUsername(); String tenant = app.substring(1, app.indexOf('_')); String secret = credentials.getPassword().getPlainText(); String server = document.getElementsByTagName("srfServerName").item(0).getTextContent(); // Normalize SRF server URL string if needed if (server.substring(server.length() - 1).equals("/")) { server = server.substring(0, server.length() - 1); } boolean https = true; if (!server.startsWith("https://")) { if (!server.startsWith("http://")) { String tmp = server; server = "https://"; server = server.concat(tmp); } else https = false; } URL urlTmp = new URL(server); if (urlTmp.getPort() == -1) { if (https) server = server.concat(":443"); else server = server.concat(":80"); } String srfProxy = ""; String srfTunnel = ""; try { srfProxy = document.getElementsByTagName("srfProxyName").item(0) != null ? document.getElementsByTagName("srfProxyName").item(0).getTextContent().trim() : null; srfTunnel = document.getElementsByTagName("srfTunnelPath").item(0) != null ? document.getElementsByTagName("srfTunnelPath").item(0).getTextContent() : null; } catch (Exception e) { throw e; } connectionData.put("app", app); connectionData.put("tunnel", srfTunnel); connectionData.put("secret", secret); connectionData.put("server", server); connectionData.put("https", (https) ? "True" : "False"); connectionData.put("proxy", srfProxy); connectionData.put("tenant", tenant); return connectionData; } catch (ParserConfigurationException e) { logger.print(e.getMessage()); logger.print("\n\r"); } catch (SAXException | IOException e) { logger.print(e.getMessage()); } return null; }
From source file:com.eucalyptus.ws.util.HmacUtils.java
public static String makeSubjectString(final Map<String, String> parameters) { String paramString = ""; Set<String> sortedKeys = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); sortedKeys.addAll(parameters.keySet()); for (String key : sortedKeys) paramString = paramString.concat(key).concat(parameters.get(key).replaceAll("\\+", " ")); try {//from w ww . jav a2s . co m return new String(URLCodec.decodeUrl(paramString.getBytes())); } catch (DecoderException e) { return paramString; } }
From source file:org.gvnix.web.report.roo.addon.addon.ReportMetadata.java
/** * Given a reportName returns the name for the controller method * "generate<reportName>". If isForm = true, it will add "Form" to the * returned method name.//from w w w .j a va2 s. com * * @param reportName * @param isForm */ public static String generateMethodName(String reportName, boolean isForm) { String methodName = "generate" + StringUtils.capitalize(reportName); if (isForm) { methodName = methodName.concat("Form"); } return methodName; }
From source file:net.seleucus.wsp.crypto.FwknopSymmetricCrypto.java
public static String sign(byte[] auth_key, String message, byte hmac_type) throws NoSuchAlgorithmException, InvalidKeyException { // Check if hmac_type is valid if (hmac_type > 4 || hmac_type < 0) throw new IllegalArgumentException("Invalid digest type was specified"); // Create Mac instance Mac hmac;// w ww . j av a 2 s .co m hmac = Mac.getInstance(HMAC_ALGORITHMS[hmac_type]); // Create key SecretKeySpec hmac_key = new SecretKeySpec(auth_key, HMAC_ALGORITHMS[hmac_type]); // Init hmac object hmac.init(hmac_key); // Prepare enc_part to calculate HMAC byte[] msg_to_hmac = FWKNOP_ENCRYPTION_HEADER.concat(message).getBytes(); // Calculate HMAC and return return message.concat(Base64.encodeBase64String(hmac.doFinal(msg_to_hmac)).replace("=", "")); }
From source file:com.openAtlas.bundleInfo.maker.PackageLite.java
private static void parseComponentData(PackageLite packageLite, XmlPullParser xmlPullParser, AttributeSet attributeSet, boolean isDisable, Component mComponent) throws XmlPullParserException { String pkgName = packageLite.packageName; for (int index = 0; index < attributeSet.getAttributeCount(); index++) { if (attributeSet.getAttributeName(index).equals("name")) { String mComponentName = attributeSet.getAttributeValue(index); if (mComponentName.startsWith(".")) { mComponentName = pkgName.concat(mComponentName); }//from w w w .j av a2 s .c o m switch (mComponent) { case PROVIDER: packageLite.providers.add(mComponentName); break; case ACTIVITY: packageLite.activitys.add(mComponentName); break; case SERVISE: packageLite.services.add(mComponentName); break; case RECEIVER: packageLite.receivers.add(mComponentName); break; default: break; } if (isDisable && !(TextUtils.equals(mComponentName, XMLDISABLECOMPONENT_SSO_ALIPAY_AUTHENTICATION_SERVICE) && TextUtils.equals(mComponentName, XMLDISABLECOMPONENT_SSO_AUTHENTICATION_SERVICE))) { packageLite.disableComponents.add(mComponentName); } } } }