예제 #1
0
  protected static final Element buildAccessRightElement(
      Document doc, Element root, String key, ExtendedMap paramsInValue) {

    Element element = XMLTool.createElement(doc, root, "accessright");

    if (key != null) {
      element.setAttribute("groupkey", key);
    }
    element.setAttribute("grouptype", paramsInValue.getString("grouptype", ""));
    element.setAttribute("adminread", paramsInValue.getString("adminread", "false"));
    element.setAttribute("read", paramsInValue.getString("read", "false"));
    element.setAttribute("update", paramsInValue.getString("update", "false"));
    element.setAttribute("delete", paramsInValue.getString("delete", "false"));
    element.setAttribute("create", paramsInValue.getString("create", "false"));
    element.setAttribute("publish", paramsInValue.getString("publish", "false"));
    element.setAttribute("administrate", paramsInValue.getString("administrate", "false"));
    element.setAttribute("approve", paramsInValue.getString("approve", "false"));
    element.setAttribute("add", paramsInValue.getString("add", "false"));

    String displayName = paramsInValue.getString("name", null);
    if (displayName != null) {
      element.setAttribute("displayname", displayName);
    }

    return element;
  }
예제 #2
0
  private void addParameters(ExtendedMap formItems, ExtendedMap parameters, String maximize) {
    int index = formItems.getInt("index", 0);
    int count = formItems.getInt("count", maximize != null ? 20 : ASSIGNED_TO_COUNT);

    parameters.put("index", index);
    parameters.put("count", count);
    parameters.put("maximize", maximize);
  }
예제 #3
0
  private void handleRecentItems(
      Document verticalDoc,
      Map<Integer, String> contentTypeKeyHandlerMapping,
      final ExtendedMap formItems,
      UserEntity user) {

    String maximize = formItems.getString("maximize", null);
    int index = formItems.getInt("index", 0);
    int count = formItems.getInt("count", maximize != null ? 20 : 10);

    ContentLogEntrySpecification logSpecification = new ContentLogEntrySpecification();
    logSpecification.setUser(user);
    logSpecification.setTypes(
        new LogType[] {LogType.ENTITY_OPENED, LogType.ENTITY_CREATED, LogType.ENTITY_UPDATED});
    logSpecification.setTableTypes(new Table[] {Table.CONTENT});
    logSpecification.setAllowDuplicateEntries(false);
    logSpecification.setAllowDeletedContent(false);

    Calendar now = GregorianCalendar.getInstance();
    final int monthsInPast = 3;
    now.add(Calendar.MONTH, -monthsInPast);
    logSpecification.setDateFilter(now.getTime());

    LogEntryResultSet logResult =
        logService.getLogEntries(logSpecification, "timestamp DESC", count, index);

    if (logResult.getLength() > 0) {

      // build contentTypeKey and handler mapping
      List<ContentKey> contentKeys = new ArrayList<ContentKey>();
      for (LogEntryEntity entity : logResult.getLogEntries()) {
        contentKeys.add(new ContentKey(entity.getKeyValue()));
      }

      ContentByContentQuery contentByContentQuery = new ContentByContentQuery();
      contentByContentQuery.setContentKeyFilter(contentKeys);
      contentByContentQuery.setUser(user);
      contentByContentQuery.setIndex(0);
      contentByContentQuery.setCount(logResult.getLength());
      ContentResultSet contentResultSet = contentService.queryContent(contentByContentQuery);
      for (ContentEntity entity : contentResultSet.getContents()) {
        contentTypeKeyHandlerMapping.put(
            entity.getContentType().getKey(),
            entity.getContentType().getContentHandlerName().getHandlerClassShortName());
      }
    }

    ContentLogXMLCreator logXMLCreator = new ContentLogXMLCreator();
    logXMLCreator.setIncludeContentData(true);
    logXMLCreator.setContentDao(contentDao);
    XMLDocument xmlDocument = logXMLCreator.createLogsDocument(logResult);

    Document lastModifiedDoc = xmlDocument.getAsDOMDocument();

    lastModifiedDoc.getDocumentElement().setAttribute("type", "lastmodified");
    XMLTool.mergeDocuments(verticalDoc, lastModifiedDoc, true);
  }
  public void handlerCustom(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems,
      String operation,
      ExtendedMap parameters,
      User user,
      Document verticalDoc)
      throws VerticalAdminException, VerticalEngineException, MessagingException, IOException {

    if (operation.equals("insert")) {
      int categoryKey = formItems.getInt("cat");
      int unitKey = admin.getUnitKey(categoryKey);
      int page = formItems.getInt("page");

      ExtendedMap xslParams = new ExtendedMap();
      xslParams.put("page", String.valueOf(page));

      Document newDoc =
          admin
              .getContent(user, Integer.parseInt(formItems.getString("key")), 0, 1, 0)
              .getAsDOMDocument();
      if (newDoc != null) {
        String filename = XMLTool.getElementText(newDoc, "/contents/content/contentdata/name");
        int index = filename.lastIndexOf(".");
        if (index != -1) {
          String filetype = filename.substring(index + 1).toLowerCase();
          if ("swf".equals(filetype)) {
            xslParams.put("flash", "true");
          } else if ("jpg".equals(filetype)
              || "jpeg".equals(filetype)
              || "png".equals(filetype)
              || "gif".equals(filetype)) {
            xslParams.put("image", "true");
          }
        }
      }

      Document xmlCategory =
          admin.getSuperCategoryNames(categoryKey, false, true).getAsDOMDocument();
      XMLTool.mergeDocuments(newDoc, xmlCategory, true);

      addCommonParameters(admin, user, request, xslParams, unitKey, -1);

      if (formItems.containsKey("subop")) {
        xslParams.put("subop", formItems.getString("subop"));
      }

      transformXML(request, response, newDoc, "editor/" + "imagepopup_selected.xsl", xslParams);
    } else {
      super.handlerCustom(
          request, response, session, admin, formItems, operation, parameters, user, verticalDoc);
    }
  }
