The Artima Developer Community
Sponsored Link

Java Answers Forum
problem with parsing script tag through HTMLEditorKit

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
K.RamPushyamitraReddy

Posts: 2
Nickname: eihttp
Registered: Nov, 2004

problem with parsing script tag through HTMLEditorKit Posted: Nov 11, 2004 12:42 AM
Reply to this message Reply
Advertisement
HI,<br>
I have written the following program called process.java to parse a file called login.html which is also given below. But I am not able to get the data which is in SCRIPT tag. Check out the output I got for the process.java. One more thing I getting "?" in place of when I copy the output and run it.<br>
Please find out the errors and give me the solution for two problems.
<br><br>
process.java<br>
------------<br>
&l t;br>
import java.util.*;<br>
import java.io.*;<br>
import javax.swing.text.*;<br>
import javax.swing.text.html.*;<br>
import javax.swing.text.html.parser.*;<br>
import java.net.*;<br>
import ParserGetter.*;<br>
class parse1 extends HTMLEditorKit.ParserCallback
{<br>
StringBuffer sb=new StringBuffer();<br>
public void handleText(char[] text,int position)<br>
{<br>
sb.append(text);<br>
System.out.println(text);<br>
}<br>
public void handleEndTag(HTML.Tag tag,int position)<br>
{<br>
sb.append("<").append("/").append(tag).append(">");<br>
System.out.println("<"+"/"+tag+">");<br>
}<br>
public void handleSimpleTag(HTML.Tag <br>tag,MutableAttributeSet attributes,int position)
{<br>
int ind=0;<br>
String store1="";<br>
String tok[]=new String[50];<br>
sb.append("<").append(tag);<br>
System.out.print("<"+tag);<br>
Enumeration e=attributes.getAttributeNames();<br>
while(e.hasMoreElements())<br>
{<br>
Object name=e.nextElement();<br>
Object value=attributes.getAttribute(name);<br>
sb.append(" ").append(name).append("=").append(value);<br>
System.out.print(" "+name+"="+value);<br>
}<br>
sb.append(">");<br>
System.out.print(">");<br>
System.out.println();<br>
}<br>
public void handleStartTag(HTML.Tag tag,MutableAttributeSet attributes,int position)
{<br>
sb.append("<").append(tag);<br>
System.out.print("<"+tag);<br>
Enumeration e=attributes.getAttributeNames();<br>
while(e.hasMoreElements())<br>
{<br>
Object name=e.nextElement();<br>
Object value=attributes.getAttribute(name);<br>
sb.append(" ").append(name).append("=").append(value);<br>
}<br>
sb.append(">");
System.out.print(">");
}<br>

}
<br>
public class process
{<br>
ParserGetter kit=null;<br>
HTMLEditorKit.Parser parser=null;<br>
public process() <br>
{
kit=new ParserGetter();<br>
parser=kit.getParser();<br>
try<br>
{<br>
URL u=new URL("http://localhost:8080/examples/jsp/project/login.html");<br>
URLConnection uc = u.openConnection();<br>
InputStream in=u.openStream();<br>
in=new BufferedInputStream(in);<br>
Reader r=new InputStreamReader(in);<br>
parse1 p=new parse1();<br>
HTMLEditorKit.ParserCallback call=p;<br>
parser.parse(r,call,true); //ignores the charaset<br>
}<br>
catch(Exception e)<br>
{<br>
e.printStackTrace();
}<br>
}<br>
public static void main(String a[])<br>
{
new process();<br>
}
}<br>
<br>
login.html<br>
----------<br>
HTML<br&g t;
TITLEHome Page of Leave Approval form /TITLE<br>
SCRIPT<br>
function validate()<br>
{<br>
if(document.login.id.value=="")<br>
{<br>
alert("Please Enter The User-id");<br>
document.login.id.focus();<br>
return false;<br>
}<br>
if(document.login.pw.value=="")<br>
{<br>
alert("Please Enter The Password");<br>
document.login.pw.focus();<br>
return false;<br>
}<br>
return true;<br>
} <br>
function fnSubmit()<br>
{<br>
if(!validate())<br>
{<br>
return;<br>
}<br>
document.login.submit();<br>
}<br>
SCRIPT <br>
BODY bgcolor="cream"><br>
FORM NAME=login TYPE ="post" ACTION="http://localhost:8080/examples/jsp/project/login.jsp"><br>
h1& gt;CENTER> L O G I N D E T A I L SCENTER>H1><br>
font size = 5 BGCOLOR="#EEEEFF"><br>
CENTER><br>
TABLE><br>
TR> <br>
TD>CENTER>FONT SIZE =4 color="green"> Login: /FONT><br>
TD>INPUT TYPE = text NAME = id><br>
TR> <br>
TD><br>
TD><br>
TR><br>
TD>CENTER>FONT SIZE =4 color="green"> Password:FONT><br>
TD>INPUT TYPE = password NAME = pw><br>
TR>
TD><br>
TD><br>
TR> <br>
TD><br>
TD>CENTER>INPUT TYPE=button NAME = Submit VALUE=Submit onClick="fnSubmit()"><br>
TR><br>
TABLE><br>
FONT><br>
BODY><br>
HTML><br>
OUTPUT for process.java:<br>
------------------------<br>
html>head>titl e>Home Page of Leave Approval form
title><br>
script></script><br>
head><br>
body>form><br>
h1>center>L O G I N D E T A I L S
</center><br>
h1><br>
font><br>
center>table >tr>td>center>font>Login:
font><br>
center><br
inp ut type=text name=id><br>
center>Password:<br>
center><br>
input type=password name=pw><br>
center>input onclick=fnSubmit() value=Submit type=button name=Submit><br>
center><br>
table><br>
</center& gt;<br>
font><br>
form><br>
</body><br>
< /html><br>
Thank you very much,<br>
With regards,<br>
pushyamitra.<br>

Topic: preinitialization Previous Topic   Next Topic Topic: JProgressBar not rendering in time

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use