public void execute(Event<UICategorySelector> event) throws Exception {
      UICategorySelector selector = event.getSource();

      ApplicationRegistryService appRegService =
          selector.getApplicationComponent(ApplicationRegistryService.class);
      List<ApplicationCategory> categories = appRegService.getApplicationCategories();
      categories = categories != null ? categories : new ArrayList<ApplicationCategory>();
      for (ApplicationCategory category : categories) {
        if (selector.getSelectedCategories().contains("category_" + category.getName())) {
          Application newApp = cloneApplication(selector.getApplication());
          UIApplicationRegistryPortlet.setPermissionToAdminGroup(newApp);
          appRegService.save(category, newApp);
        }
      }
      selector.clearSelectedCategories();

      UIContainer appInfo = selector.getParent();
      appInfo.getChild(UICategorySelector.class).setRendered(false);
      UIApplicationRegistryPortlet uiPortlet =
          appInfo.getAncestorOfType(UIApplicationRegistryPortlet.class);
      UIApplicationOrganizer uiOrganizer = uiPortlet.getChild(UIApplicationOrganizer.class);
      UIGadgetManagement uiGadgetManagement = uiPortlet.getChild(UIGadgetManagement.class);

      uiOrganizer.reload();
      if (uiGadgetManagement != null) {
        uiGadgetManagement.setSelectedGadget(selector.getApplication().getApplicationName());
      }

      event.getRequestContext().addUIComponentToUpdateByAjax(appInfo);
    }
 public List<ApplicationCategory> getAllCategories() {
   try {
     ApplicationRegistryService appRegService =
         getApplicationComponent(ApplicationRegistryService.class);
     List<ApplicationCategory> categories =
         appRegService.getApplicationCategories(new Util.CategoryComparator());
     categories = categories != null ? categories : new ArrayList<ApplicationCategory>();
     return categories;
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
 @Override
 public void execute(Event<UICategorySelector> event) throws Exception {
   UICategorySelector selector = event.getSource();
   ApplicationRegistryService appRegService =
       selector.getApplicationComponent(ApplicationRegistryService.class);
   List<ApplicationCategory> categories = appRegService.getApplicationCategories();
   UICheckBoxInput chkInput;
   for (ApplicationCategory category : categories) {
     chkInput = selector.getUIInput("category_" + category.getName());
     if (chkInput != null && chkInput.isChecked()) {
       selector.addSelectedCategory("category_" + category.getName());
     }
   }
 }
Example #4
0
 /**
  * Creates the root element.
  *
  * @param currentFolder the current folder
  * @param applicationCategories the application categories
  * @param language the language
  * @return the element
  * @throws Exception the exception
  */
 private Element createRootElement(
     String currentFolder,
     List<ApplicationCategory> applicationCategories,
     String language,
     String host)
     throws Exception {
   Document document = null;
   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
   DocumentBuilder builder = factory.newDocumentBuilder();
   document = builder.newDocument();
   if (applicationCategories.isEmpty()) {
     Locale locale = null;
     if (language == null) {
       locale = Locale.ENGLISH;
     } else {
       locale = new Locale(language);
     }
     ResourceBundle resourceBundle = ResourceBundle.getBundle(FCK_RESOURCE_BUNDLE_FILE, locale);
     String message = "";
     try {
       message = resourceBundle.getString("fckeditor.no-gadget");
     } catch (MissingResourceException e) {
       message = "fckeditor.no-gadget";
     }
     Element rootElement = document.createElement("Message");
     document.appendChild(rootElement);
     rootElement.setAttribute("number", "555");
     rootElement.setAttribute("text", message);
     rootElement.setAttribute("type", "Error");
     return rootElement;
   }
   Element rootElement = document.createElement("Connector");
   document.appendChild(rootElement);
   rootElement.setAttribute("resourceType", "Gadget");
   Element currentFolderElement = document.createElement("CurrentFolder");
   if (currentFolder == null || currentFolder.equals("/")) {
     currentFolderElement.setAttribute("name", applicationCategories.get(0).getName());
     Element foldersElement = createFolderElement(document, applicationCategories);
     rootElement.appendChild(foldersElement);
   } else {
     PortalContainer container = PortalContainer.getInstance();
     RequestLifeCycle.begin(container);
     try {
       ApplicationCategory applicationCategory =
           applicationRegistryService.getApplicationCategory(
               currentFolder.substring(1, currentFolder.length() - 1));
       currentFolderElement.setAttribute("name", applicationCategory.getDisplayName());
       Element filesElement = createFileElement(document, applicationCategory, host);
       rootElement.appendChild(filesElement);
     } finally {
       RequestLifeCycle.end();
     }
   }
   rootElement.appendChild(currentFolderElement);
   return rootElement;
 }
Example #5
0
 /**
  * Gets the gadget categories.
  *
  * @return the gadget categories
  * @throws Exception the exception
  */
 private List<ApplicationCategory> getGadgetCategories() throws Exception {
   List<ApplicationCategory> gadgetCategories = new ArrayList<ApplicationCategory>();
   PortalContainer container = PortalContainer.getInstance();
   RequestLifeCycle.begin(container);
   try {
     List<ApplicationCategory> applicationCategories =
         applicationRegistryService.getApplicationCategories();
     for (ApplicationCategory applicationCategory : applicationCategories) {
       if (!applicationRegistryService
           .getApplications(applicationCategory, ApplicationType.GADGET)
           .isEmpty()) {
         gadgetCategories.add(applicationCategory);
       }
     }
   } finally {
     RequestLifeCycle.end();
   }
   return gadgetCategories;
 }
  public void init() throws Exception {
    UIFormTableIteratorInputSet uiTableInputSet =
        createUIComponent(UIFormTableIteratorInputSet.class, null, null);
    uiTableInputSet.setName(getClass().getSimpleName());
    uiTableInputSet.setId(getClass().getSimpleName());
    uiTableInputSet.setColumns(TABLE_COLUMNS);
    addChild(uiTableInputSet);

    UIFormInputSet uiInputSet;
    UICheckBoxInput checkBoxInput;
    UIFormInputInfo uiInfo;

    HTMLEntityEncoder encoder = HTMLEntityEncoder.getInstance();

    //
    ApplicationRegistryService appRegService =
        getApplicationComponent(ApplicationRegistryService.class);
    List<ApplicationCategory> categories = getAllCategories();
    List<UIFormInputSet> uiInputSetList = new ArrayList<UIFormInputSet>();
    for (ApplicationCategory category : categories) {
      uiInputSet = new UIFormInputSet(category.getName());
      boolean defaultValue = false;
      if (application != null) {
        String definitionName = application.getDisplayName().replace(' ', '_');
        defaultValue = appRegService.getApplication(category.getName(), definitionName) != null;
      }
      checkBoxInput = new UICheckBoxInput("category_" + category.getName(), null, defaultValue);
      checkBoxInput.setOnChange("SelectBox");
      uiInfo =
          new UIFormInputInfo("categoryName", null, encoder.encode(category.getDisplayName(true)));
      uiInputSet.addChild(checkBoxInput);
      uiInputSet.addChild(uiInfo);
      uiTableInputSet.addChild(uiInputSet);
      uiInputSetList.add(uiInputSet);
    }

    UIFormPageIterator uiIterator = uiTableInputSet.getChild(UIFormPageIterator.class);
    SerializablePageList<UIFormInputSet> pageList =
        new SerializablePageList<UIFormInputSet>(UIFormInputSet.class, uiInputSetList, 5);
    uiIterator.setPageList(pageList);
  }
Example #7
0
  private void initApplicationCategories() throws Exception {
    ApplicationRegistryService prService =
        getApplicationComponent(ApplicationRegistryService.class);
    String remoteUser = WebuiRequestContext.getCurrentInstance().getRemoteUser();
    if (remoteUser == null || remoteUser.equals("")) return;

    List<ApplicationCategory> appCategories =
        prService.getApplicationCategories(new ApplicationCategoryComparator());

    Iterator<ApplicationCategory> cateItr = appCategories.iterator();
    while (cateItr.hasNext()) {
      ApplicationCategory cate = cateItr.next();

      if (!hasPermission(cate.getAccessPermissions()) || filterApps(cate).size() < 1) {
        cateItr.remove();
      } else {
        Collections.sort(cate.getApplications(), new ApplicationComparator());
      }
    }

    listAppCategories = appCategories;
  }
Example #8
0
  /**
   * Creates the file element.
   *
   * @param document the document
   * @param applicationCategory the application category
   * @return the element
   * @throws Exception the exception
   */
  private Element createFileElement(
      Document document, ApplicationCategory applicationCategory, String host) throws Exception {
    Element files = document.createElement("Files");
    List<Application> listApplication =
        applicationRegistryService.getApplications(applicationCategory, ApplicationType.GADGET);
    for (Application application : listApplication) {
      Gadget gadget = gadgetRegistryService.getGadget(application.getApplicationName());
      Element file = document.createElement("File");
      file.setAttribute("name", gadget.getName());
      file.setAttribute("fileType", "nt_unstructured");
      file.setAttribute("size", "0");
      file.setAttribute("thumbnail", gadget.getThumbnail());
      file.setAttribute("description", gadget.getDescription());

      String fullurl = "";
      if (gadget.isLocal()) {
        fullurl = "/" + PortalContainer.getCurrentRestContextName() + "/" + gadget.getUrl();
      } else {
        fullurl = gadget.getUrl();
      }
      file.setAttribute("url", fullurl);

      String data =
          "{\"context\":{\"country\":\"US\",\"language\":\"en\"},\"gadgets\":[{\"moduleId\":0,\"url\":\""
              + fullurl
              + "\",\"prefs\":[]}]}";
      URL url = new URL(host + "/eXoGadgetServer/gadgets/metadata");
      URLConnection conn = url.openConnection();
      conn.setDoOutput(true);
      OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
      wr.write(data);
      wr.flush();
      String strMetadata = IOUtils.toString(conn.getInputStream(), "UTF-8");
      wr.close();
      JSONObject metadata = new JSONObject(strMetadata.toString());

      ConversationState conversationState = ConversationState.getCurrent();
      String userId = conversationState.getIdentity().getUserId();
      String token =
          createToken(gadget.getUrl(), userId, userId, new Random().nextLong(), "default");
      JSONObject obj = metadata.getJSONArray("gadgets").getJSONObject(0);
      obj.put("secureToken", token);

      file.setAttribute("metadata", metadata.toString());
      files.appendChild(file);
    }
    return files;
  }