List of usage examples for com.liferay.portal.kernel.util FileUtil getExtension
public static String getExtension(String fileName)
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public Status lockResource(WebDAVRequest webDAVRequest, String owner, long timeout) throws WebDAVException { Resource resource = getResource(webDAVRequest); Lock lock = null;//from ww w. j av a 2 s . c om int status = HttpServletResponse.SC_OK; try { if (resource == null) { status = HttpServletResponse.SC_CREATED; HttpServletRequest request = webDAVRequest.getHttpServletRequest(); String[] pathArray = webDAVRequest.getPathArray(); long companyId = webDAVRequest.getCompanyId(); long groupId = webDAVRequest.getGroupId(); long parentFolderId = getParentFolderId(companyId, pathArray); String title = getTitle(pathArray); String extension = FileUtil.getExtension(title); String contentType = getContentType(request, null, title, extension); String description = StringPool.BLANK; String changeLog = StringPool.BLANK; File file = FileUtil.createTempFile(extension); file.createNewFile(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); FileEntry fileEntry = _dlAppService.addFileEntry(groupId, parentFolderId, title, contentType, title, description, changeLog, file, serviceContext); resource = toResource(webDAVRequest, fileEntry, false); } if (resource instanceof DLFileEntryResourceImpl) { FileEntry fileEntry = (FileEntry) resource.getModel(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAttribute(DL.MANUAL_CHECK_IN_REQUIRED, webDAVRequest.isManualCheckInRequired()); populateServiceContext(serviceContext, fileEntry); _dlAppService.checkOutFileEntry(fileEntry.getFileEntryId(), owner, timeout, serviceContext); lock = fileEntry.getLock(); } else { boolean inheritable = false; long depth = WebDAVUtil.getDepth(webDAVRequest.getHttpServletRequest()); if (depth != 0) { inheritable = true; } Folder folder = (Folder) resource.getModel(); lock = _dlAppService.lockFolder(folder.getRepositoryId(), folder.getFolderId(), owner, inheritable, timeout); } } catch (Exception e) { // DuplicateLock is 423 not 501 if (!(e instanceof DuplicateLockException)) { throw new WebDAVException(e); } status = WebDAVUtil.SC_LOCKED; } return new Status(lock, status); }
From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public int putResource(WebDAVRequest webDAVRequest) throws WebDAVException { File file = null;/*from www .j a va 2s. c o m*/ try { HttpServletRequest request = webDAVRequest.getHttpServletRequest(); String[] pathArray = webDAVRequest.getPathArray(); long companyId = webDAVRequest.getCompanyId(); long groupId = webDAVRequest.getGroupId(); long parentFolderId = getParentFolderId(companyId, pathArray); String title = getTitle(pathArray); String description = StringPool.BLANK; String changeLog = StringPool.BLANK; ServiceContext serviceContext = ServiceContextFactory.getInstance(request); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); String extension = FileUtil.getExtension(title); file = FileUtil.createTempFile(extension); FileUtil.write(file, request.getInputStream()); String contentType = getContentType(request, file, title, extension); try { FileEntry fileEntry = _dlAppService.getFileEntry(groupId, parentFolderId, title); if (!hasLock(fileEntry, webDAVRequest.getLockUuid()) && (fileEntry.getLock() != null)) { return WebDAVUtil.SC_LOCKED; } long fileEntryId = fileEntry.getFileEntryId(); description = fileEntry.getDescription(); populateServiceContext(serviceContext, fileEntry); serviceContext.setCommand(Constants.UPDATE_WEBDAV); _dlAppService.updateFileEntry(fileEntryId, title, contentType, title, description, changeLog, false, file, serviceContext); } catch (NoSuchFileEntryException nsfee) { if (_log.isDebugEnabled()) { _log.debug(nsfee, nsfee); } serviceContext.setCommand(Constants.ADD_WEBDAV); _dlAppService.addFileEntry(groupId, parentFolderId, title, contentType, title, description, changeLog, file, serviceContext); } if (_log.isInfoEnabled()) { _log.info("Added " + StringUtil.merge(pathArray, StringPool.SLASH)); } return HttpServletResponse.SC_CREATED; } catch (FileSizeException fse) { if (_log.isDebugEnabled()) { _log.debug(fse, fse); } return HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE; } catch (NoSuchFolderException nsfe) { if (_log.isDebugEnabled()) { _log.debug(nsfe, nsfe); } return HttpServletResponse.SC_CONFLICT; } catch (PrincipalException pe) { if (_log.isDebugEnabled()) { _log.debug(pe, pe); } return HttpServletResponse.SC_FORBIDDEN; } catch (PortalException pe) { if (_log.isWarnEnabled()) { _log.warn(pe, pe); } return HttpServletResponse.SC_CONFLICT; } catch (Exception e) { throw new WebDAVException(e); } finally { FileUtil.delete(file); } }
From source file:com.liferay.document.library.web.webdav.DLWebDAVStorageImpl.java
License:Open Source License
@Override public Status lockResource(WebDAVRequest webDAVRequest, String owner, long timeout) throws WebDAVException { Resource resource = getResource(webDAVRequest); Lock lock = null;/*from ww w .j a v a 2 s. c o m*/ int status = HttpServletResponse.SC_OK; try { if (resource == null) { status = HttpServletResponse.SC_CREATED; HttpServletRequest request = webDAVRequest.getHttpServletRequest(); String[] pathArray = webDAVRequest.getPathArray(); long companyId = webDAVRequest.getCompanyId(); long groupId = webDAVRequest.getGroupId(); long parentFolderId = getParentFolderId(companyId, pathArray); String title = getTitle(pathArray); String extension = FileUtil.getExtension(title); String contentType = getContentType(request, null, title, extension); String description = StringPool.BLANK; String changeLog = StringPool.BLANK; File file = FileUtil.createTempFile(extension); file.createNewFile(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddGroupPermissions(isAddGroupPermissions(groupId)); serviceContext.setAddGuestPermissions(true); FileEntry fileEntry = _dlAppService.addFileEntry(groupId, parentFolderId, title, contentType, title, description, changeLog, file, serviceContext); resource = toResource(webDAVRequest, fileEntry, false); } if (resource instanceof DLFileEntryResourceImpl) { FileEntry fileEntry = (FileEntry) resource.getModel(); ServiceContext serviceContext = new ServiceContext(); serviceContext.setAttribute(DL.MANUAL_CHECK_IN_REQUIRED, webDAVRequest.isManualCheckInRequired()); _dlAppService.checkOutFileEntry(fileEntry.getFileEntryId(), owner, timeout, serviceContext); lock = fileEntry.getLock(); } else { boolean inheritable = false; long depth = WebDAVUtil.getDepth(webDAVRequest.getHttpServletRequest()); if (depth != 0) { inheritable = true; } Folder folder = (Folder) resource.getModel(); lock = _dlAppService.lockFolder(folder.getRepositoryId(), folder.getFolderId(), owner, inheritable, timeout); } } catch (Exception e) { // DuplicateLock is 423 not 501 if (!(e instanceof DuplicateLockException)) { throw new WebDAVException(e); } status = WebDAVUtil.SC_LOCKED; } return new Status(lock, status); }
From source file:com.liferay.exportimport.resources.importer.internal.util.FileSystemImporter.java
License:Open Source License
protected String getDDMStructureLanguage(String fileName) { String extension = FileUtil.getExtension(fileName); if (extension.equals(TemplateConstants.LANG_TYPE_JSON) || extension.equals(TemplateConstants.LANG_TYPE_XML)) { return extension; }//from w w w . ja v a2s. c o m return TemplateConstants.LANG_TYPE_XML; }
From source file:com.liferay.exportimport.resources.importer.internal.util.FileSystemImporter.java
License:Open Source License
protected String getDDMTemplateLanguage(String fileName) { String extension = FileUtil.getExtension(fileName); if (extension.equals(TemplateConstants.LANG_TYPE_CSS) || extension.equals(TemplateConstants.LANG_TYPE_FTL) || extension.equals(TemplateConstants.LANG_TYPE_VM) || extension.equals(TemplateConstants.LANG_TYPE_XSL)) { return extension; }/*from ww w. j a v a 2 s . co m*/ return TemplateConstants.LANG_TYPE_VM; }
From source file:com.liferay.exportimport.resources.importer.internal.util.ResourceImporter.java
License:Open Source License
@Override protected void addLayoutPrototype(String dirName) throws Exception { Set<String> resourcePaths = servletContext.getResourcePaths(_getResourcePath(dirName)); if (resourcePaths == null) { return;//from w w w .ja v a2s . co m } for (String resourcePath : resourcePaths) { String extension = FileUtil.getExtension(resourcePath); if (!extension.equals("json")) { return; } URL url = servletContext.getResource(resourcePath); URLConnection urlConnection = url.openConnection(); addLayoutPrototype(urlConnection.getInputStream()); } }
From source file:com.liferay.httpservice.internal.servlet.BundleServletContext.java
License:Open Source License
@Override public RequestDispatcher getRequestDispatcher(String path) { String portalContextPath = PortalUtil.getPathContext(); String contextPath = getContextPath(); if (Validator.isNotNull(portalContextPath) && contextPath.startsWith(portalContextPath)) { contextPath = contextPath.substring(portalContextPath.length()); }//from w w w . j a v a2 s.c om if (path.startsWith(_PATH_MODULE_SLASH) && path.startsWith(contextPath)) { path = path.substring(contextPath.length()); } if (Validator.isNull(path)) { path = StringPool.SLASH; } if (!isValidPath(path)) { return null; } BundleFilterChain bundleFilterChain = getFilterChain(path); if (_servletsByURLPatterns.containsKey(path)) { bundleFilterChain.setServlet(_servletsByURLPatterns.get(path)); return new BundleRequestDispatcher(path, false, path, this, bundleFilterChain); } String extension = StringUtil.toLowerCase(FileUtil.getExtension(path)); boolean extensionMapping = false; if (Validator.isNotNull(extension)) { extension = "*.".concat(extension); extensionMapping = true; } String alias = path.substring(0, path.lastIndexOf(StringPool.SLASH)); while (alias.length() != 0) { if (_servletsByURLPatterns.containsKey(alias)) { bundleFilterChain.setServlet(_servletsByURLPatterns.get(alias)); return new BundleRequestDispatcher(alias, false, path, this, bundleFilterChain); } else if (_servletsByURLPatterns.containsKey(alias.concat(extension))) { bundleFilterChain.setServlet(_servletsByURLPatterns.get(alias.concat(extension))); return new BundleRequestDispatcher(alias.concat(extension), true, path, this, bundleFilterChain); } alias = path.substring(0, alias.lastIndexOf(StringPool.SLASH)); } if (_servletsByURLPatterns.containsKey(StringPool.SLASH.concat(extension))) { bundleFilterChain.setServlet(_servletsByURLPatterns.get(StringPool.SLASH.concat(extension))); return new BundleRequestDispatcher(StringPool.SLASH.concat(extension), extensionMapping, path, this, bundleFilterChain); } if (_servletsByURLPatterns.containsKey(StringPool.SLASH)) { bundleFilterChain.setServlet(_servletsByURLPatterns.get(StringPool.SLASH)); return new BundleRequestDispatcher(StringPool.SLASH, false, path, this, bundleFilterChain); } return null; }
From source file:com.liferay.journal.web.internal.upload.ImageJournalUploadFileEntryHandler.java
License:Open Source License
private void _validateFile(String fileName, long size) throws PortalException { _dlValidator.validateFileSize(fileName, size); String extension = FileUtil.getExtension(fileName); for (String imageExtension : _journalFileUploadsConfiguration.imageExtensions()) { if (StringPool.STAR.equals(imageExtension) || imageExtension.equals(StringPool.PERIOD + extension)) { return; }//from ww w .j av a 2s . c o m } throw new ImageTypeException("Invalid image type for file name " + fileName); }
From source file:com.liferay.journal.web.internal.upload.ImageJournalUploadHandler.java
License:Open Source License
@Override public void validateFile(String fileName, String contentType, long size) throws PortalException { _dlValidator.validateFileSize(fileName, size); String extension = FileUtil.getExtension(fileName); for (String imageExtension : _journalFileUploadsConfiguration.imageExtensions()) { if (StringPool.STAR.equals(imageExtension) || imageExtension.equals(StringPool.PERIOD + extension)) { return; }/*from w ww .j a v a 2 s . com*/ } throw new ImageTypeException("Invalid image type for file name " + fileName); }
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; }//from www . j a v a 2s. c om 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; }