Exemple #1
0
  /** Evaluate in a context where a string is wanted */
  public CharSequence evaluateAsString(XPathContext context) throws XPathException {

    int numArgs = argument.length;
    Controller ctrl = context.getController();

    DecimalSymbols dfs = decimalFormatSymbols;

    AtomicValue av0 = (AtomicValue) argument[0].evaluateItem(context);
    if (av0 == null) {
      av0 = DoubleValue.NaN;
    }
    NumericValue number = (NumericValue) av0;

    if (dfs == null) {
      // the decimal-format name was not resolved statically
      if (requireFixup) {
        // we registered for a fixup, but none came
        dynamicError("Unknown decimal format name", "XTDE1280", context);
        return null;
      }
      DecimalFormatManager dfm = ctrl.getExecutable().getDecimalFormatManager();
      if (numArgs == 2) {
        dfs = dfm.getDefaultDecimalFormat();
      } else {
        // the decimal-format name was given as a run-time expression
        String lexicalName = argument[2].evaluateItem(context).getStringValue();
        StructuredQName qName = null;
        try {
          qName =
              StructuredQName.fromLexicalQName(
                  lexicalName, false, context.getConfiguration().getNameChecker(), nsContext);
        } catch (XPathException e) {
          dynamicError("Invalid decimal format name. " + e.getMessage(), "XTDE1280", context);
        }

        dfs = dfm.getNamedDecimalFormat(qName);
        if (dfs == null) {
          dynamicError(
              "format-number function: decimal-format '" + lexicalName + "' is not defined",
              "XTDE1280",
              context);
          return null;
        }
      }
    }
    SubPicture[] pics = subPictures;
    if (pics == null) {
      String format = argument[1].evaluateItem(context).getStringValue();
      pics = getSubPictures(format, dfs);
    }
    return formatNumber(number, pics, dfs).toString();
  }
Exemple #2
0
 public TailCall processLeavingTail(XPathContext context) throws XPathException {
   // TODO: we're always constructing the document in memory. Sometimes we could push it out
   // directly.
   Item item = evaluateItem(context);
   if (item != null) {
     SequenceReceiver out = context.getReceiver();
     out.append(item, locationId, NodeInfo.ALL_NAMESPACES);
   }
   return null;
 }
Exemple #3
0
  /** Evaluate as an expression. */
  public Item evaluateItem(XPathContext context) throws XPathException {
    if (isLazyConstruction()
        && (context.getConfiguration().areAllNodesUntyped()
            || (validation == Validation.PRESERVE && getSchemaType() == null))) {
      return new UnconstructedDocument(this, context);
    } else {
      Controller controller = context.getController();
      DocumentInfo root;
      if (textOnly) {
        CharSequence textValue;
        if (constantText != null) {
          textValue = constantText;
        } else {
          FastStringBuffer sb = new FastStringBuffer(100);
          SequenceIterator iter = content.iterate(context);
          while (true) {
            Item item = iter.next();
            if (item == null) break;
            sb.append(item.getStringValueCS());
          }
          textValue = sb.condense();
        }
        root = new TextFragmentValue(textValue, getBaseURI());
        ((TextFragmentValue) root).setConfiguration(controller.getConfiguration());
      } else {
        try {
          XPathContext c2 = context.newMinorContext();
          c2.setOrigin(this);

          Builder builder = controller.makeBuilder();
          // builder.setSizeParameters(treeSizeParameters);
          builder.setLineNumbering(controller.getConfiguration().isLineNumbering());

          // receiver.setSystemId(getBaseURI());
          builder.setBaseURI(getBaseURI());
          builder.setTiming(false);

          PipelineConfiguration pipe = controller.makePipelineConfiguration();
          pipe.setHostLanguage(getHostLanguage());
          // pipe.setBaseURI(baseURI);
          builder.setPipelineConfiguration(pipe);

          c2.changeOutputDestination(
              null, builder, false, getHostLanguage(), validation, getSchemaType());
          Receiver out = c2.getReceiver();
          out.open();
          out.startDocument(0);

          content.process(c2);

          out.endDocument();
          out.close();

          root = (DocumentInfo) builder.getCurrentRoot();
        } catch (XPathException e) {
          e.maybeSetLocation(this);
          e.maybeSetContext(context);
          throw e;
        }
      }
      return root;
    }
  }