List of usage examples for java.lang String concat
public String concat(String str)
From source file:net.emotivecloud.scheduler.drp4one.ConfigManager.java
public static String getConfigFilePath(String configFile) { String optimisHome = optimis_Home; if (optimisHome == null) { optimis_Home = System.getenv(PROJ_HOME_ENV); optimisHome = PROJ_HOME_DEFAULT; log.warn("Please set environment variable " + PROJ_HOME_ENV + ". Using default " + PROJ_HOME_DEFAULT + "."); }//from w w w .ja v a2 s . c o m File fileObject = new File(optimisHome + configFile); if (!fileObject.exists()) { try { createDefaultConfigFile(fileObject); } catch (Exception ex) { log.error("Error reading " + optimisHome.concat(configFile) + " configuration file: " + ex.getMessage()); log.error(ex.getMessage()); } } else { System.out.println("File exists! :" + fileObject.getPath()); } return optimisHome + configFile; }
From source file:org.jasig.portlet.maps.tools.MapDataTransformer.java
/** * Update the provided MapData abbreviations, ensuring each location * has a unique and non-null ID./*from ww w. j a v a2s . co m*/ * * @param data */ protected static void setAbbreviations(MapData data) { // initialize a set for tracking in-use IDs so that we can ensure each // abbreviation is unique Set<String> usedIds = new HashSet<String>(); for (Location location : data.getLocations()) { // if the location already has an abbreviation set and it is not // a duplicate, just go ahead and use it if (StringUtils.isNotBlank(location.getAbbreviation()) && !usedIds.contains(location.getAbbreviation())) { usedIds.add(location.getAbbreviation()); } // otherwise create an automated ID for the location else { // create a default ID from the location name String defaultId = location.getName().replaceAll("[^a-zA-Z0-9]", ""); // if this ID hasn't been used yet, go ahead and use it if (!usedIds.contains(defaultId)) { location.setAbbreviation(defaultId); usedIds.add(defaultId); } // otherwise, add a progressively bigger index to the name until // we have a unique ID else { int idx = 1; String id = defaultId.concat(String.valueOf(idx)); while (usedIds.contains(id)) { idx++; id = defaultId.concat(String.valueOf(idx)); } location.setAbbreviation(id); usedIds.add(id); } } } }
From source file:org.wso2.carbon.appmanager.integration.ui.Util.HttpUtil.java
/** * convert org.apache.http.HttpResponse to org.wso2.carbon.automation.core.utils.HttpResponse * * @param res org.apache.http.HttpResponse * @return org.wso2.carbon.automation.core.utils.HttpResponse * @throws Exception/*from w w w .j a v a2 s.c o m*/ */ public static HttpResponse convertResponse(org.apache.http.HttpResponse res) throws IOException { int responseCode = res.getStatusLine().getStatusCode(); String data = ""; InputStreamReader in = null; BufferedReader br = null; try { in = new InputStreamReader((res.getEntity().getContent())); br = new BufferedReader(in); String line = ""; while ((line = br.readLine()) != null) { data = data.concat(line); } } finally { in.close(); br.close(); } HttpResponse response = new HttpResponse(data, responseCode); return response; }
From source file:Main.java
/** * <p>Left pad a String with a specified String.</p> * * <p>Pad to a size of <code>size</code>.</p> * * <pre>//from w ww . j a v a 2 s .co m * StringUtils.leftPad(null, *, *) = null * StringUtils.leftPad("", 3, "z") = "zzz" * StringUtils.leftPad("bat", 3, "yz") = "bat" * StringUtils.leftPad("bat", 5, "yz") = "yzbat" * StringUtils.leftPad("bat", 8, "yz") = "yzyzybat" * StringUtils.leftPad("bat", 1, "yz") = "bat" * StringUtils.leftPad("bat", -1, "yz") = "bat" * StringUtils.leftPad("bat", 5, null) = " bat" * StringUtils.leftPad("bat", 5, "") = " bat" * </pre> * * @param str the String to pad out, may be null * @param size the size to pad to * @param padStr the String to pad with, null or empty treated as single space * @return left padded String or original String if no padding is necessary, * <code>null</code> if null String input */ public static String leftPad(String str, int size, String padStr) { if (str == null) { return null; } if (isEmpty(padStr)) { padStr = " "; } int padLen = padStr.length(); int strLen = str.length(); int pads = size - strLen; if (pads <= 0) { return str; // returns original String when possible } if (padLen == 1 && pads <= PAD_LIMIT) { return leftPad(str, size, padStr.charAt(0)); } if (pads == padLen) { return padStr.concat(str); } else if (pads < padLen) { return padStr.substring(0, pads).concat(str); } else { char[] padding = new char[pads]; char[] padChars = padStr.toCharArray(); for (int i = 0; i < pads; i++) { padding[i] = padChars[i % padLen]; } return new String(padding).concat(str); } }
From source file:Main.java
/** * <p>Right pad a String with a specified String.</p> * * <p>The String is padded to the size of <code>size</code>.</p> * * <pre>//from ww w .ja v a2 s .c o m * StringUtils.rightPad(null, *, *) = null * StringUtils.rightPad("", 3, "z") = "zzz" * StringUtils.rightPad("bat", 3, "yz") = "bat" * StringUtils.rightPad("bat", 5, "yz") = "batyz" * StringUtils.rightPad("bat", 8, "yz") = "batyzyzy" * StringUtils.rightPad("bat", 1, "yz") = "bat" * StringUtils.rightPad("bat", -1, "yz") = "bat" * StringUtils.rightPad("bat", 5, null) = "bat " * StringUtils.rightPad("bat", 5, "") = "bat " * </pre> * * @param str the String to pad out, may be null * @param size the size to pad to * @param padStr the String to pad with, null or empty treated as single space * @return right padded String or original String if no padding is necessary, * <code>null</code> if null String input */ public static String rightPad(String str, int size, String padStr) { if (str == null) { return null; } if (isEmpty(padStr)) { padStr = " "; } int padLen = padStr.length(); int strLen = str.length(); int pads = size - strLen; if (pads <= 0) { return str; // returns original String when possible } if (padLen == 1 && pads <= PAD_LIMIT) { return rightPad(str, size, padStr.charAt(0)); } if (pads == padLen) { return str.concat(padStr); } else if (pads < padLen) { return str.concat(padStr.substring(0, pads)); } else { char[] padding = new char[pads]; char[] padChars = padStr.toCharArray(); for (int i = 0; i < pads; i++) { padding[i] = padChars[i % padLen]; } return str.concat(new String(padding)); } }
From source file:MailHandlerDemo.java
/** * Used debug problems with the logging.properties. The system property * java.security.debug=access,stack can be used to trace access to the * LogManager reset./*from w w w. j av a2 s. c o m*/ * * @param prefix a string to prefix the output. * @param err any PrintStream or null for System.out. */ @SuppressWarnings("UseOfSystemOutOrSystemErr") private static void checkConfig(String prefix, PrintStream err) { if (prefix == null || prefix.trim().length() == 0) { prefix = "DEBUG"; } if (err == null) { err = System.out; } try { err.println(prefix + ": java.version=" + System.getProperty("java.version")); err.println(prefix + ": LOGGER=" + LOGGER.getLevel()); err.println(prefix + ": JVM id " + ManagementFactory.getRuntimeMXBean().getName()); err.println(prefix + ": java.security.debug=" + System.getProperty("java.security.debug")); SecurityManager sm = System.getSecurityManager(); if (sm != null) { err.println(prefix + ": SecurityManager.class=" + sm.getClass().getName()); err.println(prefix + ": SecurityManager classLoader=" + toString(sm.getClass().getClassLoader())); err.println(prefix + ": SecurityManager.toString=" + sm); } else { err.println(prefix + ": SecurityManager.class=null"); err.println(prefix + ": SecurityManager.toString=null"); err.println(prefix + ": SecurityManager classLoader=null"); } String policy = System.getProperty("java.security.policy"); if (policy != null) { File f = new File(policy); err.println(prefix + ": AbsolutePath=" + f.getAbsolutePath()); err.println(prefix + ": CanonicalPath=" + f.getCanonicalPath()); err.println(prefix + ": length=" + f.length()); err.println(prefix + ": canRead=" + f.canRead()); err.println(prefix + ": lastModified=" + new java.util.Date(f.lastModified())); } LogManager manager = LogManager.getLogManager(); String key = "java.util.logging.config.file"; String cfg = System.getProperty(key); if (cfg != null) { err.println(prefix + ": " + cfg); File f = new File(cfg); err.println(prefix + ": AbsolutePath=" + f.getAbsolutePath()); err.println(prefix + ": CanonicalPath=" + f.getCanonicalPath()); err.println(prefix + ": length=" + f.length()); err.println(prefix + ": canRead=" + f.canRead()); err.println(prefix + ": lastModified=" + new java.util.Date(f.lastModified())); } else { err.println(prefix + ": " + key + " is not set as a system property."); } err.println(prefix + ": LogManager.class=" + manager.getClass().getName()); err.println(prefix + ": LogManager classLoader=" + toString(manager.getClass().getClassLoader())); err.println(prefix + ": LogManager.toString=" + manager); err.println(prefix + ": MailHandler classLoader=" + toString(MailHandler.class.getClassLoader())); err.println( prefix + ": Context ClassLoader=" + toString(Thread.currentThread().getContextClassLoader())); err.println(prefix + ": Session ClassLoader=" + toString(Session.class.getClassLoader())); err.println(prefix + ": DataHandler ClassLoader=" + toString(DataHandler.class.getClassLoader())); final String p = MailHandler.class.getName(); key = p.concat(".mail.to"); String to = manager.getProperty(key); err.println(prefix + ": TO=" + to); if (to != null) { err.println(prefix + ": TO=" + Arrays.toString(InternetAddress.parse(to, true))); } key = p.concat(".mail.from"); String from = manager.getProperty(key); if (from == null || from.length() == 0) { Session session = Session.getInstance(new Properties()); InternetAddress local = InternetAddress.getLocalAddress(session); err.println(prefix + ": FROM=" + local); } else { err.println(prefix + ": FROM=" + Arrays.asList(InternetAddress.parse(from, false))); err.println(prefix + ": FROM=" + Arrays.asList(InternetAddress.parse(from, true))); } synchronized (manager) { final Enumeration<String> e = manager.getLoggerNames(); while (e.hasMoreElements()) { final Logger l = manager.getLogger(e.nextElement()); if (l != null) { final Handler[] handlers = l.getHandlers(); if (handlers.length > 0) { err.println(prefix + ": " + l.getClass().getName() + ", " + l.getName()); for (Handler h : handlers) { err.println(prefix + ":\t" + toString(prefix, err, h)); } } } } } } catch (Throwable error) { err.print(prefix + ": "); error.printStackTrace(err); } err.flush(); }
From source file:at.gv.egovernment.moa.id.auth.parser.StartAuthentificationParameterParser.java
public static void parse(AuthenticationSession moasession, String target, String oaURL, String bkuURL, String templateURL, String useMandate, String ccc, String module, String action, HttpServletRequest req) throws WrongParametersException, MOAIDException { String targetFriendlyName = null; // String sso = req.getParameter(PARAM_SSO); // escape parameter strings target = StringEscapeUtils.escapeHtml(target); //oaURL = StringEscapeUtils.escapeHtml(oaURL); bkuURL = StringEscapeUtils.escapeHtml(bkuURL); templateURL = StringEscapeUtils.escapeHtml(templateURL); useMandate = StringEscapeUtils.escapeHtml(useMandate); ccc = StringEscapeUtils.escapeHtml(ccc); // sso = StringEscapeUtils.escapeHtml(sso); // check parameter //pvp2.x can use general identifier (equals oaURL in SAML1) // if (!ParamValidatorUtils.isValidOA(oaURL)) // throw new WrongParametersException("StartAuthentication", PARAM_OA, "auth.12"); if (!ParamValidatorUtils.isValidUseMandate(useMandate)) throw new WrongParametersException("StartAuthentication", PARAM_USEMANDATE, "auth.12"); if (!ParamValidatorUtils.isValidCCC(ccc)) throw new WrongParametersException("StartAuthentication", PARAM_CCC, "auth.12"); // if (!ParamValidatorUtils.isValidUseMandate(sso)) // throw new WrongParametersException("StartAuthentication", PARAM_SSO, "auth.12"); //check UseMandate flag String useMandateString = null; boolean useMandateBoolean = false; if ((useMandate != null) && (useMandate.compareTo("") != 0)) { useMandateString = useMandate;//www .jav a 2 s . c o m } else { useMandateString = "false"; } if (useMandateString.compareToIgnoreCase("true") == 0) useMandateBoolean = true; else useMandateBoolean = false; moasession.setUseMandate(useMandateString); //load OnlineApplication configuration OAAuthParameter oaParam; if (moasession.getPublicOAURLPrefix() != null) { Logger.debug("Loading OA parameters for PublicURLPrefix: " + moasession.getPublicOAURLPrefix()); oaParam = AuthConfigurationProvider.getInstance() .getOnlineApplicationParameter(moasession.getPublicOAURLPrefix()); if (oaParam == null) throw new AuthenticationException("auth.00", new Object[] { moasession.getPublicOAURLPrefix() }); } else { oaParam = AuthConfigurationProvider.getInstance().getOnlineApplicationParameter(oaURL); if (oaParam == null) throw new AuthenticationException("auth.00", new Object[] { oaURL }); // get target and target friendly name from config String targetConfig = oaParam.getTarget(); String targetFriendlyNameConfig = oaParam.getTargetFriendlyName(); if (StringUtils.isEmpty(targetConfig) || (module.equals(SAML1Protocol.PATH) && !StringUtils.isEmpty(target))) { //INFO: ONLY SAML1 legacy mode // if SAML1 is used and target attribute is given in request // use requested target // check target parameter if (!ParamValidatorUtils.isValidTarget(target)) { Logger.error("Selected target is invalid. Using target: " + target); throw new WrongParametersException("StartAuthentication", PARAM_TARGET, "auth.12"); } } else { // use target from config target = targetConfig; targetFriendlyName = targetFriendlyNameConfig; } // //check useSSO flag // String useSSOString = null; // boolean useSSOBoolean = false; // if ((sso != null) && (sso.compareTo("") != 0)) { // useSSOString = sso; // } else { // useSSOString = "false"; // } // // if (useSSOString.compareToIgnoreCase("true") == 0) // useSSOBoolean = true; // else // useSSOBoolean = false; //moasession.setSsoRequested(useSSOBoolean); moasession.setSsoRequested(true && oaParam.useSSO()); //make always SSO if OA requested it!!!! //Validate BKU URI List<String> allowedbkus = oaParam.getBKUURL(); allowedbkus.addAll(AuthConfigurationProvider.getInstance().getDefaultBKUURLs()); if (!ParamValidatorUtils.isValidBKUURI(bkuURL, allowedbkus)) throw new WrongParametersException("StartAuthentication", PARAM_BKU, "auth.12"); moasession.setBkuURL(bkuURL); if ((!oaParam.getBusinessService())) { if (isEmpty(target)) throw new WrongParametersException("StartAuthentication", PARAM_TARGET, "auth.05"); } else { if (useMandateBoolean) { Logger.error("Online-Mandate Mode for business application not supported."); throw new AuthenticationException("auth.17", null); } target = null; targetFriendlyName = null; } moasession.setPublicOAURLPrefix(oaParam.getPublicURLPrefix()); moasession.setTarget(target); moasession.setBusinessService(oaParam.getBusinessService()); //moasession.setStorkService(oaParam.getStorkService()); Logger.debug( "Business: " + moasession.getBusinessService() + " stork: " + moasession.getStorkService()); moasession.setTargetFriendlyName(targetFriendlyName); moasession.setDomainIdentifier(oaParam.getIdentityLinkDomainIdentifier()); } //check OnlineApplicationURL if (isEmpty(oaURL)) throw new WrongParametersException("StartAuthentication", PARAM_OA, "auth.05"); moasession.setOAURLRequested(oaURL); //check AuthURL String authURL = req.getScheme() + "://" + req.getServerName(); if ((req.getScheme().equalsIgnoreCase("https") && req.getServerPort() != 443) || (req.getScheme().equalsIgnoreCase("http") && req.getServerPort() != 80)) { authURL = authURL.concat(":" + req.getServerPort()); } authURL = authURL.concat(req.getContextPath() + "/"); if (!authURL.startsWith("https:")) throw new AuthenticationException("auth.07", new Object[] { authURL + "*" }); //set Auth URL from configuration moasession.setAuthURL(AuthConfigurationProvider.getInstance().getPublicURLPrefix() + "/"); //check and set SourceID if (oaParam.getSAML1Parameter() != null) { String sourceID = oaParam.getSAML1Parameter().getSourceID(); if (MiscUtil.isNotEmpty(sourceID)) moasession.setSourceID(sourceID); } if (MiscUtil.isEmpty(templateURL)) { List<TemplateType> templateURLList = oaParam.getTemplateURL(); List<String> defaulTemplateURLList = AuthConfigurationProvider.getInstance().getSLRequestTemplates(); if (templateURLList != null && templateURLList.size() > 0 && MiscUtil.isNotEmpty(templateURLList.get(0).getURL())) { templateURL = FileUtils.makeAbsoluteURL(oaParam.getTemplateURL().get(0).getURL(), AuthConfigurationProvider.getInstance().getRootConfigFileDir()); Logger.info("No SL-Template in request, load SL-Template from OA configuration (URL: " + templateURL + ")"); } else if ((defaulTemplateURLList.size() > 0) && MiscUtil.isNotEmpty(defaulTemplateURLList.get(0))) { templateURL = FileUtils.makeAbsoluteURL(defaulTemplateURLList.get(0), AuthConfigurationProvider.getInstance().getRootConfigFileDir()); Logger.info("No SL-Template in request, load SL-Template from general configuration (URL: " + templateURL + ")"); } else { Logger.error("NO SL-Tempalte found in OA config"); throw new WrongParametersException("StartAuthentication", PARAM_TEMPLATE, "auth.12"); } } if (!ParamValidatorUtils.isValidTemplate(req, templateURL, oaParam.getTemplateURL())) throw new WrongParametersException("StartAuthentication", PARAM_TEMPLATE, "auth.12"); moasession.setTemplateURL(templateURL); moasession.setCcc(ccc); }
From source file:com.khepry.utilities.GenericUtilities.java
public static void displayLogFile(String logFilePath, long logSleepMillis, String xsltFilePath, String xsldFilePath) {/*from www .j a v a2 s .co m*/ Logger.getLogger("").getHandlers()[0].close(); // only display the log file // if the logSleepMillis property // is greater than zero milliseconds if (logSleepMillis > 0) { try { Thread.sleep(logSleepMillis); File logFile = new File(logFilePath); File xsltFile = new File(xsltFilePath); File xsldFile = new File(xsldFilePath); File tmpFile = File.createTempFile("tmpLogFile", ".xhtml", logFile.getParentFile()); if (logFile.exists()) { if (xsltFile.exists() && xsldFile.exists()) { String xslFilePath; String xslFileName; String dtdFilePath; String dtdFileName; try { xslFileName = new File(logFilePath).getName().replace(".xhtml", ".xsl"); xslFilePath = logFile.getParentFile().toString().concat("/").concat(xslFileName); FileUtils.copyFile(new File(xsltFilePath), new File(xslFilePath)); dtdFileName = new File(logFilePath).getName().replace(".xhtml", ".dtd"); dtdFilePath = logFile.getParentFile().toString().concat("/").concat(dtdFileName); FileUtils.copyFile(new File(xsldFilePath), new File(dtdFilePath)); } catch (IOException ex) { String message = Level.SEVERE.toString().concat(": ").concat(ex.getLocalizedMessage()); Logger.getLogger(GenericUtilities.class.getName()).log(Level.SEVERE, message, ex); GenericUtilities.outputToSystemErr(message, logSleepMillis > 0); return; } BufferedWriter bw = Files.newBufferedWriter(Paths.get(tmpFile.getAbsolutePath()), Charset.defaultCharset(), StandardOpenOption.CREATE); List<String> logLines = Files.readAllLines(Paths.get(logFilePath), Charset.defaultCharset()); for (String line : logLines) { if (line.startsWith("<!DOCTYPE log SYSTEM \"logger.dtd\">")) { bw.write("<!DOCTYPE log SYSTEM \"" + dtdFileName + "\">\n"); bw.write("<?xml-stylesheet type=\"text/xsl\" href=\"" + xslFileName + "\"?>\n"); } else { bw.write(line.concat("\n")); } } bw.write("</log>\n"); bw.close(); } // the following statement is commented out because it's not quite ready for prime-time yet // Files.write(Paths.get(logFilePath), transformLogViaXSLT(logFilePath, xsltFilePath).getBytes(), StandardOpenOption.CREATE); Desktop.getDesktop().open(tmpFile); } else { Logger.getLogger(GenericUtilities.class.getName()).log(Level.SEVERE, logFilePath, new FileNotFoundException()); } } catch (InterruptedException | IOException ex) { Logger.getLogger(GenericUtilities.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.sds.acube.ndisc.mts.xserver.util.XNDiscUtils.java
/** * ? ? ?/* w w w.j a v a 2 s . co m*/ * * @param nFile * NFile * @return ? */ public static String getTmpPath(NFile nFile) { RandomGUID guid = null; String strFileName = null; try { guid = new RandomGUID(); if (null == nFile.getName() || 0 == nFile.getName().length()) { strFileName = guid.toString(); } else { strFileName = guid.toString().concat(".").concat(getFileExt(nFile.getName())); } String tmp_dir = XNDiscConfig.getString(XNDiscConfig.TEMP_DIR); if (tmp_dir.indexOf("/") >= 0) { strFileName = tmp_dir.concat("/").concat(strFileName); } else { strFileName = tmp_dir.concat(File.separator).concat(strFileName); } } catch (Exception e) { strFileName = null; } return strFileName; }
From source file:com.eurotong.orderhelperandroid.Common.java
public static String GetDeviceUniqueID_Based_On_MAC_But_Since_Android_6_ALWAYS_RETURN_SAME_MAC() { String mac = GetWifiMacAddress(); long id = -1; long idMod = 0; String idString = "UNKNOWN"; if (!mac.equals("UNKNOWN")) { id = ConvertMacToLong(mac);//from w ww . j a v a 2s .c o m idString = Long.toString(id); idString = idString.concat("0000000000").substring(0, 10); id = Long.parseLong(idString); idMod = id % Define.MOD; String idModString = Long.toString(idMod); idModString = "00".concat(idModString); idModString = idModString.substring(idModString.length() - 2, idModString.length()); idString = Long.toString(id) + idModString; //id=id / 10000; } return idString; }