- From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
- Date: Wed, 14 Sep 2005 15:14:19 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/2002/css-validator/html/tags In directory hutz:/tmp/cvs-serv9389/html/tags Modified Files: BaseTag.java HtmlInputStream.java HtmlParser.java HtmlParserListener.java HtmlTag.java HtmlTree.java LinkTag.java ParserFrame.java RootTag.java SimpleTagFactory.java StyleTag.java TagFactory.java Log Message: >From Jean-Guilhem Rouel (again!) Reformatting of code Fix for bug 774 [1] (even more warnings) Fix for bug 768 [2] Modification of the soap output format (each warning list and error list has the URI it refers to) [1] http://www.w3.org/Bugs/Public/show_bug.cgi?id=774 [2] http://www.w3.org/Bugs/Public/show_bug.cgi?id=768 Index: StyleTag.java =================================================================== RCS file: /sources/public/2002/css-validator/html/tags/StyleTag.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- StyleTag.java 26 Aug 2005 12:34:56 -0000 1.4 +++ StyleTag.java 14 Sep 2005 15:14:17 -0000 1.5 @@ -17,8 +17,8 @@ import html.parser.*; /** - * This class handles the <STYLE> tag in the Html Tree built by - * the Html parser. It transfers control to the StyleSheet which + * This class handles the <STYLE> tag in the Html Tree built by + * the Html parser. It transfers control to the StyleSheet which * will parse the text contained here. * * @author Vincent Mallet (Vincent.Mallet@sophia.inria.fr) @@ -27,24 +27,24 @@ */ public class StyleTag extends Block { - + public static final boolean debug = false; - + String media = null; String title = null; String type = null; - + /** * Create a new StyleTag. */ - + public StyleTag() { if (debug) System.out.println( "creating StyleTag this=" +(Object)this); } - - - public void initialize(Element elem, Attributes atts, + + + public void initialize(Element elem, Attributes atts, ParserFrame parserFrame) { super.initialize(elem, atts, parserFrame); // System.err.println("style tag line=" + line); @@ -54,29 +54,29 @@ type = atts.get("type"); } } - - + + /** * This method is called just after the attachment of a child to the tree * has been done. * @param htmlChild the child that has just been attached to the tree. */ - + // public void attachHook(HtmlTree htmlChild) { - + public void attach(Tree child, int rank) { super.attach(child, rank); - + HtmlTree htmlChild = (HtmlTree) child; - + if (debug) { - System.out.println( "StyleTag::attach() child=" - + (Object)htmlChild + " (" + System.out.println( "StyleTag::attach() child=" + + (Object)htmlChild + " (" + htmlChild.getElement().toString() + ")"); } - + String text = getChildText(htmlChild); - + if (text != null) { if ((type == null) || type.equalsIgnoreCase("text/css")) { if (media == null) { @@ -85,12 +85,12 @@ parserFrame.styleSheetParser .parseStyleElement(parserFrame.ac, new ByteArrayInputStream(text.getBytes()), - title, media, + title, media, parserFrame.getURI(), line); } } } - + /** * Helper function. Retrieves the text stored in the new child element. * @param htmlChild the child containing the text @@ -98,10 +98,10 @@ */ protected String getChildText(HtmlTree htmlChild) { Attributes atts = htmlChild.getAttributes(); - + if (atts == null) //@@ I dont think this should ever happen... return null; - + return atts.get("text"); } } Index: BaseTag.java =================================================================== RCS file: /sources/public/2002/css-validator/html/tags/BaseTag.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- BaseTag.java 26 Aug 2005 12:34:56 -0000 1.3 +++ BaseTag.java 14 Sep 2005 15:14:17 -0000 1.4 @@ -17,8 +17,8 @@ import html.parser.*; /** - * This class handles the <LINK> tag in the Html tree built by the Html Parser. - * If the link refers to an external stylesheet, control will be transfered to the + * This class handles the <LINK> tag in the Html tree built by the Html Parser. + * If the link refers to an external stylesheet, control will be transfered to the * StyleSheet object which will then parse the refered stylesheet.<BR> * Note: * <UL @@ -30,20 +30,20 @@ */ public class BaseTag extends Flow { - + public static boolean debug = false; - + /** * Create a new BaseTag. */ - + public BaseTag() { debug = Boolean.getBoolean("html.tags.debug"); if (debug) { System.out.println( "creating BaseTag this=" + (Object) this); } } - + /** * Initialize the <code>BASE</code> tag with the given element and * attributes. First initializes the superclass as before and @@ -52,34 +52,34 @@ * @param atts the attributes of this element * @param parserFrame the parser frame */ - - public void initialize(Element elem, Attributes atts, + + public void initialize(Element elem, Attributes atts, ParserFrame parserFrame) { // first, initialize as before super.initialize(elem, atts, parserFrame); - + // Then treat the StyleSheet link case. - + if (debug) - System.out.println( "BaseTag::initialize() node=" - + (Object) this + " (" + System.out.println( "BaseTag::initialize() node=" + + (Object) this + " (" + getElement().toString() + ")"); - + if (atts == null) { //@@ I dont think this should ever happen... - return; + return; } String href = atts.get("href"); - + if (debug) { System.out.println("BASE href=\"" + href + "\""); } - + if (href != null) { URL url; - - try { - url = new URL(href); + + try { + url = new URL(href); parserFrame.setBaseURI(url); } catch (MalformedURLException e) { return; // Ignore errors Index: HtmlInputStream.java =================================================================== RCS file: /sources/public/2002/css-validator/html/tags/HtmlInputStream.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- HtmlInputStream.java 8 Apr 2002 21:22:41 -0000 1.2 +++ HtmlInputStream.java 14 Sep 2005 15:14:17 -0000 1.3 @@ -11,7 +11,7 @@ Vector listeners = new Vector(); int lines = 0; int bytes = 0; - + public HtmlInputStream(InputStream in) { super(in); } @@ -27,7 +27,7 @@ } return c; } - + public int read(byte b[]) throws IOException { int c = super.read(b); for(int i = 0; i < c; i++) { @@ -41,10 +41,10 @@ } return c; } - + public int read(byte b[], int off, int len) throws IOException { int c = super.read(b, off, len); - + for(int i = 0; i < c; i++) { if(b[i+off] == '\n') { lines++; @@ -71,5 +71,5 @@ l.notifyActivity(lines, bytes); } } - + } Index: RootTag.java =================================================================== RCS file: /sources/public/2002/css-validator/html/tags/RootTag.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- RootTag.java 19 May 2002 02:16:29 -0000 1.3 +++ RootTag.java 14 Sep 2005 15:14:17 -0000 1.4 @@ -24,20 +24,20 @@ */ public class RootTag extends Block { - + public static final boolean debug = false; - + /** * Create a new StyleTag. */ - + public RootTag() { if (debug) { System.out.println( "creating RootTag this=" +(Object)this); } - } - - public void initialize(Element elem, Attributes atts, + } + + public void initialize(Element elem, Attributes atts, ParserFrame parserFrame) { super.initialize(elem, atts, parserFrame); @@ -50,5 +50,5 @@ throw new XMLInputException(xml); } } - } + } } Index: HtmlTree.java =================================================================== RCS file: /sources/public/2002/css-validator/html/tags/HtmlTree.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- HtmlTree.java 8 Sep 2005 12:23:32 -0000 1.3 +++ HtmlTree.java 14 Sep 2005 15:14:17 -0000 1.4 @@ -25,58 +25,58 @@ Element elem; Attributes atts; int line; // 970801 -vm - + /** * */ ParserFrame parserFrame = null; // 970724 -vm - - + + //============================================================ // implements: html.parser.Tag //============================================================ - + public void initialize(Element elem, Attributes atts, ParserFrame parserFrame) { this.elem = elem; this.atts = atts; this.parserFrame = parserFrame; // 970724 -vm this.line = parserFrame.line; // 970801 -vm - + checkStyleAttribute(); // 970724 -vm } - + public abstract boolean isBlock(); - + public boolean isPreformatted() { return false; } - + public Element getElement() { return elem; } - + public Attributes getAttributes() { return atts; } - - + + public StyleSheet getStyleSheet() { return parserFrame.styleSheetParser.getStyleSheet(); // 970724 -vm - } - + } + /** * @@ [DESCRIBEME] */ - + CssSelectors context = null; - + /** * Get the stylesheet context for this level in the Html tree. It will be used to * retrieve the actual stylesheet properties for the element. * @@ [CONTINUE ME] - * @throws InvalidParamException + * @throws InvalidParamException */ - + public CssSelectors getContext() throws InvalidParamException { // ContextStack context; @@ -85,16 +85,16 @@ return context; // return (CssSelectors) context.clone(); } - + // get context from parent HtmlTree atl = (HtmlTree) getParent(); - + if (atl == null) { context = new CssSelectors(parserFrame.ac); } else { context = new CssSelectors(atl.getContext()); } - + // add own context // CssContextList thisContext = new CssContextList(getElement().getName()); // context.setElement(getElement().getName().toUpperCase()); @@ -102,33 +102,33 @@ // Attributes atts = htmlNode.getAttributes(); if (atts != null) { for (int i = 0; i < atts.length(); i++) { - // thisContext = new CssContextList("." + st.nextToken(), thisContext); + // thisContext = new CssContextList("." + st.nextToken(), thisContext); try { - context.addAttribute(atts.getName(i), atts.get(i)); + context.addAttribute(atts.getName(i), atts.get(i)); } catch (Exception e) { e.printStackTrace(); } } } - + // context.push(thisContext); - - // return (CssContextStack) context.clone(); + + // return (CssContextStack) context.clone(); return context; } - - - - - - - - + + + + + + + + /** * Private counter to produce unique IDs. */ protected static int autoIdCount = 0; - + /** * Check current element to see if it has a <code>STYLE</code> attribute. * In that case, parse it using the StyleSheet object, and store it with @@ -136,18 +136,18 @@ * exists, reuse it, otherwise create a new one (it will be unique). */ public void checkStyleAttribute() { // 970724 -vm - + // boolean debug = true; // Attributes atts = htmlNode.getAttributes(); - + if (atts == null) //@@ I dont think this should ever happen... - return; - + return; + String style = atts.get("style"); String id = atts.get("id"); - + if (style != null) { // here we have a style attribute - + if (id == null) { // but we have no id: create one. id = "#auto" + autoIdCount; // a normal id should NOT contain a "#" character. id += "" + autoIdCount++; // workaround a java hashcode bug. @@ -155,17 +155,17 @@ System.out.println("HtmlTree::checkStyleAttribute(): adding id: " + id + " to node: " + elem.getName()); atts.put("id", id); } - + // parse the style attribute. parserFrame.styleSheetParser .parseStyleAttribute(parserFrame.ac, - new ByteArrayInputStream(style.getBytes()), + new ByteArrayInputStream(style.getBytes()), id, parserFrame.url, line); } } - + public String toString() { return getClass().getName() + "[" + elem + "," + atts + "," + arity() + "]"; } - + } Index: TagFactory.java =================================================================== RCS file: /sources/public/2002/css-validator/html/tags/TagFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- TagFactory.java 8 Apr 2002 21:22:41 -0000 1.2 +++ TagFactory.java 14 Sep 2005 15:14:17 -0000 1.3 @@ -15,6 +15,6 @@ /** * creates an returns a valid Tag object for the given name. - */ + */ Tag create(String name); } Index: HtmlTag.java =================================================================== RCS file: /sources/public/2002/css-validator/html/tags/HtmlTag.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- HtmlTag.java 8 Apr 2002 21:22:41 -0000 1.2 +++ HtmlTag.java 14 Sep 2005 15:14:17 -0000 1.3 @@ -11,7 +11,7 @@ /** * Initializes the tag with the given elem,atts pair. - * + * */ void initialize(Element elem, Attributes atts, ParserFrame parserFrame); } Index: LinkTag.java =================================================================== RCS file: /sources/public/2002/css-validator/html/tags/LinkTag.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- LinkTag.java 28 Feb 2003 00:16:31 -0000 1.4 +++ LinkTag.java 14 Sep 2005 15:14:17 -0000 1.5 @@ -21,8 +21,8 @@ import html.parser.*; /** - * This class handles the <LINK> tag in the Html tree built by the Html Parser. - * If the link refers to an external stylesheet, control will be transfered to the + * This class handles the <LINK> tag in the Html tree built by the Html Parser. + * If the link refers to an external stylesheet, control will be transfered to the * StyleSheet object which will then parse the refered stylesheet.<BR> * Note: * <UL @@ -34,19 +34,19 @@ */ public class LinkTag extends Flow { - + public static boolean debug = false; - + /** * Create a new LinkTag. */ - + public LinkTag() { debug = Boolean.getBoolean("html.tags.debug"); if (debug) System.out.println( "creating LinkTag this=" +(Object)this); } - + /** * Initialize the <code>LINK</code> tag with the given element and * attributes. First initializes the superclass as before and @@ -55,51 +55,51 @@ * @param atts the attributes of this element * @param parserFrame the parser frame (containing the StyleSheet) */ - - public void initialize(Element elem, Attributes atts, + + public void initialize(Element elem, Attributes atts, ParserFrame parserFrame) { // first, initialize as before super.initialize(elem, atts, parserFrame); - + // Then treat the StyleSheet link case. - + if (debug) - System.out.println( "LinkTag::initialize() node=" - + (Object) this + " (" + System.out.println( "LinkTag::initialize() node=" + + (Object) this + " (" + getElement().toString() + ")"); - + if (atts == null) { //@@ I dont think this should ever happen... - return; + return; } String rel = atts.get("rel"); String type = atts.get("type"); String href = atts.get("href"); - + if (debug) { - System.out.println("LINK rel=\"" + rel + System.out.println("LINK rel=\"" + rel + "\"" + " href=\"" + href + "\""); } - + if ((rel != null || type != null) && ((rel == null) || rel.toLowerCase().indexOf("stylesheet") != -1) && ((type == null) || type.equalsIgnoreCase("text/css"))) { // we're dealing with a stylesheet... URL url; - - try { + + try { if (parserFrame.baseURL != null) { - url = new URL(parserFrame.baseURL, href); + url = new URL(parserFrame.baseURL, href); } else { - url = new URL(parserFrame.url, href); + url = new URL(parserFrame.url, href); } } catch (MalformedURLException e) { return; // Ignore errors } - + if (debug) { System.out.println("[LinkTag::initialize(): " - + "should parse CSS url: " + + "should parse CSS url: " + url.toString() + "]"); } String media = atts.get("media"); @@ -107,7 +107,7 @@ media="all"; } parserFrame.styleSheetParser.parseURL(parserFrame.ac, - url, + url, atts.get("title"), rel, media, Index: HtmlParser.java =================================================================== RCS file: /sources/public/2002/css-validator/html/tags/HtmlParser.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- HtmlParser.java 8 Jan 2004 14:24:39 -0000 1.3 +++ HtmlParser.java 14 Sep 2005 15:14:17 -0000 1.4 @@ -33,12 +33,12 @@ Vector listeners = new Vector(); ParserFrame parserFrame = new ParserFrame(); // 970724 -vm - + TagFactory factory; String urlname; public HtmlParser(ApplContext ac, - String dtdName, String urlname, URLConnection uc) + String dtdName, String urlname, URLConnection uc) throws ParserException { super(dtdName); this.urlname = urlname; @@ -48,29 +48,29 @@ } public HtmlParser(ApplContext ac, - String dtdName, String urlname) + String dtdName, String urlname) throws ParserException { super(dtdName); this.urlname = urlname; parserFrame.ac = ac; setFactory(new SimpleTagFactory()); } - - public HtmlParser(ApplContext ac, String dtdName, + + public HtmlParser(ApplContext ac, String dtdName, TagFactory f) throws ParserException { super(dtdName); parserFrame.ac = ac; setFactory(new SimpleTagFactory()); } - + public HtmlTree getRoot() { return top; } - + public void setFactory(TagFactory f) { factory = f; } - + public Tag makeTag(Element elem, Attributes atts) { HtmlTree tag = null; if(in_error_recovery) { @@ -84,26 +84,26 @@ } return tag; } - + public void addParserListener(HtmlParserListener l) { listeners.addElement(l); } - + public void removeParserListener(HtmlParserListener l) { listeners.removeElement(l); } - + boolean in_error_recovery = false; Hashtable errorTagTable; protected void startErrorRecovery() { errorTagTable = new Hashtable(); in_error_recovery = true; } - + protected void endErrorRecovery() { in_error_recovery = false; } - + public void handleStartTag(Tag tag) { if(in_error_recovery) { current = (HtmlTree)tag; @@ -141,7 +141,7 @@ } notifyActivity(ln, 0); } - + public void handleEndTag(Tag tag) { if(in_error_recovery) { errorTagTable.put(tag.getElement().getName(), tag); @@ -160,12 +160,12 @@ // } } } - + TextElement proto = new TextElement(); - - + + Element p = new Element("p", 0); - + public void handleText(byte text[]) { // discard empty texts. if((text.length == 1) && (text[0] == ' ')) return; @@ -177,13 +177,13 @@ parserFrame.line = ln; tag.initialize(proto, atts, parserFrame); // System.out.println(" 000 HtmlParser::handleText atts=" + atts); - + /* if("body".equals(current.getElement().getName())) { // for text components outside a <p> in the body, we insert the <p> // component. HtmlTree parent = (HtmlTree)factory.create("p"); parent.initialize(p, atts); - + current.attach(parent, current.arity()); parent.attach((HtmlTree)tag, 0); } @@ -193,7 +193,7 @@ } } } - + public void handleEmptyTag(Tag tag) { //System.out.println("empty tag " + tag); if(current != null) { @@ -232,13 +232,13 @@ } notifyFatalError(null, e, ""); } - + for(int i = 0; i < listeners.size(); i++) { HtmlParserListener l = (HtmlParserListener)listeners.elementAt(i); l.notifyEnd(top, "text/html"); } - + if (Boolean.getBoolean("html.tags.verbose")) { System.out.println("\n-------------------"); System.out.println("[StyleSheet dump:]"); @@ -254,7 +254,7 @@ l.notifyConnection(cnx); } } - + InputStream makeInput(String urls) { InputStream in = null; @@ -262,7 +262,7 @@ if (urls.indexOf(':') > 0) { URLConnection urlC = null; - urlC = HTTPURL.getConnection(new URL(null, urls), + urlC = HTTPURL.getConnection(new URL(null, urls), parserFrame.ac); parserFrame.url = url = urlC.getURL(); @@ -285,7 +285,7 @@ } return null; } - + InputStream makeInput() { InputStream in = null; @@ -309,7 +309,7 @@ } return null; } - + String makeURLName(String s) { System.out.println("makeURLName: " + s); if (s.indexOf(':') > 0) { @@ -319,7 +319,7 @@ return "file:" + s; } } - + void notifyFatalError(HtmlTree root, Exception x, String s) { for(int i = 0; i < listeners.size(); i++) { HtmlParserListener l = @@ -327,13 +327,13 @@ l.notifyFatalError(root, x, s); } } - + public void notifyActivity(int lines, long bytes) { for(int i = 0; i < listeners.size(); i++) { HtmlParserListener l = (HtmlParserListener)listeners.elementAt(i); l.notifyActivity(ln, bytes); } - + } } Index: SimpleTagFactory.java =================================================================== RCS file: /sources/public/2002/css-validator/html/tags/SimpleTagFactory.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- SimpleTagFactory.java 8 Apr 2002 21:22:41 -0000 1.2 +++ SimpleTagFactory.java 14 Sep 2005 15:14:17 -0000 1.3 @@ -20,15 +20,15 @@ * subclass of HtmlTree. */ public class SimpleTagFactory implements TagFactory { - + Hashtable tagTable = new Hashtable(); Properties props; - + public SimpleTagFactory() { java.io.InputStream f = null; props = new Properties(); try { - URL url = + URL url = SimpleTagFactory.class.getResource("SimpleTagFactory.properties"); f = url.openStream(); props.load(f); @@ -42,8 +42,8 @@ } catch (Exception e) {} } } - - + + public Tag create(String name) { Class tagClass; try { @@ -62,11 +62,11 @@ catch(IllegalAccessException iax) {} catch(ClassNotFoundException x){} // new Exception().printStackTrace(); - + if (!Boolean.getBoolean("html.runningServlet")) {//vm970813 // System.out.println("warning: unknown tag: " + name); } - + HtmlTree tag = new Block(); //Tag tag = new UnknownTag(elem, atts); return tag; Index: HtmlParserListener.java =================================================================== RCS file: /sources/public/2002/css-validator/html/tags/HtmlParserListener.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- HtmlParserListener.java 8 Apr 2002 21:22:41 -0000 1.2 +++ HtmlParserListener.java 14 Sep 2005 15:14:17 -0000 1.3 @@ -22,7 +22,7 @@ * * @param url the URL being parsed. * @param root the new root Tag for this parser. - */ + */ public void notifyCreateRoot(URL url, HtmlTag root); public void notifyConnection(URLConnection cnx); @@ -31,7 +31,7 @@ * Notifies successful termination. * * @param root the root of the current Tree. - */ + */ public void notifyEnd(HtmlTag root, String contenttype); Index: ParserFrame.java =================================================================== RCS file: /sources/public/2002/css-validator/html/tags/ParserFrame.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ParserFrame.java 26 Aug 2005 12:34:56 -0000 1.3 +++ ParserFrame.java 14 Sep 2005 15:14:17 -0000 1.4 @@ -1,7 +1,7 @@ /** * ParserFrame * @author Vincent Mallet (vmallet@sophia.inria.fr) - * + * * $Id$ * * @version $Revision$ @@ -29,13 +29,13 @@ public class ParserFrame { /** - * The StyleSheet generator: it is used to parse all CSS informations, - * and then produce the specific stylesheets (CssStyles) for given + * The StyleSheet generator: it is used to parse all CSS informations, + * and then produce the specific stylesheets (CssStyles) for given * contexts. */ - // StyleSheet styleSheet = new StyleSheet(); - StyleSheetParser styleSheetParser = new StyleSheetParser(); + // StyleSheet styleSheet = new StyleSheet(); + StyleSheetParser styleSheetParser = new StyleSheetParser(); // needed by the CSS parser ApplContext ac; @@ -70,6 +70,6 @@ * Create a new ParserFrame */ - public ParserFrame() { + public ParserFrame() { } }
Received on Wednesday, 14 September 2005 15:16:00 UTC