예제 #5
0
  @SuppressWarnings("unchecked")
  private void handlerCreateContentWizardStep1(
      HttpServletRequest request,
      HttpServletResponse response,
      ExtendedMap formItems,
      ExtendedMap parameters,
      User user)
      throws VerticalAdminException, VerticalEngineException {

    final UserEntity runningUser = securityService.getUser(user);
    List<ContentTypeEntity> filteredContentTypes = new ArrayList<ContentTypeEntity>();

    for (ContentTypeEntity contentType : contentTypeDao.getAll()) {
      if (userHasAccessOnCategoriesOfContentType(runningUser, contentType, CREATE_BROWSE)) {
        filteredContentTypes.add(contentType);
      }
    }

    ContentTypeXmlCreator xmlCreator = new ContentTypeXmlCreator();
    XMLDocument doc = xmlCreator.createContentTypesDocument(filteredContentTypes);

    parameters.put("step", "1");
    parameters.put("source", formItems.getString("source", "mypage"));
    parameters.put("subop", formItems.getString("subop", ""));
    parameters.put("fieldrow", formItems.getString("fieldrow", ""));
    parameters.put("fieldname", formItems.getString("fieldname", ""));
    transformXML(request, response, doc.getAsJDOMDocument(), "createcontentwizard.xsl", parameters);
  }
예제 #6
0
  private void handleActivation(
      Document verticalDoc,
      Map<Integer, String> contentTypeKeyHandlerMapping,
      final ExtendedMap formItems,
      UserEntity user) {

    String maximize = formItems.getString("maximize", null);
    int index = formItems.getInt("index", 0);
    int count = formItems.getInt("count", maximize != null ? 20 : 3);

    ContentBySectionQuery contentBySectionQuery = new ContentBySectionQuery();
    contentBySectionQuery.setSectionFilterStatus(SectionFilterStatus.UNAPPROVED_ONLY);
    contentBySectionQuery.setSearchInAllSections();
    contentBySectionQuery.setCount(count);
    contentBySectionQuery.setUser(user);
    contentBySectionQuery.setOrderBy("timestamp DESC");
    contentBySectionQuery.setIndex(index);
    contentBySectionQuery.setFilterIncludeOfflineContent();
    contentBySectionQuery.setLevels(Integer.MAX_VALUE);

    List<CategoryAccessType> categoryAccessTypeFilter = new ArrayList<CategoryAccessType>();
    categoryAccessTypeFilter.add(CategoryAccessType.ADMINISTRATE);
    categoryAccessTypeFilter.add(CategoryAccessType.APPROVE);
    contentBySectionQuery.setCategoryAccessTypeFilter(
        categoryAccessTypeFilter, CategoryAccessTypeFilterPolicy.OR);

    ContentResultSet contentResultSet = null;
    try {
      contentResultSet = contentService.queryContent(contentBySectionQuery);
    } catch (Exception e) {
      throw new VerticalAdminException("Failed to get unapproved content", e);
    }

    // build contentTypeKey and handlerName mapping
    for (ContentEntity entity : contentResultSet.getContents()) {
      contentTypeKeyHandlerMapping.put(
          entity.getContentType().getKey(),
          entity.getContentType().getContentHandlerName().getHandlerClassShortName());
    }

    SectionXmlCreator sectionXmlCreator =
        new SectionXmlCreator(
            siteDao, new CategoryAccessResolver(groupDao), new ContentAccessResolver(groupDao));
    XMLDocument sectionDocument =
        sectionXmlCreator.createSectionsDocument(user, contentResultSet, count);

    Document waitingForActivationDoc = sectionDocument.getAsDOMDocument();
    // waitingForActivationDoc.getDocumentElement().setAttribute("type", "activation");

    XMLTool.mergeDocuments(verticalDoc, waitingForActivationDoc, true);
  }
