* Contributors:
* Christopher Lenz - initial API
*
- * $Id: XMLParser.java,v 1.1 2004-09-02 18:26:55 jsurfer Exp $
+ * $Id: XMLParser.java,v 1.2 2006-10-21 23:13:43 pombredanne Exp $
*/
package net.sourceforge.phpeclipse.xml.core.internal.parser;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
-
/**
* SAX-based default implementation of the {@link IXMLParser} interface.
*
* TODO This implementation doesn't do error recovery, as SAX doesn't allow it.
- * Maybe we partition the document and parse individual fragments so that
- * errors can be isolated to their source
+ * Maybe we partition the document and parse individual fragments so that errors
+ * can be isolated to their source
*/
public class XMLParser implements IXMLParser {
/**
XMLDocument document;
/**
- * The current top element. That is the element that has been most
+ * The current top element. That is the element that has been most
* recently opened by a start tag.
*/
private XMLElement top;
}
/*
- * @see org.xml.sax.ContentHandler#startElement(String, String, String, Attributes)
+ * @see org.xml.sax.ContentHandler#startElement(String, String, String,
+ * Attributes)
*/
- public void startElement(
- String namespaceURI, String localName, String qName, Attributes atts
- ) throws SAXException {
+ public void startElement(String namespaceURI, String localName,
+ String qName, Attributes atts) throws SAXException {
if (System.currentTimeMillis() > timeout) {
throw new SAXException("timeout");
}
}
}
- int offset = computeOffset(newTop,
- locator.getLineNumber(),
- locator.getColumnNumber());
+ int offset = computeOffset(newTop, locator.getLineNumber(), locator
+ .getColumnNumber());
if (offset >= 0) {
newTop.setSourceRegion(offset, 0);
/*
* @see org.xml.sax.ContentHandler#endElement(String, String, String)
*/
- public void endElement(
- String namespaceURI, String localName, String qName
- ) throws SAXException {
- int length = computeLength(top,
- locator.getLineNumber(),
- locator.getColumnNumber());
+ public void endElement(String namespaceURI, String localName,
+ String qName) throws SAXException {
+ int length = computeLength(top, locator.getLineNumber(), locator
+ .getColumnNumber());
if (length >= 0) {
top.setSourceRegion(top.getSourceRegion().getOffset(), length);
} else {
// this is the root element
document.setRoot(top);
- }
+ }
top = previousTop;
}
- /*
+ /*
* @see org.xml.sax.ErrorHandler#error(SAXParseException)
*/
public void error(SAXParseException e) throws SAXException {
}
}
- /*
+ /*
* @see org.xml.sax.ErrorHandler#fatalError(SAXParseException)
*/
public void fatalError(SAXParseException e) throws SAXException {
}
}
- /*
+ /*
* @see org.xml.sax.ErrorHandler#warning(SAXParseException)
*/
public void warning(SAXParseException e) throws SAXException {
*
* TODO Limit the location to the current top element
*
- * @param e the SAX parse exception
- * @param error whether the problem is an error or a warning
+ * @param e
+ * the SAX parse exception
+ * @param error
+ * whether the problem is an error or a warning
* @return the created problem object
*/
private IProblem createProblem(SAXParseException e, boolean error) {
ble.printStackTrace();
}
- return new DefaultProblem(e.getLocalizedMessage(),
- offset, offset + length, line, error);
+ return new DefaultProblem(e.getLocalizedMessage(), offset, offset
+ + length, line, error);
}
}
return null;
}
- /*
+ /*
* @see IProblemReporter#setProblemCollector(IProblemCollector)
*/
public void setProblemCollector(IProblemCollector problemCollector) {
this.problemCollector = problemCollector;
}
- /*
+ /*
* @see IXMLParser#setSource(IDocument)
*/
public void setSource(IDocument source) {
this.source = source;
}
- /*
+ /*
* @see IXMLParser#setSystemId(String)
*/
public void setSystemId(String systemId) {
if (column <= 0) {
offset = getOffset(line, 0);
int lastCharColumn = getLastCharColumn(line);
- String lineText = source
- .get(source.getLineOffset(line - 1), lastCharColumn);
+ String lineText = source.get(source.getLineOffset(line - 1),
+ lastCharColumn);
String startTag = getStartTag(element);
int lastIndex = lineText.indexOf(startTag);
return -1;
}
- private IRegion findStringBackward(
- int startOffset, String string
- ) throws BadLocationException {
+ private IRegion findStringBackward(int startOffset, String string)
+ throws BadLocationException {
int offset = startOffset;
int length = string.length();
return null;
}
- private IRegion findStringForward(
- int startOffset, String string
- ) throws BadLocationException {
+ private IRegion findStringForward(int startOffset, String string)
+ throws BadLocationException {
int offset = startOffset;
int length = string.length();
/**
* Given an XML element, this method reconstructs the corresponding end tag
- * of the element, including the namespace prefix if there was one.
+ * of the element, including the namespace prefix if there was one.
*
- * @param element the XML element for which the end tag should be contructed
+ * @param element
+ * the XML element for which the end tag should be contructed
* @return the end tag as string
*/
private String getEndTag(IXMLElement element) {
/**
* Reconstructs and returns the start tag corresponding to the given XML
- * element, excluding any attribute specifications or the closing
+ * element, excluding any attribute specifications or the closing
* <tt>></tt> character.
*
- * @param element the XML element for which the start tag should be
- * constructed
+ * @param element
+ * the XML element for which the start tag should be constructed
* @return the start tag as string, excluding everything after the tag name
* itself
*/
int getLastCharColumn(int line) throws BadLocationException {
String lineDelimiter = source.getLineDelimiter(line - 1);
- int lineDelimiterLength = (lineDelimiter != null)
- ? lineDelimiter.length() : 0;
+ int lineDelimiterLength = (lineDelimiter != null) ? lineDelimiter
+ .length() : 0;
return source.getLineLength(line - 1) - lineDelimiterLength;
}