/** Adds a component. */
  protected void addComponent(HTMLComponent component) {

    // add component to list
    fHTMLComponents.addElement(component);

    // add recognized features and set default states
    String[] features = component.getRecognizedFeatures();
    addRecognizedFeatures(features);
    int featureCount = features != null ? features.length : 0;
    for (int i = 0; i < featureCount; i++) {
      Boolean state = component.getFeatureDefault(features[i]);
      if (state != null) {
        setFeature(features[i], state.booleanValue());
      }
    }

    // add recognized properties and set default values
    String[] properties = component.getRecognizedProperties();
    addRecognizedProperties(properties);
    int propertyCount = properties != null ? properties.length : 0;
    for (int i = 0; i < propertyCount; i++) {
      Object value = component.getPropertyDefault(properties[i]);
      if (value != null) {
        setProperty(properties[i], value);
      }
    }
  } // addComponent(HTMLComponent)
Beispiel #2
0
 public HTMLParser(java.io.Writer out, String encoding, String configScriptTag, String pathInfo) {
   String projectPath = pathInfo.substring(pathInfo.indexOf(WS_WORKSPACE) + WS_WORKSPACE.length());
   projectPath = projectPath.substring(0, projectPath.lastIndexOf('/'));
   int removeCount = projectPath.indexOf("WebContent") == -1 ? 1 : 2;
   int segCount = countSegments(projectPath) - removeCount;
   StringBuffer sb = new StringBuffer();
   for (int i = 0; i < segCount; i++) {
     sb.append("../");
   }
   sb.append("lib/zazl/zazl.js");
   zazlPath = sb.toString();
   this.encoding = encoding;
   this.configScriptTag = configScriptTag;
   parser = new HTMLConfiguration();
   parser.setFeature(AUGMENTATIONS, true);
   XMLDocumentFilter[] filters = {this, new Identity(), new HTMLWriter(out, this.encoding)};
   parser.setProperty(FILTERS, filters);
 }
  /** Default constructor. */
  public HTMLConfiguration() {

    // add components
    addComponent(fDocumentScanner);
    addComponent(fTagBalancer);
    addComponent(fNamespaceBinder);

    //
    // features
    //

    // recognized features
    String VALIDATION = "http://xml.org/sax/features/validation";
    String[] recognizedFeatures = {
      AUGMENTATIONS, NAMESPACES, VALIDATION, REPORT_ERRORS, SIMPLE_ERROR_FORMAT, BALANCE_TAGS,
    };
    addRecognizedFeatures(recognizedFeatures);
    setFeature(AUGMENTATIONS, false);
    setFeature(NAMESPACES, true);
    setFeature(VALIDATION, false);
    setFeature(REPORT_ERRORS, false);
    setFeature(SIMPLE_ERROR_FORMAT, false);
    setFeature(BALANCE_TAGS, true);

    // HACK: Xerces 2.0.0
    if (XERCES_2_0_0) {
      // NOTE: These features should not be required but it causes a
      //       problem if they're not there. This will be fixed in
      //       subsequent releases of Xerces.
      recognizedFeatures =
          new String[] {
            "http://apache.org/xml/features/scanner/notify-builtin-refs",
          };
      addRecognizedFeatures(recognizedFeatures);
    }

    // HACK: Xerces 2.0.1
    if (XERCES_2_0_0 || XERCES_2_0_1 || XML4J_4_0_x) {
      // NOTE: These features should not be required but it causes a
      //       problem if they're not there. This should be fixed in
      //       subsequent releases of Xerces.
      recognizedFeatures =
          new String[] {
            "http://apache.org/xml/features/validation/schema/normalized-value",
            "http://apache.org/xml/features/scanner/notify-char-refs",
          };
      addRecognizedFeatures(recognizedFeatures);
    }

    //
    // properties
    //

    // recognized properties
    String[] recognizedProperties = {
      NAMES_ELEMS, NAMES_ATTRS, FILTERS, ERROR_REPORTER,
    };
    addRecognizedProperties(recognizedProperties);
    setProperty(NAMES_ELEMS, "upper");
    setProperty(NAMES_ATTRS, "lower");
    setProperty(ERROR_REPORTER, fErrorReporter);

    // HACK: Xerces 2.0.0
    if (XERCES_2_0_0) {
      // NOTE: This is a hack to get around a problem in the Xerces 2.0.0
      //       AbstractSAXParser. If it uses a parser configuration that
      //       does not have a SymbolTable, then it will remove *all*
      //       attributes. This will be fixed in subsequent releases of
      //       Xerces.
      String SYMBOL_TABLE = "http://apache.org/xml/properties/internal/symbol-table";
      recognizedProperties =
          new String[] {
            SYMBOL_TABLE,
          };
      addRecognizedProperties(recognizedProperties);
      Object symbolTable =
          ObjectFactory.createObject(
              "org.apache.xerces.util.SymbolTable", "org.apache.xerces.util.SymbolTable");
      setProperty(SYMBOL_TABLE, symbolTable);
    }
  } // <init>()