예제 #7
0
  private void handleAssignedToMe(
      Document verticalDoc,
      Map<Integer, String> contentTypeKeyHandlerMapping,
      final ExtendedMap formItems,
      UserEntity user) {
    String maximize = formItems.getString("maximize", null);
    int index = formItems.getInt("index", 0);
    int count = formItems.getInt("count", maximize != null ? 20 : ASSIGNED_TO_COUNT);

    ContentSpecification contentSpecification = new ContentSpecification();
    // contentSpecification.setUser( user );
    contentSpecification.setAssignee(user);
    contentSpecification.setAssignedDraftsOnly(false);

    ContentResultSet contentResultSet =
        contentService.getContent(
            contentSpecification, "c.assignmentDueDate ASC, c.timestamp DESC", count, index);

    for (ContentEntity content : contentResultSet.getContents()) {
      contentTypeKeyHandlerMapping.put(
          content.getContentType().getKey(),
          content.getContentType().getContentHandlerName().getHandlerClassShortName());
    }

    ContentXMLCreator contentXMLCreator = new ContentXMLCreator();
    contentXMLCreator.setResultIndexing(index, count);
    contentXMLCreator.setIncludeOwnerAndModifierData(true);
    contentXMLCreator.setIncludeContentData(true);
    contentXMLCreator.setIncludeCategoryData(true);
    contentXMLCreator.setIncludeAccessRightsInfo(false);
    contentXMLCreator.setIncludeRelatedContentsInfo(false);
    contentXMLCreator.setIncludeRepositoryPathInfo(true);
    contentXMLCreator.setIncludeVersionsInfoForAdmin(true);
    contentXMLCreator.setIncludeAssignment(true);
    contentXMLCreator.setIncludeDraftInfo(true);
    contentXMLCreator.setIncludeSectionActivationInfo(true);
    XMLDocument xmlDocument =
        contentXMLCreator.createContentVersionsDocument(
            user, contentResultSet, new RelatedContentResultSetImpl());

    Document doc = xmlDocument.getAsDOMDocument();
    doc.getDocumentElement().setAttribute("type", "assignedto");

    XMLTool.mergeDocuments(verticalDoc, doc, true);
  }
  public void handlerCustom(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems,
      String operation)
      throws VerticalAdminException, VerticalEngineException {

    if (operation.equals("selectsite")) {
      String returnKey = null;
      String returnView = null;
      int returnRow = -1;

      if (!(request.getParameter("returnkey") == null
          || request.getParameter("returnkey").toString().equals(""))) {
        returnKey = request.getParameter("returnkey").toString();
      } else {
        String message = "Parameter not found: returnkey";
        VerticalAdminLogger.errorAdmin(message);
      }

      if (!(request.getParameter("returnview") == null
          || request.getParameter("returnview").toString().equals(""))) {
        returnView = request.getParameter("returnview").toString();
      } else {
        String message = "Parameter not found: returnview";
        VerticalAdminLogger.errorAdmin(message);
      }

      if (!(request.getParameter("returnrow") == null
          || request.getParameter("returnrow").toString().equals(""))) {
        returnRow = Integer.parseInt(request.getParameter("returnrow").toString());
      }

      Document doc = admin.getContentTypes(false).getAsDOMDocument();

      HashMap<String, String> parameters = new HashMap<String, String>();
      parameters.put("returnview", returnView);
      parameters.put("returnkey", returnKey);

      if (returnRow != -1) {
        parameters.put("returnrow", String.valueOf(returnRow));
      }

      transformXML(request, response, doc, "contenttype_selector.xsl", parameters);
    } else if ("regenerateindex".equals(operation)) {
      int contentTypeKey = formItems.getInt("contenttypekey");
      //            ( "regenerate index for content type key: " + contentTypeKey );

      admin.regenerateIndexForContentType(contentTypeKey);

      redirectClientToReferer(request, response);
    }
  }
예제 #9
0
  public void handlerMove(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems,
      ExtendedMap parameters,
      User user,
      Document verticalDoc,
      boolean moveFolder) {

    ResourceKey sourceKey = ResourceKey.from(formItems.getString("sourceKey"));
    ResourceBase source = resourceService.getResource(sourceKey);
    if (source == null) {
      throw new IllegalArgumentException("Source (" + sourceKey + ") not found");
    }

    ResourceKey destinationKey = ResourceKey.from(formItems.getString("destinationKey"));
    ResourceFolder destination = resourceService.getResourceFolder(destinationKey);
    if (destination == null) {
      throw new IllegalArgumentException("Destination (" + destinationKey + ") not found");
    }

    ResourceKey newSourceKey = resourceService.moveResource(source, destination);

    if (moveFolder) {
      URL url = new URL(request.getHeader("referer"));
      MultiValueMap params = new MultiValueMap();
      params.putAll(url.getParameterMap());
      if (params.containsKey("reload")) {
        params.remove("reload");
      }
      params.put("reload", "true");
      if (params.containsKey("path")) {
        params.remove("path");
      }
      params.put("path", resolvePathForNewFolder(sourceKey, newSourceKey));
      redirectClientToAdminPath("adminpage", params, request, response);
    } else {
      redirectClientToReferer(request, response);
    }
  }
예제 #10
0
  public void handlerUpdate(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems)
      throws VerticalAdminException, VerticalEngineException {

    String message = "OperationWrapper UPDATE is not implemented (page=%0)";
    VerticalAdminLogger.errorAdmin(this.getClass(), 0, message, formItems.get("page"), null);
  }
예제 #11
0
  private void handleForceLocale(
      ResolverContext context, HttpServletResponse response, ExtendedMap formItems) {

    ForcedResolverValueLifetimeSettings forceLocaleLifeTimeSetting =
        getForcedDeviceClassSetting(formItems, ForcedResolverValueLifetimeSettings.permanent);

    String localeString = formItems.getString(FORM_ITEM_LOCALE);

    localeResolverService.setForcedLocale(
        context, response, forceLocaleLifeTimeSetting, localeString);
  }
