Merged gcj-eclipse branch to trunk.

From-SVN: r120621
This commit is contained in:
Tom Tromey
2007-01-09 19:58:05 +00:00
parent c648dedbde
commit 97b8365caf
17478 changed files with 606493 additions and 100744 deletions
+1 -1
View File
@@ -316,7 +316,7 @@ public class DomAttr
private void mutating(String oldValue, String newValue, short why)
{
if (!reportMutations || parent == null)
if (!reportMutations || parent == null || equal(newValue, oldValue))
{
return;
}
+2 -1
View File
@@ -668,6 +668,7 @@ public abstract class DomNode
{
insertionEvent(null, child);
}
length++;
}
return child;
@@ -1561,7 +1562,7 @@ public abstract class DomNode
// Climb to the top of this subtree and handle capture, letting
// each node (from the top down) capture until one stops it or
// until we get to this one.
current = parent;
current = (parent == null) ? this : parent;
if (current.depth >= ANCESTORS_INIT)
{
DomNode[] newants = new DomNode[current.depth + 1];
@@ -43,6 +43,7 @@ import java.util.LinkedList;
import java.util.List;
import javax.xml.XMLConstants;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentType;
import org.w3c.dom.Element;
import org.w3c.dom.Entity;
@@ -72,7 +73,7 @@ import gnu.xml.dom.DomNode;
*
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
class SAXEventSink
public class SAXEventSink
implements ContentHandler, LexicalHandler, DTDHandler, DeclHandler
{
@@ -110,6 +111,11 @@ class SAXEventSink
interrupted = true;
}
protected Document getDocument()
{
return doc;
}
// -- ContentHandler2 --
public void setDocumentLocator(Locator locator)
@@ -1021,9 +1021,18 @@ public class SAXParser
SAXParser parser = new SAXParser(validating, namespaceAware,
xIncludeAware);
InputSource input = new InputSource(args[pos]);
XMLReader reader = parser.getXMLReader();
reader.setContentHandler(handler);
reader.parse(input);
java.io.FileReader fr = new java.io.FileReader(args[pos]);
input.setCharacterStream(fr);
try
{
XMLReader reader = parser.getXMLReader();
reader.setContentHandler(handler);
reader.parse(input);
}
finally
{
fr.close();
}
pos++;
}
}
@@ -664,12 +664,10 @@ public class XMLStreamWriterImpl
public void writeDTD(String dtd)
throws XMLStreamException
{
// Really thoroughly pointless method...
try
{
if (!isName(dtd))
throw new IllegalArgumentException("illegal Name: " + dtd);
// XXX: Should we parse the doctypedecl at this point to ensure
// wellformedness?
writer.write("<!DOCTYPE ");
writer.write(dtd);
writer.write('>');
@@ -0,0 +1,97 @@
/* SAXTemplatesHandler.java --
Copyright (C) 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.xml.transform;
import javax.xml.transform.Templates;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.TemplatesHandler;
import org.w3c.dom.Document;
import gnu.xml.dom.ls.SAXEventSink;
/**
* A content handler that acts as a sink for SAX parse events,
* constructing an XSL stylesheet.
* Internally, this class simply creates a DOM tree from the events,
* and then parses the DOM into a Templates object.
*
* @author Chris Burdess (dog@gnu.org)
*/
class SAXTemplatesHandler
extends SAXEventSink
implements TemplatesHandler
{
final TransformerFactoryImpl factory;
String systemId;
SAXTemplatesHandler(TransformerFactoryImpl factory)
{
this.factory = factory;
}
public String getSystemId()
{
return systemId;
}
public void setSystemId(String systemId)
{
this.systemId = systemId;
}
public Templates getTemplates()
{
Document doc = getDocument();
if (doc == null)
throw new IllegalStateException("Parsing of stylesheet incomplete");
DOMSource ds = new DOMSource(doc, systemId);
try
{
return factory.newTemplates(ds);
}
catch (TransformerConfigurationException e)
{
String msg = "Unable to construct templates from this event stream";
IllegalStateException e2 = new IllegalStateException(msg);
e2.initCause(e);
throw e2;
}
}
}
@@ -0,0 +1,111 @@
/* SAXTransformerHandler.java --
Copyright (C) 2006 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package gnu.xml.transform;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.TransformerHandler;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import gnu.xml.dom.ls.SAXEventSink;
/**
* A SAX event sink that processes an XML source represented as a stream of
* SAX events into a result tree.
* This works by simply buffering all the events into a DOM tree and then
* using this DOM tree as the source of the transformation.
*
* @author Chris Burdess (dog@gnu.org)
*/
class SAXTransformerHandler
extends SAXEventSink
implements TransformerHandler
{
final TransformerFactoryImpl factory;
final Transformer transformer;
String systemId;
Result result;
SAXTransformerHandler(TransformerFactoryImpl factory, Transformer transformer)
{
this.factory = factory;
this.transformer = transformer;
}
public String getSystemId()
{
return systemId;
}
public void setSystemId(String systemId)
{
this.systemId = systemId;
}
public Transformer getTransformer()
{
return transformer;
}
public void setResult(Result result)
{
this.result = result;
}
public void endDocument()
throws SAXException
{
super.endDocument();
try
{
Document doc = getDocument();
DOMSource ds = new DOMSource(doc, systemId);
transformer.transform(ds, result);
}
catch (TransformerException e)
{
SAXException e2 = new SAXException(e.getMessage());
e2.initCause(e);
throw e2;
}
}
}
@@ -324,7 +324,8 @@ public class StreamSerializer
break;
case Node.TEXT_NODE:
value = node.getNodeValue();
if (!"yes".equals(node.getUserData("disable-output-escaping")))
if (!"yes".equals(node.getUserData("disable-output-escaping")) &&
mode != Stylesheet.OUTPUT_TEXT)
value = encode(value, false, false);
out.write(encodeText(value));
break;
@@ -60,11 +60,15 @@ import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TemplatesHandler;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.XMLFilter;
import gnu.xml.dom.DomDocument;
/**
@@ -73,7 +77,7 @@ import gnu.xml.dom.DomDocument;
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
*/
public class TransformerFactoryImpl
extends TransformerFactory
extends SAXTransformerFactory
{
final XPathFactory xpathFactory;
@@ -316,7 +320,8 @@ public class TransformerFactoryImpl
StreamSource.FEATURE.equals(name) ||
StreamResult.FEATURE.equals(name) ||
DOMSource.FEATURE.equals(name) ||
DOMResult.FEATURE.equals(name))
DOMResult.FEATURE.equals(name) ||
SAXTransformerFactory.FEATURE.equals(name))
{
return true;
}
@@ -346,6 +351,49 @@ public class TransformerFactoryImpl
return userListener;
}
// -- SAXTransformerFactory --
public TemplatesHandler newTemplatesHandler()
throws TransformerConfigurationException
{
return new SAXTemplatesHandler(this);
}
public TransformerHandler newTransformerHandler()
throws TransformerConfigurationException
{
Transformer transformer = newTransformer();
return new SAXTransformerHandler(this, transformer);
}
public TransformerHandler newTransformerHandler(Source source)
throws TransformerConfigurationException
{
Transformer transformer = newTransformer(source);
return new SAXTransformerHandler(this, transformer);
}
public TransformerHandler newTransformerHandler(Templates templates)
throws TransformerConfigurationException
{
Transformer transformer = templates.newTransformer();
return new SAXTransformerHandler(this, transformer);
}
public XMLFilter newXMLFilter(Source source)
throws TransformerConfigurationException
{
throw new UnsupportedOperationException();
}
public XMLFilter newXMLFilter(Templates templates)
throws TransformerConfigurationException
{
throw new UnsupportedOperationException();
}
// -- SAXTransformerFactory end --
/**
* Syntax: TransformerFactoryImpl [<stylesheet> [<input> [<output>]]]
*/
@@ -53,6 +53,7 @@ import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.URIResolver;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamSource;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
@@ -118,10 +119,9 @@ class XSLURIResolver
try
{
URL url = resolveURL(systemId, base, href);
Node node = null;
InputStream in = null;
if (source instanceof StreamSource)
if (source != null && source instanceof StreamSource)
{
StreamSource ss = (StreamSource) source;
in = ss.getInputStream();
@@ -134,8 +134,25 @@ class XSLURIResolver
}
}
}
else if (source != null && source instanceof SAXSource)
{
SAXSource ss = (SAXSource) source;
if (ss.getInputSource() != null)
{
in = ss.getInputSource().getByteStream();
if (in == null)
{
Reader reader = ss.getInputSource().getCharacterStream();
if (reader != null)
{
in = new ReaderInputStream(reader);
}
}
}
}
if (in == null)
{
URL url = resolveURL(systemId, base, href);
if (url != null)
{
systemId = url.toString();
+35
View File
@@ -59,6 +59,7 @@ import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -80,6 +81,38 @@ public abstract class Expr
".####################################################",
new DecimalFormatSymbols(Locale.US));
static class ExprNodeSet implements NodeList
{
private ArrayList list;
ExprNodeSet(Collection collection)
{
if (collection instanceof ArrayList)
list = (ArrayList) collection;
else
list = new ArrayList(collection);
}
public int getLength()
{
return list.size();
}
public Node item(int index)
{
try
{
return (Node) list.get(index);
}
catch (ArrayIndexOutOfBoundsException e)
{
return null;
}
}
}
public Object evaluate(Object item, QName returnType)
throws XPathExpressionException
{
@@ -132,6 +165,8 @@ public abstract class Expr
{
throw new XPathExpressionException("return value is not a node-set");
}
if (ret != null)
ret = new ExprNodeSet((Collection) ret);
}
}
return ret;