コード例 #1
0
  public String buildContentTypeXML(ExtendedMap formItems, boolean reload) {
    StringWriter sw = new StringWriter();

    try {
      Document doc = XMLTool.createDocument();

      // Create unit element
      Element contentType = XMLTool.createRootElement(doc, "contenttype");

      if (formItems.containsKey("key")) {
        contentType.setAttribute("key", formItems.getString("key"));
      }
      if (formItems.containsKey("sitekey")) {
        contentType.setAttribute("sitekey", formItems.getString("sitekey"));
      }
      if (formItems.containsKey("contenthandlerkey")) {
        contentType.setAttribute("contenthandlerkey", formItems.getString("contenthandlerkey"));
      }
      if (formItems.containsKey("csskey")) {
        contentType.setAttribute("csskey", formItems.getString("csskey"));
      }

      XMLTool.createElement(doc, contentType, "name", formItems.getString("name", ""));
      XMLTool.createElement(
          doc, contentType, "description", formItems.getString("description", ""));

      // Module XML
      String moduleXML = formItems.getString("module", "");
      if (moduleXML == null || moduleXML.length() == 0) {
        XMLTool.createElement(doc, contentType, "moduledata");
      } else {
        if (!reload) {
          try {
            Document modDocTemp = XMLTool.domparse(moduleXML, "contenttype");

            Document modDoc = XMLTool.createDocument("moduledata");
            XMLTool.mergeDocuments(modDoc, modDocTemp, false);

            contentType.appendChild(doc.importNode(modDoc.getDocumentElement(), true));
          } catch (Exception e) {
            addError(2, "module", moduleXML);
          }
        }
      }
      XMLTool.printDocument(sw, doc);
    } catch (Exception e) {
      System.err.println("[Error] Something failed:\n" + e.toString());
    }
    return sw.toString();
  }
コード例 #2
0
  protected boolean logUserStoreLogin(
      User user,
      AdminService admin,
      String remoteIP,
      String remoteHost,
      UserStoreKey userStoreKey) {

    try {
      Document doc = XMLTool.createDocument("logentry");
      Element rootElement = doc.getDocumentElement();
      // UserStoreKey userStoreKey = user.getUserStoreKey();
      if (userStoreKey != null) {
        rootElement.setAttribute("userstorekey", String.valueOf(userStoreKey));
      }
      rootElement.setAttribute("sitekey", String.valueOf(0));
      rootElement.setAttribute("typekey", String.valueOf(LogType.LOGIN_USERSTORE.asInteger()));
      rootElement.setAttribute("inetaddress", remoteIP);
      XMLTool.createElement(doc, rootElement, "data");

      admin.createLogEntries(user, XMLTool.documentToString(doc));
    } catch (VerticalSecurityException vse) {
      String message = "Failed to create log entry because of security error: %t";
      VerticalAdminLogger.error(this.getClass(), 1, message, vse);
      return false;
    }

    return true;
  }
コード例 #3
0
  public void addErrorsXML(Document doc) {
    if (errorCodes.size() > 0) {
      Element errorsElem = XMLTool.createElement(doc, doc.getDocumentElement(), "errors");

      for (int i = 0; i < errorCodes.size(); i++) {
        ErrorCode ec = errorCodes.get(i);
        Element errorElem = XMLTool.createElement(doc, errorsElem, "error");
        errorElem.setAttribute("code", Integer.toString(ec.code));
        errorElem.setAttribute("name", ec.name);

        Element valueElem = XMLTool.createElement(doc, errorElem, "value");
        XMLTool.createCDATASection(doc, valueElem, ec.value);
      }
    }
    errorCodes.removeAllElements();
  }
コード例 #4
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;
  }
コード例 #5
0
  private void toXML(final Element parent) {
    final Document doc = parent.getOwnerDocument();
    final Element sessionElem = XMLTool.createElement(doc, parent, "session");

    for (final Map.Entry<String, Object> entry : entrySet()) {
      final Element attributeElem = XMLTool.createElement(doc, sessionElem, "attribute");
      attributeElem.setAttribute("name", entry.getKey());

      final Object value = entry.getValue();
      if (value instanceof Document) {
        final Document xmlDoc = (Document) value;
        final Element rootElem = xmlDoc.getDocumentElement();
        attributeElem.appendChild(doc.importNode(rootElem, true));
      } else if (value != null) {
        XMLTool.createTextNode(doc, attributeElem, value.toString());
      }
    }
  }