예제 #12
0
  private void handleForceDeviceClass(
      ResolverContext context, HttpServletResponse response, ExtendedMap formItems) {

    ForcedResolverValueLifetimeSettings forcedDeviceClassSetting =
        getForcedDeviceClassSetting(formItems, ForcedResolverValueLifetimeSettings.permanent);

    String deviceClass = formItems.getString(FORM_ITEM_DEVICE_CLASS);

    deviceClassResolverService.setForcedDeviceClass(
        context, response, forcedDeviceClassSetting, deviceClass);
  }
  public void handlerCreate(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems)
      throws VerticalAdminException, VerticalEngineException {

    User user = securityService.getLoggedInAdminConsoleUser();

    // Enforce unique names
    String name = formItems.getString("name");
    if (admin.getContentTypeKeyByName(name) > -1) {
      addError(7, "name", name);
    }

    String xmlData = buildContentTypeXML(formItems, false);

    ContentHandlerKey contentHandlerKey =
        new ContentHandlerKey(formItems.getString("contenthandlerkey"));
    ContentHandlerEntity contentHandler = contentHandlerDao.findByKey(contentHandlerKey);
    ContentHandlerName contentHandlerName = ContentHandlerName.parse(contentHandler.getClassName());
    String errorInConfig = validateConfig(contentHandlerName, xmlData);

    if (this.hasErrors() || errorInConfig != null) {
      if (errorInConfig != null) {
        String moduleXML = formItems.getString("module", "");
        addError(2, "module", moduleXML);
        formItems.put("errorInConfig", errorInConfig);
      }
      handlerForm(request, response, session, admin, formItems);
      return;
    }

    admin.createContentType(user, xmlData);

    MultiValueMap queryParams = new MultiValueMap();
    queryParams.put("page", formItems.get("page"));
    queryParams.put("op", "browse");
    redirectClientToAdminPath("adminpage", queryParams, request, response);
  }
예제 #14
0
  public boolean handlerSelect(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems)
      throws VerticalAdminException {

    String message = "OperationWrapper SELECT is not implemented (page=%0)";
    VerticalAdminLogger.errorAdmin(this.getClass(), 0, message, formItems.get("page"), null);
    return false;
  }
예제 #15
0
  public void handlerPage(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      ExtendedMap formItems,
      ExtendedMap parameters,
      User oldUser,
      Document verticalDoc)
      throws VerticalAdminException, VerticalEngineException {

    Map<Integer, String> contentTypeKeyHandlerMapping = new HashMap<Integer, String>();

    UserEntity user = securityService.getUser(oldUser);
    String maximize = formItems.getString("maximize", null);

    // ----
    // get last modified
    // ----
    if (maximize == null || "lastmodified".equals(maximize)) {
      handleRecentItems(verticalDoc, contentTypeKeyHandlerMapping, formItems, user);
    }

    // ----
    // Get content assigned to current user
    // ----
    if (maximize == null || "assignedto".equals(maximize)) {
      handleAssignedToMe(verticalDoc, contentTypeKeyHandlerMapping, formItems, user);
    }

    // ----
    // Get content waiting for activation
    // ---

    if (maximize == null || "activation".equals(maximize)) {
      handleActivation(verticalDoc, contentTypeKeyHandlerMapping, formItems, user);
    }

    // Default browse config
    Document defaultBrowseConfig =
        AdminStore.getXml(session, "defaultbrowseconfig.xml").getAsDOMDocument();
    XMLTool.mergeDocuments(verticalDoc, defaultBrowseConfig, true);

    Document contentTypeKeyHandlerMappingDoc =
        createContentTypeKeyHandlerMappingXml(contentTypeKeyHandlerMapping);
    XMLTool.mergeDocuments(verticalDoc, contentTypeKeyHandlerMappingDoc, true);

    // Feedback
    addFeedback(verticalDoc, formItems);

    addParameters(formItems, parameters, maximize);

    transformXML(request, response, verticalDoc, "dashboard.xsl", parameters);
  }
예제 #16
0
  private ExtendedMap parseSimpleRequest(HttpServletRequest request, boolean keepEmpty) {
    ExtendedMap formItems = new ExtendedMap(keepEmpty);

    Enumeration paramNames = request.getParameterNames();
    while (paramNames.hasMoreElements()) {
      String key = paramNames.nextElement().toString();
      String[] paramValues = request.getParameterValues(key);

      if (paramValues != null) {
        if (paramValues.length == 1 && paramValues[0] != null) {
          String value = paramValues[0];
          if (value.length() > 0) {
            if ("true".equals(value)) {
              formItems.putBoolean(key, true);
            } else if ("false".equals(value)) {
              formItems.putBoolean(key, false);
            } else {
              formItems.putString(key, value);
            }
          } else if (keepEmpty) {
            formItems.putString(key, value);
          }
        } else if (paramValues.length > 1) {
          formItems.put(key, paramValues);
        }
      }
    }

    return formItems;
  }
