private void addElementsToProperties(List elements, Properties props, String parentPath) {

    for (java.lang.Object o : elements) {
      Node ele = (Node) o;
      if (ele.getNodeType() != 1) { // text
        continue;
      }
      String contents = ele.getText().trim();

      String newParentPath = "";

      if (!StringUtils.isEmpty(parentPath)) {
        newParentPath = parentPath + ".";
      }
      newParentPath += ele.getName();

      if (!StringUtils.isEmpty(contents)) {
        props.setProperty(newParentPath, contents);
      }
      if (ele instanceof Element) {
        List children = ((Element) ele).content();

        addElementsToProperties(children, props, newParentPath);
      }
    }
  }
Exemplo n.º 2
0
 private boolean canInclude(String path, List<Node> rules, Matcher matcher) {
   boolean canInclude = false;
   logger.info(
       "[Timing] Testing inclusion rule: "
           + (new SimpleDateFormat("HH:mm:ss.SSS")).format(new Date()));
   /* Rules are listed from least to most important */
   matcher.find();
   for (Node rule : rules) {
     String mode = rule.getName();
     String tokenizedRule = rule.getText();
     for (int i = 1; i <= matcher.groupCount(); i++) {
       tokenizedRule = tokenizedRule.replaceAll("\\$" + i, matcher.group(i));
     }
     if ("include".equals(mode)) {
       if (path.matches(tokenizedRule)) {
         canInclude = true;
       }
     } else if ("exclude".equals(mode)) {
       if (path.matches(tokenizedRule)) {
         canInclude = false;
       }
     } else {
       logger.warn("Inclusion rule mode " + mode + " not supported.");
     }
   }
   logger.info(
       "[Timing] Finished testing inclusion rule: "
           + (new SimpleDateFormat("HH:mm:ss.SSS")).format(new Date()));
   return canInclude;
 }
Exemplo n.º 3
0
  /**
   * 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数 注意:远程解析XML出错,与服务器是否支持SSL等配置有关
   *
   * @return 时间戳字符串
   * @throws IOException
   * @throws DocumentException
   * @throws MalformedURLException
   */
  @SuppressWarnings("unchecked")
  public static String query_timestamp()
      throws MalformedURLException, DocumentException, IOException {

    // 构造访问query_timestamp接口的URL串
    String strUrl =
        ALIPAY_GATEWAY_NEW
            + "service=query_timestamp&partner="
            + AlipayConfig.partner
            + "&_input_charset"
            + AlipayConfig.input_charset;
    StringBuffer result = new StringBuffer();

    SAXReader reader = new SAXReader();
    Document doc = reader.read(new URL(strUrl).openStream());

    List<Node> nodeList = doc.selectNodes("//alipay/*");

    for (Node node : nodeList) {
      // 截取部分不需要解析的信息
      if (node.getName().equals("is_success") && node.getText().equals("T")) {
        // 判断是否有成功标示
        List<Node> nodeList1 = doc.selectNodes("//response/timestamp/*");
        for (Node node1 : nodeList1) {
          result.append(node1.getText());
        }
      }
    }

    return result.toString();
  }
