@Override
  public String getConfigFormSnippet(
      ConnectorManager connectorManager,
      String connectorType,
      String connectorName,
      Locale locale) {
    Element xml;

    Map<String, String> paramsMap = new HashMap<String, String>();
    paramsMap.put(ServletUtil.QUERY_PARAM_LANG, locale.getLanguage());

    if (connectorName == null) {
      // New connector
      paramsMap.put(ServletUtil.XMLTAG_CONNECTOR_TYPE, connectorType);
      xml = ConnectorManagerRequestUtils.sendGet(connectorManager, "/getConfigForm", paramsMap);
    } else {
      // Existing connector
      paramsMap.put(ServletUtil.XMLTAG_CONNECTOR_NAME, connectorName);
      xml =
          ConnectorManagerRequestUtils.sendGet(
              connectorManager, "/getConnectorConfigToEdit", paramsMap);
    }

    Element formSnippet =
        xml.element(ServletUtil.XMLTAG_CONFIGURE_RESPONSE).element(ServletUtil.XMLTAG_FORM_SNIPPET);
    CDATA cdata = (CDATA) formSnippet.node(0);
    String configFormSnippetText = cdata.getStringValue();

    return configFormSnippetText;
  }
 private void processElementChildren(
     final Element element, final String key, final Map<String, String> properties) {
   for (int i = 0, size = element.nodeCount(); i < size; i++) {
     Node node = element.node(i);
     if (logger.isDebugEnabled()) {
       logger.debug(String.format("Processing xml element %s", node.getPath()));
     }
     if (node instanceof Element) {
       StringBuilder sbPrefix = new StringBuilder(key);
       if (sbPrefix.length() > 0) {
         sbPrefix.append(".");
       }
       sbPrefix.append(node.getName());
       if (!excludeProperties.contains(sbPrefix.toString())) {
         processElementChildren((Element) node, sbPrefix.toString(), properties);
       }
     } else {
       StringBuilder sb = new StringBuilder();
       if (properties.containsKey(key)) {
         sb.append(properties.get(key));
         if (sb.length() > 0) {
           sb.append(multivalueSeparator);
         }
       }
       String value = node.getText();
       if (StringUtils.isNotBlank(value)) {
         if (logger.isDebugEnabled()) {
           logger.debug(String.format("Adding value [%s] for property [%s].", value, key));
         }
         sb.append(value);
         properties.put(key, StringUtils.trim(sb.toString()));
       }
     }
   }
 }
Пример #3
0
 /**
  * 遍历解析元素
  *
  * @param element
  */
 public void treeWalk(Element element) {
   for (int i = 0, size = element.nodeCount(); i < size; i++) {
     Node node = element.node(i);
     if (node instanceof Element) {
       treeWalk((Element) node);
     } else {
       // 处理....
     }
   }
 }
Пример #4
0
  // Implementation methods
  // -------------------------------------------------------------------------
  protected void writeElement(Element element) throws IOException {
    int size = element.nodeCount();
    String qualifiedName = element.getQualifiedName();

    writePrintln();
    indent();

    writer.write("<");
    writer.write(qualifiedName);

    int previouslyDeclaredNamespaces = namespaceStack.size();
    Namespace ns = element.getNamespace();

    if (isNamespaceDeclaration(ns)) {
      namespaceStack.push(ns);
      writeNamespace(ns);
    }

    // Print out additional namespace declarations
    boolean textOnly = true;

    for (int i = 0; i < size; i++) {
      Node node = element.node(i);

      if (node instanceof Namespace) {
        Namespace additional = (Namespace) node;

        if (isNamespaceDeclaration(additional)) {
          namespaceStack.push(additional);
          writeNamespace(additional);
        }
      } else if (node instanceof Element) {
        textOnly = false;
      } else if (node instanceof Comment) {
        textOnly = false;
      }
    }

    writeAttributes(element);

    lastOutputNodeType = Node.ELEMENT_NODE;

    if (size <= 0) {
      writeEmptyElementClose(qualifiedName);
    } else {
      writer.write(">");

      if (textOnly) {
        // we have at least one text node so lets assume
        // that its non-empty
        writeElementContent(element);
      } else {
        // we know it's not null or empty from above
        ++indentLevel;

        writeElementContent(element);

        --indentLevel;

        writePrintln();
        indent();
      }

      writer.write("</");
      writer.write(qualifiedName);
      writer.write(">");
    }

    // remove declared namespaceStack from stack
    while (namespaceStack.size() > previouslyDeclaredNamespaces) {
      namespaceStack.pop();
    }

    lastOutputNodeType = Node.ELEMENT_NODE;
  }