예제 #17
0
 public void handlerMenu(
     HttpServletRequest request,
     HttpServletResponse response,
     HttpSession session,
     AdminService admin,
     ExtendedMap formItems,
     ExtendedMap parameters,
     User user,
     Document verticalDoc)
     throws VerticalAdminException, TransformerException, IOException {
   String message = "OperationWrapper MENU is not implemented (page=%0)";
   VerticalAdminLogger.errorAdmin(this.getClass(), 0, message, formItems.get("page"), null);
 }
  /** Insert the method's description here. */
  public void handlerBrowse(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems)
      throws VerticalAdminException {

    List<ContentTypeEntity> allContentTypes = contentTypeDao.getAll();
    ContentTypeXmlCreator xmlCreator = new ContentTypeXmlCreator();

    XMLDocument contentTypesDoc = xmlCreator.createContentTypesDocument(allContentTypes);

    Document doc = contentTypesDoc.getAsDOMDocument();

    // Parameters
    ExtendedMap parameters = new ExtendedMap();
    parameters.put("page", String.valueOf(request.getParameter("page").toString()));
    addSortParamteres("name", "ascending", formItems, session, parameters);

    transformXML(request, response, doc, "contenttype_browse.xsl", parameters);
  }
예제 #19
0
  public void handlerCustom(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems,
      String operation)
      throws VerticalAdminException, VerticalEngineException {

    String message = "Custom operation is not implemented (page=%0): %1";

    Object[] msgData = new Object[] {formItems.get("page"), operation};
    VerticalAdminLogger.errorAdmin(this.getClass(), 0, message, msgData, null);
  }
예제 #20
0
 public void handlerWizard(
     HttpServletRequest request,
     HttpServletResponse response,
     HttpSession session,
     AdminService admin,
     ExtendedMap formItems,
     ExtendedMap parameters,
     User user,
     String wizardName)
     throws VerticalAdminException, VerticalEngineException, TransformerException, IOException {
   String message = "OperationWrapper WIZARD is not implemented (page=%0,wizardName=%1)";
   Object[] msgData = {formItems.get("page"), wizardName};
   VerticalAdminLogger.errorAdmin(this.getClass(), 0, message, msgData, null);
 }
예제 #21
0
  public void handlerRemove(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems,
      String key)
      throws VerticalAdminException, VerticalEngineException {

    String message = "OperationWrapper REMOVE is not implemented (page=%0,key=%1)";

    Object[] msgData = new Object[] {formItems.get("page"), key};
    VerticalAdminLogger.errorAdmin(this.getClass(), 0, message, msgData, null);
  }
예제 #22
0
  public static final Document buildAccessRightsXML(
      Element rootElem, String key, ExtendedMap formItems, int accessrightsType) {

    // Handle this in calling methods instead
    // if (!formItems.containsKey("updateaccessrights"))
    //    return null;

    Document doc;
    Element elmAccessRights;
    if (rootElem != null) {
      doc = rootElem.getOwnerDocument();
      elmAccessRights = XMLTool.createElement(doc, rootElem, "accessrights");
    } else {
      doc = XMLTool.createDocument("accessrights");
      elmAccessRights = doc.getDocumentElement();
    }

    if (key != null) {
      elmAccessRights.setAttribute("key", key);
    }
    if (accessrightsType != Integer.MIN_VALUE) {
      elmAccessRights.setAttribute("type", String.valueOf(accessrightsType));
    }

    for (Object parameterKey : formItems.keySet()) {
      String paramName = (String) parameterKey;
      if (paramName.startsWith("accessright[key=")) {
        String paramValue = formItems.getString(paramName);
        ExtendedMap paramsInName = ParamsInTextParser.parseParamsInText(paramName, "[", "]", ";");
        ExtendedMap paramsInValue = ParamsInTextParser.parseParamsInText(paramValue, "[", "]", ";");

        buildAccessRightElement(doc, elmAccessRights, paramsInName.getString("key"), paramsInValue);
      }
    }

    return doc;
  }
예제 #23
0
  private ForcedResolverValueLifetimeSettings getForcedDeviceClassSetting(
      ExtendedMap formItems, ForcedResolverValueLifetimeSettings defaultSetting) {

    String forcedDeviceClassParameter =
        formItems.getString(FORCE_VALUE_SETTING_KEY, defaultSetting.name());

    ForcedResolverValueLifetimeSettings forcedDeviceClassSetting;
    try {
      forcedDeviceClassSetting =
          ForcedResolverValueLifetimeSettings.valueOf(
              StringUtils.lowerCase(forcedDeviceClassParameter));
    } catch (IllegalArgumentException e) {
      throw new VerticalUserServicesException(
          "Force deviceclass setting is invalid: " + forcedDeviceClassParameter);
    }
    return forcedDeviceClassSetting;
  }
예제 #24
0
  private void handlerPopup(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems,
      ExtendedMap parameters,
      User user,
      Document verticalDoc)
      throws VerticalAdminException {

    parameters.put("mimetype", formItems.get("mimetype", ""));
    parameters.put("extension", formItems.get("extension", ""));
    parameters.put("fieldname", formItems.get("fieldname"));
    parameters.put("user-agent", request.getHeader("user-agent"));

    transformXML(request, response, verticalDoc, "resource_selector_frameset.xsl", parameters);
  }