Exemplo n.º 4
0
  /**
   * @param componentDefinition
   * @param props
   */
  private static void updateComponent(final Element componentDefinition, final HashMap props) {
    Iterator iter = props.keySet().iterator();

    while (iter.hasNext()) {
      Object key = iter.next();
      Node node = componentDefinition.selectSingleNode(key.toString());
      if (node == null) {
        node = componentDefinition.addElement(key.toString());
      }
      if (PivotViewComponent.OPTIONS.equals(node.getName())) {
        List optionsList = (List) props.get(key);
        Iterator optsIter = optionsList.iterator();
        while (optsIter.hasNext()) {
          String anOption = optsIter.next().toString();
          Node anOptionNode = node.selectSingleNode(anOption);
          if (anOptionNode == null) {
            ((Element) node).addElement(anOption);
          }
        }
      } else {
        Object value = props.get(key);
        if (value != null) {
          // remove existing text
          node.setText(""); // $NON-NLS-1$
          ((Element) node).addCDATA(value.toString());
        }
      }
    }
    // the property "mdx" is no longer being put in the hashmap. So,
    // query will be passed properly now.
  }
  /**
   * sbarkdull: method appears to never be used anywhere
   *
   * @param actionRootNode
   * @param logger
   * @param nodePath
   * @param mapTo
   * @return
   */
  static int parseActionResourceDefinitions(
      final Node actionRootNode, final ILogger logger, final String nodePath, final Map mapTo) {

    try {
      List resources = actionRootNode.selectNodes(nodePath);

      // TODO create objects to represent the types
      // TODO need source variable list
      Iterator resourcesIterator = resources.iterator();

      Node resourceNode;
      String resourceName;
      while (resourcesIterator.hasNext()) {
        resourceNode = (Node) resourcesIterator.next();
        resourceName = resourceNode.getName();
        if (mapTo != null) {
          mapTo.put(
              resourceName,
              XmlDom4JHelper.getNodeText("@mapping", resourceNode, resourceName)); // $NON-NLS-1$
        }
      }
      return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK;
    } catch (Exception e) {
      logger.error(
          Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0006_PARSING_RESOURCE"),
          e); //$NON-NLS-1$
    }
    return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC;
  }
 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()));
       }
     }
   }
 }
  private static IActionSequence getNextLoopGroup(
      final ISequenceDefinition seqDef,
      final Node actionsNode,
      final String solutionPath,
      final String solutionName,
      final ILogger logger,
      final int loggingLevel) {

    String loopParameterName = XmlDom4JHelper.getNodeText("@loop-on", actionsNode); // $NON-NLS-1$
    boolean loopUsingPeek =
        "true"
            .equalsIgnoreCase(
                XmlDom4JHelper.getNodeText("@peek-only", actionsNode)); // $NON-NLS-1$ //$NON-NLS-2$

    Node actionDefinitionNode;
    ActionDefinition actionDefinition;

    List actionDefinitionList = new ArrayList();

    List nodeList = actionsNode.selectNodes("*"); // $NON-NLS-1$
    Iterator actionDefinitionNodes = nodeList.iterator();
    while (actionDefinitionNodes.hasNext()) {
      actionDefinitionNode = (Node) actionDefinitionNodes.next();
      if (actionDefinitionNode.getName().equals("actions")) { // $NON-NLS-1$
        actionDefinitionList.add(
            SequenceDefinition.getNextLoopGroup(
                seqDef, actionDefinitionNode, solutionPath, solutionName, logger, loggingLevel));
      } else if (actionDefinitionNode.getName().equals("action-definition")) { // $NON-NLS-1$
        actionDefinition = new ActionDefinition(actionDefinitionNode, logger);
        actionDefinition.setLoggingLevel(loggingLevel);
        actionDefinitionList.add(actionDefinition);
      }
    }
    // action sequences with 0 actions are valid, see: JIRA PLATFORM-837

    IConditionalExecution conditionalExecution =
        SequenceDefinition.parseConditionalExecution(
            actionsNode, logger, "condition"); // $NON-NLS-1$

    ActionSequence sequence =
        new ActionSequence(loopParameterName, seqDef, actionDefinitionList, loopUsingPeek);

    sequence.setConditionalExecution(conditionalExecution);
    return sequence;
  }
Exemplo n.º 8
0
 private void getDescentantElements(Branch node) {
   String tagName = selector.getTagName();
   Iterator<Node> nodeIterator = node.nodeIterator();
   while (nodeIterator.hasNext()) {
     Node child = nodeIterator.next();
     if (child.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
       if (tagName.equals("*") || child.getName().equals(tagName)) {
         result.add((Branch) child);
       }
       getDescentantElements((Branch) child);
     }
   }
 }
Exemplo n.º 9
0
 /**
  * Get child elements.
  *
  * @see <a href="http://www.w3.org/TR/css3-selectors/#child-combinators">Child combinators</a>
  */
 private void getChildElements() {
   String tag = selector.getTagName();
   for (Branch node : nodes) {
     Iterator<Node> nodeIterator = node.nodeIterator();
     while (nodeIterator.hasNext()) {
       Node child = nodeIterator.next();
       if (child.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE) {
         continue;
       }
       if (tag.equals(child.getName()) || tag.equals(Selector.UNIVERSAL_TAG)) {
         result.add((Branch) child);
       }
     }
   }
 }
Exemplo n.º 10
0
 /**
  * TODO 针对较小的UL合并行时做的调整
  *
  * @param element 当前节点
  * @throws Exception
  */
 @SuppressWarnings("unchecked")
 public void modifyUL(Element element, HashSet<String> hashSet, String enginId) throws Exception {
   List<Node> nodeList = element.content();
   Node nc;
   Element ec;
   String name;
   for (int m = 0; m < nodeList.size(); m++) {
     nc = nodeList.get(m);
     if (nc.getNodeType() == Node.ELEMENT_NODE) {
       name = nc.getName();
       ec = (Element) nc;
       // 如果该孩子节点标签不是BR,收集该孩子节点
       if (BR.equalsIgnoreCase(name)) {
         nodeList.remove(m--);
         element.setContent(nodeList);
       }
       modifyUL(ec, hashSet, enginId);
     }
   }
 }
