Ejemplo n.º 1
0
 /**
  * Evaluate an XPath expression on the document as an attribute value template, and return its
  * string value.
  */
 public static String evaluateAsAvt(
     PropertyContext propertyContext,
     XPathCache.XPathContext xpathContext,
     Item contextItem,
     String xpathString) {
   return evaluateAsAvt(
       propertyContext,
       Collections.singletonList(contextItem),
       1,
       xpathString,
       xpathContext.prefixToURIMap,
       xpathContext.variableToValueMap,
       xpathContext.functionLibrary,
       xpathContext.functionContext,
       xpathContext.baseURI,
       xpathContext.locationData);
 }
Ejemplo n.º 2
0
 /** Evaluate an XPath expression on the document. */
 public static List evaluate(
     PropertyContext propertyContext,
     Item contextItem,
     String xpathString,
     Map<String, String> prefixToURIMap,
     Map<String, ValueRepresentation> variableToValueMap,
     FunctionLibrary functionLibrary,
     FunctionContext functionContext,
     String baseURI,
     LocationData locationData) {
   return evaluate(
       propertyContext,
       Collections.singletonList(contextItem),
       1,
       xpathString,
       prefixToURIMap,
       variableToValueMap,
       functionLibrary,
       functionContext,
       baseURI,
       locationData);
 }
Ejemplo n.º 3
0
 public static PooledXPathExpression getXPathExpression(
     PropertyContext propertyContext,
     Item contextItem,
     String xpathString,
     Map<String, String> prefixToURIMap,
     Map<String, ValueRepresentation> variableToValueMap,
     FunctionLibrary functionLibrary,
     String baseURI,
     LocationData locationData) {
   final List<Item> contextItems = Collections.singletonList(contextItem);
   return getXPathExpression(
       propertyContext,
       contextItems,
       1,
       xpathString,
       prefixToURIMap,
       variableToValueMap,
       functionLibrary,
       baseURI,
       false,
       false,
       locationData);
 }
Ejemplo n.º 4
0
  private static List<String> analyzeExpression(Expression expression, String xpathString) {
    if (expression instanceof ComputedExpression) {
      try {
        final PathMap pathmap = new PathMap((ComputedExpression) expression, new Configuration());
        logger.info("TEST XPATH PATHS - path for expression: " + xpathString);
        pathmap.diagnosticDump(System.out);

        final int dependencies = expression.getDependencies();

        if ((dependencies & StaticProperty.DEPENDS_ON_CONTEXT_ITEM) != 0) {
          System.out.println("  xxx DEPENDS_ON_CONTEXT_ITEM");
          return null;
        }
        if ((dependencies & StaticProperty.DEPENDS_ON_CURRENT_ITEM) != 0) {
          System.out.println("  xxx DEPENDS_ON_CURRENT_ITEM");
          return null;
        }
        if ((dependencies & StaticProperty.DEPENDS_ON_CONTEXT_DOCUMENT) != 0) {
          System.out.println("  xxx DEPENDS_ON_CONTEXT_DOCUMENT");
          return null;
        }
        if ((dependencies & StaticProperty.DEPENDS_ON_LOCAL_VARIABLES) != 0) {
          System.out.println("  xxx DEPENDS_ON_LOCAL_VARIABLES");
          // Some day we'll have variables
          return null;
        }
        if ((dependencies & StaticProperty.NON_CREATIVE) != 0) {
          System.out.println("  xxx NON_CREATIVE");
        }

        final List<String> instancesList = new ArrayList<String>();

        final PathMap.PathMapRoot[] roots = pathmap.getPathMapRoots();
        for (final PathMap.PathMapRoot root : roots) {
          final Expression rootExpression = root.getRootExpression();

          if (rootExpression instanceof Instance || rootExpression instanceof XXFormsInstance) {
            final FunctionCall functionCall = (FunctionCall) rootExpression;

            // TODO: Saxon 9.0 expressions should test "instanceof StringValue" to "instanceof
            // StringLiteral"
            if (functionCall.getArguments()[0] instanceof StringValue) {
              final String instanceName =
                  ((StringValue) functionCall.getArguments()[0]).getStringValue();
              instancesList.add(instanceName);
            } else {
              // Instance name is not known at compile time
              return null;
            }
          } else if (rootExpression
              instanceof Doc) { // don't need document() function as that is XSLT
            final FunctionCall functionCall = (FunctionCall) rootExpression;

            // TODO: Saxon 9.0 expressions should test "instanceof StringValue" to "instanceof
            // StringLiteral"
            if (functionCall.getArguments()[0] instanceof StringValue) {
              //                            final String literalURI = ((StringValue)
              // functionCall.getArguments()[0]).getStringValue();
              return null;
            } else {
              // Document name is not known at compile time
              return null;
            }
          } else if (rootExpression instanceof ContextItemExpression) {
            return null;
          } else if (rootExpression instanceof RootExpression) {
            // We depend on the current XForms model.
            return null;
          }

          //                                final PathMap.PathMapArc[] rootArcs = root.getArcs();
          //
          //                                for (int j = 0; j < rootArcs.length; j++) {
          //                                    final PathMapArc currentArc = rootArcs[j];
          //                                    final AxisExpression getStep
          //                                }

        }
        return instancesList;

      } catch (Exception e) {
        logger.error("EXCEPTION WHILE ANALYZING PATHS: " + xpathString);
        return null;
      }
    } else {
      logger.info("TEST XPATH PATHS - expression not a ComputedExpression: " + xpathString);
      return Collections.emptyList();
    }
  }