예제 #25
0
  public void handlerInUseBy(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems,
      ExtendedMap parameters,
      User user,
      Document verticalDoc)
      throws VerticalAdminException {

    ResourceKey resourceKey = ResourceKey.from(formItems.getString("resourcekey"));
    ResourceXmlCreator xmlCreator = new ResourceXmlCreator();
    ResourceFile resourceFile = resourceService.getResourceFile(resourceKey);
    Document doc = null;
    if (resourceFile != null) {
      xmlCreator.setUsedByMap(resourceService.getUsedBy(resourceFile.getResourceKey()));
      doc = xmlCreator.createResourceXml(resourceFile).getAsDOMDocument();
    }
    transformXML(request, response, doc, "resource_inuseby.xsl", parameters);
  }
예제 #26
0
  /**
   * Process incoming requests for information
   *
   * @param request Object that encapsulates the request to the servlet
   * @param response Object that encapsulates the response from the servlet
   */
  private void performTask(HttpServletRequest request, HttpServletResponse response) {
    HttpSession session;
    session = request.getSession(false);
    response.setContentType("text/html;charset=UTF-8");

    // Make IE 9 behave like IE 8
    // http://msdn.microsoft.com/en-us/library/cc288325%28v=vs.85%29.aspx#Servers
    response.setHeader("X-UA-Compatible", "IE=EmulateIE8");

    if (session == null) {
      VerticalAdminLogger.debug(
          this.getClass(), 100, "Session is null. Redirecting to login.", null);

      // failed to get session, redirect to login page
      try {
        redirectClientToAdminPath("login", (MultiValueMap) null, request, response);
      } catch (VerticalAdminException vae) {
        String message = "Failed to redirect to login page: %t";
        VerticalAdminLogger.fatalAdmin(this.getClass(), 0, message, vae);
      }
    } else {
      // lookup admin bean
      AdminService admin = lookupAdminBean();
      User user = securityService.getLoggedInAdminConsoleUser();
      if (user == null) {
        // no logged in user, invalidate session and redirect to login page
        String message = "No user logged in. Redirecting to login.";
        VerticalAdminLogger.debug(this.getClass(), 0, message, null);
        try {
          redirectClientToAdminPath("login", (MultiValueMap) null, request, response);
        } catch (VerticalAdminException vae) {
          message = "Failed to redirect to login page: %t";
          VerticalAdminLogger.fatalAdmin(this.getClass(), 0, message, vae);
        }
      } else {
        response.setContentType("text/html; charset=UTF-8");
        try {
          ExtendedMap formItems = parseForm(request, false);

          String operation;
          if (formItems.containsKey("op")) {
            operation = formItems.getString("op");
          } else {
            operation = request.getParameter("op");
          }

          // Common parameters and variables
          ExtendedMap parameters = new ExtendedMap();
          int unitKey = formItems.getInt("selectedunitkey", -1);
          int menuKey = formItems.getInt("selectedmenukey", -1);
          int page = formItems.getInt("page", -1);
          if (page == 993) {
            int contentKey = -1;

            String contentKeyStr = request.getParameter("key");
            if (contentKeyStr != null) {
              contentKey = Integer.parseInt(contentKeyStr);
            }

            if (contentKey == -1) {
              String versionKeyStr = request.getParameter("versionkey");
              if (versionKeyStr != null) {
                int versionKey = Integer.parseInt(versionKeyStr);
                contentKey = admin.getContentKeyByVersionKey(versionKey);
              }
            }

            if (contentKey != -1) {
              int contentTypeKey = admin.getContentTypeKey(contentKey);
              page = contentTypeKey + 999;
              formItems.put("page", page);
            }
          }

          if (page == 991) {
            int categoryKey = formItems.getInt("categorykey", -1);
            if (categoryKey == -1) {
              categoryKey = formItems.getInt("cat", -1);
            }

            if (categoryKey != -1) {
              int contentTypeKey = admin.getContentTypeKeyByCategory(categoryKey);
              if (contentTypeKey != -1) {
                page = contentTypeKey + 999;
              }
            }
          }
          parameters.put("page", Integer.toString(page));
          addCommonParameters(admin, user, request, parameters, unitKey, menuKey);
          Document verticalDoc = XMLTool.createDocument("data");

          if ("create".equals(operation)) {
            handlerCreate(request, response, session, admin, formItems);
          } else if ("update".equals(operation)) {
            handlerUpdate(request, response, session, admin, formItems);
          } else if ("remove".equals(operation)) {
            String keyStr = request.getParameter("key");
            if (StringUtil.isIntegerString(keyStr)) {
              int key = -1;
              try {
                key = Integer.parseInt(keyStr);
              } catch (NumberFormatException nfe) {
                String message = "Failed to parse key (%0): %t";
                VerticalAdminLogger.errorAdmin(this.getClass(), 5, message, keyStr, nfe);
              }
              handlerRemove(request, response, session, admin, formItems, key);
            } else {
              handlerRemove(request, response, session, admin, formItems, keyStr);
            }
          } else if ("copy".equals(operation)) {
            String keyStr = request.getParameter("key");
            int key = -1;
            try {
              key = Integer.parseInt(keyStr);
            } catch (NumberFormatException nfe) {
              String message = "Failed to parse key (%0): %t";
              VerticalAdminLogger.errorAdmin(this.getClass(), 5, message, keyStr, nfe);
            }

            handlerCopy(request, response, session, admin, formItems, user, key);
          } else if ("import".equals(operation)) {
            throw new IllegalArgumentException("Unsupported operation: import");
          } else if ("browse".equals(operation)) {
            handlerBrowse(
                request, response, session, admin, formItems, parameters, user, verticalDoc);
          } else if ("select".equals(operation)) {
            handlerSelect(request, response, session, admin, formItems);
          } else if ("show".equals(operation)) {
            handlerShow(request, response, session, admin, formItems);
          } else if ("form".equals(operation)) {
            this.clearErrors();
            handlerForm(request, response, session, admin, formItems);
          } else if ("searchform".equals(operation)) {
            handlerSearch(request, response, session, admin, formItems);
          } else if ("searchresults".equals(operation)) {
            handlerSearchResults(request, response, session, admin, formItems);
          } else if ("report".equals(operation)) {
            String subOp = formItems.getString("subop");
            handlerReport(request, response, session, admin, formItems, subOp);
          } else if ("closewindow".equals(operation)) {
            closeWindow(response);
          } else if ("preview".equals(operation)) {
            handlerPreview(request, response, session, admin, formItems);
          } else if ("menu".equals(operation)) {
            handlerMenu(
                request, response, session, admin, formItems, parameters, user, verticalDoc);
          } else if ("notify".equals(operation)) {
            handlerNotify(request, response, session, admin, formItems, user);
          } else if ("wizard".equals(operation)) {
            String wizardName = formItems.getString("name");
            handlerWizard(
                request, response, session, admin, formItems, parameters, user, wizardName);
          } else if (operation != null) {
            handlerCustom(
                request,
                response,
                session,
                admin,
                formItems,
                operation,
                parameters,
                user,
                verticalDoc);
          } else {
            handlerCustom(request, response, session, admin, formItems, "missing");
          }
        } catch (Exception e) {
          try {
            if (!(e instanceof VerticalException) && !(e instanceof VerticalRuntimeException)) {
              String message = "Unexpected error occurred during handling of admin page: %t";
              VerticalAdminLogger.error(this.getClass(), 8, message, e);
            }
            ErrorPageServlet.Error error = new ErrorPageServlet.ThrowableError(e);
            session.setAttribute("com.enonic.vertical.error", error);
            redirectClientToAdminPath("errorpage", (MultiValueMap) null, request, response);
          } catch (VerticalAdminException vae) {
            String message = "Failed to redirect to error page: %t";
            VerticalAdminLogger.fatalAdmin(this.getClass(), 0, message, vae);
          }
        }
      }
    }
  }