Exemplo n.º 11
0
  /**
   * 根据xpath路径获得指定的节点信息列表 <br>
   * 列表中每一个Map代表一个节点,key为节点的属性名称,value为对应属性的值 <br>
   * <br>
   * <b>key统一为小写</b><br>
   * <br>
   * key为<b>node_name</b>表示该节点的名称<br>
   * key为<b>node_value</b>表示该节点的值
   *
   * @param document 待解析的文档对象
   * @param xpath 节点路径
   * @return 节点列表
   */
  public static List<Map<String, String>> getNodeInfoList(Document document, String xpath) {
    List<Map<String, String>> result = null;

    // 进行命名空间处理
    if (!StringUtils.isEmptyString(document.getRootElement().getNamespaceURI())) {
      // 将xpath中增加命名空间
      xpath = xpath.replaceAll(XPATH_NAMESPACE_REGEX, XPATH_REPLACE_NAMESPACE);
    }

    List list = document.selectNodes(xpath);

    if (list != null && list.size() > 0) {
      result = new ArrayList<Map<String, String>>();

      for (Object obj : list) {
        Element element = (Element) obj;

        Map<String, String> map = new HashMap<String, String>();

        map.put("node_name", element.getName()); // 节点名称
        map.put("node_value", element.getText()); // 节点值

        List attrList = element.attributes();

        if (attrList != null && attrList.size() > 0) {
          for (Object o : attrList) {
            Node attr = (Node) o;

            map.put(attr.getName().toLowerCase(), attr.getText());
          }
        }

        result.add(map);
      }
    }

    return result;
  }
