Reorganize the SAX event pipeline, this fixes the problem of slow parsing when the namespace is not correct
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@350057 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
cbd121a8be
commit
8158ed0a6a
2 files changed
+88
-77
No files matched your search
@@ -21,8 +21,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXParseException;
|
||||
import org.xml.sax.helpers.XMLFilterImpl;
|
||||
|
||||
/**
|
||||
@@ -31,36 +31,26 @@ import org.xml.sax.helpers.XMLFilterImpl;
|
||||
*
|
||||
* @author <a href="mailto:ltheussl@apache.org">Lukas Theussl</a>
|
||||
*/
|
||||
|
||||
public class XPathLocationTracker extends XMLFilterImpl
|
||||
{
|
||||
|
||||
private State state;
|
||||
private static final Integer[] ints = new Integer[]
|
||||
{
|
||||
new Integer(0),
|
||||
new Integer(1),
|
||||
new Integer(2),
|
||||
new Integer(3),
|
||||
new Integer(4)
|
||||
new Integer( 0 ),
|
||||
new Integer( 1 ),
|
||||
new Integer( 2 ),
|
||||
new Integer( 3 ),
|
||||
new Integer( 4 )
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor: sets the ContentHandler.
|
||||
* @param handler The ContentHandler
|
||||
*/
|
||||
public XPathLocationTracker( ContentHandler handler )
|
||||
{
|
||||
setContentHandler(handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriding ContentHandler.
|
||||
* @throws SAXException SAXException
|
||||
*/
|
||||
public void startDocument() throws SAXException
|
||||
{
|
||||
state = new State(null);
|
||||
state = new State( null );
|
||||
super.startDocument();
|
||||
}
|
||||
|
||||
@@ -82,11 +72,19 @@ public class XPathLocationTracker extends XMLFilterImpl
|
||||
* @param atts atts
|
||||
* @throws SAXException SAXException
|
||||
*/
|
||||
public void startElement(String uri, String localName,
|
||||
String qName, Attributes atts) throws SAXException
|
||||
public void startElement( String uri, String localName,
|
||||
String qName, Attributes atts ) throws SAXException
|
||||
{
|
||||
state = state.push(qName);
|
||||
super.startElement(uri, localName, qName, atts);
|
||||
state = state.push( qName );
|
||||
try
|
||||
{
|
||||
super.startElement( uri, localName, qName, atts );
|
||||
}
|
||||
catch ( SAXParseException e )
|
||||
{
|
||||
// ignored on purpose: just avoid to throw an exception here
|
||||
// it is thrown by the ErrorHandler in JaxpMsvBean instead
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,10 +94,18 @@ public class XPathLocationTracker extends XMLFilterImpl
|
||||
* @param qName qName
|
||||
* @throws SAXException SAXException
|
||||
*/
|
||||
public void endElement(String uri, String localName, String qName)
|
||||
public void endElement( String uri, String localName, String qName )
|
||||
throws SAXException
|
||||
{
|
||||
super.endElement(uri, localName, qName);
|
||||
try
|
||||
{
|
||||
super.endElement( uri, localName, qName );
|
||||
}
|
||||
catch ( SAXParseException e )
|
||||
{
|
||||
// ignored on purpose: just avoid to throw an exception here
|
||||
// it is thrown by the ErrorHandler in JaxpMsvBean instead
|
||||
}
|
||||
state = state.pop();
|
||||
}
|
||||
|
||||
@@ -114,17 +120,19 @@ public class XPathLocationTracker extends XMLFilterImpl
|
||||
if ( state == null )
|
||||
{
|
||||
throw new IllegalStateException(
|
||||
"startDocument event is not invoked");
|
||||
"startDocument event is not invoked" );
|
||||
}
|
||||
return state.getXPath();
|
||||
}
|
||||
|
||||
private static Integer getInt(int i)
|
||||
private static Integer getInt( int i )
|
||||
{
|
||||
if ( i < ints.length )
|
||||
{
|
||||
return ints[i];
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Integer(i);
|
||||
}
|
||||
}
|
||||
@@ -148,8 +156,10 @@ public class XPathLocationTracker extends XMLFilterImpl
|
||||
currentName = rawName;
|
||||
if ( child == null )
|
||||
{
|
||||
child = new State(this);
|
||||
} else {
|
||||
child = new State( this );
|
||||
}
|
||||
else
|
||||
{
|
||||
child.reset();
|
||||
}
|
||||
return child;
|
||||
@@ -163,14 +173,16 @@ public class XPathLocationTracker extends XMLFilterImpl
|
||||
|
||||
private void count( String rawName )
|
||||
{
|
||||
Integer i = (Integer) counter.get(rawName);
|
||||
Integer i = (Integer) counter.get( rawName );
|
||||
if ( i == null )
|
||||
{
|
||||
i = getInt(1);
|
||||
} else {
|
||||
i = getInt(i.intValue() + 1);
|
||||
i = getInt( 1 );
|
||||
}
|
||||
counter.put(rawName, i);
|
||||
else
|
||||
{
|
||||
i = getInt( i.intValue() + 1 );
|
||||
}
|
||||
counter.put( rawName, i );
|
||||
}
|
||||
|
||||
private void reset()
|
||||
@@ -185,16 +197,18 @@ public class XPathLocationTracker extends XMLFilterImpl
|
||||
if ( parent == null ) // root
|
||||
{
|
||||
xPath = "/";
|
||||
if ( currentName != null)
|
||||
if ( currentName != null )
|
||||
{
|
||||
xPath += currentName;
|
||||
}
|
||||
} else { // child node
|
||||
}
|
||||
else // child node
|
||||
{
|
||||
xPath = parent.getXPath();
|
||||
if ( currentName != null )
|
||||
{
|
||||
xPath += '/' + currentName;
|
||||
Integer i = (Integer) counter.get(currentName);
|
||||
Integer i = (Integer) counter.get( currentName );
|
||||
xPath += '[' + i.toString() + ']';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user