예제 #27
0
  private ExtendedMap parseMultiPartRequest(HttpServletRequest request)
      throws FileUploadException, IOException {
    ExtendedMap formItems = new ExtendedMap();
    List paramList = fileUpload.parseRequest(request);
    for (Object parameter : paramList) {
      FileItem fileItem = (FileItem) parameter;

      String name = fileItem.getFieldName();

      if (fileItem.isFormField()) {
        String value = fileItem.getString("UTF-8");
        if (formItems.containsKey(name)) {
          ArrayList<Object> values = new ArrayList<Object>();
          Object obj = formItems.get(name);
          if (obj instanceof Object[]) {
            String[] objArray = (String[]) obj;
            for (int i = 0; i < objArray.length; i++) {
              values.add(objArray[i]);
            }
          } else {
            values.add(obj);
          }
          values.add(value);
          formItems.put(name, values.toArray(new String[values.size()]));
        } else {
          formItems.put(name, value);
        }
      } else {
        if (fileItem.getSize() > 0) {
          if (formItems.containsKey(name)) {
            ArrayList<Object> values = new ArrayList<Object>();
            Object obj = formItems.get(name);
            if (obj instanceof FileItem[]) {
              FileItem[] objArray = (FileItem[]) obj;
              for (int i = 0; i < objArray.length; i++) {
                values.add(objArray[i]);
              }
            } else {
              values.add(obj);
            }
            values.add(fileItem);
            formItems.put(name, values.toArray(new FileItem[values.size()]));
          } else {
            formItems.put(name, fileItem);
          }
        }
      }
    }

    // Add parameters from url
    Map paramMap = URLUtil.decodeParameterMap(request.getParameterMap());
    for (Object parameterEntry : paramMap.entrySet()) {
      Map.Entry entry = (Map.Entry) parameterEntry;
      String key = (String) entry.getKey();
      String[] values = (String[]) entry.getValue();
      for (String value : values) {
        formItems.put(key, value);
      }
    }

    // Remove all empty parameters that are NOT in an array
    ArrayList<String> remove = new ArrayList<String>();
    for (Object parameterKey : formItems.keySet()) {
      String key = (String) parameterKey;
      Object value = formItems.get(key);
      if (!(value instanceof String[])
          && value instanceof String
          && ((String) value).length() == 0) {
        remove.add(key);
      }
    }
    for (String key : remove) {
      formItems.remove(key);
    }

    return formItems;
  }
예제 #28
0
 public void addFeedback(Document doc, ExtendedMap formItems) {
   if (formItems.containsKey("feedback")) {
     addFeedback(doc, formItems.getInt("feedback"));
   }
 }