Exemplo n.º 12
0
  /**
   * 解析xml字符串
   *
   * @param xmlStr 支付宝处理后返回的字符串
   * @return Map
   */
  @SuppressWarnings("unchecked")
  public static Map<String, String> readXml(String xmlStr) {
    try {
      Document document = DocumentHelper.parseText(xmlStr);
      Map<String, String> responseMap = new HashMap<>();

      List<Node> nodeList = document.selectNodes("//alipay/*");
      for (Node node : nodeList) {
        if (node.getName().equals("is_success")) {
          responseMap.put(node.getName(), node.getText());
        }
        if (node.getName().equals("error")) {
          responseMap.put(node.getName(), node.getText());
        }

        if (node.getName().equals("request")) {
          List<Node> nodeList1 = document.selectNodes("//request/*");
          for (Node node1 : nodeList1) {
            responseMap.put(node1.getName(), node1.getText());
          }
        }
        if (node.getName().equals("response")) {
          // 判断是否有成功标示
          // List<Node> nodeList2 = document.selectNodes("//response/payonline/*");
          List<Node> nodeList2 = document.selectNodes("//response/trade/*");
          for (Node node2 : nodeList2) {
            responseMap.put(node2.getName(), node2.getText());
          }
        }
        if (node.getName().equals("sign")) {
          responseMap.put(node.getName(), node.getText());
        }
        if (node.getName().equals("sign_type")) {
          responseMap.put(node.getName(), node.getText());
        }
      }
      return responseMap;

    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
Exemplo n.º 13
0
  private int parseResourceDefinitions(final Node actionRootNode, final ILogger logger) {

    resourceDefinitions = new ListOrderedMap();

    try {
      List resources = actionRootNode.selectNodes("resources/*"); // $NON-NLS-1$

      // TODO create objects to represent the types
      // TODO need source variable list
      Iterator resourcesIterator = resources.iterator();

      Node resourceNode;
      String resourceName;
      String resourceTypeName;
      String resourceMimeType;
      int resourceType;
      ActionResource resource;
      Node typeNode, mimeNode;
      while (resourcesIterator.hasNext()) {
        resourceNode = (Node) resourcesIterator.next();
        typeNode = resourceNode.selectSingleNode("./*"); // $NON-NLS-1$
        if (typeNode != null) {
          resourceName = resourceNode.getName();
          resourceTypeName = typeNode.getName();
          resourceType = ActionResource.getResourceType(resourceTypeName);
          String resourceLocation = XmlDom4JHelper.getNodeText("location", typeNode); // $NON-NLS-1$
          if (resourceType == IActionSequenceResource.SOLUTION_FILE_RESOURCE) {
            if (resourceLocation == null) {
              logger.error(
                  Messages.getInstance()
                      .getErrorString(
                          "SequenceDefinition.ERROR_0008_RESOURCE_NO_LOCATION",
                          resourceName)); //$NON-NLS-1$
              continue;
            }
          } else if (resourceType == IActionSequenceResource.STRING) {
            resourceLocation = XmlDom4JHelper.getNodeText("string", resourceNode); // $NON-NLS-1$
          } else if (resourceType == IActionSequenceResource.XML) {
            // resourceLocation = XmlHelper.getNodeText("xml", resourceNode); //$NON-NLS-1$
            Node xmlNode = typeNode.selectSingleNode("./location/*"); // $NON-NLS-1$
            // Danger, we have now lost the character encoding of the XML in this node
            // see BISERVER-895
            resourceLocation = (xmlNode == null) ? "" : xmlNode.asXML(); // $NON-NLS-1$
          }
          mimeNode = typeNode.selectSingleNode("mime-type"); // $NON-NLS-1$
          if (mimeNode != null) {
            resourceMimeType = mimeNode.getText();
            resource =
                new ActionResource(
                    resourceName,
                    resourceType,
                    resourceMimeType,
                    solutionName,
                    solutionPath,
                    resourceLocation);
            resourceDefinitions.put(resourceName, resource);
          } else {
            logger.error(
                Messages.getInstance()
                    .getErrorString(
                        "SequenceDefinition.ERROR_0007_RESOURCE_NO_MIME_TYPE",
                        resourceName)); //$NON-NLS-1$
          }
        }
        // input = new ActionParameter( resourceName, resourceType, null
        // );
        // resourceDefinitions.put( inputName, input );
      }
      return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK;
    } catch (Exception e) {
      logger.error(
          Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0006_PARSING_RESOURCE"),
          e); //$NON-NLS-1$
    }
    return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC;
  }
Exemplo n.º 14
0
  static int parseParameters(
      final Node actionRootNode,
      final ILogger logger,
      final String nodePath,
      final Map parameterMap,
      final Map mapTo,
      final boolean inputVar) {
    try {
      List parameters = actionRootNode.selectNodes(nodePath);

      // TODO create objects to represent the types
      // TODO need source variable list
      Iterator parametersIterator = parameters.iterator();
      Node parameterNode;
      String parameterName;
      String parameterType;
      ActionParameter parameter;
      List variableNodes;
      List variables;
      Node variableNode;
      Iterator variablesIterator;
      String variableSource;
      String variableName;
      int variableIdx;
      Object defaultValue = null;

      while (parametersIterator.hasNext()) {
        parameterNode = (Node) parametersIterator.next();
        parameterName = parameterNode.getName();
        parameterType = XmlDom4JHelper.getNodeText("@type", parameterNode); // $NON-NLS-1$

        if (mapTo != null) {
          mapTo.put(
              parameterName,
              XmlDom4JHelper.getNodeText("@mapping", parameterNode, parameterName)); // $NON-NLS-1$
        }

        defaultValue = SequenceDefinition.getDefaultValue(parameterNode);
        // get the list of sources for this parameter
        variableNodes =
            parameterNode.selectNodes(
                (inputVar) ? "sources/*" : "destinations/*"); // $NON-NLS-1$ //$NON-NLS-2$
        variablesIterator = variableNodes.iterator();
        variableIdx = 1;
        variables = new ArrayList();
        while (variablesIterator.hasNext()) {
          variableNode = (Node) variablesIterator.next();
          // try to resolve the parameter value for this
          try {
            variableSource = variableNode.getName();
            variableName = variableNode.getText();
            ActionParameterSource variable =
                new ActionParameterSource(variableSource, variableName);
            if (SequenceDefinition.debug) {
              logger.debug(
                  Messages.getInstance()
                      .getString(
                          "SequenceDefinition.DEBUG_ADDING_SOURCE_FOR_PARAMETER",
                          variableSource,
                          parameterName)); //$NON-NLS-1$
            }

            variables.add(variable);
          } catch (Exception e) {
            logger.error(
                Messages.getInstance()
                    .getErrorString(
                        "SequenceDefinition.ERROR_0004_VARIABLE_SOURCE_NOT_VALID",
                        Integer.toString(variableIdx),
                        parameterName),
                e); //$NON-NLS-1$
          }
          variableIdx++;
        }
        if (defaultValue != null) {
          if (SequenceDefinition.debug) {
            logger.debug(
                Messages.getInstance()
                    .getString(
                        "SequenceDefinition.DEBUG_USING_DEFAULT_VALUE",
                        defaultValue.toString(),
                        parameterName)); //$NON-NLS-1$
          }
        }
        parameter =
            new ActionParameter(parameterName, parameterType, null, variables, defaultValue);
        parameterMap.put(parameterName, parameter);
      }
      return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK;
    } catch (Exception e) {
      logger.error(
          Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0005_PARSING_PARAMETERS"),
          e); //$NON-NLS-1$
    }

    return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC;
  }