Beispiel #1
0
 /**
  * Apply the whitespace normalization rules for this simple type
  *
  * @param value the string before whitespace normalization
  * @return the string after whitespace normalization
  */
 public String applyWhitespaceNormalization(String value) {
   return Whitespace.collapseWhitespace(value).toString();
 }
Beispiel #2
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);
    }
  }
Beispiel #3
0
  protected void openDocument() throws XPathException {
    if (writer == null) {
      makeWriter();
    }
    if (started) return;
    started = true;
    // This method is sometimes called twice, especially during an identity transform
    // This check stops two DOCTYPE declarations being output.

    String versionProperty = outputProperties.getProperty(OutputKeys.VERSION);
    if (versionProperty != null) {
      if (versionProperty.equals("4.0") || versionProperty.equals("4.01")) {
        version = 4;
      } else if (versionProperty.equals("5.0")) {
        version = 5;
      } else {
        XPathException err = new XPathException("Unsupported HTML version: " + versionProperty);
        err.setErrorCode("SESU0013");
        throw err;
      }
    }

    String byteOrderMark = outputProperties.getProperty(SaxonOutputKeys.BYTE_ORDER_MARK);

    if ("yes".equals(byteOrderMark)
        && "UTF-8".equalsIgnoreCase(outputProperties.getProperty(OutputKeys.ENCODING))) {
      try {
        writer.write('\uFEFF');
      } catch (java.io.IOException err) {
        // Might be an encoding exception; just ignore it
      }
    }

    String systemId = outputProperties.getProperty(OutputKeys.DOCTYPE_SYSTEM);
    String publicId = outputProperties.getProperty(OutputKeys.DOCTYPE_PUBLIC);

    // Treat "" as equivalent to absent. This goes beyond what the spec strictly allows.
    if ("".equals(systemId)) {
      systemId = null;
    }
    if ("".equals(publicId)) {
      publicId = null;
    }
    if (systemId != null || publicId != null || version == 5) {
      writeDocType("html", systemId, publicId);
    }

    empty = false;
    inScript = -1000000;

    // Handle saxon:character-representation

    String representation = outputProperties.getProperty(SaxonOutputKeys.CHARACTER_REPRESENTATION);
    if (representation != null) {
      String nonASCIIrep;
      String excludedRep;
      int semi = representation.indexOf(';');
      if (semi < 0) {
        nonASCIIrep = Whitespace.trim(representation);
        excludedRep = nonASCIIrep;
      } else {
        nonASCIIrep = Whitespace.trim(representation.substring(0, semi));
        excludedRep = Whitespace.trim(representation.substring(semi + 1));
      }
      nonASCIIRepresentation = representationCode(nonASCIIrep);
      excludedRepresentation = representationCode(excludedRep);
      if (excludedRepresentation == REP_NATIVE) {
        excludedRepresentation = REP_ENTITY;
      }
    }
  }