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";
  }
  protected void addFileEntry(boolean rootFolder) throws PortalException, SystemException {

    long folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;

    if (!rootFolder) {
      folderId = _folder.getFolderId();
    }

    String fileName = "Title.txt";
    String description = StringPool.BLANK;
    String changeLog = StringPool.BLANK;

    String content = "Content: Enterprise. Open Source. For Life.";

    byte[] bytes = content.getBytes();

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddCommunityPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    _fileEntry =
        DLAppServiceUtil.addFileEntry(
            _groupId, folderId, fileName, description, changeLog, bytes, serviceContext);
  }
Esempio n. 3
0
  public int copyCollectionResource(
      WebDAVRequest webDavRequest,
      Resource resource,
      String destination,
      boolean overwrite,
      long depth)
      throws WebDAVException {

    try {
      String[] destinationArray = WebDAVUtil.getPathArray(destination, true);

      long companyId = webDavRequest.getCompanyId();

      long parentFolderId = IGFolderConstants.DEFAULT_PARENT_FOLDER_ID;

      try {
        parentFolderId = getParentFolderId(companyId, destinationArray);
      } catch (NoSuchFolderException nsfe) {
        return HttpServletResponse.SC_CONFLICT;
      }

      IGFolder folder = (IGFolder) resource.getModel();

      long groupId = WebDAVUtil.getGroupId(companyId, destination);
      String name = WebDAVUtil.getResourceName(destinationArray);
      String description = folder.getDescription();

      int status = HttpServletResponse.SC_CREATED;

      if (overwrite) {
        if (deleteResource(groupId, parentFolderId, name)) {
          status = HttpServletResponse.SC_NO_CONTENT;
        }
      }

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddCommunityPermissions(isAddCommunityPermissions(groupId));
      serviceContext.setAddGuestPermissions(true);
      serviceContext.setScopeGroupId(groupId);

      if (depth == 0) {
        IGFolderServiceUtil.addFolder(parentFolderId, name, description, serviceContext);
      } else {
        IGFolderServiceUtil.copyFolder(
            folder.getFolderId(), parentFolderId, name, description, serviceContext);
      }

      return status;
    } catch (DuplicateFolderNameException dfne) {
      return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (PrincipalException pe) {
      return HttpServletResponse.SC_FORBIDDEN;
    } catch (Exception e) {
      throw new WebDAVException(e);
    }
  }
Esempio n. 4
0
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest);
    String fileLogoParam = "file";
    File file = uploadRequest.getFile(fileLogoParam);
    ServiceContext sc;

    try {

      sc = ServiceContextFactory.getInstance(this.getClass().getName(), actionRequest);
      // Make sure the uploaded images can be view by any one;
      sc.setAddCommunityPermissions(true);
      sc.setAddGuestPermissions(true);

      IGFolder folder = Functions.getIGFolder(sc);
      // String fileName = uploadRequest.getFileName(fileLogoParam);
      String contentType = uploadRequest.getContentType(fileLogoParam);

      IGImage image =
          IGImageLocalServiceUtil.addImage(
              sc.getUserId(),
              folder.getFolderId(),
              file.getName() + (new Time()).toString(),
              file.getName(),
              file,
              contentType,
              sc);

      HttpServletRequest servletRequest = PortalUtil.getHttpServletRequest(actionRequest);
      String res =
          image.getImageId()
              + "|"
              + ProGateUtil.getImageURL(image.getSmallImageId(), servletRequest)
              + "|"
              + ProGateUtil.getImageURL(image.getLargeImageId(), servletRequest);
      ProGateUtil.servletPrint(actionResponse, res);

    } catch (PortalException e) {
      // TODO Auto-generated catch block

      e.printStackTrace();
    } catch (SystemException se) {

      se.printStackTrace();
    } catch (NullPointerException e2) {

      e2.printStackTrace();
    }
  }
