All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.googlecode.html.filters.Identity Maven / Gradle / Ivy

There is a newer version: 0.63
Show newest version
/*
 * Copyright 2002-2009 Andy Clark, Marc Guillemot
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.googlecode.html.filters;

import com.googlecode.html.HTMLEventInfo;
import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xni.XNIException;

/**
 * This filter performs the identity operation of the original document event stream generated by
 * the HTML scanner by removing events that are synthesized by the tag balancer. This operation is
 * essentially the same as turning off tag-balancing in the parser. However, this filter is useful
 * when you want the tag balancer to report "errors" but do not want the synthesized events in the
 * output.
 * 

* Note: This filter requires the augmentations feature to be turned on. For * example: *

*

 *  XMLParserConfiguration parser = new HTMLConfiguration();
 *  parser.setFeature("http://cyberneko.org/html/features/augmentations", true);
 * 
*

* Note: This isn't exactly the identify transform because the element and * attributes names may have been modified from the original document. For example, by default, * NekoHTML converts element names to upper-case and attribute names to lower-case. * * @author Andy Clark * @version $Id: Identity.java,v 1.4 2005/02/14 03:56:54 andyc Exp $ */ public class Identity extends DefaultFilter { // // Constants // /** * Augmentations feature identifier. */ protected static final String AUGMENTATIONS = "http://cyberneko.org/html/features/augmentations"; /** * Filters property identifier. */ protected static final String FILTERS = "http://cyberneko.org/html/properties/filters"; // // XMLDocumentHandler methods // /** * Returns true if the information provided is synthesized. */ protected static boolean synthesized(Augmentations augs) { HTMLEventInfo info = (HTMLEventInfo) augs.getItem(AUGMENTATIONS); return info != null ? info.isSynthesized() : false; } // synthesized(Augmentations):boolean /** * Empty element. */ public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { if (augs == null || !synthesized(augs)) { super.emptyElement(element, attributes, augs); } } // emptyElement(QName,XMLAttributes,Augmentations) /** * End element. */ public void endElement(QName element, Augmentations augs) throws XNIException { if (augs == null || !synthesized(augs)) { super.endElement(element, augs); } } // endElement(QName,XMLAttributes,Augmentations) // // Protected static methods // /** * Start element. */ public void startElement(QName element, XMLAttributes attributes, Augmentations augs) throws XNIException { if (augs == null || !synthesized(augs)) { super.startElement(element, attributes, augs); } } // startElement(QName,XMLAttributes,Augmentations) } // class Identity





© 2015 - 2024 Weber Informatics LLC | Privacy Policy