protected String fileUpload( CommandArgument commandArgument, String fileName, File file, String extension) { try { Group group = commandArgument.getCurrentGroup(); Folder folder = _getFolder(group.getGroupId(), commandArgument.getCurrentFolder()); long folderId = folder.getFolderId(); String title = fileName; String description = StringPool.BLANK; String changeLog = StringPool.BLANK; ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddCommunityPermissions(true); serviceContext.setAddGuestPermissions(true); DLAppServiceUtil.addFileEntry( group.getGroupId(), folderId, title, description, changeLog, file, serviceContext); } catch (Exception e) { throw new FCKException(e); } return "0"; }
private void _getFolders(CommandArgument commandArgument, Document document, Node rootNode) throws Exception { Element foldersElement = document.createElement("Folders"); rootNode.appendChild(foldersElement); if (commandArgument.getCurrentFolder().equals(StringPool.SLASH)) { getRootFolders(commandArgument, document, foldersElement); } else { Group group = commandArgument.getCurrentGroup(); Folder folder = _getFolder(group.getGroupId(), commandArgument.getCurrentFolder()); List<Folder> folders = DLAppServiceUtil.getFolders(group.getGroupId(), folder.getFolderId()); for (Folder curFolder : folders) { Element folderElement = document.createElement("Folder"); foldersElement.appendChild(folderElement); folderElement.setAttribute("name", curFolder.getName()); } } }
private void _getFolders(CommandArgument commandArgument, Document document, Node rootNode) throws Exception { Element foldersElement = document.createElement("Folders"); rootNode.appendChild(foldersElement); if (commandArgument.getCurrentFolder().equals(StringPool.SLASH)) { getRootFolders(commandArgument, document, foldersElement); } else { Group group = commandArgument.getCurrentGroup(); List<Layout> layouts = LayoutLocalServiceUtil.getLayouts( group.getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID); if (("/" + commandArgument.getCurrentGroupName() + "/") .equals(commandArgument.getCurrentFolder())) { for (Layout layout : layouts) { Element folderElement = document.createElement("Folder"); foldersElement.appendChild(folderElement); folderElement.setAttribute("name", "~" + _getLayoutName(layout).replace('/', '>')); } } else { String layoutName = _getLayoutName(commandArgument.getCurrentFolder()); Layout layout = null; for (int i = 0; i < layouts.size(); i++) { layout = _getLayout(layoutName, layouts.get(i)); if (layout != null) { break; } } if (layout != null) { List<Layout> layoutChildren = layout.getChildren(); for (int i = 0; i < layoutChildren.size(); i++) { layout = layoutChildren.get(i); Element folderElement = document.createElement("Folder"); foldersElement.appendChild(folderElement); folderElement.setAttribute("name", "~" + _getLayoutName(layout).replace('/', '>')); } } } } }
public void getFoldersAndFiles( CommandArgument argument, HttpServletRequest request, HttpServletResponse response) { Document doc = _createDocument(); Node root = _createRoot( doc, argument.getCommand(), argument.getType(), argument.getCurrentFolder(), getPath(argument)); getFoldersAndFiles(argument, doc, root); _writeDocument(doc, response); }
public void execute( CommandArgument commandArgument, HttpServletRequest request, HttpServletResponse response) { CommandReceiver commandReceiver = CommandReceiverFactory.getCommandReceiver(commandArgument.getType()); commandReceiver.fileUpload(commandArgument, request, response); }
public void createFolder( CommandArgument argument, HttpServletRequest request, HttpServletResponse response) { Document doc = _createDocument(); Node root = _createRoot( doc, argument.getCommand(), argument.getType(), argument.getCurrentFolder(), StringPool.BLANK); Element errorEl = doc.createElement("Error"); root.appendChild(errorEl); String returnValue = "0"; try { returnValue = createFolder(argument); } catch (FCKException fcke) { Throwable cause = fcke.getCause(); returnValue = "110"; if (cause != null) { String causeString = GetterUtil.getString(cause.toString()); if (causeString.indexOf("DuplicateFolderNameException") != -1) { returnValue = "101"; } else if (causeString.indexOf("FolderNameException") != -1) { returnValue = "102"; } else if (causeString.indexOf("NoSuchGroupException") != -1) { returnValue = "103"; } else { throw fcke; } } } errorEl.setAttribute("number", returnValue); _writeDocument(doc, response); }
private void _getFiles(CommandArgument commandArgument, Document document, Node rootNode) throws Exception { Element filesElement = document.createElement("Files"); rootNode.appendChild(filesElement); if (Validator.isNull(commandArgument.getCurrentGroupName())) { return; } Group group = commandArgument.getCurrentGroup(); Folder folder = _getFolder(group.getGroupId(), commandArgument.getCurrentFolder()); List<FileEntry> fileEntries = DLAppServiceUtil.getFileEntries(group.getGroupId(), folder.getFolderId()); for (FileEntry fileEntry : fileEntries) { Element fileElement = document.createElement("File"); filesElement.appendChild(fileElement); fileElement.setAttribute("name", fileEntry.getTitle()); fileElement.setAttribute("desc", fileEntry.getTitle()); fileElement.setAttribute("size", getSize(fileEntry.getSize())); StringBundler url = new StringBundler(5); ThemeDisplay themeDisplay = commandArgument.getThemeDisplay(); url.append(themeDisplay.getPathMain()); url.append("/document_library/get_file?uuid="); url.append(fileEntry.getUuid()); url.append("&groupId="); url.append(group.getGroupId()); fileElement.setAttribute("url", url.toString()); } }
protected void getRootFolders(CommandArgument argument, Document doc, Element foldersEl) throws Exception { LinkedHashMap<String, Object> groupParams = new LinkedHashMap<String, Object>(); groupParams.put("usersGroups", new Long(argument.getUserId())); List<Group> groups = GroupLocalServiceUtil.search( argument.getCompanyId(), null, null, groupParams, QueryUtil.ALL_POS, QueryUtil.ALL_POS); List<Organization> userOrgs = OrganizationLocalServiceUtil.getUserOrganizations(argument.getUserId(), true); for (Organization organization : userOrgs) { groups.add(0, organization.getGroup()); } if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED || PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED) { Group userGroup = GroupLocalServiceUtil.getUserGroup(argument.getCompanyId(), argument.getUserId()); groups.add(0, userGroup); } ThemeDisplay themeDisplay = argument.getThemeDisplay(); long scopeGroupId = themeDisplay.getScopeGroupId(); for (Group group : groups) { Element folderEl = doc.createElement("Folder"); foldersEl.appendChild(folderEl); boolean setNameAttribute = false; if (group.hasStagingGroup()) { Group stagingGroup = group.getStagingGroup(); if (stagingGroup.getGroupId() == scopeGroupId) { folderEl.setAttribute( "name", stagingGroup.getGroupId() + " - " + HtmlUtil.escape(stagingGroup.getDescriptiveName())); setNameAttribute = true; } } if (!setNameAttribute) { folderEl.setAttribute( "name", group.getGroupId() + " - " + HtmlUtil.escape(group.getDescriptiveName())); } } }
protected String createFolder(CommandArgument commandArgument) { try { Group group = commandArgument.getCurrentGroup(); Folder folder = _getFolder(group.getGroupId(), StringPool.SLASH + commandArgument.getCurrentFolder()); long parentFolderId = folder.getFolderId(); String name = commandArgument.getNewFolder(); String description = StringPool.BLANK; ServiceContext serviceContext = new ServiceContext(); serviceContext.setAddCommunityPermissions(true); serviceContext.setAddGuestPermissions(true); DLAppServiceUtil.addFolder( group.getGroupId(), parentFolderId, name, description, serviceContext); } catch (Exception e) { throw new FCKException(e); } return "0"; }
private void _getFiles(CommandArgument commandArgument, Document document, Node rootNode) throws Exception { if (commandArgument.getCurrentFolder().equals(StringPool.SLASH)) { return; } Element filesElement = document.createElement("Files"); rootNode.appendChild(filesElement); Group group = commandArgument.getCurrentGroup(); List<Layout> layouts = LayoutLocalServiceUtil.getLayouts( group.getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID); if (("/" + commandArgument.getCurrentGroupName() + "/") .equals(commandArgument.getCurrentFolder())) { for (Layout layout : layouts) { Element fileElement = document.createElement("File"); filesElement.appendChild(fileElement); fileElement.setAttribute("name", _getLayoutName(layout)); fileElement.setAttribute("desc", _getLayoutName(layout)); fileElement.setAttribute("size", StringPool.BLANK); fileElement.setAttribute( "url", PortalUtil.getLayoutURL(layout, commandArgument.getThemeDisplay(), false)); } } else { String layoutName = _getLayoutName(commandArgument.getCurrentFolder()); Layout layout = null; for (int i = 0; i < layouts.size(); i++) { layout = _getLayout(layoutName, layouts.get(i)); if (layout != null) { break; } } if (layout == null) { return; } List<Layout> layoutChildren = layout.getChildren(); for (int i = 0; i < layoutChildren.size(); i++) { layout = layoutChildren.get(i); Element fileElement = document.createElement("File"); filesElement.appendChild(fileElement); fileElement.setAttribute("name", _getLayoutName(layout)); fileElement.setAttribute("desc", _getLayoutName(layout)); fileElement.setAttribute("size", getSize()); fileElement.setAttribute( "url", PortalUtil.getLayoutURL(layout, commandArgument.getThemeDisplay(), false)); } } }