Example #1
0
  /**
   * Analyze a picture string into two sub-pictures.
   *
   * @param picture the picture as written (possibly two subpictures separated by a semicolon)
   * @param dfs the decimal format symbols
   * @return an array of two sub-pictures, the positive and the negative sub-pictures respectively.
   *     If there is only one sub-picture, the second one is null.
   */
  private SubPicture[] getSubPictures(String picture, DecimalSymbols dfs) throws XPathException {
    int[] picture4 = StringValue.expand(picture);
    SubPicture[] pics = new SubPicture[2];
    if (picture4.length == 0) {
      XPathException err = new XPathException("format-number() picture is zero-length");
      err.setErrorCode("XTDE1310");
      throw err;
    }
    int sep = -1;
    for (int c = 0; c < picture4.length; c++) {
      if (picture4[c] == dfs.patternSeparator) {
        if (c == 0) {
          grumble("first subpicture is zero-length");
        } else if (sep >= 0) {
          grumble("more than one pattern separator");
        } else if (sep == picture4.length - 1) {
          grumble("second subpicture is zero-length");
        }
        sep = c;
      }
    }

    if (sep < 0) {
      pics[0] = new SubPicture(picture4, dfs);
      pics[1] = null;
    } else {
      int[] pic0 = new int[sep];
      System.arraycopy(picture4, 0, pic0, 0, sep);
      int[] pic1 = new int[picture4.length - sep - 1];
      System.arraycopy(picture4, sep + 1, pic1, 0, picture4.length - sep - 1);
      pics[0] = new SubPicture(pic0, dfs);
      pics[1] = new SubPicture(pic1, dfs);
    }
    return pics;
  }
Example #2
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
      }
    }
  }