1 27 package org.htmlparser.scanners; 28 29 import java.util.Vector ; 30 31 import org.htmlparser.Attribute; 32 import org.htmlparser.Node; 33 import org.htmlparser.NodeFactory; 34 import org.htmlparser.PrototypicalNodeFactory; 35 import org.htmlparser.Remark; 36 import org.htmlparser.Tag; 37 import org.htmlparser.Text; 38 import org.htmlparser.lexer.Cursor; 39 import org.htmlparser.lexer.Lexer; 40 import org.htmlparser.lexer.Page; 41 import org.htmlparser.scanners.ScriptDecoder; 42 import org.htmlparser.tags.ScriptTag; 43 import org.htmlparser.util.NodeList; 44 import org.htmlparser.util.ParserException; 45 46 49 public class ScriptScanner 50 extends 51 CompositeTagScanner 52 { 53 76 public static boolean STRICT = false; 77 78 81 public ScriptScanner() 82 { 83 } 84 85 92 public Tag scan (Tag tag, Lexer lexer, NodeList stack) 93 throws ParserException 94 { 95 String language; 96 String code; 97 Node content; 98 int position; 99 Node node; 100 Attribute attribute; 101 Vector vector; 102 103 if (tag instanceof ScriptTag) 104 { 105 language = ((ScriptTag)tag).getLanguage (); 106 if ((null != language) && 107 (language.equalsIgnoreCase ("JScript.Encode") || 108 language.equalsIgnoreCase ("VBScript.Encode"))) 109 { 110 code = ScriptDecoder.Decode (lexer.getPage (), lexer.getCursor ()); 111 ((ScriptTag)tag).setScriptCode (code); 112 } 113 } 114 content = lexer.parseCDATA (!STRICT); 115 position = lexer.getPosition (); 116 node = lexer.nextNode (false); 117 if (null != node) 118 if (!(node instanceof Tag) || !( ((Tag)node).isEndTag () 119 && ((Tag)node).getTagName ().equals (tag.getIds ()[0]))) 120 { 121 lexer.setPosition (position); 122 node = null; 123 } 124 125 if (null == node) 127 { 128 attribute = new Attribute ("/script", null); 129 vector = new Vector (); 130 vector.addElement (attribute); 131 node = lexer.getNodeFactory ().createTagNode ( 132 lexer.getPage (), position, position, vector); 133 } 134 tag.setEndTag ((Tag)node); 135 if (null != content) 136 { 137 tag.setChildren (new NodeList (content)); 138 content.setParent (tag); 139 } 140 node.setParent (tag); 141 tag.doSemanticAction (); 142 143 return (tag); 144 } 145 } 146 | Popular Tags |