예제 #29
0
  protected void addSortParamteres(
      String defaultSortBy,
      String defaultSortByDirection,
      ExtendedMap inParams,
      HttpSession session,
      HashMap<String, Object> outParams) {

    // Get choosen sort by user
    String sortBy = inParams.getString("sortby", null);
    String sortByDirection = inParams.getString("sortby-direction", null);

    String page = inParams.getString("page");
    String op = inParams.getString("op");

    // s[page="+page+",op=browse,s]
    StringBuffer sb_sortByKey = new StringBuffer("s[page=");
    sb_sortByKey.append(page);
    sb_sortByKey.append(",op=");
    sb_sortByKey.append(op);
    sb_sortByKey.append(",s]");
    String sortByKey = sb_sortByKey.toString();
    // s[page="+page+",op=browse,sd]
    StringBuffer sb_sortByDirectionKey = new StringBuffer("s[page=");
    sb_sortByDirectionKey.append(page);
    sb_sortByDirectionKey.append(",op=");
    sb_sortByDirectionKey.append(op);
    sb_sortByDirectionKey.append(",sd]");
    String sortByDirectionKey = sb_sortByDirectionKey.toString();

    // ("sortByKey = " + sortByKey);
    // ("sortByDirectionKey = " + sortByDirectionKey);

    // There is no choosen sort by user, get last sort from session
    if (sortBy == null || sortByDirection == null) {
      sortBy = (String) session.getAttribute(sortByKey);
      sortByDirection = (String) session.getAttribute(sortByDirectionKey);

      // If there is no last sort from session, use default
      if (sortBy == null) {
        sortBy = defaultSortBy;
      }
      if (sortByDirection == null) {
        sortByDirection = defaultSortByDirection;
      }
    }
    // User have specified a sort-direction, store it until next time
    else {
      // Hack in order to sort timestamp columns in descending direction by default
      if ("timestamp".equals(sortBy)) {
        if (!"timestamp".equals(session.getAttribute(sortByKey))) {
          sortByDirection = "descending";
        }
      } else if ("/content/@timestamp".equals(sortBy)) {
        if (!"/content/@timestamp".equals(session.getAttribute(sortByKey))) {
          sortByDirection = "DESC";
        }
      }

      session.setAttribute(sortByKey, sortBy);
      session.setAttribute(sortByDirectionKey, sortByDirection);
    }

    outParams.put("sortby", sortBy);
    outParams.put("sortby-direction", sortByDirection);
  }
예제 #30
0
  protected Document buildChangedAccessRightsXML(ExtendedMap formItems) {

    Document doc = XMLTool.createDocument("changedaccessrights");
    Element changed = doc.getDocumentElement();

    // Lager xml for diffen - de som er fjernet
    for (Object parameterKey : formItems.keySet()) {

      String paramName = (String) parameterKey;
      if (paramName.startsWith("original_accessright[key=")) {

        ExtendedMap paramsInName = ParamsInTextParser.parseParamsInText(paramName, "[", "]", ";");
        String key = paramsInName.getString("key");

        if (!formItems.containsKey("accessright[key=" + key + "]")) {
          String paramValue = formItems.getString(paramName);
          ExtendedMap paramsInValue =
              ParamsInTextParser.parseParamsInText(paramValue, "[", "]", ";");
          Element elmAccessRight = buildAccessRightElement(doc, changed, key, paramsInValue);
          elmAccessRight.setAttribute("diffinfo", "removed");
        }
      }
    }
    // Lager xml for diffen - de som er lagt til
    for (Object parameterKey : formItems.keySet()) {
      String paramName = (String) parameterKey;
      if (paramName.startsWith("accessright[key=")) {

        ExtendedMap paramsInName = ParamsInTextParser.parseParamsInText(paramName, "[", "]", ";");
        String key = paramsInName.getString("key");

        if (!formItems.containsKey("original_accessright[key=" + key + "]")) {

          String paramValue = formItems.getString(paramName);
          ExtendedMap paramsInValue =
              ParamsInTextParser.parseParamsInText(paramValue, "[", "]", ";");

          Element elmAccessRight = buildAccessRightElement(doc, changed, key, paramsInValue);
          elmAccessRight.setAttribute("diffinfo", "added");
        }
      }
    }
    // Lager xml for diffen - de som er endret
    for (Object paramKey : formItems.keySet()) {

      String paramName = (String) paramKey;

      if (paramName.startsWith("accessright[key=")) {

        ExtendedMap paramsInName = ParamsInTextParser.parseParamsInText(paramName, "[", "]", ";");
        String key = paramsInName.getString("key");

        if (formItems.containsKey("original_accessright[key=" + key + "]")) {

          String originalValue = formItems.getString("original_accessright[key=" + key + "]");
          String currentValue = formItems.getString(paramName);
          if (!currentValue.equals(originalValue)) {

            ExtendedMap paramsInValue =
                ParamsInTextParser.parseParamsInText(currentValue, "[", "]", ";");
            Element elmAccessRight = buildAccessRightElement(doc, changed, key, paramsInValue);
            elmAccessRight.setAttribute("diffinfo", "modified");
          }
        }
      }
    }

    return doc;
  }