List of usage examples for com.liferay.portal.kernel.util StringPool UTF8
String UTF8
To view the source code for com.liferay.portal.kernel.util StringPool UTF8.
Click Source Link
From source file:com.liferay.portlet.documentlibrary.service.persistence.DLContentPersistenceTest.java
License:Open Source License
public void testUpdateExisting() throws Exception { long pk = nextLong(); DLContent newDLContent = _persistence.create(pk); newDLContent.setGroupId(nextLong()); newDLContent.setCompanyId(nextLong()); newDLContent.setRepositoryId(nextLong()); newDLContent.setPath(randomString()); newDLContent.setVersion(randomString()); String newDataString = randomString(); byte[] newDataBytes = newDataString.getBytes(StringPool.UTF8); Blob newDataBlob = new OutputBlob(new UnsyncByteArrayInputStream(newDataBytes), newDataBytes.length); newDLContent.setData(newDataBlob);// w w w. java 2 s.c o m newDLContent.setSize(nextLong()); _persistence.update(newDLContent, false); DLContent existingDLContent = _persistence.findByPrimaryKey(newDLContent.getPrimaryKey()); assertEquals(existingDLContent.getContentId(), newDLContent.getContentId()); assertEquals(existingDLContent.getGroupId(), newDLContent.getGroupId()); assertEquals(existingDLContent.getCompanyId(), newDLContent.getCompanyId()); assertEquals(existingDLContent.getRepositoryId(), newDLContent.getRepositoryId()); assertEquals(existingDLContent.getPath(), newDLContent.getPath()); assertEquals(existingDLContent.getVersion(), newDLContent.getVersion()); Blob existingData = existingDLContent.getData(); assertTrue(Arrays.equals(existingData.getBytes(1, (int) existingData.length()), newDataBytes)); assertEquals(existingDLContent.getSize(), newDLContent.getSize()); }
From source file:com.liferay.portlet.documentlibrary.service.persistence.DLContentPersistenceTest.java
License:Open Source License
protected DLContent addDLContent() throws Exception { long pk = nextLong(); DLContent dlContent = _persistence.create(pk); dlContent.setGroupId(nextLong());//from ww w .ja v a 2 s . c o m dlContent.setCompanyId(nextLong()); dlContent.setRepositoryId(nextLong()); dlContent.setPath(randomString()); dlContent.setVersion(randomString()); String dataString = randomString(); byte[] dataBytes = dataString.getBytes(StringPool.UTF8); Blob dataBlob = new OutputBlob(new UnsyncByteArrayInputStream(dataBytes), dataBytes.length); dlContent.setData(dataBlob); dlContent.setSize(nextLong()); _persistence.update(dlContent, false); return dlContent; }
From source file:com.liferay.portlet.journal.action.GetArticlesAction.java
License:Open Source License
protected byte[] getContent(HttpServletRequest request, List<JournalArticle> articles) throws Exception { long groupId = ParamUtil.getLong(request, "groupId"); String languageId = LanguageUtil.getLanguageId(request); ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); Map<String, String> tokens = JournalUtil.getTokens(groupId, themeDisplay); Document resultsDoc = SAXReaderUtil.createDocument(StringPool.UTF8); Element resultSetEl = resultsDoc.addElement("result-set"); for (JournalArticle article : articles) { Element resultEl = resultSetEl.addElement("result"); Document articleDoc = SAXReaderUtil.read(article.getContentByLocale(languageId)); resultEl.content().add(articleDoc.getRootElement().createCopy()); resultEl = resultEl.element("root"); JournalUtil.addAllReservedEls(resultEl, tokens, article, languageId); }/*from w ww .ja va 2 s. co m*/ return DDMXMLUtil.formatXML(resultsDoc).getBytes(StringPool.UTF8); }
From source file:com.liferay.portlet.journal.action.RSSAction.java
License:Open Source License
protected byte[] getRSS(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); JournalFeed feed = null;/*w ww . ja va2 s . c o m*/ long id = ParamUtil.getLong(resourceRequest, "id"); long groupId = ParamUtil.getLong(resourceRequest, "groupId"); String feedId = ParamUtil.getString(resourceRequest, "feedId"); if (id > 0) { feed = JournalFeedLocalServiceUtil.getFeed(id); } else { feed = JournalFeedLocalServiceUtil.getFeed(groupId, feedId); } String languageId = LanguageUtil.getLanguageId(resourceRequest); long plid = PortalUtil.getPlidFromFriendlyURL(themeDisplay.getCompanyId(), feed.getTargetLayoutFriendlyUrl()); Layout layout = themeDisplay.getLayout(); if (plid > 0) { try { layout = LayoutLocalServiceUtil.getLayout(plid); } catch (NoSuchLayoutException nsle) { } } String rss = exportToRSS(resourceRequest, resourceResponse, feed, languageId, layout, themeDisplay); return rss.getBytes(StringPool.UTF8); }
From source file:com.liferay.portlet.journal.webdav.JournalStructureResourceImpl.java
License:Open Source License
@Override public InputStream getContentAsStream() throws WebDAVException { try {// w w w . j av a 2s .co m return new UnsyncByteArrayInputStream(_structure.getXsd().getBytes(StringPool.UTF8)); } catch (Exception e) { throw new WebDAVException(e); } }
From source file:com.liferay.portlet.journal.webdav.JournalTemplateResourceImpl.java
License:Open Source License
@Override public InputStream getContentAsStream() throws WebDAVException { try {/* ww w .ja v a 2 s . c o m*/ return new UnsyncByteArrayInputStream(_template.getXsl().getBytes(StringPool.UTF8)); } catch (Exception e) { throw new WebDAVException(e); } }
From source file:com.liferay.portlet.journalcontent.action.ExportArticleAction.java
License:Open Source License
protected void getFile(long groupId, String articleId, String targetExtension, String[] allowedExtensions, String languageId, ThemeDisplay themeDisplay, HttpServletRequest request, HttpServletResponse response) throws Exception { try {/*from www .j a va2s . c o m*/ JournalArticleDisplay articleDisplay = JournalContentUtil.getDisplay(groupId, articleId, null, languageId, themeDisplay); int pages = articleDisplay.getNumberOfPages(); StringBundler sb = new StringBundler(pages + 12); sb.append("<html>"); sb.append("<head>"); sb.append("<meta content=\""); sb.append(ContentTypes.TEXT_HTML_UTF8); sb.append("\" http-equiv=\"content-type\" />"); sb.append("<base href=\""); sb.append(themeDisplay.getPortalURL()); sb.append("\" />"); sb.append("</head>"); sb.append("<body>"); sb.append(articleDisplay.getContent()); for (int i = 2; i <= pages; i++) { articleDisplay = JournalContentUtil.getDisplay(groupId, articleId, "export", languageId, themeDisplay, i); sb.append(articleDisplay.getContent()); } sb.append("</body>"); sb.append("</html>"); InputStream is = new UnsyncByteArrayInputStream(sb.toString().getBytes(StringPool.UTF8)); String title = articleDisplay.getTitle(); String sourceExtension = "html"; String fileName = title.concat(StringPool.PERIOD).concat(sourceExtension); if (Validator.isNotNull(targetExtension) && ArrayUtil.contains(allowedExtensions, targetExtension)) { String id = DLUtil.getTempFileId(articleDisplay.getId(), String.valueOf(articleDisplay.getVersion()), languageId); File convertedFile = DocumentConversionUtil.convert(id, is, sourceExtension, targetExtension); if (convertedFile != null) { fileName = title.concat(StringPool.PERIOD).concat(targetExtension); is = new FileInputStream(convertedFile); } } String contentType = MimeTypesUtil.getContentType(fileName); ServletResponseUtil.sendFile(request, response, fileName, is, contentType); } catch (Exception e) { _log.error(e, e); } }
From source file:com.liferay.portlet.journalcontent.action.WebContentAction.java
License:Open Source License
@Override public void serveResource(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws Exception { String contentType = ParamUtil.getString(resourceRequest, "contentType"); if (Validator.isNotNull(contentType)) { resourceResponse.setContentType(contentType); }//w w w .j a v a 2 s. co m if (resourceRequest.getResourceID() != null) { super.serveResource(mapping, form, portletConfig, resourceRequest, resourceResponse); } else { PortletPreferences preferences = resourceRequest.getPreferences(); ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY); long groupId = ParamUtil.getLong(resourceRequest, "groupId"); if (groupId < 1) { groupId = GetterUtil.getLong(preferences.getValue("groupId", StringPool.BLANK)); } String articleId = ParamUtil.getString(resourceRequest, "articleId"); String templateId = ParamUtil.getString(resourceRequest, "templateId"); if (Validator.isNull(articleId)) { articleId = GetterUtil.getString(preferences.getValue("articleId", StringPool.BLANK)); templateId = GetterUtil.getString(preferences.getValue("templateId", StringPool.BLANK)); } String viewMode = ParamUtil.getString(resourceRequest, "viewMode"); String languageId = LanguageUtil.getLanguageId(resourceRequest); int page = ParamUtil.getInteger(resourceRequest, "page", 1); String xmlRequest = PortletRequestUtil.toXML(resourceRequest, resourceResponse); JournalArticleDisplay articleDisplay = null; if ((groupId > 0) && Validator.isNotNull(articleId)) { articleDisplay = JournalContentUtil.getDisplay(groupId, articleId, templateId, viewMode, languageId, themeDisplay, page, xmlRequest); } if (articleDisplay != null) { OutputStream os = resourceResponse.getPortletOutputStream(); try { String content = articleDisplay.getContent(); byte[] bytes = content.getBytes(StringPool.UTF8); os.write(bytes); } finally { os.close(); } } } }
From source file:com.liferay.portlet.layoutsadmin.action.RobotsAction.java
License:Open Source License
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { try {/*from ww w . j a va 2 s .c o m*/ String host = GetterUtil.getString(PortalUtil.getHost(request)); LayoutSet layoutSet = null; try { layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(host); } catch (LayoutSetVirtualHostException lsvhe) { Company company = PortalUtil.getCompany(request); if (host.equals(company.getVirtualHostname()) && Validator.isNotNull(PropsValues.VIRTUAL_HOSTS_DEFAULT_SITE_NAME)) { Group defaultGroup = GroupLocalServiceUtil.getGroup(company.getCompanyId(), PropsValues.VIRTUAL_HOSTS_DEFAULT_SITE_NAME); layoutSet = defaultGroup.getPublicLayoutSet(); } } /*================ start changes ================*/ catch (NoSuchLayoutSetException | NoSuchVirtualHostException nse) { if (_log.isErrorEnabled()) { _log.error( "Ignored exception: " + nse.getMessage() + " Headers: " + printRequestHeaders(request)); } } /*================ end changes ================*/ String robots = RobotsUtil.getRobots(layoutSet); ServletResponseUtil.sendFile(request, response, null, robots.getBytes(StringPool.UTF8), ContentTypes.TEXT_PLAIN_UTF8); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn(e, e); } PortalUtil.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e, request, response); } return null; }
From source file:com.liferay.portlet.layoutsadmin.action.SitemapAction.java
License:Open Source License
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { try {/*from w ww . j av a 2 s . c o m*/ ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); long groupId = ParamUtil.getLong(request, "groupId"); boolean privateLayout = ParamUtil.getBoolean(request, "privateLayout"); LayoutSet layoutSet = null; if (groupId > 0) { Group group = GroupLocalServiceUtil.getGroup(groupId); if (group.isStagingGroup()) { groupId = group.getLiveGroupId(); } layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(groupId, privateLayout); } else { String host = PortalUtil.getHost(request); layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(host); } String sitemap = SitemapUtil.getSitemap(layoutSet.getGroupId(), layoutSet.isPrivateLayout(), themeDisplay); ServletResponseUtil.sendFile(request, response, null, sitemap.getBytes(StringPool.UTF8), ContentTypes.TEXT_XML_UTF8); } catch (NoSuchLayoutSetException nslse) { PortalUtil.sendError(HttpServletResponse.SC_NOT_FOUND, nslse, request, response); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn(e, e); } PortalUtil.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e, request, response); } return null; }