コード例 #1
0
  public NodeList queryAbstractElementDocElem(
      String sheetName, String queryExpression, String requiredField) throws Exception {
    if (!queryExpression.contains(Constants.QUERY_EQUALS_EXP)) {
      throw new IllegalArgumentException("expression should contain =", null);
    }
    ArrayList<String> keyValSequence = new ArrayList<String>();
    if (queryExpression.contains(Constants.QUERY_CONCAT_EXP)) {
      String[] expressionArray_joined = queryExpression.split(Constants.QUERY_CONCAT_EXP);
      for (String equalsExpression : expressionArray_joined) {
        String[] expressionArray_equals = equalsExpression.split(Constants.QUERY_EQUALS_EXP);
        keyValSequence.add(expressionArray_equals[0]);
        keyValSequence.add(expressionArray_equals[1]);
      }
    } else {
      String[] expressionArray_equals = queryExpression.split(Constants.QUERY_EQUALS_EXP);
      keyValSequence.add(expressionArray_equals[0]);
      keyValSequence.add(expressionArray_equals[1]);
    }
    String[] expressionArray1 = {};
    String[] e = keyValSequence.toArray(expressionArray1);
    this.sheetName = sheetName;
    String toRet = "";
    if (docNew == null) {
      docNew = getSimpleXmlFromXls();
      RobotCache.getXmlCache().put(cacheId, docNew);
      docNew = RobotCache.getXmlCache().get(cacheId);
    } else {
      log.debug("Working with docNew from cache");
    }

    XPath xpath = XPathFactory.newInstance().newXPath();

    //		String query = "//Row/Record[(@key=\"" +expressionArray[0]+"\" and @value=\""
    // +expressionArray[1]+"\" )" +
    //				" and  (@key=\"" +expressionArray[2]+"\" and @value=\"" +expressionArray[3]+"\")"+
    //				"]/../Record[@key=\"" +requiredField+"\"]";
    String query = "";
    if (e.length > 2) {
      query = "//Row[" + e[0] + "='" + e[1] + "' and " + e[2] + "='" + e[3] + "']";
    } else {
      query = "//Row[" + e[0] + "='" + e[1] + "']";
    }

    log.debug("Query is " + query);

    XPathExpression expr = xpath.compile(query);
    Object result = expr.evaluate(docNew, XPathConstants.NODESET);
    NodeList tableRowNodes = (NodeList) result;

    log.info("returning " + tableRowNodes);

    return tableRowNodes;
  }
コード例 #2
0
 public XlsReader(File f) {
   this.file = f;
   cacheId = f.getName();
   docNew = RobotCache.getXmlCache().get(cacheId);
 }