Hi,

I am working on a little project based on a logging screen and
displaying some information to the user if the log was a success.

I used this code to make the log screen: 
http://www.dariusz-borowski.com/wp/?p=20

But instead of writing the username and password in LoggingServiceImpl
I want to parse an xml file "users.xml" and get this information from
there.

I have been trying different methods without any success.

Could any one give me an advice about it?

Thanks


users.xml:
<?xml version="1.0" encoding="UTF-8"?>
   <users>
       <user id="1" groupId="11">
                <login>guest</login>
                <password>hello</password>
                <firstname>ab</firstname>
                <lastname>cd</lastname>
       </user>

       <user id="2" groupId="11">
                <login>guest2</login>
                <password>hello</password>
                <firstname>ef</firstname>
                <lastname>gh</lastname>
       </user>
</users>

ParseUser.java:
package com.db.project.server;

import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.Attributes;

import java.io.FileReader;
import java.io.IOException;
import java.io.StringReader;


public class ParseUser extends DefaultHandler{
        private static String result = null;

        private boolean inUser = false;
        private boolean inLog = false;
        private boolean inPwd = false;
        private boolean inFN = false;
        private boolean inLN = false;

        private boolean okFN = false;
        private boolean logCorrect = false;
        private boolean thisOne = false;

        private String found = "";



        public ParseUser() {
                super();
                result = "";
        }

        public void startElement(String uri, String localName,
                        String rawName, Attributes attributes){

                if ("user".equals(localName)){
                        inUser = true;
                        found = 
attributes.getValue("id")+"___"+attributes.getValue
("groupId")+"___";
                }
                else if ("login".equals(localName))
                        inLog = true;
                else if ("password".equals(localName))
                        inPwd = true;
                else if ("firstname".equals(localName))
                        inFN = true;
                else if ("lastname".equals(localName))
                        inLN = true;
        }


        public void endElement(String uri, String localName,
                        String rawName, Attributes attributes){

                if ("user".equals(localName)){
                        inUser = false;
                }
                else if ("login".equals(localName))
                        inLog = false;
                else if ("password".equals(localName))
                        inPwd = false;
                else if ("firstname".equals(localName))
                        inFN = false;
                else if ("lastname".equals(localName))
                        inLN = false;   }

        public void endDocument(){
                //System.out.print(result);
        }

        public void characters(char[] ch, int start, int length) {
                String data = new String(ch,start,length).trim();


                if(inLog && data.equals("walid")){
                        logCorrect = true;
                }
                if(logCorrect && inPwd && data.equals("lol")){
                        thisOne = true;
                        logCorrect = false;
                        result = found;
                }
                if(thisOne && inFN){
                        result = result + "firstN:"+data +"___";
                        okFN  = true; thisOne = false;
                }
                if(okFN && inLN){
                        result = result + "lastN:"+ data;
                        okFN = false;
                }
        }

        public String myParse(String uri) throws SAXException, IOException {
                XMLReader xr = XMLReaderFactory.createXMLReader();
                xr.setContentHandler(this);
                xr.setErrorHandler(this);
                StringReader r = new StringReader(uri);
                xr.parse(new InputSource(r));
                return result;
        }

//              public static void main(String args[]) throws Exception {
//                      XMLReader xr = XMLReaderFactory.createXMLReader();
//                      ParseUser handler = new ParseUser();
//                      xr.setContentHandler(handler);
//                      xr.setErrorHandler(handler);
//
//                      FileReader r = new FileReader("data/users.xml");
//                      xr.parse(new InputSource(r));
//                      System.out.println("** "+ result +" **");
//              }
}



This does not work:
public class LoginServiceImpl extends RemoteServiceServlet implements
                LoginService {

        public String loginServer(String name, String pwd){

                ParseUser pr = new ParseUser();
                String result = "";

                try {
                        result = pr.myParse("data/users.xml");
                } catch (Exception e) {
                        e.printStackTrace();
                        System.out.println(e.getMessage()+" parsing");
                }
                System.out.println(result);
                return  result;
        }
}


....at org.mortbay.thread.BoundedThreadPool$PoolThread.run
(BoundedThreadPool.java:442)
Content is not allowed in prolog. parsing
-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.


Reply via email to