Пример #1
0
  public void prepareAttributes() throws TransformerConfigurationException {

    String disableAtt = null;

    AttributeCollection atts = getAttributeList();

    for (int a = 0; a < atts.getLength(); a++) {
      int nc = atts.getNameCode(a);
      String f = getNamePool().getClarkName(nc);
      if (f == StandardNames.DISABLE_OUTPUT_ESCAPING) {
        disableAtt = atts.getValue(a).trim();
      } else {
        checkUnknownAttribute(nc);
      }
    }

    if (disableAtt != null) {
      if (disableAtt.equals("yes")) {
        disable = true;
      } else if (disableAtt.equals("no")) {
        disable = false;
      } else {
        compileError("disable-output-escaping attribute must be either 'yes' or 'no'", "XT0020");
      }
    }
  }
Пример #2
0
  public void prepareAttributes() throws XPathException {

    AttributeCollection atts = getAttributeList();

    String nameAtt = null;
    String namespaceAtt = null;
    String selectAtt = null;
    String separatorAtt = null;
    String validationAtt = null;
    String typeAtt = null;

    for (int a = 0; a < atts.getLength(); a++) {
      int nc = atts.getNameCode(a);
      String f = getNamePool().getClarkName(nc);
      if (f == StandardNames.NAME) {
        nameAtt = Whitespace.trim(atts.getValue(a));
      } else if (f == StandardNames.NAMESPACE) {
        namespaceAtt = Whitespace.trim(atts.getValue(a));
      } else if (f == StandardNames.SELECT) {
        selectAtt = atts.getValue(a);
      } else if (f == StandardNames.SEPARATOR) {
        separatorAtt = atts.getValue(a);
      } else if (f == StandardNames.VALIDATION) {
        validationAtt = Whitespace.trim(atts.getValue(a));
      } else if (f == StandardNames.TYPE) {
        typeAtt = Whitespace.trim(atts.getValue(a));
      } else {
        checkUnknownAttribute(nc);
      }
    }

    if (nameAtt == null) {
      reportAbsence("name");
      return;
    }
    attributeName = makeAttributeValueTemplate(nameAtt);
    if (attributeName instanceof StringLiteral) {
      if (!getConfiguration()
          .getNameChecker()
          .isQName(((StringLiteral) attributeName).getStringValue())) {
        invalidAttributeName("Attribute name " + Err.wrap(nameAtt) + " is not a valid QName");
      }
      if (nameAtt.equals("xmlns")) {
        if (namespace == null) {
          invalidAttributeName("Invalid attribute name: xmlns");
        }
      }
      if (nameAtt.startsWith("xmlns:")) {
        if (namespaceAtt == null) {
          invalidAttributeName("Invalid attribute name: " + Err.wrap(nameAtt));
        } else {
          // ignore the prefix "xmlns"
          nameAtt = nameAtt.substring(6);
          attributeName = new StringLiteral(nameAtt);
        }
      }
    }

    if (namespaceAtt != null) {
      namespace = makeAttributeValueTemplate(namespaceAtt);
      if (namespace instanceof StringLiteral) {
        if (!AnyURIValue.isValidURI(((StringLiteral) namespace).getStringValue())) {
          compileError("The value of the namespace attribute must be a valid URI", "XTDE0865");
        }
      }
    }

    if (selectAtt != null) {
      select = makeExpression(selectAtt);
    }

    if (separatorAtt == null) {
      if (selectAtt == null) {
        separator = new StringLiteral(StringValue.EMPTY_STRING);
      } else {
        separator = new StringLiteral(StringValue.SINGLE_SPACE);
      }
    } else {
      separator = makeAttributeValueTemplate(separatorAtt);
    }

    if (validationAtt != null) {
      validationAction = Validation.getCode(validationAtt);
      if (validationAction != Validation.STRIP && !getExecutable().isSchemaAware()) {
        validationAction = Validation.STRIP;
        compileError("To perform validation, a schema-aware XSLT processor is needed", "XTSE1660");
      }
      if (validationAction == Validation.INVALID) {
        compileError("Invalid value of validation attribute", "XTSE0020");
        validationAction = getContainingStylesheet().getDefaultValidation();
      }
    } else {
      validationAction = getContainingStylesheet().getDefaultValidation();
    }

    if (typeAtt != null) {
      if (!getExecutable().isSchemaAware()) {
        compileError(
            "The @type attribute is available only with a schema-aware XSLT processor", "XTSE1660");
      } else {
        SchemaType type = getSchemaType(typeAtt);
        if (type == null) {
          compileError("Unknown attribute type " + typeAtt, "XTSE1520");
        } else {
          if (type.isSimpleType()) {
            schemaType = (SimpleType) type;
          } else {
            compileError("Type annotation for attributes must be a simple type", "XTSE1530");
            type = null;
          }
        }
        validationAction = Validation.BY_TYPE;
      }
    }

    if (typeAtt != null && validationAtt != null) {
      compileError("The validation and type attributes are mutually exclusive", "XTSE1505");
      validationAction = getContainingStylesheet().getDefaultValidation();
      schemaType = null;
    }
  }