List of usage examples for com.liferay.portal.kernel.util StringPool SLASH
String SLASH
To view the source code for com.liferay.portal.kernel.util StringPool SLASH.
Click Source Link
From source file:com.liferay.knowledgebase.admin.importer.KBArticleImporter.java
License:Open Source License
protected Map<String, List<String>> getFolderNameFileEntryNamesMap(ZipReader zipReader) { Map<String, List<String>> folderNameFileEntryNamesMap = new TreeMap<String, List<String>>(); for (String zipEntry : zipReader.getEntries()) { String extension = FileUtil.getExtension(zipEntry); if (!ArrayUtil.contains(PortletPropsValues.MARKDOWN_IMPORTER_ARTICLE_EXTENSIONS, StringPool.PERIOD.concat(extension))) { continue; }// www .java 2 s. co m String folderName = zipEntry.substring(0, zipEntry.lastIndexOf(StringPool.SLASH)); List<String> fileEntryNames = folderNameFileEntryNamesMap.get(folderName); if (fileEntryNames == null) { fileEntryNames = new ArrayList<String>(); } fileEntryNames.add(zipEntry); folderNameFileEntryNamesMap.put(folderName, fileEntryNames); } return folderNameFileEntryNamesMap; }
From source file:com.liferay.knowledgebase.admin.importer.PrioritizationStrategy.java
License:Open Source License
protected double getNumericalPrefix(String filePath, boolean isChildArticleFile) { double numericalPrefix = -1.0; if (isChildArticleFile) { String fileName = filePath; int i = filePath.lastIndexOf(CharPool.SLASH); if (i != -1) { fileName = filePath.substring(i + 1); }//ww w . j av a 2 s . c om String digits = StringUtil.extractLeadingDigits(fileName); if (Validator.isNull(digits)) { return numericalPrefix; } return GetterUtil.getDouble(digits); } else { String[] pathEntries = filePath.split(StringPool.SLASH); if (pathEntries == null) { String digits = StringUtil.extractLeadingDigits(filePath); if (Validator.isNull(digits)) { return numericalPrefix; } return GetterUtil.getDouble(digits); } int length = pathEntries.length; for (int i = length - 1; i > -1; i--) { String fileName = pathEntries[i]; String digits = StringUtil.extractLeadingDigits(fileName); if (Validator.isNull(digits)) { continue; } numericalPrefix = GetterUtil.getDouble(digits); if (numericalPrefix >= 1.0) { return numericalPrefix; } } } return numericalPrefix; }
From source file:com.liferay.knowledgebase.admin.importer.util.KBArticleImporterUtil.java
License:Open Source License
public static String extractImageFileName(String html) { String imageSrc = null;/* w ww . ja v a2 s .c om*/ String[] lines = StringUtil.split(html, StringPool.QUOTE); for (int i = 0; i < lines.length; i++) { if (lines[i].endsWith("src=")) { if ((i + 1) < lines.length) { imageSrc = lines[i + 1]; } break; } } if (Validator.isNull(imageSrc)) { if (_log.isWarnEnabled()) { _log.warn("Missing src attribute for image " + html); } return null; } String[] paths = StringUtil.split(imageSrc, StringPool.SLASH); if (paths.length < 1) { if (_log.isWarnEnabled()) { _log.warn("Expected image file path to contain a slash " + html); } return null; } return paths[paths.length - 1]; }
From source file:com.liferay.knowledgebase.admin.importer.util.KBArticleMarkdownConverter.java
License:Open Source License
protected String buildSourceURL(String baseSourceURL, String fileEntryName) { if (!Validator.isUrl(baseSourceURL)) { return null; }//w ww .jav a2 s . c om int pos = baseSourceURL.length() - 1; while (pos >= 0) { char c = baseSourceURL.charAt(pos); if (c != CharPool.SLASH) { break; } pos--; } StringBundler sb = new StringBundler(3); sb.append(baseSourceURL.substring(0, pos + 1)); if (!fileEntryName.startsWith(StringPool.SLASH)) { sb.append(StringPool.SLASH); } sb.append(fileEntryName); return sb.toString(); }
From source file:com.liferay.knowledgebase.admin.importer.util.KBArticleMarkdownConverter.java
License:Open Source License
protected String getUrlTitle(String heading) { String urlTitle = null;/* w w w .j a v a 2 s . c o m*/ int x = heading.indexOf("[](id="); int y = heading.indexOf(StringPool.CLOSE_PARENTHESIS, x); if (y > (x + 1)) { int equalsSign = heading.indexOf(StringPool.EQUAL, x); urlTitle = heading.substring(equalsSign + 1, y); urlTitle = StringUtil.replace(urlTitle, StringPool.SPACE, StringPool.DASH); urlTitle = StringUtil.toLowerCase(urlTitle); } if (!urlTitle.startsWith(StringPool.SLASH)) { urlTitle = StringPool.SLASH + urlTitle; } return urlTitle; }
From source file:com.liferay.knowledgebase.admin.lar.AdminPortletDataHandlerImpl.java
License:Open Source License
protected void exportKBArticleAttachments(PortletDataContext portletDataContext, Element rootElement, KBArticle kbArticle) throws Exception { Element kbArticleAttachmentsElement = rootElement.addElement("kb-article-attachments"); kbArticleAttachmentsElement.addAttribute("resource-prim-key", String.valueOf(kbArticle.getResourcePrimKey())); String rootPath = getPortletPath(portletDataContext) + "/kbarticles/attachments/" + kbArticle.getResourcePrimKey(); for (String fileName : kbArticle.getAttachmentsFileNames()) { String shortFileName = FileUtil.getShortFileName(fileName); String path = rootPath + StringPool.SLASH + shortFileName; byte[] bytes = DLStoreUtil.getFileAsBytes(kbArticle.getCompanyId(), CompanyConstants.SYSTEM, fileName); Element fileElement = kbArticleAttachmentsElement.addElement("file"); fileElement.addAttribute("path", path); fileElement.addAttribute("short-file-name", shortFileName); portletDataContext.addZipEntry(path, bytes); }/*from w ww . j a va 2s .c o m*/ }
From source file:com.liferay.knowledgebase.admin.lar.AdminPortletDataHandlerImpl.java
License:Open Source License
protected void exportKBArticleVersions(PortletDataContext portletDataContext, Element kbArticleElement, long resourcePrimKey) throws Exception { Element versionsElement = kbArticleElement.addElement("versions"); String rootPath = getPortletPath(portletDataContext) + "/kbarticles/versions/" + resourcePrimKey; List<KBArticle> kbArticles = KBArticleUtil.findByR_S(resourcePrimKey, WorkflowConstants.STATUS_APPROVED, QueryUtil.ALL_POS, QueryUtil.ALL_POS, new KBArticleModifiedDateComparator(true)); for (KBArticle kbArticle : kbArticles) { String path = rootPath + StringPool.SLASH + kbArticle.getKbArticleId() + ".xml"; Element curKBArticleElement = versionsElement.addElement("kb-article"); curKBArticleElement.addAttribute("path", path); portletDataContext.addZipEntry(path, kbArticle); }// w ww . ja v a 2s . c o m }
From source file:com.liferay.knowledgebase.admin.lar.AdminPortletDataHandlerImpl.java
License:Open Source License
protected void importKBArticleAttachments(PortletDataContext portletDataContext, long importId, Map<String, String> dirNames, Element rootElement) throws Exception { List<Element> kbArticleAttachmentsElements = rootElement.elements("kb-article-attachments"); for (Element kbArticleAttachmentsElement : kbArticleAttachmentsElements) { String resourcePrimKey = kbArticleAttachmentsElement.attributeValue("resource-prim-key"); String dirName = "knowledgebase/temp/import/" + importId + StringPool.SLASH + resourcePrimKey; DLStoreUtil.addDirectory(portletDataContext.getCompanyId(), CompanyConstants.SYSTEM, dirName); List<Element> fileElements = kbArticleAttachmentsElement.elements("file"); ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(portletDataContext.getCompanyId()); serviceContext.setScopeGroupId(portletDataContext.getScopeGroupId()); for (Element fileElement : fileElements) { String shortFileName = fileElement.attributeValue("short-file-name"); String fileName = dirName + StringPool.SLASH + shortFileName; byte[] bytes = portletDataContext.getZipEntryAsByteArray(fileElement.attributeValue("path")); DLStoreUtil.addFile(portletDataContext.getCompanyId(), CompanyConstants.SYSTEM, fileName, bytes); }// w ww. java 2 s . c o m dirNames.put(resourcePrimKey, dirName); } }
From source file:com.liferay.knowledgebase.hook.upgrade.v1_1_0.util.KBArticleAttachmentsUtil.java
License:Open Source License
public static void updateAttachments(KBArticle kbArticle) { try {/* w ww . j a v a2 s. co m*/ long folderId = kbArticle.getClassPK(); String oldDirName = "knowledgebase/articles/" + folderId; String newDirName = "knowledgebase/kbarticles/" + folderId; DLStoreUtil.addDirectory(kbArticle.getCompanyId(), CompanyConstants.SYSTEM, newDirName); String[] fileNames = DLStoreUtil.getFileNames(kbArticle.getCompanyId(), CompanyConstants.SYSTEM, oldDirName); ServiceContext serviceContext = new ServiceContext(); serviceContext.setCompanyId(kbArticle.getCompanyId()); serviceContext.setScopeGroupId(kbArticle.getGroupId()); for (String fileName : fileNames) { String shortFileName = FileUtil.getShortFileName(fileName); byte[] bytes = DLStoreUtil.getFileAsBytes(kbArticle.getCompanyId(), CompanyConstants.SYSTEM, fileName); DLStoreUtil.addFile(kbArticle.getCompanyId(), CompanyConstants.SYSTEM, newDirName + StringPool.SLASH + shortFileName, bytes); } DLStoreUtil.deleteDirectory(kbArticle.getCompanyId(), CompanyConstants.SYSTEM, oldDirName); if (_log.isInfoEnabled()) { _log.info("Added attachments for " + folderId); } } catch (Exception e) { _log.error(e.getMessage()); } }
From source file:com.liferay.knowledgebase.service.impl.KBArticleLocalServiceImpl.java
License:Open Source License
@Override public KBArticle fetchKBArticleByUrlTitle(long groupId, long kbFolderId, String urlTitle) { urlTitle = StringUtil.replaceFirst(urlTitle, StringPool.SLASH, StringPool.BLANK); KBArticle kbArticle = fetchLatestKBArticleByUrlTitle(groupId, kbFolderId, urlTitle, WorkflowConstants.STATUS_APPROVED); if (kbArticle == null) { kbArticle = fetchLatestKBArticleByUrlTitle(groupId, kbFolderId, urlTitle, WorkflowConstants.STATUS_PENDING); }//from www . j a v a2 s .c om return kbArticle; }