Question: change the following array to an arrayList. (java) public class BasicXmlValidator implements XmlValidator { BasicStringStack Stringstack; BasicStringStack linestack; private String[] Lines; private String word; public

change the following array to an arrayList. (java) public class BasicXmlValidator implements XmlValidator { BasicStringStack Stringstack; BasicStringStack linestack; private String[] Lines; private String word; public String[] validate(String xmlDocument) { // TODO Auto-generated method stub Stringstack = new BasicStringStack(); linestack = new BasicStringStack(); Lines = (xmlDocument.split(" ")); String[] result = null; for (int i = 1; i < Lines.length; i++) { int begin = Lines[i].indexOf("<"); int end = Lines[i].indexOf(">"); if ((begin >= 0) && (end >= 0)) { String string = Lines[i].substring((begin + 1), (end)); word = string.substring(string.indexOf(" ") + 1, string.length() - 1); while (word.indexOf(" ") != word.lastIndexOf(" ") && (word.indexOf("=") >= 0)) { if (word.charAt(word.indexOf("=") + 1) != '"') { String temp[]; temp = word.split(" "); for (int o = 0; o < temp.length; o++) { String[] tempExex = temp[o].split("="); String[] tempEx = string.split(" "); if ((tempExex.length > 1) && (!(tempExex[1].startsWith("\"")))) { result = new String[5]; result[0] = "Attribute not quoted"; result[1] = tempEx[0]; result[3] = tempExex[0]; result[2] = result[4] = Integer.toString(i + 1); ; return result; } } } if (word.indexOf("=") >= 0) { word = word.substring(word.indexOf(" ") + 1, word.length()); } } if ((string.indexOf(" ") > 0) && (string.charAt(string.length() - 1) != '/')) { string = string.substring(0, string.indexOf(" ")); } int begin2 = Lines[i].lastIndexOf("<"); int end2 = Lines[i].lastIndexOf(">"); String string2 = Lines[i].substring((begin2 + 1), (end2)); if ((string.charAt(0) != '?') && (string.charAt(0) != '!') && (string.charAt(0) != ' ') && (string.charAt(string.length() - 1) != '/')) { if (string.charAt(0) != '/') { Stringstack.push(string); linestack.push(Integer.toString(i + 1)); } if (string.charAt(0) == '/') { if (Stringstack.peek(0) != null) { if (string.substring(1, string.length()).equals(Stringstack.peek(0))) { Stringstack.pop(); linestack.pop(); } else { if (result == null) { result = new String[5]; result[0] = "Tag mismatch"; result[1] = Stringstack.peek(0); result[2] = linestack.peek(0); result[3] = string.substring(1, string.length()); result[4] = Integer.toString(i + 1); } } } else { if (result == null) { result = new String[3]; result[0] = "Orphan closing tag"; result[1] = string.substring(1, string.length()); result[2] = Integer.toString(i + 1); } } } } if (begin2 != begin) { if ((string2.indexOf(0) != '?') && (string2.indexOf(0) != '!') && (string2.indexOf(0) != ' ') && (string2.indexOf(string2.length() - 1) != '/')) { if (string2.charAt(0) != '/') { Stringstack.push(string); linestack.push(Integer.toString(i + 1)); } if (string2.charAt(0) == '/') { if (Stringstack.peek(0) != null) { if (string2.substring(1, string2.length()).equals(Stringstack.peek(0))) { Stringstack.pop(); linestack.pop(); } else { if (result == null) { result = new String[5]; result[0] = "Tag mismatch"; result[1] = Stringstack.peek(0); result[2] = linestack.peek(0); result[3] = string.substring(1, string.length()); result[4] = Integer.toString(i + 1); } } } } } } } } if ((Stringstack.peek(0) != null) && result == null) { result = new String[3]; result[0] = "Unclosed tag at end"; result[1] = Stringstack.peek(0); result[2] = linestack.peek(0); } return result; } } 

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//BasicStringStack.java

package xmlvalidator; public class BasicStringStack implements StringStack { class StackNode { String item; StackNode next; } private int count; private StackNode top; private StackNode current; @Override public void push(String item) { // TODO Auto-generated method stub StackNode newNode = new StackNode(); newNode.item = item; newNode.next = top; // c b a top = newNode; count++; } @Override public String pop() { // TODO Auto-generated method stub if (top == null) return null; else { StackNode tempNode = top; top = top.next; count--; return tempNode.item; } } @Override public String peek(int position) { // TODO Auto-generated method stub current = top; if (current == null) return null; else { int i = 0; while (i < position) { i++; current = current.next; } return current.item; } } @Override public int getCount() { // TODO Auto-generated method stub return count; } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!