/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: XMLParser.java,v 1.2 2008/06/25 05:51:32 qcheng Exp $
*
*/
/**
* This is a simple parser that can be used to parse and create in-memory
* DOM-like representation of an xml document. The logic for this parser is
* based on an adhoc implementation which requires that the XML document be
* well formed syntactically and does not do any further validation of any
* type.
*/
/**
* This method returns an ordered colloection of tokens that can together
* represent the entire XML document. This method is used as the first
* phase parsing or scanning of the XML document.
*
* @param isreader
* the reader attached to the source of the document.
*
* @return an ordered collection of <code>Token</code>s that together
* represent the entire XML document.
*
* @throws Exception
* if the parse was not successful
*/
int boundCount = 0;
boolean inComment = false;
boolean inCompoundToken = false;
boolean inQuotes = false;
int length;
char[] cbuf = new char[1];
if (ch == '"') {
continue;
} else {
continue;
}
}
if (inQuotes) {
continue;
}
if (ch == '<') {
if (inComment) {
} else if (boundCount == 0) {
}
boundCount++;
} else if (boundCount > 0) {
boundCount++;
} else {
}
} else if (ch == '>') {
if (!inComment) {
boundCount--;
if (boundCount == 0) {
}
continue;
}
.equals("--")) {
if (inComment) {
boundCount--;
inComment = false;
}
if (boundCount == 0) {
}
} else {
}
} else {
throw new Exception("Char > in begining of token");
}
} else if (ch == '-') {
if (!inComment) {
inComment = true;
}
}
} else {
}
}
if (inQuotes) {
throw new Exception("unbalanced quote encountered");
}
if (boundCount > 0) {
throw new Exception("unbalanced token encountered: boundCount = "
+ boundCount);
} else if (boundCount < 0) {
}
}
return result;
}
/**
* This method is used as the second phase parser to create an ordered
* collection of attributes from a given attribute string.
*
* @param attributeString
* the attribute string fragment to be parsed
* @return an ordered collection of attributes
*
* @throws Exception
* if the parse was not successful
*/
boolean inQuotes = false;
boolean inName = true;
boolean inValue = false;
if (ch == '"') {
{
continue;
} else {
continue;
}
}
if (inQuotes) {
continue;
}
if (ch == ' ') {
if (inValue) {
throw new Exception("Failed to parse attribute: "
+ attributeString);
}
inValue = false;
inName = true;
continue;
}
if (inName) {
continue;
}
}
if (ch == '=') {
if (inName) {
inName = false;
inValue = true;
continue;
}
}
}
if (!inValue) {
throw new Exception("Failed to parse attributes: "
+ attributeString);
}
throw new Exception("Failed to parse attribute: "
+ attributeString);
}
}
}
return result;
}
XMLParser() {
setXMLTokenFactory(new XMLTokenFactory());
}
int getNextTokenIndex() {
return this.getXMLTokenFactory().getNextTokenIndex();
}
this.xmlTokenFactory = xmlTokenFactory;
}
return xmlTokenFactory;
}
}