Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-05-2012, 10:27 PM   PM User | #1
wisner94
New Coder

 
Join Date: Sep 2011
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
wisner94 is an unknown quantity at this point
Question XOM's attribute lengths?

I'm using XOM in a JSP project to record logins/logouts in an XML file. However, I'm having some trouble with displaying the data. The following is from the XML file:

Code:
pass="xxxx<br>session id: 2382F6D0618F81F9E9CD7505A191C435"
Unfortunately, my Java code reading the XML file prints this value as

Code:
password: xxxx<br>session id: 2382F6D0618F81F...
Is it possible that my attribute value is too long? Is there any way to correct this?

By the way, the following code parses my XML file.

Code:
	//returns the table with the various access types and information
	public static String fetchLog(String urlDate) throws IOException, ValidityException, ParsingException, NullPointerException {
            String urlYear = urlDate.substring(0,4);
            String urlMonth = urlDate.substring(4,6);
            String derivedFileName = urlYear + "-" + urlMonth + ".log";
            File logFile = new File(filePath + derivedFileName);
            String table = "";
		//TODO add ability to log page to see actions & fix bridge so actions will work
            if(logFile.exists()) {

                    Builder parser = new Builder();
                    Document logDoc = parser.build(filePath + derivedFileName);
                    Element log = logDoc.getRootElement();

                    //These are the actual elements and attributes from the log file.
                    String type;
                    String user = "";
                    String other = "";
                    String time;
                    String ip = "";
                    String host = "";

                    //These compose the table. 
                    String typeCell;
                    String userCell;
                    String otherCell = "";
                    String timeCell;
                    String ipCell;
                    String hostCell;

                    for (int i = 0; i < log.getChildCount(); i++) {
                            Node child = log.getChild(i);
                            type = child.toString().replace("[nu.xom.Element: ", "").replace("]", "");
                            user = ((Element) child).getAttribute("user").toString().replace("[nu.xom.Attribute: user=\"", "").replace("\"]", "");
                            time = ((Element) child).getAttribute("time").toString().replace("[nu.xom.Attribute: time=\"", "").replace("\"]", "");

                            if(user.isEmpty()) {
                                    user = "<i>none</i>";
                            }

                            if(type.contains("login") || type.contains("illegal") || type.contains("invalid")) {
                                    ip = ((Element) child).getAttribute("ip").toString().replace("[nu.xom.Attribute: ip=\"", "").replace("\"]", "");
                                    host = ((Element) child).getAttribute("host").toString().replace("[nu.xom.Attribute: host=\"", "").replace("\"]", "");

                                    if(type.contains("login") || type.contains("invalid")) {
                                            other = "password: " + ((Element) child).getAttribute("pass").toString().replace("[nu.xom.Attribute: pass=\"", "").replace("\"]", "");
                                    } else if(type.contains("illegal")) {
                                            other = "page: " + ((Element) child).getAttribute("page").toString().replace("[nu.xom.Attribute: page=\"", "").replace("\"]", "");
                                    }

                            } else if(type.contains("logout")) {
                                    ip = "";
                                    host = "";
                                    other = "";
                            }

                            typeCell = "<td>" + type + "</td>";
                            userCell = "<td>" + user + "</td>";
                            otherCell = "<td>" + other + "</td>";
                            timeCell = "<td>" + time + "</td>";
                            ipCell = "<td>" + ip + "</td>";
                            hostCell = "<td>" + host + "</td>";
                            table = "<tr>" + typeCell + userCell + timeCell + otherCell + ipCell + hostCell + "</tr>" + table;
                    }
                    table = "<table cellpadding='10' cellspacing='5' border='1' rules='all' border='border' id='table'>"
                                    + "<tr><td>access type</td><td>username</td><td>time</td><td>other information</td><td>hostname</td><td>ip address</td></tr>"
                                    + table + "</table>";
            } else {
                    table = "No log can be found for this month. Verify that your log file location is correct in the settings.";
            }
            return table;
    }
wisner94 is offline   Reply With Quote
Reply

Bookmarks

Tags
java, jsp, xml, xom

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:30 AM.


Advertisement
Log in to turn off these ads.