Exemplo n.º 1
0
  public void checkArguments(ExpressionVisitor visitor) throws XPathException {
    StaticContext env = visitor.getStaticContext();
    if (checked) return;
    checked = true;
    super.checkArguments(visitor);
    if (argument[1] instanceof StringLiteral) {
      // picture is known statically - optimize for this common case
      picture = ((StringLiteral) argument[1]).getStringValue();
    }
    if (argument.length == 3) {
      if (argument[2] instanceof StringLiteral) {
        // common case, decimal format name is supplied as a string literal

        String lexicalName = ((StringLiteral) argument[2]).getStringValue();

        StructuredQName qName;
        try {
          qName =
              StructuredQName.fromLexicalQName(
                  lexicalName,
                  false,
                  visitor.getConfiguration().getNameChecker(),
                  env.getNamespaceResolver());
        } catch (XPathException e) {
          XPathException se = new XPathException("Invalid decimal format name. " + e.getMessage());
          se.setErrorCode("XTDE1280");
          throw se;
        }

        DecimalFormatManager dfm =
            ((ExpressionContext) env).getXSLStylesheet().getDecimalFormatManager();
        requireFixup = true;
        dfm.registerUsage(qName, this);
        // this causes a callback to the fixup() method, either now, or later if it's a forwards
        // reference
      } else {
        // we need to save the namespace context
        nsContext = env.getNamespaceResolver();
      }
    } else {
      // two arguments only: it uses the default decimal format
      if (env instanceof ExpressionContext) {
        // this is XSLT
        DecimalFormatManager dfm =
            ((ExpressionContext) env).getXSLStylesheet().getDecimalFormatManager();
        dfm.registerUsage(DecimalFormatManager.DEFAULT_NAME, this);
        // Note: if using the "default default", there will be no fixup call.
      } else {
        // using saxon:decimal-format in some other environment
      }
    }
  }
 public void checkArguments(StaticContext env) throws XPathException {
   if (checked) return;
   checked = true;
   super.checkArguments(env);
   Optimizer opt = env.getConfiguration().getOptimizer();
   argument[1] = ExpressionTool.unsorted(opt, argument[1], false);
   if (argument[0] instanceof StringValue) {
     // common case, key name is supplied as a constant
     try {
       keyFingerprint =
           ((ExpressionContext) env)
               .getFingerprint(((StringValue) argument[0]).getStringValue(), false);
     } catch (XPathException e) {
       StaticError err =
           new StaticError(
               "Error in key name "
                   + ((StringValue) argument[0]).getStringValue()
                   + ": "
                   + e.getMessage());
       err.setLocator(this);
       err.setErrorCode("XTDE1260");
       throw err;
     }
     if (keyFingerprint == -1) {
       StaticError err =
           new StaticError(
               "Key " + ((StringValue) argument[0]).getStringValue() + " has not been defined");
       err.setLocator(this);
       err.setErrorCode("XTDE1260");
       throw err;
     }
   } else {
     // we need to save the namespace context
     nsContext = env.getNamespaceResolver();
   }
 }