X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse.xml.core/src/net/sourceforge/phpeclipse/xml/core/internal/parser/XMLParser.java b/net.sourceforge.phpeclipse.xml.core/src/net/sourceforge/phpeclipse/xml/core/internal/parser/XMLParser.java index 81a0e64..0428da4 100644 --- a/net.sourceforge.phpeclipse.xml.core/src/net/sourceforge/phpeclipse/xml/core/internal/parser/XMLParser.java +++ b/net.sourceforge.phpeclipse.xml.core/src/net/sourceforge/phpeclipse/xml/core/internal/parser/XMLParser.java @@ -8,7 +8,7 @@ * 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; @@ -39,13 +39,12 @@ import org.xml.sax.SAXException; 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 { /** @@ -58,7 +57,7 @@ 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; @@ -83,11 +82,11 @@ public class XMLParser implements IXMLParser { } /* - * @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"); } @@ -103,9 +102,8 @@ public class XMLParser implements IXMLParser { } } - int offset = computeOffset(newTop, - locator.getLineNumber(), - locator.getColumnNumber()); + int offset = computeOffset(newTop, locator.getLineNumber(), locator + .getColumnNumber()); if (offset >= 0) { newTop.setSourceRegion(offset, 0); @@ -119,12 +117,10 @@ public class XMLParser implements IXMLParser { /* * @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); @@ -136,11 +132,11 @@ public class XMLParser implements IXMLParser { } 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 { @@ -149,7 +145,7 @@ public class XMLParser implements IXMLParser { } } - /* + /* * @see org.xml.sax.ErrorHandler#fatalError(SAXParseException) */ public void fatalError(SAXParseException e) throws SAXException { @@ -158,7 +154,7 @@ public class XMLParser implements IXMLParser { } } - /* + /* * @see org.xml.sax.ErrorHandler#warning(SAXParseException) */ public void warning(SAXParseException e) throws SAXException { @@ -182,8 +178,10 @@ public class XMLParser implements IXMLParser { * * 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) { @@ -204,8 +202,8 @@ public class XMLParser implements IXMLParser { ble.printStackTrace(); } - return new DefaultProblem(e.getLocalizedMessage(), - offset, offset + length, line, error); + return new DefaultProblem(e.getLocalizedMessage(), offset, offset + + length, line, error); } } @@ -262,21 +260,21 @@ public class XMLParser implements IXMLParser { 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) { @@ -337,8 +335,8 @@ public class XMLParser implements IXMLParser { 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); @@ -364,9 +362,8 @@ public class XMLParser implements IXMLParser { 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(); @@ -382,9 +379,8 @@ public class XMLParser implements IXMLParser { 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(); @@ -403,9 +399,10 @@ public class XMLParser implements IXMLParser { /** * 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) { @@ -422,11 +419,11 @@ public class XMLParser implements IXMLParser { /** * 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 * > 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 */ @@ -451,8 +448,8 @@ public class XMLParser implements IXMLParser { 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; }