コード例 #6
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;
  }
コード例 #7
0
  public void handlerForm(
      HttpServletRequest request,
      HttpServletResponse response,
      HttpSession session,
      AdminService admin,
      ExtendedMap formItems)
      throws VerticalAdminException {

    boolean createContent = formItems.containsKey("create");
    boolean reloading = formItems.getString("reload", "").equals("true");
    boolean usehandlerindexing = false;
    HashMap<String, String> parameters = new HashMap<String, String>();
    Element contentTypeElem = null;
    Document xmlData = null;
    Document doc = null;
    String referer = request.getHeader("referer");

    int contentTypeKey = -1;
    String generateKey = formItems.getString("generatectykey", "");
    if (generateKey.equals("true")) {
      parameters.put("generatectykey", "true");
    } else {
      String keyStr = (String) request.getParameter("key");
      if (keyStr != null && keyStr.length() > 0) {
        contentTypeKey = Integer.parseInt(keyStr);
      }
    }

    int contentHandlerKey = formItems.getInt("contenthandlerkey", 0);

    if (reloading || hasErrors()) {
      if (reloading) {
        usehandlerindexing = true;
      }

      doc = XMLTool.createDocument("contenttypes");
      Document contentTypeDoc = XMLTool.domparse(buildContentTypeXML(formItems, reloading));
      contentTypeElem = contentTypeDoc.getDocumentElement();
      if (formItems.containsKey("key")) {
        int key = formItems.getInt("key");
        int contentCount = admin.getContentCountByContentType(key);
        contentTypeElem.setAttribute("contentcount", String.valueOf(contentCount));
      }
      doc.getDocumentElement().appendChild(doc.importNode(contentTypeElem, true));

      referer = formItems.getString("referer");
    } else if (contentTypeKey == -1) {
      // Blank form, make dummy document
      doc = XMLTool.createDocument("contenttypes");

      usehandlerindexing = true;

      // Create content type element
      contentTypeElem = XMLTool.createElement(doc, doc.getDocumentElement(), "contenttype");
      createContent = true;
    } else {
      // Edit content type
      xmlData = admin.getContentType(contentTypeKey, true).getAsDOMDocument();

      doc = xmlData;

      contentTypeElem = XMLTool.getElement(doc.getDocumentElement(), "contenttype");
      String contentHandlerString = contentTypeElem.getAttribute("contenthandlerkey");
      if (contentHandlerString.length() > 0) {
        contentHandlerKey = Integer.parseInt(contentHandlerString);
      }
      String cssString = contentTypeElem.getAttribute("csskey");
      if (cssString.length() > 0) {
        ResourceKey cssKey = new ResourceKey(cssString);
        parameters.put("cssname", cssKey.toString());

        ResourceFile contentTypeStylesheet = this.resourceService.getResourceFile(cssKey);
        if (contentTypeStylesheet == null) {
          parameters.put("cssexist", "false");
        } else {
          parameters.put("cssexist", "true");
        }
      }
    }
    Document contentHandlersDoc = admin.getContentHandlers().getAsDOMDocument();
    doc.getDocumentElement()
        .appendChild(doc.importNode(contentHandlersDoc.getDocumentElement(), true));

    addErrorsXML(doc);

    if (createContent) {
      parameters.put("create", "1");
    } else {
      parameters.put("create", "0");
    }
    parameters.put("referer", referer);

    if (contentHandlerKey > -1) {
      parameters.put("contenthandlerkey", Integer.toString(contentHandlerKey));
    }
    parameters.put("usehandlerindexing", String.valueOf(usehandlerindexing));
    parameters.put("page", String.valueOf(request.getParameter("page").toString()));
    parameters.put("errorInConfig", formItems.getString("errorInConfig", ""));

    transformXML(request, response, doc, "contenttype_form.xsl", parameters);
  }