List of usage examples for org.apache.commons.lang StringUtils substringAfterLast
public static String substringAfterLast(String str, String separator)
Gets the substring after the last occurrence of a separator.
From source file:eu.europa.esig.dss.client.http.commons.CommonsDataLoader.java
/** * This method retrieves data using LDAP protocol. * - CRL from given LDAP url, e.g. ldap://ldap.infonotary.com/dc=identity-ca,dc=infonotary,dc=com * - ex URL from AIA ldap://xadessrv.plugtests.net/CN=LevelBCAOK,OU=Plugtests_2015-2016,O=ETSI,C=FR?cACertificate;binary * * @param urlString//from w w w . j a va 2s . c o m * @return */ private byte[] ldapGet(final String urlString) { final Hashtable<String, String> env = new Hashtable<String, String>(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory"); env.put(Context.PROVIDER_URL, urlString); try { String attributeName = StringUtils.substringAfterLast(urlString, "?"); if (StringUtils.isEmpty(attributeName)) { // default was CRL attributeName = "certificateRevocationList;binary"; } final DirContext ctx = new InitialDirContext(env); final Attributes attributes = ctx.getAttributes(StringUtils.EMPTY); final Attribute attribute = attributes.get(attributeName); final byte[] ldapBytes = (byte[]) attribute.get(); if (ArrayUtils.isEmpty(ldapBytes)) { throw new DSSException("Cannot download CRL from: " + urlString); } return ldapBytes; } catch (Exception e) { LOG.warn(e.getMessage(), e); } return null; }
From source file:com.amalto.core.storage.SystemStorageWrapper.java
@Override public String getDocumentAsString(String clusterName, String uniqueID, String encoding) throws XmlServerException { if (encoding == null) { encoding = "UTF-8"; //$NON-NLS-1$ }//from ww w. j a va 2s . c o m Storage storage = getStorage(clusterName); ComplexTypeMetadata type = getType(clusterName, storage, uniqueID); if (type == null) { return null; // TODO } UserQueryBuilder qb; boolean isUserFormat = false; String documentUniqueID; if (DROPPED_ITEM_TYPE.equals(type.getName())) { // head.Product.Product.0- (but DM1.Bird.bid3) if (uniqueID.endsWith("-")) { //$NON-NLS-1$ uniqueID = uniqueID.substring(0, uniqueID.length() - 1); } // TODO Code may not correctly handle composite id (but no system objects use this) documentUniqueID = uniqueID; if (StringUtils.countMatches(uniqueID, ".") >= 3) { //$NON-NLS-1$ documentUniqueID = StringUtils.substringAfter(uniqueID, "."); //$NON-NLS-1$ } } else if (COMPLETED_ROUTING_ORDER.equals(type.getName()) || FAILED_ROUTING_ORDER.equals(type.getName())) { documentUniqueID = uniqueID; } else { // TMDM-5513 custom form layout pk contains double dot .. to split, but it's a system definition object // like this Product..Product..product_layout isUserFormat = !uniqueID.contains("..") && uniqueID.indexOf('.') > 0; //$NON-NLS-1$ documentUniqueID = uniqueID; if (uniqueID.startsWith(PROVISIONING_PREFIX_INFO)) { documentUniqueID = StringUtils.substringAfter(uniqueID, PROVISIONING_PREFIX_INFO); } else if (uniqueID.startsWith(BROWSEITEM_PREFIX_INFO)) { documentUniqueID = StringUtils.substringAfter(uniqueID, BROWSEITEM_PREFIX_INFO); //$NON-NLS-1$ } else if (isUserFormat) { documentUniqueID = StringUtils.substringAfterLast(uniqueID, "."); //$NON-NLS-1$ } } qb = from(type).where(eq(type.getKeyFields().iterator().next(), documentUniqueID)); StorageResults results = null; try { storage.begin(); results = storage.fetch(qb.getSelect()); String xmlString = getXmlString(clusterName, type, results.iterator(), uniqueID, encoding, isUserFormat); storage.commit(); return xmlString; } catch (IOException e) { storage.rollback(); throw new XmlServerException(e); } finally { if (results != null) { results.close(); } } }
From source file:edu.ku.brc.af.ui.forms.MultiView.java
/** * Get the Permissions for the data type from the views. * @param view the view// w w w . j a v a 2 s . c om * @param shortClassName the short class name if it is already know (null can be passed in) * @return the permissions */ public static PermissionSettings getPremissionFromView(final ViewIFace view, final String shortClassName) { String shortClass = StringUtils.isNotEmpty(shortClassName) ? shortClassName : StringUtils.substringAfterLast(view.getClassName(), "."); if (shortClass == null) { shortClass = view.getClassName(); } return SecurityMgr.getInstance().getPermission("DO." + shortClass.toLowerCase()); }
From source file:adalid.util.velocity.BaseBuilder.java
private void createTextFilePropertiesFile(String source, String target) { boolean java = StringUtils.endsWithIgnoreCase(source, ".java"); boolean bundle = StringUtils.endsWithIgnoreCase(source, ".properties"); File sourceFile = new File(source); String sourceFileName = sourceFile.getName(); String sourceFileSimpleName = StringUtils.substringBeforeLast(sourceFileName, "."); String sourceFolderName = sourceFile.getParentFile().getName(); String sourceFolderSimpleName = StringUtils.substringBeforeLast(sourceFolderName, "."); String sourceEntityName = getOptionalEntityName(sourceFileSimpleName, sourceFolderSimpleName); String properties = source.replace(projectFolderPath, velocityPlatformsTargetFolderPath) + ".properties"; String folder = StringUtils.substringBeforeLast(properties, FS); String template = StringUtils.substringAfter(target, velocityFolderPath + FS).replace(FS, "/"); String path = StringUtils.substringBeforeLast(StringUtils.substringAfter(source, projectFolderPath), FS) .replace(FS, "/").replace(project, PROJECT_ALIAS).replace("eclipse.settings", ".settings"); path = replaceAliasWithRootFolderName(path); String pack = null;/*from w w w .ja v a 2s . c o m*/ if (java || bundle) { String s1 = StringUtils.substringAfter(path, SRC); if (StringUtils.contains(s1, PROJECT_ALIAS)) { String s2 = StringUtils.substringBefore(s1, PROJECT_ALIAS); String s3 = SRC + s2; String s4 = StringUtils.substringBefore(path, s3) + s3; String s5 = StringUtils.substringAfter(s1, PROJECT_ALIAS).replace("/", "."); path = StringUtils.removeEnd(s4, "/"); pack = ROOT_PACKAGE_NAME + s5; } } path = finalisePath(path); String file = StringUtils.substringAfterLast(source, FS).replace(project, PROJECT_ALIAS) .replace("eclipse.project", ".project"); List<String> lines = new ArrayList<>(); lines.add("template = " + template); // lines.add("template-type = velocity"); lines.add("path = " + path); if (StringUtils.isNotBlank(pack)) { lines.add("package = " + pack); } lines.add("file = " + file); if (sourceFileSimpleName.equals("eclipse") || sourceFolderSimpleName.equals("eclipse") || sourceFolderSimpleName.equals("nbproject")) { lines.add("disabled = true"); } else if (sourceEntityName != null) { lines.add("disabled-when-missing = " + sourceEntityName); } if (source.endsWith(".css") || source.endsWith(".jrtx")) { lines.add("preserve = true"); } else if (ArrayUtils.contains(preservableFiles, sourceFileName)) { lines.add("preserve = true"); } lines.add("dollar.string = $"); lines.add("pound.string = #"); lines.add("backslash.string = \\\\"); FilUtils.mkdirs(folder); if (write(properties, lines, WINDOWS_CHARSET)) { propertiesFilesCreated++; } }
From source file:eionet.cr.staging.exp.ExportRunner.java
/** * Export row.//from w w w . j a va2s . co m * * @param rs * the rs * @param rowIndex * the row index * @param repoConn * the repo conn * @param vf * the vf * @throws SQLException * the sQL exception * @throws RepositoryException * the repository exception * @throws DAOException */ private void exportRow(ResultSet rs, int rowIndex, RepositoryConnection repoConn, ValueFactory vf) throws SQLException, RepositoryException, DAOException { if (rowIndex == 1) { loadExistingConcepts(); } // Prepare subject URI on the basis of the template in the query configuration. String subjectUri = queryConf.getObjectUriTemplate(); if (StringUtils.isBlank(subjectUri)) { throw new IllegalArgumentException( "The object URI template in the query configuration must not be blank!"); } subjectUri = StringUtils.replace(subjectUri, "<dataset>", datasetIdentifier); // Prepare the map of ObjectDTO to be added to the subject later. LinkedHashMap<URI, ArrayList<Value>> valuesByPredicate = new LinkedHashMap<URI, ArrayList<Value>>(); // Add rdf:type predicate-value. addPredicateValue(valuesByPredicate, rdfTypeURI, objectTypeURI); // Add the DataCube dataset predicate-value. Assume this point cannot be reached if dataset value is empty. addPredicateValue(valuesByPredicate, datasetPredicateURI, datasetValueURI); // Add predicate-value pairs for hidden properties. if (hiddenProperties != null) { for (ObjectHiddenProperty hiddenProperty : hiddenProperties) { addPredicateValue(valuesByPredicate, hiddenProperty.getPredicateURI(), hiddenProperty.getValueValue()); } } boolean hasIndicatorMapping = false; // Loop through the query configuration's column mappings, construct ObjectDTO for each. for (Entry<String, ObjectProperty> entry : queryConf.getColumnMappings().entrySet()) { String colName = entry.getKey(); String colValue = rs.getString(colName); ObjectProperty property = entry.getValue(); if (property.getId().equals(INDICATOR)) { hasIndicatorMapping = true; } if (StringUtils.isBlank(colValue)) { if (property.getId().equals(BREAKDOWN)) { colValue = DEFAULT_BREAKDOWN_CODE; } else if (property.getId().equals(INDICATOR)) { colValue = DEFAULT_INDICATOR_CODE; } } if (StringUtils.isNotBlank(colValue)) { // Replace property place-holders in subject ID subjectUri = StringUtils.replace(subjectUri, "<" + property.getId() + ">", colValue); URI predicateURI = property.getPredicateURI(); if (predicateURI != null) { String propertyValue = property.getValueTemplate(); if (propertyValue == null) { propertyValue = colValue; } else { // Replace the column value place-holder in the value template (the latter cannot be specified by user) propertyValue = StringUtils.replace(propertyValue, "<value>", colValue); } recordMissingConcepts(property, colValue, propertyValue); Value value = null; if (property.isLiteralRange()) { try { String dataTypeUri = property.getDataType(); value = vf.createLiteral(propertyValue, dataTypeUri == null ? null : vf.createURI(dataTypeUri)); } catch (IllegalArgumentException e) { value = vf.createLiteral(propertyValue); } } else { value = vf.createURI(propertyValue); } addPredicateValue(valuesByPredicate, predicateURI, value); } } } // If there was no column mapping for the indicator, but a fixed indicator URI has been provided then use the latter. if (!hasIndicatorMapping && indicatorValueURI != null) { addPredicateValue(valuesByPredicate, indicatorPredicateURI, indicatorValueURI); } // If <indicator> column placeholder not replaced yet, then use the fixed indicator URI if given. if (subjectUri.indexOf("<indicator>") != -1) { String indicatorCode = StringUtils.substringAfterLast(queryConf.getIndicatorUri(), "/"); if (StringUtils.isBlank(indicatorCode)) { // No fixed indicator URI given either, resort to the default. indicatorCode = DEFAULT_INDICATOR_CODE; } subjectUri = StringUtils.replace(subjectUri, "<indicator>", indicatorCode); } // If <breakdown> column placeholder not replaced yet, then use the default. if (subjectUri.indexOf("<breakdown>") != -1) { subjectUri = StringUtils.replace(subjectUri, "<breakdown>", DEFAULT_BREAKDOWN_CODE); } // Loop over predicate-value pairs and create the triples in the triple store. if (!valuesByPredicate.isEmpty()) { int tripleCountBefore = tripleCount; URI subjectURI = vf.createURI(subjectUri); for (Entry<URI, ArrayList<Value>> entry : valuesByPredicate.entrySet()) { ArrayList<Value> values = entry.getValue(); if (values != null && !values.isEmpty()) { URI predicateURI = entry.getKey(); for (Value value : values) { repoConn.add(subjectURI, predicateURI, value, graphURI); graphs.add(graphURI.stringValue()); tripleCount++; if (tripleCount % 5000 == 0) { LOGGER.debug(tripleCount + " triples exported so far"); } // Time periods should be harvested afterwards. if (Predicates.DAS_TIMEPERIOD.equals(predicateURI.stringValue())) { if (value instanceof URI) { timePeriods.add(value.stringValue()); } } } } } if (tripleCount > tripleCountBefore) { subjectCount++; } } }
From source file:com.jaxio.celerio.model.Attribute.java
public String getColumnNameLanguage() { if (columnNameHasLanguageSuffix()) { return StringUtils.substringAfterLast(getColumnName(), "_").toLowerCase(); } else {/*w w w. j a v a 2 s. c o m*/ throw new IllegalStateException( "Can be invoked only if columnNameHasLanguageSuffix returns true, please write safer code"); } }
From source file:com.cubusmail.server.mail.MessageHandler.java
/** * @return//from w w w . ja v a2 s . c om * @throws MessagingException * @throws IOException */ public GWTMessage getGWTMessage() throws MessagingException, IOException { GWTMessage gwtMsg = new GWTMessage(); gwtMsg.setFrom(getFrom()); gwtMsg.setFromArray(ConvertUtil.convertAddress(this.message.getFrom())); gwtMsg.setTo(getTo()); gwtMsg.setToArray(ConvertUtil.convertAddress(this.message.getRecipients(RecipientType.TO))); gwtMsg.setCc(getCc()); gwtMsg.setCcArray(ConvertUtil.convertAddress(this.message.getRecipients(RecipientType.CC))); gwtMsg.setBcc(getBcc()); gwtMsg.setReplyTo(getReplyTo()); gwtMsg.setReplyToArray(getReplyToArray()); gwtMsg.setSubject(getSubject()); gwtMsg.setDate(this.message.getSentDate()); if (isHtmlMessage()) { gwtMsg.setMessageText(getMessageTextHtml()); } else { gwtMsg.setMessageText(getMessageTextPlain()); } gwtMsg.setHtmlMessage(isHtmlMessage()); gwtMsg.setHasImages(isHasImages()); gwtMsg.setTrustImages(isTrustImages()); gwtMsg.setAcknowledgement(isAcknowledgement()); gwtMsg.setReadBefore(this.readBefore); gwtMsg.setRead(isRead()); gwtMsg.setDraft(isDraftMessage()); long id = getId(); gwtMsg.setId(id); List<MimePart> parts = MessageUtils.attachmentsFromPart(this.message); if (parts.size() > 0) { GWTAttachment[] attachments = new GWTAttachment[parts.size()]; for (int i = 0; i < parts.size(); i++) { attachments[i] = new GWTAttachment(); String fileName = parts.get(i).getFileName(); if (StringUtils.isEmpty(fileName)) { fileName = this.applicationContext.getMessage("message.unknown.attachment", null, SessionManager.get().getLocale()); } attachments[i].setFileName(fileName); int size = parts.get(i).getSize(); if (parts.get(i).getSize() == -1) { try { size = parts.get(i).getInputStream().available(); } catch (IOException e) { size = -1; } } NumberFormat sizeFormat = MessageUtils.createSizeFormat(SessionManager.get().getLocale()); size = MessageUtils.calculateAttachmentSize(size); attachments[i].setSize(size); attachments[i].setSizeText(MessageUtils.formatPartSize(attachments[i].getSize(), sizeFormat)); attachments[i].setMessageId(id); attachments[i].setIndex(i); String extension = StringUtils.substringAfterLast(parts.get(i).getFileName(), "."); if (extension != null) { extension = extension.toLowerCase(); if (ArrayUtils.contains(PREVIEW_EXTENSIONS, extension)) { attachments[i].setPreview(true); } } } gwtMsg.setAttachments(attachments); } Preferences preferences = SessionManager.get().getPreferences(); GWTMessageRecord[] messageArray = ConvertUtil.convertMessagesToStringArray(this.applicationContext, preferences, (IMAPFolder) this.message.getFolder(), 1, new Message[] { this.message }); gwtMsg.setMessageRecord(messageArray[0]); return gwtMsg; }
From source file:com.htmlhifive.tools.wizard.library.LibraryList.java
/** * ?????./*w w w. j av a 2s . c om*/ * * @param site * @param folder * @param existsFileList ??? * @param noExistsFileList ????? * @return ????true? */ private boolean checkSite(Site site, IContainer folder, String installSubPath, List<String> existsFileList, List<String> noExistsFileList) { String siteUrl = site.getUrl(); String path = H5IOUtils.getURLPath(siteUrl); if (path == null) { return false; } IContainer savedFolder = folder; if (StringUtils.isNotEmpty(installSubPath) && savedFolder != null) { savedFolder = savedFolder.getFolder(Path.fromOSString(installSubPath)); } if (StringUtils.isNotEmpty(site.getExtractPath()) && savedFolder != null) { savedFolder = savedFolder.getFolder(Path.fromOSString(site.getExtractPath()));// .getRawLocation().toFile(); } String[] fileList = null; String wildCardStr = site.getFilePattern(); if (path.endsWith(".zip") || path.endsWith(".jar") || wildCardStr != null) { // ZIP?? String wildCardPath = ""; if (wildCardStr != null && wildCardStr.contains("/")) { // ?. wildCardStr = StringUtils.substringAfterLast(site.getFilePattern(), "/"); // wildCardPath?*???????????. if (!wildCardStr.contains("*")) { // *????? wildCardPath = StringUtils.substringBeforeLast(site.getFilePattern(), "/"); // folder = new File(folder, wildCardPath); if (folder != null) { savedFolder = folder.getFolder(Path.fromOSString(wildCardPath)); } } } if (savedFolder != null) { if (site.getReplaceFileName() != null) { fileList = savedFolder.getRawLocation().toFile() .list(new WildcardFileFilter(site.getReplaceFileName())); } else { if (wildCardStr != null) { fileList = savedFolder.getRawLocation().toFile().list(new WildcardFileFilter(wildCardStr)); } else { fileList = savedFolder.getRawLocation().toFile().list(); } } } if (fileList != null && fileList.length > 0) { if (!wildCardPath.isEmpty()) { for (String fileName : fileList) { existsFileList.add(wildCardPath + "/" + fileName); } } else { existsFileList.addAll(Arrays.asList(fileList)); } } else if (savedFolder != null) { //noExistsFileList.add(savedFolder.getFullPath().toString() + "/" + wildCardStr); noExistsFileList.add(savedFolder.getProjectRelativePath().toString() + "/" + wildCardStr); if ((savedFolder.getFullPath().toString() + "/" + wildCardStr) .startsWith(savedFolder.getFullPath().toString() + "/")) { noExistsFileList.add((savedFolder.getFullPath().toString() + "/" + wildCardStr) .substring(folder.getFullPath().toString().length() + 1)); } else { noExistsFileList.add(savedFolder.getFullPath().toString() + "/" + wildCardStr); } //folder } else { // ?????????????????. noExistsFileList.add(wildCardStr); } } else { // zip. IFile file = null; if (savedFolder != null) { if (site.getReplaceFileName() != null) { file = savedFolder.getFile(Path.fromOSString(site.getReplaceFileName())); } else { file = savedFolder.getFile(Path.fromOSString(StringUtils.substringAfterLast(path, "/"))); } if (file.exists()) { fileList = new String[] { file.getName() }; existsFileList.add(file.getName()); } else { // ???? if (file.getFullPath().toString().startsWith(folder.getFullPath().toString() + "/")) { noExistsFileList.add(file.getFullPath().toString() .substring(folder.getFullPath().toString().length() + 1)); } else { noExistsFileList.add(file.getFullPath().toString()); } } } else { // ?????????????????. if (site.getReplaceFileName() != null) { noExistsFileList.add(site.getReplaceFileName()); } else { noExistsFileList.add(StringUtils.substringAfterLast(path, "/")); } } } // ??????????? if (fileList != null && fileList.length > 0) { return true; } return false; }
From source file:adalid.util.velocity.SecondBaseBuilder.java
private void createTextFilePropertiesFile(String source, String target) { boolean java = StringUtils.endsWithIgnoreCase(source, ".java"); boolean bundle = StringUtils.endsWithIgnoreCase(source, ".properties"); File sourceFile = new File(source); String sourceFileName = sourceFile.getName(); String sourceFileSimpleName = StringUtils.substringBeforeLast(sourceFileName, "."); String sourceFolderName = sourceFile.getParentFile().getName(); String sourceFolderSimpleName = StringUtils.substringBeforeLast(sourceFolderName, "."); String sourceEntityName = getOptionalEntityName(sourceFileSimpleName, sourceFolderSimpleName); String properties = source.replace(projectFolderPath, velocityPlatformsTargetFolderPath) + ".properties"; String folder = StringUtils.substringBeforeLast(properties, FS); String template = StringUtils.substringAfter(target, velocityFolderPath + FS).replace(FS, "/"); String path = StringUtils.substringBeforeLast(StringUtils.substringAfter(source, projectFolderPath), FS) .replace(FS, "/").replace(project, PROJECT_ALIAS).replace("eclipse.settings", ".settings"); path = replaceAliasWithRootFolderName(path); String pack = null;/*w ww.ja v a 2 s. c o m*/ if (java || bundle) { String s1 = StringUtils.substringAfter(path, SRC); if (StringUtils.contains(s1, PROJECT_ALIAS)) { String s2 = StringUtils.substringBefore(s1, PROJECT_ALIAS); String s3 = SRC + s2; String s4 = StringUtils.substringBefore(path, s3) + s3; String s5 = StringUtils.substringAfter(s1, PROJECT_ALIAS).replace("/", "."); path = StringUtils.removeEnd(s4, "/"); pack = ROOT_PACKAGE_NAME + s5; } } path = finalisePath(path); String file = StringUtils.substringAfterLast(source, FS).replace(project, PROJECT_ALIAS) .replace("eclipse.project", ".project"); List<String> lines = new ArrayList<>(); lines.add("template = " + template); // lines.add("template-type = velocity"); lines.add("path = " + path); if (StringUtils.isNotBlank(pack)) { lines.add("package = " + pack); } lines.add("file = " + file); if (sourceFileSimpleName.equals("eclipse") || sourceFolderSimpleName.equals("eclipse") || sourceFolderSimpleName.equals("nbproject")) { lines.add("disabled = true"); } else if (sourceEntityName != null) { lines.add("disabled-when-missing = " + sourceEntityName); } if (preservable(sourceFile)) { lines.add("preserve = true"); } lines.add("dollar.string = $"); lines.add("pound.string = #"); lines.add("backslash.string = \\\\"); FilUtils.mkdirs(folder); if (write(properties, lines, WINDOWS_CHARSET)) { propertiesFilesCreated++; } }
From source file:com.cubusmail.mail.MessageHandler.java
/** * @return/*w ww. ja v a2s .c om*/ * @throws MessagingException * @throws IOException */ public GWTMessage getGWTMessage() throws MessagingException, IOException { GWTMessage gwtMsg = new GWTMessage(); gwtMsg.setFrom(getFrom()); gwtMsg.setFromArray(ConvertUtil.convertAddress(this.message.getFrom())); gwtMsg.setTo(getTo()); gwtMsg.setToArray(ConvertUtil.convertAddress(this.message.getRecipients(RecipientType.TO))); gwtMsg.setCc(getCc()); gwtMsg.setCcArray(ConvertUtil.convertAddress(this.message.getRecipients(RecipientType.CC))); gwtMsg.setBcc(getBcc()); gwtMsg.setReplyTo(getReplyTo()); gwtMsg.setReplyToArray(getReplyToArray()); gwtMsg.setSubject(getSubject()); gwtMsg.setDate(this.message.getSentDate()); if (isHtmlMessage()) { gwtMsg.setMessageText(getMessageTextHtml()); } else { gwtMsg.setMessageText(getMessageTextPlain()); } gwtMsg.setHtmlMessage(isHtmlMessage()); gwtMsg.setHasImages(isHasImages()); gwtMsg.setTrustImages(isTrustImages()); gwtMsg.setAcknowledgement(isAcknowledgement()); gwtMsg.setReadBefore(this.readBefore); gwtMsg.setRead(isRead()); gwtMsg.setDraft(isDraftMessage()); long id = getId(); gwtMsg.setId(id); List<MimePart> parts = MessageUtils.attachmentsFromPart(this.message); if (parts.size() > 0) { GWTAttachment[] attachments = new GWTAttachment[parts.size()]; for (int i = 0; i < parts.size(); i++) { attachments[i] = new GWTAttachment(); String fileName = parts.get(i).getFileName(); if (StringUtils.isEmpty(fileName)) { fileName = this.applicationContext.getMessage("message.unknown.attachment", null, SessionManager.get().getLocale()); } attachments[i].setFileName(fileName); int size = parts.get(i).getSize(); if (parts.get(i).getSize() == -1) { try { size = parts.get(i).getInputStream().available(); } catch (IOException e) { size = -1; } } NumberFormat sizeFormat = MessageUtils.createSizeFormat(SessionManager.get().getLocale()); size = MessageUtils.calculateAttachmentSize(size); attachments[i].setSize(size); attachments[i].setSizeText(MessageUtils.formatPartSize(attachments[i].getSize(), sizeFormat)); attachments[i].setMessageId(id); attachments[i].setIndex(i); String extension = StringUtils.substringAfterLast(parts.get(i).getFileName(), "."); if (extension != null) { extension = extension.toLowerCase(); if (ArrayUtils.contains(PREVIEW_EXTENSIONS, extension)) { attachments[i].setPreview(true); } } } gwtMsg.setAttachments(attachments); } return gwtMsg; }