List of usage examples for java.lang String concat
public String concat(String str)
From source file:com.albert.util.StringUtilCommon.java
public static String maskDriverLicence(String dl) { if (isEmpty(dl) || isEmpty(dl.trim())) { return dl; } else {/* w w w . j a v a 2 s .c o m*/ String last4Digit = dl.substring(11); String mask = "***********"; String maskedDl = mask.concat(last4Digit); return maskedDl; } }
From source file:com.us.util.FileHelper.java
/** * //from w w w. j a va 2 s . com * * @param packName ?? * @param fileName ?? * @return */ public static InputStream getFileInPackage(String packName, String fileName) { try { String packdir = packName.replace('.', '/'); Enumeration<URL> dirs = Thread.currentThread().getContextClassLoader().getResources(packdir); while (dirs.hasMoreElements()) { URL url = dirs.nextElement(); if (url.getProtocol().equals("file")) { String filePath = URLDecoder.decode(url.getFile(), "UTF-8"); return new FileInputStream(filePath + "/" + fileName); } else if (url.getProtocol().equals("jar")) { return FileHelper.class.getClassLoader() .getResourceAsStream(packdir.concat("/").concat(fileName)); } } } catch (IOException e) { throw UsMsgException.newInstance(String.format(":%s.%s", packName, fileName), e); } return null; }
From source file:org.sakuli.services.receiver.gearman.model.builder.OutputBuilder.java
/** * Add to the assigned 'performanceData' a new data set in respect of the template {@link * #PERFORMANCE_DATA_TEMPLATE}./*from w ww .j a v a 2 s . co m*/ */ public static String addPerformanceDataRow(String performanceData, String name, String value, String warning, String critical) { performanceData = (performanceData == null) ? "" : performanceData; name = (name == null) ? "" : StringUtils.replace(name.trim(), " ", "_"); value = (value == null) ? "" : value.trim(); warning = (warning == null) ? "" : warning.trim(); critical = (critical == null) ? "" : critical.trim(); //format string and remove not needed spaces at beginn and ending return performanceData.concat(" ") .concat(String.format(PERFORMANCE_DATA_TEMPLATE, name, value, warning, critical)).trim(); }
From source file:com.github.cereda.arara.langchecker.LanguageUtils.java
/** * Pumps the elements to a string representation according to the provided * number of times.//from w w w. j av a 2 s .c om * @param lines The list of pairs. * @param number The number of times for elements to be pumped. * @return A string representation. */ private static String pump(List<Pair<Integer, Character>> lines, int number) { // local counter, acting as a // safe check for elements int i = 0; // if there is nothing else to // be pumped, return an empty string if (lines.isEmpty()) { return ""; } // at first, the result is an // empty string String result = ""; // let's get the correct number of elements // or return the result as it is in case of // less elements than expected while ((i < number) && (!lines.isEmpty())) { // build the result, removing the first // element in the provided list result = result.concat(String.valueOf(lines.remove(0))).concat(" "); i++; } // return the trimmed element, so the trailing // space added in the previous loop is gone return result.trim(); }
From source file:co.cask.common.security.server.ExternalAuthenticationServerTestBase.java
/** * LDAP server and related handler configurations. *///from w ww.j av a 2 s . co m private static SecurityConfiguration getSecurityConfiguration(SecurityConfiguration cConf) { String configBase = Constants.AUTH_HANDLER_CONFIG_BASE; // Use random port for testing cConf.setInt(Constants.AUTH_SERVER_BIND_PORT, Networks.getRandomPort()); cConf.setInt(Constants.AuthenticationServer.SSL_PORT, Networks.getRandomPort()); cConf.set(Constants.AUTH_HANDLER_CLASS, LDAPAuthenticationHandler.class.getName()); cConf.set(Constants.LOGIN_MODULE_CLASS_NAME, LDAPLoginModule.class.getName()); cConf.set(configBase.concat("debug"), "true"); cConf.set(configBase.concat("hostname"), "localhost"); cConf.set(configBase.concat("port"), Integer.toString(ldapPort)); cConf.set(configBase.concat("userBaseDn"), "dc=example,dc=com"); cConf.set(configBase.concat("userRdnAttribute"), "cn"); cConf.set(configBase.concat("userObjectClass"), "inetorgperson"); URL keytabUrl = ExternalAuthenticationServerTestBase.class.getClassLoader().getResource("test.keytab"); Assert.assertNotNull(keytabUrl); cConf.set(Constants.CFG_CDAP_MASTER_KRB_KEYTAB_PATH, keytabUrl.getPath()); cConf.set(Constants.CFG_CDAP_MASTER_KRB_PRINCIPAL, "test_principal"); return cConf; }
From source file:com.liferay.sync.engine.util.SyncSystemTestUtil.java
public static void addUser(String name, long syncAccountId) throws Exception { Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("-organizationIds", null); parameters.put("-roleIds", null); parameters.put("-userGroupIds", null); parameters.put("autoPassword", false); parameters.put("autoScreenName", false); parameters.put("birthdayDay", 1); parameters.put("birthdayMonth", 1); parameters.put("birthdayYear", 1901); parameters.put("companyId", getCompanyId(syncAccountId)); parameters.put("emailAddress", name.concat("@liferay.com")); parameters.put("facebookId", 0); parameters.put("firstName", name); parameters.put("groupIds", getGuestGroupId(syncAccountId)); parameters.put("jobTitle", ""); parameters.put("lastName", ""); parameters.put("locale", Locale.getDefault()); parameters.put("male", true); parameters.put("middleName", ""); parameters.put("openId", ""); parameters.put("password1", "test"); parameters.put("password2", "test"); parameters.put("prefixId", 0); parameters.put("screenName", name); parameters.put("sendEmail", false); parameters.put("suffixId", 0); executePost("/user/add-user", parameters, syncAccountId); }
From source file:de.ingrid.portal.portlets.admin.AdminPortalProfilePortlet.java
/** * Copy directory to file system./*from ww w .j av a2 s.c om*/ * * @param source * @param dest * @throws IOException */ private static void copyDir(String source, String dest) throws IOException { File sourceDir = new File(source); File destDir = new File(dest); File[] sourceFiles = sourceDir.listFiles(); if (!destDir.exists()) { if (sourceDir != null) { if (sourceDir.isDirectory()) { destDir.mkdir(); } } } for (int i = 0; i < sourceFiles.length; i++) { File sourceFile = sourceFiles[i]; File destFile = new File(dest.concat("/").concat(sourceFile.getName())); if (sourceFile.isDirectory()) { copyDir(sourceFile.getAbsolutePath(), destFile.getAbsolutePath()); } else { copy(sourceFile, destFile); } } }
From source file:utils.APIExporter.java
/** * generate a archive of exporting API/*w ww .j av a 2s .co m*/ * @param apiName name of the API * @param provider provider of the API * @param version version of the API * @param accessToken valid access token */ private static void exportAPI(String destinationLocation, String apiName, String provider, String version, String accessToken) throws APIExportException { ApiImportExportConfiguration config = ApiImportExportConfiguration.getInstance(); //creating a directory to hold API details String APIFolderPath = destinationLocation.concat(File.separator + apiName + "-" + version); ImportExportUtils.createDirectory(APIFolderPath); //building the API id String apiId = provider + "-" + apiName + "-" + version; String responseString; try { //getting API meta- information CloseableHttpClient client = HttpClientGenerator.getHttpClient(config.getCheckSSLCertificate()); String metaInfoUrl = config.getPublisherUrl() + "apis/" + apiId; HttpGet request = new HttpGet(metaInfoUrl); request.setHeader(javax.ws.rs.core.HttpHeaders.AUTHORIZATION, ImportExportConstants.CONSUMER_KEY_SEGMENT + " " + accessToken); CloseableHttpResponse response = client.execute(request); if (response.getStatusLine().getStatusCode() == 404) { ////// TODO: 8/24/16 int value constant String message = "API " + apiId + "does not exist/ not found "; log.warn(message); return; } HttpEntity entity = response.getEntity(); responseString = EntityUtils.toString(entity, ImportExportConstants.CHARSET); } catch (IOException e) { String errorMsg = "Error occurred while retrieving the API meta information"; log.error(errorMsg, e); throw new APIExportException(errorMsg, e); } //creating directory to hold meta-information String metaInfoFolderPath = APIFolderPath.concat(File.separator + "meta-information"); ImportExportUtils.createDirectory(metaInfoFolderPath); //set API status and scope before exporting setJsonValues(responseString, ImportExportConstants.STATUS_CONSTANT, ImportExportConstants.CREATED); setJsonValues(responseString, ImportExportConstants.SCOPE_CONSTANT, null); try { //writing meta-information Object json = mapper.readValue(responseString, Object.class); String formattedJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(json); writeFile(metaInfoFolderPath + File.separator + "api.json", formattedJson); } catch (IOException e) { String error = "Error occurred while formatting the json string"; log.error(error, e); throw new APIExportException(error, e); } JSONObject jsonObj = null; try { jsonObj = (JSONObject) parser.parse(responseString); String swagger = (String) jsonObj.get(ImportExportConstants.SWAGGER); writeFile(metaInfoFolderPath + File.separator + "swagger.json", swagger); } catch (ParseException e) { log.error("error occurred while getting swagger definision"); } //get API uuid String uuid = null; if (jsonObj != null) { uuid = (String) jsonObj.get(ImportExportConstants.UUID); } //export api thumbnail String thumbnailUrl = null; if (jsonObj != null) { thumbnailUrl = (String) jsonObj.get(ImportExportConstants.THUMBNAIL); } if (thumbnailUrl != null) { exportAPIThumbnail(uuid, accessToken, APIFolderPath); } //export api documents String documentationSummary = getAPIDocumentation(accessToken, uuid); exportAPIDocumentation(uuid, documentationSummary, accessToken, APIFolderPath); }
From source file:co.cask.cdap.security.server.ExternalAuthenticationServerTestBase.java
/** * LDAP server and related handler configurations. *///from ww w. ja va2s. c om private static CConfiguration getConfiguration(CConfiguration cConf) { String configBase = Constants.Security.AUTH_HANDLER_CONFIG_BASE; // Use random port for testing cConf.setInt(Constants.Security.AUTH_SERVER_BIND_PORT, Networks.getRandomPort()); cConf.setInt(Constants.Security.AuthenticationServer.SSL_PORT, Networks.getRandomPort()); cConf.set(Constants.Security.AUTH_HANDLER_CLASS, LDAPAuthenticationHandler.class.getName()); cConf.set(Constants.Security.LOGIN_MODULE_CLASS_NAME, LDAPLoginModule.class.getName()); cConf.set(configBase.concat("debug"), "true"); cConf.set(configBase.concat("hostname"), "localhost"); cConf.set(configBase.concat("port"), Integer.toString(ldapPort)); cConf.set(configBase.concat("userBaseDn"), "dc=example,dc=com"); cConf.set(configBase.concat("userRdnAttribute"), "cn"); cConf.set(configBase.concat("userObjectClass"), "inetorgperson"); URL keytabUrl = ExternalAuthenticationServerTestBase.class.getClassLoader().getResource("test.keytab"); Assert.assertNotNull(keytabUrl); cConf.set(Constants.Security.CFG_CDAP_MASTER_KRB_KEYTAB_PATH, keytabUrl.getPath()); cConf.set(Constants.Security.CFG_CDAP_MASTER_KRB_PRINCIPAL, "test_principal"); return cConf; }
From source file:com.abiquo.abiserver.appslibrary.stub.AppsLibraryStubImpl.java
@Deprecated // TODO remove// w w w. j a v a 2 s . c o m private static Response response(final ClientResponse response) { String cause = new String(); try { ErrorsDto errors = response.getEntity(ErrorsDto.class); for (ErrorDto e : errors.getCollection()) { cause = cause.concat(e.getMessage()); } } catch (Exception e) { cause = response.getEntity(String.class); } return Response.status(response.getStatusCode()).entity(cause).build(); }