Esempio 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
      }
    }
  }
Esempio n. 2
0
  protected static void checkContentSequence(
      StaticContext env, Expression content, int validation, SchemaType type)
      throws XPathException {
    Expression[] components;
    if (content instanceof Block) {
      components = ((Block) content).getChildren();
    } else {
      components = new Expression[] {content};
    }

    int elementCount = 0;
    boolean isXSLT = content.getHostLanguage() == Configuration.XSLT;
    TypeHierarchy th = env.getConfiguration().getTypeHierarchy();
    for (int i = 0; i < components.length; i++) {
      ItemType it = components[i].getItemType(th);
      if (it instanceof NodeTest) {
        int possibleNodeKinds = ((NodeTest) it).getNodeKindMask();
        if (possibleNodeKinds == 1 << Type.ATTRIBUTE) {
          XPathException de =
              new XPathException("Cannot create an attribute node whose parent is a document node");
          de.setErrorCode(isXSLT ? "XTDE0420" : "XPTY0004");
          de.setLocator(components[i]);
          throw de;
        } else if (possibleNodeKinds == 1 << Type.NAMESPACE) {
          XPathException de =
              new XPathException("Cannot create a namespace node whose parent is a document node");
          de.setErrorCode(isXSLT ? "XTDE0420" : "XQTY0024");
          de.setLocator(components[i]);
          throw de;
        }
        if (possibleNodeKinds == 1 << Type.ELEMENT) {
          elementCount++;
          if (elementCount > 1
              && (validation == Validation.STRICT
                  || validation == Validation.LAX
                  || type != null)) {
            XPathException de =
                new XPathException("A valid document must have only one child element");
            if (isXSLT) {
              de.setErrorCode("XTTE1550");
            } else {
              de.setErrorCode("XQDY0061");
            }
            de.setLocator(components[i]);
            throw de;
          }
          if (validation == Validation.STRICT && components[i] instanceof FixedElement) {
            SchemaDeclaration decl =
                env.getConfiguration()
                    .getElementDeclaration(
                        ((FixedElement) components[i]).getNameCode(null) & NamePool.FP_MASK);
            if (decl != null) {
              ((FixedElement) components[i])
                  .getContentExpression()
                  .checkPermittedContents(decl.getType(), env, true);
            }
          }
        }
      }
    }
  }