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

    AttributeCollection atts = getAttributeList();

    for (int a = 0; a < atts.getLength(); a++) {
      int nc = atts.getNameCode(a);
      String f = getNamePool().getClarkName(nc);
      if (f.equals(StandardNames.MODE)) {
        modeAtt = Whitespace.trim(atts.getValue(a));
      } else if (f.equals(StandardNames.NAME)) {
        nameAtt = Whitespace.trim(atts.getValue(a));
      } else if (f.equals(StandardNames.MATCH)) {
        matchAtt = atts.getValue(a);
      } else if (f.equals(StandardNames.PRIORITY)) {
        priorityAtt = Whitespace.trim(atts.getValue(a));
      } else if (f.equals(StandardNames.AS)) {
        asAtt = atts.getValue(a);
      } else {
        checkUnknownAttribute(nc);
      }
    }
    try {
      if (modeAtt == null) {
        modeNames = new StructuredQName[1];
        modeNames[0] = Mode.DEFAULT_MODE_NAME;
      } else {
        if (matchAtt == null) {
          compileError(
              "The mode attribute must be absent if the match attribute is absent", "XTSE0500");
        }
        // mode is a space-separated list of mode names, or "#default", or "#all"

        int count = 0;
        boolean allModes = false;
        StringTokenizer st = new StringTokenizer(modeAtt, " \t\n\r", false);
        while (st.hasMoreTokens()) {
          st.nextToken();
          count++;
        }

        if (count == 0) {
          compileError("The mode attribute must not be empty", "XTSE0550");
        }

        modeNames = new StructuredQName[count];
        count = 0;
        st = new StringTokenizer(modeAtt, " \t\n\r", false);
        while (st.hasMoreTokens()) {
          String s = st.nextToken();
          StructuredQName mname;
          if ("#default".equals(s)) {
            mname = Mode.DEFAULT_MODE_NAME;
          } else if ("#all".equals(s)) {
            allModes = true;
            mname = Mode.ALL_MODES;
          } else {
            mname = makeQName(s);
          }
          for (int e = 0; e < count; e++) {
            if (modeNames[e].equals(mname)) {
              compileError("In the list of modes, the value " + s + " is duplicated", "XTSE0550");
            }
          }
          modeNames[count++] = mname;
        }
        if (allModes && (count > 1)) {
          compileError("mode='#all' cannot be combined with other modes", "XTSE0550");
        }
      }
    } catch (NamespaceException err) {
      compileError(err.getMessage(), "XTSE0280");
    } catch (XPathException err) {
      if (err.getErrorCodeLocalPart() == null) {
        err.setErrorCode("XTSE0280");
      } else if (err.getErrorCodeLocalPart().equals("XTSE0020")) {
        err.setErrorCode("XTSE0550");
      }
      err.setIsStaticError(true);
      compileError(err);
    }

    try {
      if (nameAtt != null) {
        StructuredQName qName = makeQName(nameAtt);
        setObjectName(qName);
        diagnosticId = nameAtt;
      }
    } catch (NamespaceException err) {
      compileError(err.getMessage(), "XTSE0280");
    } catch (XPathException err) {
      if (err.getErrorCodeLocalPart() == null) {
        err.setErrorCode("XTSE0280");
      }
      err.setIsStaticError(true);
      compileError(err);
    }

    prioritySpecified = (priorityAtt != null);
    if (prioritySpecified) {
      if (matchAtt == null) {
        compileError(
            "The priority attribute must be absent if the match attribute is absent", "XTSE0500");
      }
      try {
        // it's got to be a valid decimal, but we want it as a double, so parse it twice
        if (!DecimalValue.castableAsDecimal(priorityAtt)) {
          compileError("Invalid numeric value for priority (" + priority + ')', "XTSE0530");
        }
        priority = Double.parseDouble(priorityAtt);
      } catch (NumberFormatException err) {
        // shouldn't happen
        compileError("Invalid numeric value for priority (" + priority + ')', "XTSE0530");
      }
    }

    if (matchAtt != null) {
      match = makePattern(matchAtt);
      if (diagnosticId == null) {
        diagnosticId = "match=\"" + matchAtt + '\"';
        if (modeAtt != null) {
          diagnosticId += " mode=\"" + modeAtt + '\"';
        }
      }
    }

    if (match == null && nameAtt == null)
      compileError("xsl:template must have a name or match attribute (or both)", "XTSE0500");

    if (asAtt != null) {
      requiredType = makeSequenceType(asAtt);
    }
  }