List of usage examples for java.lang String concat
public String concat(String str)
From source file:com.panet.imeta.core.xml.XMLHandler.java
/** * Load a file into an XML document//w w w. j av a2 s . c om * * @param inputStream * The stream to load a document from * @param systemId * Provide a base for resolving relative URIs. * @param ignoreEntities * Ignores external entities and returns an empty dummy. * @param namespaceAware * support XML namespaces. * @return the Document if all went well, null if an error occured! */ public static final Document loadXMLFile(InputStream inputStream, String systemID, boolean ignoreEntities, boolean namespaceAware) throws KettleXMLException { DocumentBuilderFactory dbf; DocumentBuilder db; Document doc; try { // Check and open XML document // dbf = DocumentBuilderFactory.newInstance(); dbf.setIgnoringComments(true); dbf.setNamespaceAware(namespaceAware); db = dbf.newDocumentBuilder(); // even dbf.setValidating(false) will the parser NOT prevent from // checking the existance of the DTD // thus we need to give the BaseURI (systemID) below to have a // chance to get it // or return empty dummy documents for all external entities // (sources) // if (ignoreEntities) { db.setEntityResolver(new DTDIgnoringEntityResolver()); } try { if (Const.isEmpty(systemID)) { // Normal parsing // doc = db.parse(inputStream); } else { // Do extra verifications // String systemIDwithEndingSlash = systemID.trim(); // make sure we have an ending slash, otherwise the last // part will be ignored // if (!systemIDwithEndingSlash.endsWith("/") && !systemIDwithEndingSlash.endsWith("\\")) { systemIDwithEndingSlash = systemIDwithEndingSlash.concat("/"); } doc = db.parse(inputStream, systemIDwithEndingSlash); } } catch (FileNotFoundException ef) { throw new KettleXMLException(ef); } finally { if (inputStream != null) inputStream.close(); } return doc; } catch (Exception e) { throw new KettleXMLException("Error reading information from input stream", e); } }
From source file:org.jasig.portlet.degreeprogress.dao.xml.HttpDegreeProgressDaoImpl.java
/** * Get a request entity prepared for basic authentication. *//*from ww w .j ava 2 s .c om*/ protected HttpEntity<?> getRequestEntity(PortletRequest request) { String username = usernameEvaluator.evaluate(request); String password = passwordEvaluator.evaluate(request); if (log.isDebugEnabled()) { boolean hasPassword = password != null; log.debug("Preparing HttpEntity for user '" + username + "' (password provided = " + hasPassword + ")"); } HttpHeaders requestHeaders = new HttpHeaders(); String authString = username.concat(":").concat(password); String encodedAuthString = new Base64().encodeToString(authString.getBytes()); requestHeaders.set("Authorization", "Basic ".concat(encodedAuthString)); HttpEntity<?> rslt = new HttpEntity<Object>(requestHeaders); return rslt; }
From source file:com.asual.summer.core.ErrorResolver.java
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) {//from www .j a va 2s. co m if (e instanceof BindException) { BindException be = (BindException) e; Map<String, Map<String, Object>> errors = new HashMap<String, Map<String, Object>>(); for (FieldError fe : (List<FieldError>) be.getFieldErrors()) { Map<String, Object> error = new HashMap<String, Object>(); Object[] args = fe.getArguments(); String key = fe.isBindingFailure() ? fe.getCodes()[2].replaceFirst("typeMismatch", "conversion") : "validation." + fe.getCodes()[2]; String message = ResourceUtils.getMessage(key, args); if (message == null) { if (!fe.isBindingFailure()) { if (key.split("\\.").length > 3) { message = ResourceUtils .getMessage(key.substring(0, key.indexOf(".", key.indexOf(".") + 1)) + key.substring(key.lastIndexOf(".")), args); } if (message == null && key.split("\\.").length > 2) { message = ResourceUtils .getMessage(key.substring(0, key.indexOf(".", key.indexOf(".") + 1)), args); } } else if (fe.isBindingFailure() && key.split("\\.").length > 2) { message = ResourceUtils.getMessage( key.substring(0, key.indexOf(".")) + key.substring(key.lastIndexOf(".")), args); } else { message = fe.getDefaultMessage(); } } error.put("message", message != null ? message : "Error (" + key + ")"); error.put("value", fe.getRejectedValue()); errors.put(fe.getField(), error); } for (ObjectError oe : (List<ObjectError>) be.getGlobalErrors()) { Map<String, Object> error = new HashMap<String, Object>(); Object[] args = oe.getArguments(); String key = "global" + (oe.getCodes() != null ? "." + oe.getCodes()[2] : ""); String message = ResourceUtils.getMessage(key, args); if (message == null) { if (key.split("\\.").length > 3) { message = ResourceUtils.getMessage(key.substring(0, key.indexOf(".", key.indexOf(".") + 1)) + key.substring(key.lastIndexOf(".")), args); } if (message == null && key.split("\\.").length > 2) { message = ResourceUtils.getMessage(key.substring(0, key.indexOf(".", key.indexOf(".") + 1)), args); } if (message == null) { message = oe.getDefaultMessage(); } } error.put("message", message != null ? message : "Error (" + key + ")"); error.put("value", oe.getObjectName()); errors.put(oe.getObjectName(), error); } String form = (String) RequestUtils.getParameter("_form"); if (form != null) { if (request.getAttribute(ERRORS) == null) { request.setAttribute(ERRORS, errors); request.setAttribute(be.getObjectName(), be.getTarget()); return new ModelAndView(new InternalResourceView( form.concat(form.contains("?") ? "&" : "?").concat("_error=true"))); } } else { List<String> pairs = new ArrayList<String>(); for (String key : errors.keySet()) { pairs.add(key + "=" + errors.get(key).get("message")); } try { response.sendError(HttpServletResponse.SC_BAD_REQUEST, StringUtils.join(pairs, ";")); } catch (IOException ioe) { logger.error(ioe.getMessage(), ioe); } } } return null; }
From source file:org.gvnix.service.roo.addon.addon.converters.JavaTypeListConverter.java
/** * Converts the input String from the shell to a Prefix to the completions. * //from www . j a va2 s .com * @param existingData String value from the command attribute. * @return {@link String} completePrefix to add for completions. */ private String convertInputIntoPrefixCompletion(String existingData) { String[] existingDataList; String completeExistingDataList = ""; existingDataList = StringUtils.split(existingData, ","); for (int i = 0; i < existingDataList.length - 1; i++) { if (completeExistingDataList.compareTo("") == 0) { completeExistingDataList = completeExistingDataList.concat(existingDataList[i]); } else { completeExistingDataList = completeExistingDataList.concat(",").concat(existingDataList[i]); } } if (existingDataList.length > 1) { completeExistingDataList = completeExistingDataList.concat(","); } return completeExistingDataList; }
From source file:org.esupportail.portlet.filemanager.services.cifs.CifsAccessImpl.java
/** * @param path//ww w. j a va2 s. com * @return */ @Override public List<JsTreeFile> getChildren(String path, SharedUserPortletParameters userParameters) { List<JsTreeFile> files = new ArrayList<JsTreeFile>(); try { String ppath = path; this.open(userParameters); if (!ppath.endsWith("/")) ppath = ppath.concat("/"); SmbFile resource = new SmbFile(this.getUri() + ppath, userAuthenticator); if (resource.canRead()) { for (SmbFile child : resource.listFiles()) { try { if (!child.isHidden() || userParameters.isShowHiddenFiles()) { files.add(resourceAsJsTreeFile(child, userParameters, false, true)); } } catch (SmbException se) { log.warn("The resource isn't accessible and so will be ignored", se); } } } else { log.warn("The resource can't be read " + resource.toString()); } return files; } catch (SmbAuthException sae) { log.error(sae.getMessage()); throw new EsupStockPermissionDeniedException(sae); } catch (SmbException se) { log.error(se.getMessage()); throw new EsupStockException(se); } catch (MalformedURLException me) { log.error(me.getMessage()); throw new EsupStockException(me); } }
From source file:fr.univrouen.poste.services.ArchiveService.java
@Transactional(readOnly = true) public void archive(String destFolder) throws IOException, SQLException { List<PosteCandidature> posteCandidatures = PosteCandidature.findAllPosteCandidatures(); File destFolderFile = new File(destFolder); if (destFolderFile.mkdir()) { Writer csvGlobalWriter = new FileWriter(destFolder.concat("/candidatures.csv")); csvService.csvWrite(csvGlobalWriter, posteCandidatures); Writer statWriter = new FileWriter(destFolder.concat("/stat.txt")); StatBean stat = statService.stats(); statWriter.write(stat.toText()); statWriter.close();/* w w w. j a v a 2s . com*/ final String[] header = new String[] { "id", "filename", "sendDate", "owner" }; final CellProcessor[] processors = getProcessors(); for (PosteCandidature posteCandidature : posteCandidatures) { String folderName = destFolder.concat("/"); String numEmploi = posteCandidature.getPoste().getNumEmploi(); numEmploi = numEmploi.replaceAll("[^a-zA-Z0-9.-]", "_"); folderName = folderName.concat(numEmploi).concat("/"); File folder = new File(folderName); folder.mkdir(); folderName = folderName.concat(posteCandidature.getRecevable() ? "Recevable" : "Non_Recevable") .concat("/"); folder = new File(folderName); folder.mkdir(); if (posteCandidature.getAuditionnable() != null) { folderName = folderName .concat(posteCandidature.getAuditionnable() ? "Auditionnable" : "Non_Auditionnable") .concat("/"); folder = new File(folderName); folder.mkdir(); } String nom = posteCandidature.getCandidat().getNom().replaceAll("[^a-zA-Z0-9.-]", "_"); String prenom = posteCandidature.getCandidat().getPrenom().replaceAll("[^a-zA-Z0-9.-]", "_"); String numCandidat = posteCandidature.getCandidat().getNumCandidat().replaceAll("[^a-zA-Z0-9.-]", "_"); folderName = folderName.concat(nom).concat("-"); folderName = folderName.concat(prenom).concat("-"); folderName = folderName.concat(numCandidat).concat("/"); folder = new File(folderName); folder.mkdir(); ICsvBeanWriter beanWriter = new CsvBeanWriter(new FileWriter(folderName.concat("metadata.csv")), CsvPreference.STANDARD_PREFERENCE); beanWriter.writeHeader(header); for (PosteCandidatureFile posteCandidatureFile : posteCandidature.getCandidatureFiles()) { String fileName = posteCandidatureFile.getId().toString().concat("-") .concat(posteCandidatureFile.getFilename()); String folderFileName = folderName.concat(fileName); File file = new File(folderFileName); file.createNewFile(); OutputStream outputStream = new FileOutputStream(file); InputStream inputStream = posteCandidatureFile.getBigFile().getBinaryFile().getBinaryStream(); IOUtils.copyLarge(inputStream, outputStream); ArchiveMetadataFileBean archiveMetadataFileBean = new ArchiveMetadataFileBean(fileName, posteCandidatureFile.getFilename(), posteCandidatureFile.getSendTime(), posteCandidature.getCandidat().getEmailAddress()); beanWriter.write(archiveMetadataFileBean, header, processors); } beanWriter.close(); if (!posteCandidature.getMemberReviewFiles().isEmpty()) { folderName = folderName.concat("Rapports_commission").concat("/"); folder = new File(folderName); folder.mkdir(); beanWriter = new CsvBeanWriter(new FileWriter(folderName.concat("metadata.csv")), CsvPreference.STANDARD_PREFERENCE); beanWriter.writeHeader(header); for (MemberReviewFile memberReviewFile : posteCandidature.getMemberReviewFiles()) { String fileName = memberReviewFile.getId().toString().concat("-") .concat(memberReviewFile.getFilename()); String folderFileName = folderName.concat(fileName); File file = new File(folderFileName); file.createNewFile(); OutputStream outputStream = new FileOutputStream(file); InputStream inputStream = memberReviewFile.getBigFile().getBinaryFile().getBinaryStream(); IOUtils.copyLarge(inputStream, outputStream); ArchiveMetadataFileBean archiveMetadataFileBean = new ArchiveMetadataFileBean(fileName, memberReviewFile.getFilename(), memberReviewFile.getSendTime(), memberReviewFile.getMember().getEmailAddress()); beanWriter.write(archiveMetadataFileBean, header, processors); } beanWriter.close(); } } } else { logger.error("Le rpertoire " + destFolder + " n'a pas pu tre cr. Vrifiez qu'il n'existe pas dj, que l'application a bien les droits de le crer, etc."); } }
From source file:arduinouno.MainWindow.java
private void dataVectorToCSVFile(File theFile, Double[][] theDataVector) { PrintWriter writer;//from w w w . j a va2s. c o m int columns = theDataVector[0].length; String header = new String(); for (int j = 0; j < columns; j++) { if (j == columns - 1) { header = header.concat("A" + j); } else { header = header.concat("A" + j + ","); } } try { writer = new PrintWriter(theFile, "UTF-8"); int i = 0; writer.println(header); while (i < theDataVector.length) { String line = new String(); for (int j = 0; j < columns; j++) { Double value = theDataVector[i][j]; if (j == columns - 1) { line = line.concat("\"" + String.format("%.2f", value) + "\""); } else { line = line.concat("\"" + String.format("%.2f", value) + "\"" + ","); } } writer.println(line); i++; } writer.close(); } catch (FileNotFoundException | UnsupportedEncodingException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:it.scoppelletti.programmerpower.web.rest.RestRouter.java
/** * Associa un URI al bean che ne implementa la corrispondente risorsa. * //w w w . jav a 2s. co m * @param uri URI. * @param beanName Nome del bean. */ private void attach(String uri, String beanName) { String ctxPath; myLogger.trace("Attach URI {} to REST resource {}.", uri, beanName); // Restlet 2.0.11: Il componente ServletAdapter funziona correttamente // se e solo se gli URI ai quali sono collegate le risorse REST // includono anche il contesto dell'applicazione Web. if (myServletCtx != null) { ctxPath = myServletCtx.getContextPath(); if (!Strings.isNullOrEmpty(ctxPath)) { uri = ctxPath.concat(uri); } } attach(uri, new SpringBeanFinder(this, myApplCtx, beanName)); }
From source file:org.jasig.portlet.newsreader.dao.HibernateNewsStore.java
public void initNews(NewsSet set, Set<String> roles) { try {/*from w ww. j a v a 2 s.c o m*/ // if the user doesn't have any roles, we don't have any // chance of getting predefined newss, so just go ahead // and return if (roles.isEmpty()) return; String query = "from PredefinedNewsDefinition def " + "left join fetch def.defaultRoles role where " + ":setId not in (select config.newsSet.id " + "from def.userConfigurations config)"; if (roles.size() > 0) query = query.concat("and role in (:roles)"); Query q = this.getSession().createQuery(query); q.setLong("setId", set.getId()); if (roles.size() > 0) q.setParameterList("roles", roles); List<PredefinedNewsDefinition> defs = q.list(); for (PredefinedNewsDefinition def : defs) { PredefinedNewsConfiguration config = new PredefinedNewsConfiguration(); config.setNewsDefinition(def); set.addNewsConfiguration(config); } } catch (HibernateException ex) { throw convertHibernateAccessException(ex); } }