List of usage examples for com.liferay.portal.kernel.util StringPool DASH
String DASH
To view the source code for com.liferay.portal.kernel.util StringPool DASH.
Click Source Link
From source file:au.com.permeance.liferay.portal.documentlibrary.util.DLFileNameNormalizerImpl.java
License:Open Source License
public String normalize(String fileName, char[] replaceChars) { if (Validator.isNull(fileName)) { return fileName; }/*from www . j a v a 2 s . c o m*/ fileName = GetterUtil.getString(fileName); fileName = fileName.toLowerCase(); fileName = Normalizer.normalizeToAscii(fileName); StringBuilder sb = null; int index = 0; for (int i = 0; i < fileName.length(); i++) { char c = fileName.charAt(i); if ((Arrays.binarySearch(_REPLACE_CHARS, c) >= 0) || ((replaceChars != null) && ArrayUtil.contains(replaceChars, c))) { if (sb == null) { sb = new StringBuilder(); } if (i > index) { sb.append(fileName.substring(index, i)); } sb.append(CharPool.DASH); // sb.append(CharPool.UNDERLINE); index = i + 1; } } if (sb != null) { if (index < fileName.length()) { sb.append(fileName.substring(index)); } fileName = sb.toString(); } while (fileName.indexOf(StringPool.DOUBLE_DASH) >= 0) { fileName = StringUtil.replace(fileName, StringPool.DOUBLE_DASH, StringPool.DASH); } return fileName; }
From source file:com.acs.DDMXSD.java
License:Open Source License
public String getHTML(PageContext pageContext, Element element, Fields fields, String namespace, String mode, boolean readOnly, Locale locale) throws Exception { StringBundler sb = new StringBundler(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String portletId = PortalUtil.getPortletId(request); String portletNamespace = PortalUtil.getPortletNamespace(portletId); List<Element> dynamicElementElements = element.elements("dynamic-element"); for (Element dynamicElementElement : dynamicElementElements) { FreeMarkerContext freeMarkerContext = getFreeMarkerContext(dynamicElementElement, locale); freeMarkerContext.put("portletNamespace", portletNamespace); freeMarkerContext.put("namespace", namespace); if (fields != null) { freeMarkerContext.put("fields", fields); }/*from ww w . j a v a 2 s . c o m*/ Map<String, Object> field = (Map<String, Object>) freeMarkerContext.get("fieldStructure"); String childrenHTML = getHTML(pageContext, dynamicElementElement, fields, namespace, mode, readOnly, locale); field.put("children", childrenHTML); String fieldNamespace = dynamicElementElement.attributeValue("fieldNamespace", _DEFAULT_NAMESPACE); String url = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); url = url.substring(0, url.lastIndexOf('/')); String defaultResourcePath = url + "/" + _TPL_DEFAULT_PATH; boolean fieldReadOnly = GetterUtil.getBoolean(field.get("readOnly")); if ((fieldReadOnly && Validator.isNotNull(mode) && mode.equalsIgnoreCase(DDMTemplateConstants.TEMPLATE_MODE_EDIT)) || readOnly) { fieldNamespace = _DEFAULT_READ_ONLY_NAMESPACE; defaultResourcePath = _TPL_DEFAULT_READ_ONLY_PATH; } String type = dynamicElementElement.attributeValue("type"); String templateName = StringUtil.replaceFirst(type, fieldNamespace.concat(StringPool.DASH), StringPool.BLANK); StringBundler resourcePath = new StringBundler(5); resourcePath.append(_TPL_PATH); resourcePath.append(fieldNamespace.toLowerCase()); resourcePath.append(CharPool.SLASH); resourcePath.append(templateName); resourcePath.append(_TPL_EXT); sb.append(processFTL(pageContext, freeMarkerContext, resourcePath.toString(), defaultResourcePath)); } return sb.toString(); }
From source file:com.bemis.portal.customer.service.impl.CustomerProfileLocalServiceImpl.java
License:Open Source License
protected String formatCountryName(String countryName) { return StringUtil.toLowerCase(countryName.replace(StringPool.SPACE, StringPool.DASH)); }
From source file:com.exp.portlet.halcon.utils.FriendlyURLNormalizer.java
License:Open Source License
public static String normalize(String friendlyURL, char[] replaceChars) { if (Validator.isNull(friendlyURL)) { return friendlyURL; }//from w w w . j av a2 s . co m friendlyURL = GetterUtil.getString(friendlyURL); friendlyURL = friendlyURL.toLowerCase(); friendlyURL = AsciiUtils.convertNonAscii(friendlyURL); char[] charArray = friendlyURL.toCharArray(); for (int i = 0; i < charArray.length; i++) { char oldChar = charArray[i]; char newChar = oldChar; if (ArrayUtil.contains(_REPLACE_CHARS, oldChar) || ((replaceChars != null) && ArrayUtil.contains(replaceChars, oldChar))) { newChar = CharPool.DASH; } if (oldChar != newChar) { charArray[i] = newChar; } } friendlyURL = new String(charArray); while (friendlyURL.contains(StringPool.DASH + StringPool.DASH)) { friendlyURL = StringUtil.replace(friendlyURL, StringPool.DASH + StringPool.DASH, StringPool.DASH); } if (friendlyURL.startsWith(StringPool.DASH)) { friendlyURL = friendlyURL.substring(1, friendlyURL.length()); } if (friendlyURL.endsWith(StringPool.DASH)) { friendlyURL = friendlyURL.substring(0, friendlyURL.length() - 1); } /*return friendlyURL;*/ return FilterTextsUtils.deleteStopWords(friendlyURL, StringPool.DASH); }
From source file:com.exp.portlet.halcon.utils.FriendlyURLNormalizer.java
License:Open Source License
public static String normalizeNoStopWords(String friendlyURL, char[] replaceChars) { if (Validator.isNull(friendlyURL)) { return friendlyURL; }//from w ww . jav a 2 s . com friendlyURL = GetterUtil.getString(friendlyURL); friendlyURL = friendlyURL.toLowerCase(); friendlyURL = AsciiUtils.convertNonAscii(friendlyURL); char[] charArray = friendlyURL.toCharArray(); for (int i = 0; i < charArray.length; i++) { char oldChar = charArray[i]; char newChar = oldChar; if (ArrayUtil.contains(_REPLACE_CHARS, oldChar) || ((replaceChars != null) && ArrayUtil.contains(replaceChars, oldChar))) { newChar = CharPool.DASH; } if (oldChar != newChar) { charArray[i] = newChar; } } friendlyURL = new String(charArray); while (friendlyURL.contains(StringPool.DASH + StringPool.DASH)) { friendlyURL = StringUtil.replace(friendlyURL, StringPool.DASH + StringPool.DASH, StringPool.DASH); } if (friendlyURL.startsWith(StringPool.DASH)) { friendlyURL = friendlyURL.substring(1, friendlyURL.length()); } if (friendlyURL.endsWith(StringPool.DASH)) { friendlyURL = friendlyURL.substring(0, friendlyURL.length() - 1); } return friendlyURL; }
From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java
License:Open Source License
public JSONArray getYldToMaturity(String portfolioIds) { JSONArray jsonArray = JSONFactoryUtil.createJSONArray(); for (int i = 0; i < yldToMaturityRange.length; i++) { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); if (i <= 5) { jsonObject.put("yldToMaturityRange", yldToMaturityRange[i][0] + StringPool.DASH + yldToMaturityRange[i][1]); } else {//from w w w.j a va 2s. c o m jsonObject.put("yldToMaturityRange", yldToMaturityRange[i][0] + StringPool.PLUS); } for (int j = 0; j < durationRange.length; j++) { jsonObject.put((int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1], 0.0d); jsonObject.put("index" + j, (i + StringPool.COLON + j)); } jsonArray.put(jsonObject); } Connection conn = null; try { conn = DataAccess.getConnection(); String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]", "[$FING_BOND_WHERE_CLAUSE$]" }; String[] replacements = { portfolioIds, ",f.*", ",fing_Bond f", "and a.assetId = f.assetId" }; String sql = StringUtil.replace(CustomSQLUtil.get(QUERY), tokens, replacements); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); double totalValueOfBonds = 0.0; while (rs.next()) { double dur_mid = rs.getDouble("dur_mid"); double yld_ytm_bid = rs.getDouble("yld_ytm_bid"); double currentMarketValue = rs.getDouble("currentMarketValue"); totalValueOfBonds += currentMarketValue; for (int i = 0; i < yldToMaturityRange.length; i++) { if (yld_ytm_bid > yldToMaturityRange[i][0] && yld_ytm_bid <= yldToMaturityRange[i][1]) { JSONObject jsonObj = jsonArray.getJSONObject(i); for (int j = 0; j < durationRange.length; j++) { if (dur_mid > durationRange[j][0] && dur_mid <= durationRange[j][1]) { String key = (int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1]; jsonObj.put(key, jsonObj.getDouble(key) + currentMarketValue); } } } } } rs.close(); stmt.close(); for (int i = 0; i < yldToMaturityRange.length; i++) { JSONObject jsonObj = jsonArray.getJSONObject(i); for (int j = 0; j < durationRange.length; j++) { String key = (int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1]; jsonObj.put(key, jsonObj.getDouble(key) * 100 / totalValueOfBonds); } } // append a summary row JSONObject summary = JSONFactoryUtil.createJSONObject(); summary.put("summary", true); summary.put("yldToMaturityRange", "Total"); for (int i = 0; i < yldToMaturityRange.length; i++) { JSONObject jsonObj = jsonArray.getJSONObject(i); for (int j = 0; j < durationRange.length; j++) { String key = (int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1]; if (Double.isNaN(summary.getDouble(key))) { summary.put(key, jsonObj.getDouble(key)); } else { summary.put(key, summary.getDouble(key) + jsonObj.getDouble(key)); } } } jsonArray.put(summary); } catch (SQLException e) { e.printStackTrace(); } finally { DataAccess.cleanUp(conn); } return jsonArray; }
From source file:com.fingence.slayer.service.impl.PortfolioServiceImpl.java
License:Open Source License
public String getBaseCurrency(long portfolioId) { String baseCurrency = StringPool.BLANK; try {/*from w w w .j a v a 2 s. c o m*/ Portfolio portfolio = portfolioLocalService.fetchPortfolio(portfolioId); if (Validator.isNotNull(portfolio)) { Currency currency = currencyService.getCurrency(portfolio.getBaseCurrency()); baseCurrency = currency.getCurrencyCode() + StringPool.DASH + currency.getCurrencyDesc(); } } catch (SystemException e) { e.printStackTrace(); } return baseCurrency; }
From source file:com.fmdp.webform.portlet.WebFormPortlet.java
License:Open Source License
public void saveData(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); String portletId = PortalUtil.getPortletId(actionRequest); PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletId); boolean requireCaptcha = GetterUtil.getBoolean(preferences.getValue("requireCaptcha", StringPool.BLANK)); String successURL = GetterUtil.getString(preferences.getValue("successURL", StringPool.BLANK)); boolean sendAsEmail = GetterUtil.getBoolean(preferences.getValue("sendAsEmail", StringPool.BLANK)); boolean sendThanksEmail = GetterUtil.getBoolean(preferences.getValue("sendThanksEmail", StringPool.BLANK)); boolean saveToDatabase = GetterUtil.getBoolean(preferences.getValue("saveToDatabase", StringPool.BLANK)); String databaseTableName = GetterUtil .getString(preferences.getValue("databaseTableName", StringPool.BLANK)); boolean saveToFile = GetterUtil.getBoolean(preferences.getValue("saveToFile", StringPool.BLANK)); boolean uploadToDisk = GetterUtil.getBoolean(preferences.getValue("uploadToDisk", StringPool.BLANK)); boolean uploadToDM = GetterUtil.getBoolean(preferences.getValue("uploadToDM", StringPool.BLANK)); long newFolderId = GetterUtil.getLong(preferences.getValue("newFolderId", StringPool.BLANK)); String fileName = GetterUtil.getString(preferences.getValue("fileName", StringPool.BLANK)); String uploadDiskDir = GetterUtil.getString(preferences.getValue("uploadDiskDir", StringPool.BLANK)); if (requireCaptcha) { try {/* w w w . j av a 2s . c om*/ CaptchaUtil.check(actionRequest); } catch (CaptchaTextException cte) { SessionErrors.add(actionRequest, CaptchaTextException.class.getName()); return; } } UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest); Map<String, String> fieldsMap = new LinkedHashMap<String, String>(); String fileAttachment = ""; for (int i = 1; true; i++) { String fieldLabel = preferences.getValue("fieldLabel" + i, StringPool.BLANK); String fieldType = preferences.getValue("fieldType" + i, StringPool.BLANK); if (Validator.isNull(fieldLabel)) { break; } if (StringUtil.equalsIgnoreCase(fieldType, "paragraph")) { continue; } if (StringUtil.equalsIgnoreCase(fieldType, "file")) { if (_log.isDebugEnabled()) { _log.debug("Field name for file: " + fieldLabel); } File file = uploadRequest.getFile("field" + i); String sourceFileName = uploadRequest.getFileName("field" + i); if (_log.isDebugEnabled()) { _log.debug("File attachment: " + sourceFileName); } JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); if (Validator.isNotNull(sourceFileName) && !"".equals(sourceFileName)) { if (uploadRequest.getSize("field" + i) == 0) { SessionErrors.add(actionRequest, "uploadToDiskError", "Uploaded file size is 0"); if (_log.isDebugEnabled()) { _log.debug("Uploaded file size is 0"); } return; } // List<String> uploadResults = new ArrayList<String>(); String uploadResult = ""; if (uploadToDisk) { uploadResult = uploadFile(file, sourceFileName, uploadDiskDir); if (uploadResult.equalsIgnoreCase("File Upload Error")) { SessionErrors.add(actionRequest, "uploadToDiskError", uploadResult); return; } fileAttachment = uploadDiskDir + File.separator + uploadResult; //uploadResults.add(uploadResult); jsonObject.put("fsOriginalName", sourceFileName); jsonObject.put("fsName", uploadResult); } if (uploadToDM) { uploadResult = ""; String contentType = MimeTypesUtil.getContentType(file); Folder folderName = DLAppLocalServiceUtil.getFolder(newFolderId); if (_log.isDebugEnabled()) { _log.debug("DM Folder: " + folderName.getName()); } InputStream inputStream = new FileInputStream(file); long repositoryId = folderName.getRepositoryId(); try { String selectedFileName = sourceFileName; while (true) { try { DLAppLocalServiceUtil.getFileEntry(themeDisplay.getScopeGroupId(), newFolderId, selectedFileName); StringBundler sb = new StringBundler(5); sb.append(FileUtil.stripExtension(selectedFileName)); sb.append(StringPool.DASH); sb.append(StringUtil.randomString()); sb.append(StringPool.PERIOD); sb.append(FileUtil.getExtension(selectedFileName)); selectedFileName = sb.toString(); } catch (Exception e) { break; } } FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(themeDisplay.getUserId(), repositoryId, newFolderId, selectedFileName, //file.getName(), contentType, selectedFileName, "", "", inputStream, file.length(), serviceContext); if (_log.isDebugEnabled()) { _log.debug("DM file uploade: " + fileEntry.getTitle()); } //Map<String, Serializable> workflowContext = new HashMap<String, Serializable>(); //workflowContext.put("event",DLSyncConstants.EVENT_UPDATE); //DLFileEntryLocalServiceUtil.updateStatus(themeDisplay.getUserId(), fileEntry.getFileVersion().getFileVersionId(), WorkflowConstants.STATUS_APPROVED, workflowContext, serviceContext); uploadResult = String.valueOf(fileEntry.getFileEntryId()); //uploadResults.add(uploadResult); String docUrl = themeDisplay.getPortalURL() + "/c/document_library/get_file?uuid=" + fileEntry.getUuid() + "&groupId=" + themeDisplay.getScopeGroupId(); jsonObject.put("fe", uploadResult); jsonObject.put("feOriginalName", sourceFileName); jsonObject.put("feName", fileEntry.getTitle()); jsonObject.put("feUrl", docUrl); } catch (PortalException pe) { SessionErrors.add(actionRequest, "uploadToDmError"); _log.error("The upload to DM failed", pe); return; } catch (Exception e) { _log.error("The upload to DM failed", e); return; } } jsonObject.put("Status", "With Attachment"); } else { jsonObject.put("Status", "No Attachment"); } fieldsMap.put(fieldLabel, jsonObject.toString()); } else { fieldsMap.put(fieldLabel, uploadRequest.getParameter("field" + i)); } } Set<String> validationErrors = null; try { validationErrors = validate(fieldsMap, preferences); } catch (Exception e) { SessionErrors.add(actionRequest, "validationScriptError", e.getMessage().trim()); return; } User currentUser = PortalUtil.getUser(actionRequest); String userEmail = ""; if (!Validator.isNull(currentUser)) { userEmail = currentUser.getEmailAddress(); if (_log.isDebugEnabled()) { _log.debug("User email for the form author: " + userEmail); } fieldsMap.put("email-from", userEmail); } else { fieldsMap.put("email-from", "guest"); } DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone(themeDisplay.getTimeZone().getID())); Date dateobj = new Date(); fieldsMap.put("email-sent-on", df.format(dateobj)); if (validationErrors.isEmpty()) { boolean emailSuccess = true; boolean databaseSuccess = true; boolean fileSuccess = true; boolean emailThanksSuccess = true; if (sendAsEmail) { emailSuccess = WebFormUtil.sendEmail(themeDisplay.getCompanyId(), fieldsMap, preferences, fileAttachment); } if (sendThanksEmail && !Validator.isNull(currentUser)) { emailThanksSuccess = WebFormUtil.sendThanksEmail(themeDisplay.getCompanyId(), fieldsMap, preferences, userEmail); } if (saveToDatabase) { if (Validator.isNull(databaseTableName)) { databaseTableName = WebFormUtil.getNewDatabaseTableName(portletId); preferences.setValue("databaseTableName", databaseTableName); preferences.store(); } databaseSuccess = saveDatabase(themeDisplay.getCompanyId(), fieldsMap, preferences, databaseTableName); } if (saveToFile) { fileSuccess = saveFile(fieldsMap, fileName); } if (emailSuccess && emailThanksSuccess && databaseSuccess && fileSuccess) { if (Validator.isNull(successURL)) { SessionMessages.add(actionRequest, "success"); } else { SessionMessages.add(actionRequest, portletId + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE); } } else { SessionErrors.add(actionRequest, "error"); } } else { for (String badField : validationErrors) { SessionErrors.add(actionRequest, "error" + badField); } } if (SessionErrors.isEmpty(actionRequest) && Validator.isNotNull(successURL)) { actionResponse.sendRedirect(successURL); } }
From source file:com.htmsd.slayer.service.impl.ShoppingCartLocalServiceImpl.java
License:Open Source License
public String[] getValueTokens(ShoppingOrder shoppingOrder) { DecimalFormat df = new DecimalFormat("0.00"); String[] valueTokens = new String[9]; String currentYear = String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); String orderId = HConstants.HTMSD + currentYear.substring(2, 4) + shoppingOrder.getOrderId(); ShoppingItem shoppingItem = CommonUtil.getShoppingItem(shoppingOrder.getShoppingItemId()); valueTokens[0] = shoppingOrder.getUserName(); valueTokens[1] = orderId;//from w w w.j a va 2s. c o m valueTokens[2] = (Validator.isNotNull(shoppingItem) ? shoppingItem.getProductCode() + StringPool.DASH + shoppingItem.getName() : StringPool.DASH); valueTokens[3] = df.format(Validator.isNotNull(shoppingItem) ? shoppingItem.getSellingPrice() : 0); valueTokens[4] = String.valueOf(shoppingOrder.getQuantity()); valueTokens[5] = df.format(shoppingOrder.getTotalPrice()); valueTokens[6] = CommonUtil.getPriceInNumberFormat(shoppingOrder.getTotalPrice(), HConstants.RUPEE_SYMBOL); valueTokens[7] = shoppingOrder.getShippingMoble(); valueTokens[8] = GenerateInvoice.getAddress(shoppingOrder); return valueTokens; }
From source file:com.liferay.adaptive.media.web.internal.portlet.action.EditImageConfigurationEntryMVCActionCommand.java
License:Open Source License
private String _getAutomaticUuid(long companyId, String normalizedName, String oldUuid) { String curUuid = normalizedName; for (int i = 1;; i++) { if (curUuid.equals(oldUuid)) { break; }/*w w w . ja v a2s .co m*/ Optional<AdaptiveMediaImageConfigurationEntry> adaptiveMediaImageConfigurationEntryOptional = _adaptiveMediaImageConfigurationHelper .getAdaptiveMediaImageConfigurationEntry(companyId, curUuid); if (!adaptiveMediaImageConfigurationEntryOptional.isPresent()) { break; } String suffix = StringPool.DASH + i; curUuid = FriendlyURLNormalizerUtil.normalize(normalizedName + suffix); } return curUuid; }