Esempio n. 5
0
  public Status makeCollection(WebDAVRequest webDavRequest) throws WebDAVException {

    try {
      HttpServletRequest request = webDavRequest.getHttpServletRequest();

      if (request.getContentLength() > 0) {
        return new Status(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
      }

      String[] pathArray = webDavRequest.getPathArray();

      long companyId = webDavRequest.getCompanyId();
      long groupId = webDavRequest.getGroupId();
      long parentFolderId = getParentFolderId(companyId, pathArray);
      String name = WebDAVUtil.getResourceName(pathArray);
      String description = StringPool.BLANK;

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddCommunityPermissions(isAddCommunityPermissions(groupId));
      serviceContext.setAddGuestPermissions(true);
      serviceContext.setPlid(getPlid(webDavRequest.getGroupId()));
      serviceContext.setScopeGroupId(webDavRequest.getGroupId());

      IGFolderServiceUtil.addFolder(parentFolderId, name, description, serviceContext);

      String location = StringUtil.merge(pathArray, StringPool.SLASH);

      return new Status(location, HttpServletResponse.SC_CREATED);
    } catch (DuplicateFolderNameException dfne) {
      return new Status(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
    } catch (NoSuchFolderException nsfe) {
      return new Status(HttpServletResponse.SC_CONFLICT);
    } catch (PrincipalException pe) {
      return new Status(HttpServletResponse.SC_FORBIDDEN);
    } catch (Exception e) {
      throw new WebDAVException(e);
    }
  }
Esempio n. 6
0
  public static WikiNode getFirstVisibleNode(PortletRequest portletRequest)
      throws PortalException, SystemException {

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    WikiNode node = null;

    int nodesCount = WikiNodeLocalServiceUtil.getNodesCount(themeDisplay.getScopeGroupId());

    if (nodesCount == 0) {
      Layout layout = themeDisplay.getLayout();

      ServiceContext serviceContext =
          ServiceContextFactory.getInstance(WikiNode.class.getName(), portletRequest);

      serviceContext.setAddCommunityPermissions(true);

      if (layout.isPublicLayout()) {
        serviceContext.setAddGuestPermissions(true);
      } else {
        serviceContext.setAddGuestPermissions(false);
      }

      node = WikiNodeLocalServiceUtil.addDefaultNode(themeDisplay.getUserId(), serviceContext);
    } else {
      node = WikiUtil.getFirstNode(portletRequest);

      if (node == null) {
        throw new PrincipalException();
      }

      return node;
    }

    portletRequest.setAttribute(WebKeys.WIKI_NODE, node);

    return node;
  }
  public void setUp() throws Exception {
    super.setUp();

    String name = "Test Folder";
    String description = "This is a test folder.";

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddCommunityPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    try {
      DLAppServiceUtil.deleteFolder(_groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, name);
    } catch (NoSuchFolderException nsfe) {
    }

    _folder =
        DLAppServiceUtil.addFolder(
            _groupId,
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            name,
            description,
            serviceContext);
  }
  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";
  }
Esempio n. 9
0
  public int putResource(WebDAVRequest webDavRequest) throws WebDAVException {
    File file = null;

    try {
      HttpServletRequest request = webDavRequest.getHttpServletRequest();

      String[] pathArray = webDavRequest.getPathArray();

      long companyId = webDavRequest.getCompanyId();
      long groupId = webDavRequest.getGroupId();
      long parentFolderId = getParentFolderId(companyId, pathArray);
      String name = WebDAVUtil.getResourceName(pathArray);
      String description = StringPool.BLANK;

      file = FileUtil.createTempFile(FileUtil.getExtension(name));

      FileUtil.write(file, request.getInputStream());

      String contentType = MimeTypesUtil.getContentType(name);

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddCommunityPermissions(isAddCommunityPermissions(groupId));
      serviceContext.setAddGuestPermissions(true);

      try {
        IGImage image =
            IGImageServiceUtil.getImageByFolderIdAndNameWithExtension(
                groupId, parentFolderId, name);

        long imageId = image.getImageId();

        description = image.getDescription();

        String[] assetTagNames =
            AssetTagLocalServiceUtil.getTagNames(IGImage.class.getName(), imageId);

        serviceContext.setAssetTagNames(assetTagNames);

        IGImageServiceUtil.updateImage(
            imageId, groupId, parentFolderId, name, description, file, contentType, serviceContext);
      } catch (NoSuchImageException nsie) {
        IGImageServiceUtil.addImage(
            groupId, parentFolderId, name, description, file, contentType, serviceContext);
      }

      return HttpServletResponse.SC_CREATED;
    } catch (PrincipalException 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 {
      if (file != null) {
        file.delete();
      }
    }
  }
Esempio n. 10
0
  public int copySimpleResource(
      WebDAVRequest webDavRequest, Resource resource, String destination, boolean overwrite)
      throws WebDAVException {

    File file = null;

    try {
      String[] destinationArray = WebDAVUtil.getPathArray(destination, true);

      long companyId = webDavRequest.getCompanyId();

      long parentFolderId = IGFolderConstants.DEFAULT_PARENT_FOLDER_ID;

      try {
        parentFolderId = getParentFolderId(companyId, destinationArray);
      } catch (NoSuchFolderException nsfe) {
        return HttpServletResponse.SC_CONFLICT;
      }

      IGImage image = (IGImage) resource.getModel();

      long groupId = WebDAVUtil.getGroupId(companyId, destination);
      String name = WebDAVUtil.getResourceName(destinationArray);
      String description = image.getDescription();
      String contentType = MimeTypesUtil.getContentType(image.getNameWithExtension());

      file = FileUtil.createTempFile(image.getImageType());

      InputStream is = resource.getContentAsStream();

      FileUtil.write(file, is);

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setAddCommunityPermissions(isAddCommunityPermissions(groupId));
      serviceContext.setAddGuestPermissions(true);

      int status = HttpServletResponse.SC_CREATED;

      if (overwrite) {
        if (deleteResource(groupId, parentFolderId, name)) {
          status = HttpServletResponse.SC_NO_CONTENT;
        }
      }

      IGImageServiceUtil.addImage(
          groupId, parentFolderId, name, description, file, contentType, serviceContext);

      return status;
    } catch (DuplicateFolderNameException dfne) {
      return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (DuplicateFileException dfe) {
      return HttpServletResponse.SC_PRECONDITION_FAILED;
    } catch (PrincipalException pe) {
      return HttpServletResponse.SC_FORBIDDEN;
    } catch (Exception e) {
      throw new WebDAVException(e);
    } finally {
      if (file != null) {
        file.delete();
      }
    }
  }
Esempio n. 11
0
  public static void getPage(HttpServletRequest request) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    long nodeId = ParamUtil.getLong(request, "nodeId");
    String title = ParamUtil.getString(request, "title");
    double version = ParamUtil.getDouble(request, "version");

    WikiNode node = null;

    try {
      if (nodeId > 0) {
        node = WikiNodeServiceUtil.getNode(nodeId);
      }
    } catch (NoSuchNodeException nsne) {
    }

    if (node == null) {
      node = (WikiNode) request.getAttribute(WebKeys.WIKI_NODE);

      if (node != null) {
        nodeId = node.getNodeId();
      }
    }

    if (Validator.isNull(title)) {
      title = WikiPageConstants.FRONT_PAGE;
    }

    WikiPage page = null;

    try {
      page = WikiPageServiceUtil.getPage(nodeId, title, version);
    } catch (NoSuchPageException nspe) {
      if (title.equals(WikiPageConstants.FRONT_PAGE) && (version == 0)) {
        long userId = PortalUtil.getUserId(request);

        if (userId == 0) {
          long companyId = PortalUtil.getCompanyId(request);

          userId = UserLocalServiceUtil.getDefaultUserId(companyId);
        }

        ServiceContext serviceContext = new ServiceContext();

        Layout layout = themeDisplay.getLayout();

        serviceContext.setAddCommunityPermissions(true);

        if (layout.isPublicLayout()) {
          serviceContext.setAddGuestPermissions(true);
        } else {
          serviceContext.setAddGuestPermissions(false);
        }

        boolean workflowEnabled = WorkflowThreadLocal.isEnabled();

        try {
          WorkflowThreadLocal.setEnabled(false);

          page =
              WikiPageLocalServiceUtil.addPage(
                  userId, nodeId, title, null, WikiPageConstants.NEW, true, serviceContext);
        } finally {
          WorkflowThreadLocal.setEnabled(workflowEnabled);
        }
      } else {
        throw nspe;
      }
    }

    request.setAttribute(WebKeys.WIKI_PAGE, page);
  }