List of usage examples for com.liferay.portal.kernel.util FileUtil getShortFileName
public static String getShortFileName(String fullFileName)
From source file:com.liferay.exportimport.resources.importer.internal.util.FileSystemImporter.java
License:Open Source License
protected void addDDMTemplate(long templateGroupId, long ddmStructureId, String fileName, String language, String script, String type, String mode) throws Exception { fileName = FileUtil.getShortFileName(fileName); fileName = FileUtil.stripExtension(fileName); String name = getName(fileName); DDMTemplate ddmTemplate = ddmTemplateLocalService.fetchTemplate(groupId, portal.getClassNameId(DDMStructure.class), getKey(fileName)); if (ddmTemplate != null) { if (!developerModeEnabled) { if (_log.isInfoEnabled()) { _log.info(StringBundler.concat("DDM template with name ", name, " and version ", String.valueOf(version), " already exists")); }// ww w . j ava 2 s . co m return; } if (!updateModeEnabled) { ddmTemplateLocalService.deleteTemplate(ddmTemplate); } } try { if (!updateModeEnabled || (ddmTemplate == null)) { ddmTemplateLocalService.addTemplate(userId, templateGroupId, portal.getClassNameId(DDMStructure.class), ddmStructureId, portal.getClassNameId(JournalArticle.class), getKey(fileName), getMap(name), null, type, mode, language, script, true, false, StringPool.BLANK, null, serviceContext); } else { ddmTemplateLocalService.updateTemplate(userId, ddmTemplate.getTemplateId(), portal.getClassNameId(DDMStructure.class), getMap(name), null, DDMTemplateConstants.TEMPLATE_TYPE_DISPLAY, null, language, script, ddmTemplate.getCacheable(), serviceContext); } } catch (PortalException pe) { if (_log.isWarnEnabled()) { _log.warn("Unable to import DDM template " + fileName, pe); } throw pe; } }
From source file:com.liferay.exportimport.resources.importer.internal.util.ResourceImporter.java
License:Open Source License
@Override protected void addDDMStructures(String parentStructureId, String dirName) throws Exception { Set<String> resourcePaths = servletContext.getResourcePaths(_getResourcePath(dirName)); if (resourcePaths == null) { return;//w w w . j a v a 2 s.c o m } for (String resourcePath : resourcePaths) { if (resourcePath.endsWith(StringPool.SLASH)) { continue; } String name = FileUtil.getShortFileName(resourcePath); URL url = servletContext.getResource(resourcePath); URLConnection urlConnection = url.openConnection(); addDDMStructures(parentStructureId, name, urlConnection.getInputStream()); } }
From source file:com.liferay.exportimport.resources.importer.internal.util.ResourceImporter.java
License:Open Source License
@Override protected void addDDMTemplates(String ddmStructureKey, String dirName) throws Exception { Set<String> resourcePaths = servletContext.getResourcePaths(_getResourcePath(dirName)); if (resourcePaths == null) { return;// www .ja va 2s . c o m } for (String resourcePath : resourcePaths) { if (resourcePath.endsWith(StringPool.SLASH)) { continue; } String name = FileUtil.getShortFileName(resourcePath); URL url = servletContext.getResource(resourcePath); URLConnection urlConnection = url.openConnection(); addDDMTemplates(ddmStructureKey, name, urlConnection.getInputStream()); } }
From source file:com.liferay.exportimport.resources.importer.internal.util.ResourceImporter.java
License:Open Source License
protected void addDLFileEntry(String resourcePath) throws Exception { Long parentFolderId = _folderIds.get(FileUtil.getPath(resourcePath) + StringPool.SLASH); if (parentFolderId == null) { parentFolderId = 0L;//w w w .j a v a 2 s . c o m } URL url = servletContext.getResource(resourcePath); URLConnection urlConnection = url.openConnection(); addDLFileEntry(parentFolderId, FileUtil.getShortFileName(resourcePath), urlConnection.getInputStream(), urlConnection.getContentLength()); }
From source file:com.liferay.exportimport.resources.importer.internal.util.ResourceImporter.java
License:Open Source License
@Override protected long addDLFolder(long parentFolderId, String resourcePath) throws Exception { long folderId = super.addDLFolder(parentFolderId, FileUtil.getShortFileName(FileUtil.getPath(resourcePath))); _folderIds.put(resourcePath, folderId); Set<String> resourcePaths = servletContext.getResourcePaths(resourcePath); if ((resourcePaths == null) || resourcePaths.isEmpty()) { return folderId; }/* www. java 2s. c o m*/ for (String curResourcePath : resourcePaths) { if (curResourcePath.endsWith(StringPool.SLASH)) { addDLFolder(folderId, curResourcePath); } else { addDLFileEntry(curResourcePath); } } return folderId; }
From source file:com.liferay.exportimport.resources.importer.internal.util.ResourceImporter.java
License:Open Source License
@Override protected void addJournalArticles(String ddmStructureKey, String ddmTemplateKey, String dirName, long folderId) throws Exception { Set<String> resourcePaths = servletContext.getResourcePaths(_getResourcePath(dirName)); if (resourcePaths == null) { return;/* w w w .ja va 2 s . com*/ } for (String resourcePath : resourcePaths) { if (resourcePath.endsWith(StringPool.SLASH)) { String folderName = FileUtil.getShortFileName( StringUtil.replaceLast(resourcePath, CharPool.FORWARD_SLASH, StringPool.BLANK)); JournalFolder journalFolder = journalFolderLocalService.fetchFolder(groupId, folderName); if (journalFolder == null) { journalFolder = journalFolderLocalService.addFolder(userId, groupId, folderId, folderName, StringPool.BLANK, serviceContext); } addJournalArticles(ddmStructureKey, ddmTemplateKey, dirName + CharPool.FORWARD_SLASH + folderName, journalFolder.getFolderId()); } else { String name = FileUtil.getShortFileName(resourcePath); URL url = servletContext.getResource(resourcePath); URLConnection urlConnection = url.openConnection(); addJournalArticles(ddmStructureKey, ddmTemplateKey, name, folderId, urlConnection.getInputStream()); } } }
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 w w . j a va 2s . co m }
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 {/*from w w w . j a v a 2 s. c o 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.opensocial.shindig.service.LiferayMediaItemService.java
License:Open Source License
protected String getFileName(MediaItem mediaItem, Http.Options options) { Http.Response response = options.getResponse(); String contentDisposition = response.getHeader(HttpHeaders.CONTENT_DISPOSITION); if (contentDisposition == null) { return FileUtil.getShortFileName(mediaItem.getUrl()); }/*from ww w .j a va 2s . c o m*/ Matcher fileNameMatcher = _fileNamePattern.matcher(contentDisposition); if (fileNameMatcher.find()) { return fileNameMatcher.group(1); } else { return mediaItem.getTitle(); } }
From source file:com.liferay.portlet.calendar.action.ExportEventsAction.java
License:Open Source License
@Override public void processAction(ActionMapping mapping, ActionForm form, PortletConfig portletConfig, ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { File file = null;/*from w w w . j a v a 2s . com*/ try { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long eventId = ParamUtil.getLong(actionRequest, "eventId"); String exportFileName = ParamUtil.getString(actionRequest, "exportFileName"); if (Validator.isNull(exportFileName)) { exportFileName = "liferay.ics"; } else { exportFileName = FileUtil.getShortFileName(exportFileName); } if (eventId > 0) { file = CalEventServiceUtil.exportEvent(eventId); } else { file = CalEventServiceUtil.exportGroupEvents(themeDisplay.getScopeGroupId(), exportFileName); } HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest); HttpServletResponse response = PortalUtil.getHttpServletResponse(actionResponse); ServletResponseUtil.sendFile(request, response, exportFileName, new FileInputStream(file), ContentTypes.TEXT_CALENDAR); setForward(actionRequest, ActionConstants.COMMON_NULL); } catch (Exception e) { _log.error(e, e); } finally { FileUtil.delete(file); } }