Why would happen this kind of Exception?...@@

K

klynn47

Without seeing your code, we can't say anything for sure,
but a ClassCastException can occur if you try to cast
a superclass reference to a subclass reference, but the reference isn't
compatible with the subclass.
 
M

mike

Followings is my codes.

Any suggestion is welcome.

thank you
May goodness be with you all

--------------------------------------------------
code MyVisitor.java
--------------------------------------------------
import org.htmlparser.Parser;
import org.htmlparser.tags.LinkTag;
import org.htmlparser.util.ParserException;
import org.htmlparser.visitors.NodeVisitor;
import org.htmlparser.*;
import org.htmlparser.tags.ScriptTag;
import org.htmlparser.tags.ImageTag;
import java.util.Vector;
import java.util.Enumeration;
import org.htmlparser.tags.*;
import org.htmlparser.tags.StyleTag;



public class MyVisitor extends NodeVisitor
{
public MyVisitor()
{

}
public void visitTag(Tag tag)
{
Vector attributes;
Attribute attribute;
attributes = tag.getAttributesEx();
attribute = (Attribute)attributes.elementAt(0);
attribute.setName(attribute.getName().toLowerCase());

// System.out.print(tag.toHtml());
char MyQuote='"';
Vector AttributeVector;
AttributeVector=tag.getAttributesEx();
for (Enumeration e = AttributeVector.elements() ;
e.hasMoreElements();) {
((Attribute)e).setQuote(MyQuote);
}



if (tag instanceof LinkTag){

System.out.print(tag.getAttribute("href"));
System.out.print("****");
tag.setAttribute("href","http://www.yzu.edu.tw/"+tag.getAttribute("href";));
System.out.print(tag.getAttribute("href"));
System.out.print("////");

Vector AttributeLinkTagVector;
String JavaScriptbuffer;

AttributeLinkTagVector=tag.getAttributesEx();
for (Enumeration e2th=AttributeVector.elements() ;
e2th.hasMoreElements();) {

JavaScriptbuffer=((Attribute)e2th).getRawValue();
if(JavaScriptbuffer.startsWith("JavaScript"))
{
tag.removeAttribute("href");
tag.removeAttribute("onMouseOver");
tag.removeAttribute("onMouseOut");
}

}

}
if (tag instanceof DoctypeTag){
//System.out.print(tag.toHtml());
}

if (tag instanceof ImageTag){
tag.setAttribute("alt","*");
//System.out.print(tag.toHtml());

System.out.print(tag.getAttribute("src"));
System.out.print("****");
tag.setAttribute("src","http://www.yzu.edu.tw"+tag.getAttribute("src";));
System.out.print(tag.getAttribute("src"));
System.out.print("////");
}

if (tag instanceof Html){

/* String DOCTYPEHEADER1="<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML
1.0 Transitional//EN\"";
String DOCTYPEHEADER2="\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";;
String DOCTYPEHEADER=DOCTYPEHEADER1+DOCTYPEHEADER2;
*/
tag.setAttribute("xmlns","http://www.w3.org/1999/xhtml";);
tag.setAttribute("xml:lang","en-US");
tag.setAttribute("lang","en-US");

//<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en-US"
lang="en-US">
// Set attribute with given key, value pair.
System.out.print(tag.toHtml());
}
if(tag instanceof StyleTag){
tag.setAttribute("type","text/css",'"');
System.out.print(tag.toHtml());
}

if(tag instanceof StyleTag){
tag.setAttribute("type","text/css",'"');
System.out.print(tag.toHtml());
}
}
}
--------------------------------------------------
code ToHtmlDemoTest2.java
--------------------------------------------------
import org.htmlparser.Parser;
import org.htmlparser.util.NodeIterator;
import org.htmlparser.util.*;
import org.htmlparser.util.ParserException;
import org.htmlparser.visitors.HtmlPage;
import org.htmlparser.tags.*;
import org.htmlparser.visitors.NodeVisitor;
import org.htmlparser.*;
import org.htmlparser.filters.*;
import org.htmlparser.filters.*;
import java.io.*;

public class ToHtmlDemoTest2
{
public static void main (String[] args) throws ParserException
{

Parser parser = new Parser("http://www.yzu.edu.tw";);

MyVisitor visitor = new MyVisitor();
NodeList list = new NodeList();
NodeFilter filter=new NotFilter(new TagNameFilter("Script"));

NodeIterator iterator = parser.elements();
while(iterator.hasMoreNodes()){
list.add(iterator.nextNode());
}
list.keepAllNodesThatMatch(filter,true);
parser.visitAllNodesWith(visitor);
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top