List of usage examples for com.liferay.portal.kernel.util StringUtil replaceFirst
public static String replaceFirst(String s, String[] oldSubs, String[] newSubs)
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.jav a 2 s.co 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.fb.filter.OpenGraphFilter.java
License:Open Source License
protected String getContent(HttpServletRequest request, String content) { if (ArrayUtil.isEmpty(_appNamespaces)) { if (_companyId == 0) { _companyId = PortalUtil.getCompanyId(request); }/*from ww w.ja v a2s .c o m*/ try { _appNamespaces = PrefsPropsUtil.getStringArray(_companyId, "APP_NAMESPACES", StringPool.NEW_LINE); } catch (Exception e) { _log.error(e); } } if (ArrayUtil.isEmpty(_appNamespaces)) { StringBundler sb = new StringBundler(2 + 4 * _appNamespaces.length); sb.append(_START_HEAD); sb.append(" og:http://ogp.me/ns fb:http://ogp.me/ns/fb "); for (String appNamespace : _appNamespaces) { sb.append(appNamespace); sb.append(":http://ogp.me/ns/fb/"); sb.append(appNamespace); sb.append(StringPool.SPACE); } content = StringUtil.replaceFirst(content, _START_HEAD, sb.toString()); } return content; }
From source file:com.liferay.alloy.util.ReservedAttributeUtil.java
License:Open Source License
public static String getOriginalName(String componentName, String attributeName) { String originalName = StringUtils.uncapitalize( StringUtil.replaceFirst(attributeName, componentName.toLowerCase(), StringPool.BLANK)); if (isReserved(originalName)) { attributeName = originalName;//from w w w.ja v a 2 s . com } return attributeName; }
From source file:com.liferay.documentlibrary.hook.filter.DLRecordFilter.java
License:Open Source License
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { boolean isLogsEnabled = GetterUtil.getBoolean(PropsUtil.get("document.download.logs.enabled"), Boolean.FALSE);/*from ww w .jav a2 s .co m*/ if (isLogsEnabled) { try { HttpServletRequest httpRequest = PortalUtil .getOriginalServletRequest((HttpServletRequest) servletRequest); String uri = (String) servletRequest.getAttribute(WebKeys.INVOKER_FILTER_URI); /** * In WebServerServlet(Parent servlet) it returns path like /1024/123/Document+Name/uuid * While in this filter URI is like /document/1024/123/Document+Name/uuid. So to use OOB methods * I have replaced intial /document/ with blank. */ uri = StringUtil.replaceFirst(uri, "/documents/", StringPool.BLANK); String[] pathArray = StringUtil.split(uri, CharPool.SLASH); if (Validator.isNumber(pathArray[0])) { User user = _getUser(httpRequest); PrincipalThreadLocal.setName(user.getUserId()); PrincipalThreadLocal.setPassword(PortalUtil.getUserPassword(httpRequest)); PermissionChecker permissionChecker = PermissionCheckerFactoryUtil.create(user); PermissionThreadLocal.setPermissionChecker(permissionChecker); FileEntry fileEntry = getFileEntry(pathArray); String remoteIpAddress = httpRequest.getRemoteAddr(); addDLRecordLog(fileEntry, user, remoteIpAddress); } //System.out.println("URI " + uri); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } } filterChain.doFilter(servletRequest, servletResponse); }
From source file:com.liferay.dynamic.data.mapping.internal.render.DDMFormFieldFreeMarkerRenderer.java
License:Open Source License
protected String processFTL(HttpServletRequest request, HttpServletResponse response, String fieldNamespace, String type, String mode, boolean readOnly, Map<String, Object> freeMarkerContext) throws Exception { if (Validator.isNull(fieldNamespace)) { fieldNamespace = _DEFAULT_NAMESPACE; }/* w ww.j a va 2 s . co m*/ TemplateResource templateResource = _defaultTemplateResource; Map<String, Object> fieldStructure = (Map<String, Object>) freeMarkerContext.get("fieldStructure"); boolean fieldReadOnly = GetterUtil.getBoolean(fieldStructure.get("readOnly")); if ((fieldReadOnly && Validator.isNotNull(mode) && StringUtil.equalsIgnoreCase(mode, DDMTemplateConstants.TEMPLATE_MODE_EDIT)) || readOnly) { fieldNamespace = _DEFAULT_READ_ONLY_NAMESPACE; templateResource = _defaultReadOnlyTemplateResource; } String templateName = StringUtil.replaceFirst(type, fieldNamespace.concat(StringPool.DASH), StringPool.BLANK); StringBundler sb = new StringBundler(5); sb.append(_TPL_PATH); sb.append(StringUtil.toLowerCase(fieldNamespace)); sb.append(CharPool.SLASH); sb.append(templateName); sb.append(_TPL_EXT); String resource = sb.toString(); URL url = getResource(resource); if (url != null) { templateResource = getTemplateResource(resource); } if (templateResource == null) { throw new Exception("Unable to load template resource " + resource); } Template template = TemplateManagerUtil.getTemplate(TemplateConstants.LANG_TYPE_FTL, templateResource, false); for (Map.Entry<String, Object> entry : freeMarkerContext.entrySet()) { template.put(entry.getKey(), entry.getValue()); } TemplateManager templateManager = TemplateManagerUtil.getTemplateManager(TemplateConstants.LANG_TYPE_FTL); templateManager.addTaglibSupport(template, request, response); return processFTL(request, response, template); }
From source file:com.liferay.exportimport.content.processor.base.BaseTextExportImportContentProcessor.java
License:Open Source License
protected String replaceImportLinksToLayouts(PortletDataContext portletDataContext, String content) throws Exception { List<String> oldLinksToLayout = new ArrayList<>(); List<String> newLinksToLayout = new ArrayList<>(); Matcher matcher = importLinksToLayoutPattern.matcher(content); Map<Long, Long> layoutPlids = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Layout.class); String layoutsImportMode = MapUtil.getString(portletDataContext.getParameterMap(), PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE, PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_UUID); while (matcher.find()) { long oldPlid = GetterUtil.getLong(matcher.group(4)); Long newPlid = MapUtil.getLong(layoutPlids, oldPlid); long oldGroupId = GetterUtil.getLong(matcher.group(6)); long newGroupId = oldGroupId; long oldLayoutId = GetterUtil.getLong(matcher.group(1)); long newLayoutId = oldLayoutId; Layout layout = LayoutLocalServiceUtil.fetchLayout(newPlid); if (layout != null) { newGroupId = layout.getGroupId(); newLayoutId = layout.getLayoutId(); } else if (_log.isDebugEnabled()) { StringBundler sb = new StringBundler(5); sb.append("Unable to get layout with plid "); sb.append(oldPlid);// w w w . ja v a2s . c om sb.append(", using layout ID "); sb.append(newLayoutId); sb.append(" instead"); _log.debug(sb.toString()); } String oldLinkToLayout = matcher.group(0); String newLinkToLayout = StringUtil.replaceFirst(oldLinkToLayout, new String[] { StringPool.AT + oldPlid, String.valueOf(oldLayoutId) }, new String[] { StringPool.BLANK, String.valueOf(newLayoutId) }); if ((layout != null) && layout.isPublicLayout() && layoutsImportMode .equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) { newLinkToLayout = StringUtil.replace(newLinkToLayout, "private-group", "public"); } if ((oldGroupId != 0) && (oldGroupId != newGroupId)) { newLinkToLayout = StringUtil.replaceLast(newLinkToLayout, String.valueOf(oldGroupId), String.valueOf(newGroupId)); } oldLinksToLayout.add(oldLinkToLayout); newLinksToLayout.add(newLinkToLayout); } content = StringUtil.replace(content, ArrayUtil.toStringArray(oldLinksToLayout.toArray()), ArrayUtil.toStringArray(newLinksToLayout.toArray())); return content; }
From source file:com.liferay.exportimport.internal.content.processor.LinksToLayoutsExportImportContentProcessor.java
License:Open Source License
protected String replaceImportLinksToLayouts(PortletDataContext portletDataContext, String content) throws Exception { List<String> oldLinksToLayout = new ArrayList<>(); List<String> newLinksToLayout = new ArrayList<>(); Matcher matcher = _importLinksToLayoutPattern.matcher(content); Map<Long, Long> layoutPlids = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Layout.class); String layoutsImportMode = MapUtil.getString(portletDataContext.getParameterMap(), PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE, PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_MERGE_BY_LAYOUT_UUID); while (matcher.find()) { long oldPlid = GetterUtil.getLong(matcher.group(4)); Long newPlid = MapUtil.getLong(layoutPlids, oldPlid); long oldGroupId = GetterUtil.getLong(matcher.group(6)); long newGroupId = oldGroupId; long oldLayoutId = GetterUtil.getLong(matcher.group(1)); long newLayoutId = oldLayoutId; Layout layout = _layoutLocalService.fetchLayout(newPlid); if (layout != null) { newGroupId = layout.getGroupId(); newLayoutId = layout.getLayoutId(); } else if (_log.isWarnEnabled()) { _log.warn("Unable to get layout with plid " + oldPlid); }//from w ww . j a v a 2 s. com String oldLinkToLayout = matcher.group(0); String newLinkToLayout = StringUtil.replaceFirst(oldLinkToLayout, new String[] { StringPool.AT + oldPlid, String.valueOf(oldLayoutId) }, new String[] { StringPool.BLANK, String.valueOf(newLayoutId) }); if ((layout != null) && layout.isPublicLayout() && layoutsImportMode .equals(PortletDataHandlerKeys.LAYOUTS_IMPORT_MODE_CREATED_FROM_PROTOTYPE)) { newLinkToLayout = StringUtil.replace(newLinkToLayout, "private-group", "public"); } if ((oldGroupId != 0) && (oldGroupId != newGroupId)) { newLinkToLayout = StringUtil.replaceLast(newLinkToLayout, String.valueOf(oldGroupId), String.valueOf(newGroupId)); } oldLinksToLayout.add(oldLinkToLayout); newLinksToLayout.add(newLinkToLayout); } content = StringUtil.replace(content, ArrayUtil.toStringArray(oldLinksToLayout.toArray()), ArrayUtil.toStringArray(newLinksToLayout.toArray())); return content; }
From source file:com.liferay.invitation.invite.members.internal.upgrade.v1_0_0.UpgradeNamespace.java
License:Open Source License
private String _getOldTableName() { if (MemberRequestTable.TABLE_NAME.startsWith(_NEW_NAMESPACE)) { return StringUtil.replaceFirst(MemberRequestTable.TABLE_NAME, _NEW_NAMESPACE, _OLD_NAMESPACE); }/*from ww w . j ava 2s . c o m*/ return _OLD_NAMESPACE + MemberRequestTable.TABLE_NAME; }
From source file:com.liferay.journal.content.search.web.internal.upgrade.v1_0_1.UpgradePortletId.java
License:Open Source License
protected void upgradePortletId() throws Exception { try (PreparedStatement ps1 = connection .prepareStatement("select contentSearchId, portletId from JournalContentSearch"); PreparedStatement ps2 = AutoBatchPreparedStatementUtil.concurrentAutoBatch(connection, "update JournalContentSearch set portletId = ? where " + "contentSearchId = ?"); ResultSet rs = ps1.executeQuery()) { while (rs.next()) { long contentSearchId = rs.getLong("contentSearchId"); String portletId = rs.getString("portletId"); String newPortletId = StringUtil.replaceFirst(portletId, _OLD_ROOT_PORTLET_ID, _NEW_ROOT_PORTLET_ID); ps2.setString(1, newPortletId); ps2.setLong(2, contentSearchId); ps2.addBatch();//from w ww.j av a2 s . co m } ps2.executeBatch(); } }
From source file:com.liferay.journal.internal.exportimport.content.processor.JournalFeedExportImportContentProcessor.java
License:Open Source License
@Override public String replaceExportContentReferences(PortletDataContext portletDataContext, StagedModel stagedModel, String content, boolean exportReferencedContent, boolean escapeContent) throws Exception { JournalFeed feed = (JournalFeed) stagedModel; Group group = _groupLocalService.getGroup(portletDataContext.getScopeGroupId()); String newGroupFriendlyURL = group.getFriendlyURL(); newGroupFriendlyURL = newGroupFriendlyURL.substring(1); String[] friendlyURLParts = StringUtil.split(feed.getTargetLayoutFriendlyUrl(), StringPool.FORWARD_SLASH); String oldGroupFriendlyURL = friendlyURLParts[2]; if (newGroupFriendlyURL.equals(oldGroupFriendlyURL)) { String targetLayoutFriendlyUrl = StringUtil.replaceFirst(feed.getTargetLayoutFriendlyUrl(), StringPool.SLASH + newGroupFriendlyURL + StringPool.SLASH, StringPool.SLASH + DATA_HANDLER_GROUP_FRIENDLY_URL + StringPool.SLASH); feed.setTargetLayoutFriendlyUrl(targetLayoutFriendlyUrl); }// w w w . j a va2s .co m Group targetLayoutGroup = _groupLocalService.fetchFriendlyURLGroup(portletDataContext.getCompanyId(), StringPool.SLASH + oldGroupFriendlyURL); boolean privateLayout = false; if (!PropsValues.LAYOUT_FRIENDLY_URL_PUBLIC_SERVLET_MAPPING .equals(StringPool.SLASH + friendlyURLParts[1])) { privateLayout = true; } String targetLayoutFriendlyURL = StringPool.SLASH + friendlyURLParts[3]; Layout targetLayout = _layoutLocalService.fetchLayoutByFriendlyURL(targetLayoutGroup.getGroupId(), privateLayout, targetLayoutFriendlyURL); Element feedElement = portletDataContext.getExportDataElement(feed); portletDataContext.addReferenceElement(feed, feedElement, targetLayout, PortletDataContext.REFERENCE_TYPE_DEPENDENCY, true); return content; }