import org.apache.fop.datatypes.Ints;
import org.apache.fop.fo.expr.PropertyException;
import org.apache.fop.xml.XMLEvent;
-import org.apache.fop.xml.XMLNamespaces;
+import org.apache.fop.xml.Namespaces;
/**
* The FO Attributes data structures and methods needed to manage the
* <tt>HashMap</tt>s which contain the attribute lists for each
* namespace which may be active for a particular FO element. The
* <tt>ArrayList</tt> is indexed by the URIIndex for this namespace
- * which is maintained in an <tt>XMLNamespaces</tt> object by the
+ * which is maintained in an <tt>Namespaces</tt> object by the
* <tt>FOTree</tt> object which is processing the FO input. The
* values in the <tt>HashMap</tt>s are indexed by the local name of the
* attribute.
int attrUriIndex = foNode.namespaces.getURIIndex(attrUri);
//System.out.println("FONode:" + event);
- if (attrUriIndex == XMLNamespaces.DefAttrNSIndex) {
+ if (attrUriIndex == Namespaces.DefAttrNSIndex) {
// Standard attribute namespace
// Is this a known (valid) property?
int propIndex = PropNames.getPropertyIndex(attrLocalname);
System.out.println("Creating nSpaceAttrMaps");
nSpaceAttrMaps = new ArrayList(attrUriIndex + 1);
// Add the fo list
- for (int j = 0; j < XMLNamespaces.DefAttrNSIndex; j++)
+ for (int j = 0; j < Namespaces.DefAttrNSIndex; j++)
nSpaceAttrMaps.add(new HashMap(0));
System.out.println("Adding foAttrMap");
* derived from the one maintained in <i>nSpaceAttrMaps</i>.
*/
public Map getAttrMap(int uriIndex) {
- if (uriIndex == XMLNamespaces.DefAttrNSIndex)
+ if (uriIndex == Namespaces.DefAttrNSIndex)
return Collections.unmodifiableMap(foAttrMap);
if (nSpaceAttrMaps != null) {
if (uriIndex >= nSpaceAttrMaps.size()) return null;
public String getUriAttrValue(int uriIndex, String localName)
throws PropertyException
{
- if (uriIndex == XMLNamespaces.DefAttrNSIndex)
+ if (uriIndex == Namespaces.DefAttrNSIndex)
return getFoAttrValue(PropNames.getPropertyIndex(localName));
return (String)
(((HashMap)nSpaceAttrMaps.get(uriIndex)).get(localName));
// the entries from the merging foAttrs
for (int i = 0; i < attrLen; i++) {
// skip foAttrMap
- if (i == XMLNamespaces.DefAttrNSIndex) continue;
+ if (i == Namespaces.DefAttrNSIndex) continue;
((HashMap) nSpaceAttrMaps.get(i))
.putAll(foAttrs.getAttrMap(i));
}
import org.apache.fop.messaging.MessageHandler;
import org.apache.fop.xml.XMLEvent;
import org.apache.fop.xml.SyncedXmlEventsBuffer;
-import org.apache.fop.xml.XMLNamespaces;
+import org.apache.fop.xml.Namespaces;
/**
* Class for nodes in the FO tree.
protected final SyncedXmlEventsBuffer xmlevents;
/** The namespaces object associated with <i>xmlevents</i>. */
- protected XMLNamespaces namespaces;
+ protected Namespaces namespaces;
/** The FO type. */
public final int type;
import org.apache.fop.xml.FoXMLEvent;
import org.apache.fop.xml.SyncedXmlEventsBuffer;
import org.apache.fop.xml.XMLEvent;
-import org.apache.fop.xml.XMLNamespaces;
+import org.apache.fop.xml.Namespaces;
/**
* <tt>FoRoot</tt> is the class which processes the fo:root start element
// Clean up root's FO tree build environment
makeSparsePropsSet();
// Provide some stats
- for (int i = 0; i <= XMLNamespaces.LAST_NS_INDEX; i++) {
+ for (int i = 0; i <= Namespaces.LAST_NS_INDEX; i++) {
System.out.println("Namespace " + namespaces.getIndexURI(i));
System.out.println("Size of event pool: " +
namespaces.getNSPoolSize(i));
private static final String revision = "$Revision$";
/** Required argument for constructing new <tt>XMLEvent</tt>s. */
- //protected final XMLNamespaces namespaces;
+ //protected final Namespaces namespaces;
/**
* The zero-argument constructor
*/
private int foType = FObjectNames.NO_FO;
/**
- * @param namespaces the <code>XMLNamespaces</code> object
+ * @param namespaces the <code>Namespaces</code> object
* @param sequence the sequence number of the event within its
* namespace
* @param uriIndex the namesopace index
*/
- public FoXMLEvent (XMLNamespaces namespaces, int sequence, int uriIndex) {
+ public FoXMLEvent (Namespaces namespaces, int sequence, int uriIndex) {
super(namespaces, sequence, uriIndex);
}
* The fully defined constructor takes values for each of the data
* elements.
*/
- public FoXMLEvent(XMLNamespaces namespaces, int sequence,
+ public FoXMLEvent(Namespaces namespaces, int sequence,
int type, String chars, int uriIndex,
String localName, String qName,
AttributesImpl attributes,
foType = ev.foType;
}
- public FoXMLEvent(XMLNamespaces namespaces, int sequence,
+ public FoXMLEvent(Namespaces namespaces, int sequence,
int uriIndex, int type, String chars) {
super(namespaces, sequence, uriIndex, type, chars);
}
- public FoXMLEvent(XMLNamespaces namespaces, int sequence,
+ public FoXMLEvent(Namespaces namespaces, int sequence,
int type, int uriIndex, AttributesImpl attributes, int foType) {
super(namespaces, sequence, uriIndex);
this.type = type;
import org.apache.fop.apps.FOPException;
import org.apache.fop.configuration.Configuration;
import org.apache.fop.fo.FObjectNames;
-import org.apache.fop.xml.XMLNamespaces;
+import org.apache.fop.xml.Namespaces;
/**
* <tt>FoXmlSerialHandler</tt> is the <tt>ContentHandler</tt> for the
private SyncedXmlEventsBuffer events;
private XMLReader parser;
- private XMLNamespaces namespaces;
+ private Namespaces namespaces;
private InputSource source;
private Thread foThread;
private boolean errorDump;
*/
public void startDocument() throws NoSuchElementException {
synchronized (events) {
- XMLEvent event = acquireXMLEvent(XMLNamespaces.DefAttrNSIndex);
+ XMLEvent event = acquireXMLEvent(Namespaces.DefAttrNSIndex);
//System.out.println("StartDocument thread "
// + Thread.currentThread().getName());
event.type = XMLEvent.STARTDOCUMENT;
*/
public void endDocument() throws NoSuchElementException {
synchronized (events) {
- XMLEvent event = acquireXMLEvent(XMLNamespaces.DefAttrNSIndex);
+ XMLEvent event = acquireXMLEvent(Namespaces.DefAttrNSIndex);
//System.out.println("EndDocument thread "
//+ Thread.currentThread().getName());
event.type = XMLEvent.ENDDOCUMENT;
try {
int uriIndex = namespaces.getURIIndex(uri);
XMLEvent event = acquireXMLEvent(uriIndex);
- if (uriIndex == XMLNamespaces.XSLNSpaceIndex) {
+ if (uriIndex == Namespaces.XSLNSpaceIndex) {
event.setFoType(FObjectNames.getFOIndex(localName));
}
//System.out.println("startElement: acquired " + event.id);
//+ Thread.currentThread().getName());
event.type = XMLEvent.ENDELEMENT;
event.uriIndex = uriIndex;
- if (uriIndex == XMLNamespaces.XSLNSpaceIndex) {
+ if (uriIndex == Namespaces.XSLNSpaceIndex) {
event.setFoType(FObjectNames.getFOIndex(localName));
}
event.localName = localName;
// downstream processing to determine the environment in
// which the characters belong.
XMLEvent event
- = namespaces.acquireXMLEvent(XMLNamespaces.DefAttrNSIndex);
+ = namespaces.acquireXMLEvent(Namespaces.DefAttrNSIndex);
//System.out.println("characters thread "
// + Thread.currentThread().getName());
event.type = XMLEvent.CHARACTERS;
}
public Poolable clear() {
- nsType = XMLNamespaces.NO_NS_TYPE;
+ nsType = Namespaces.NO_NS_TYPE;
return super.clear();
}
}
--- /dev/null
+/*
+ * $Id$
+ *
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The end-user documentation included with the redistribution, if any,
+ * must include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if and
+ * wherever such third-party acknowledgments normally appear.
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior written
+ * permission. For written permission, please contact apache@apache.org.
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com> . For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/> .
+ *
+ * @author <a href="mailto:pbwest@powerup.com.au"> Peter B. West </a>
+ *
+ * @version $Revision$ $Name$
+ */
+package org.apache.fop.xml;
+
+import org.apache.fop.apps.FOPException;
+import org.apache.fop.datastructs.SyncedCircularBuffer;
+import org.apache.fop.pool.*;
+
+/**
+ * Maintains the namespaces encountered by an invocation of
+ * <tt>XMLSerialHandler</tt>.
+ * One instance of <i>Namespaces</i> is maintained across all documents
+ * that may be processed in a single invocation of <tt>XMLSerialhandler</tt>.
+ * A reference to that instance is kept with every instance of <tt>XMLEvent</tt>.
+ * An <code>XMLEventPool</code> pool of event objects is maintained for every
+ * namesapce encountered in parsing. The pool for the
+ * http://www.w3.org/1999/XSL/Format (XSL_FO) namespace is created immediately;
+ * other pools are created only as elements from a particular namespace are
+ * encountered.
+ */
+
+public class Namespaces {
+
+ private static final String tag = "$Name$";
+ private static final String revision = "$Revision$";
+
+ /**
+ * Null namespace, as for attribute default and for use with SAX events
+ * without namespaces, e.g. START_DOCUMENT.
+ */
+ public static final String DefAttrNSpace = "";
+ /** The XSL_FO namespace */
+ public static final String XSLNamespace =
+ "http://www.w3.org/1999/XSL/Format";
+ /** The FOP extensions namespace */
+ public static final String FOXNamespace =
+ "http://xml.apache.org/fop/extensions";
+ /** The SVG namespace */
+ public static final String SVGNamespace = "http://www.w3.org/2000/svg";
+
+ public static final int NO_NAMESPACE = -1;
+
+ /**
+ * Generic undefined type for namespace-specific event types.
+ */
+ public static final int NO_NS_TYPE = -1;
+
+ /** Index for associated namespace */
+ public static final int DefAttrNSIndex = 0
+ ,XSLNSpaceIndex = 1
+ ,FOXNSpaceIndex = 2
+ ,SVGNSpaceIndex = 3
+ ;
+ /** Highest-numbered namespace index */
+ public static final int LAST_NS_INDEX = SVGNSpaceIndex;
+
+ private static final int BUFFER_SIZE
+ = SyncedCircularBuffer.DEFAULTBUFSIZE;
+
+ /** Initial size of pool for associated namespace */
+ public static final int
+ INITIAL_DEF_ATTR_NS_POOL_SIZE = BUFFER_SIZE / 2
+ ,INITIAL_XSL_NS_POOL_SIZE = BUFFER_SIZE
+ ,INITIAL_FOX_NS_POOL_SIZE = BUFFER_SIZE / 2
+ ,INITIAL_SVG_NS_POOL_SIZE = BUFFER_SIZE / 2
+ ;
+
+ /**
+ * An array of namespace URIs. Effectively, a mapping of an <tt>int</tt>
+ * index onto a URI. The array is initialized with the known URIs which FOP
+ * is expected to handle.
+ */
+ private String[] uris =
+ { DefAttrNSpace, XSLNamespace, FOXNamespace, SVGNamespace };
+
+ /**
+ * An array of <code>XMLEventPool</code>s. This ArrayList is indexed by
+ * the namespace index used in this <code>Namespaces</code> object.
+ * This allows for the maintenance of individual event pools for each
+ * namespace active in the current document.
+ */
+ private XMLEventPool[] pools = new XMLEventPool[LAST_NS_INDEX + 1];
+
+ /**
+ * The pool for <code>UriLocalName</code> objects.
+ */
+ private UriLocalNamePool uriLocalNamePool;
+
+ /**
+ * Sequenced objects for use by <tt>XMLEvent</tt>s. Because an
+ * <tt>XMLEvent</tt> object must always be associated with an
+ * <i>XMLNamespace</i> object, this namespace object will act as a
+ * singleton for <tt>XMLEvent</tt>s. This field provides a counter for
+ * those objects. The range of values which may be assigned to
+ * <i>nsSequences</i> is restricted by <i>nsSeqMasks</i>.
+ */
+ private int nsSequences[] = new int[LAST_NS_INDEX + 1];
+
+ /**
+ * This field is used to provide sequence numbers for
+ * <code>Poolable UriLocalName</code> objects.
+ */
+ private int uriLocalSeq = 0;
+
+ /**
+ * Number of bits in the nsSequences mask for the associated namespace.
+ * This value will determine the number of nsSequences values the pool
+ * for the associated namespace will track.
+ */
+ private static final int DEF_ATTR_SEQ_BITS = 14
+ ,FO_SEQ_BITS = 18
+ ,FOX_SEQ_BITS = 14
+ ,SVG_SEQ_BITS = 16
+ ;
+
+ /**
+ * Masks to restrict the range of values within which the nsSequences value
+ * for each namespace may cycle.
+ */
+ private final int[] nsSeqMasks =
+ {
+ (1 << DEF_ATTR_SEQ_BITS) - 1
+ ,(1 << FO_SEQ_BITS) - 1
+ ,(1 << FOX_SEQ_BITS) - 1
+ ,(1 << SVG_SEQ_BITS) - 1 };
+
+ /**
+ * Mask to restrict the range of values within which uriLocalSeq will
+ * cycle.
+ */
+ private final int uriLocalSeqMask = (1 << FO_SEQ_BITS) - 1;
+
+ public Namespaces() {
+ for (int i = 0; i <= LAST_NS_INDEX; i++) {
+ pools[i] = null;
+ nsSequences[i] = 0;
+ }
+ pools[DefAttrNSIndex] =
+ new XMLEventPool(INITIAL_DEF_ATTR_NS_POOL_SIZE);
+ pools[XSLNSpaceIndex] =
+ new XMLEventPool(INITIAL_XSL_NS_POOL_SIZE);
+ pools[FOXNSpaceIndex] =
+ new XMLEventPool(INITIAL_FOX_NS_POOL_SIZE);
+ pools[SVGNSpaceIndex] =
+ new XMLEventPool(INITIAL_SVG_NS_POOL_SIZE);
+ uriLocalNamePool = new UriLocalNamePool(BUFFER_SIZE);
+ }
+
+ /**
+ * The increment access function for the nsSequences associated with the given
+ * URI index.
+ *
+ * @param nsIndex
+ * the namespace index
+ * @return the next positive nsSequences number. This number may wrap but is
+ * guaranteed to be within the range nsSeqMasks >= nsSequences >= 0.
+ * @throws FOPException
+ * if the namespace index is out of range
+ */
+ public int getNextSequence(int nsIndex) throws FOPException {
+ if (nsIndex < 0 || nsIndex > LAST_NS_INDEX) {
+ throw new FOPException(
+ "Namespace index " + nsIndex + " out of range.");
+ }
+ synchronized (nsSequences) {
+ nsSequences[nsIndex] = ++nsSequences[nsIndex] & nsSeqMasks[nsIndex];
+ return nsSequences[nsIndex];
+ }
+ }
+
+ /**
+ * The access function for the nsSequences associated with the given URI
+ * index.
+ *
+ * @param nsIndex
+ * the namespace index
+ * @return the current nsSequences number
+ * @throws FOPException
+ * if the index is out of range
+ */
+ public int getSequenceValue(int nsIndex) throws FOPException {
+ if (nsIndex < 0 || nsIndex > LAST_NS_INDEX) {
+ throw new FOPException(
+ "Namespace index " + nsIndex + " out of range.");
+ }
+ return nsSequences[nsIndex];
+ }
+
+ /**
+ * @return size of the <tt>uris</tt> <ttArrayList</tt>.
+ */
+ public int getUrisLength() {
+ return uris.length;
+ }
+
+ /**
+ * Get the index corresponding to the parameter URI.
+ *
+ * @param uri
+ * the namespace uri
+ * @return integer index of the namespace URI
+ * @throws FOPException
+ * if <code>uri</code> not recognized
+ */
+ public int getURIIndex(String uri) throws FOPException {
+ int i;
+ for (i = 0; i < uris.length; i++) {
+ if (uri.equals(uris[i]))
+ return i;
+ }
+ throw new FOPException("Unknown URI " + uri);
+ }
+
+ /**
+ * @param index
+ * the integer index of the namespace URI
+ * @return the corresponding namespace URI
+ */
+ public String getIndexURI(int index) {
+ return uris[index];
+ }
+
+ /**
+ * Generate a new XMLEvent, based on the uriIndex argument. The uriIndex
+ * must be valid for this Namespaces object; i.e. it must correspond to
+ * a namespace being tracked in this object.
+ *
+ * @param nsIndex
+ * the namespace index
+ * @return an appropriate <code>XMLEvent</code>
+ */
+ public XMLEvent makeXMLEvent(int nsIndex) throws FOPException {
+ if (nsIndex < 0 | nsIndex >= (uris.length)) {
+ throw new FOPException("URI index out or range");
+ }
+ return newXMLEvent(nsIndex);
+ }
+
+ /**
+ * Generate a new XMLEvent, based on the uriIndex argument. This
+ * private method is for interanl use when the <code>nsIndex</code> is
+ * known to be in range.
+ *
+ * @param nsIndex
+ * the namespace index
+ * @return an appropriate <code>XMLEvent</code>
+ */
+ private XMLEvent newXMLEvent(int nsIndex) {
+ // The only currently known subclass of XMLEvent is FoXMLEvent
+ switch (nsIndex) {
+ case DefAttrNSIndex :
+ // Produce an XMLEvent, e.g. for START_DOCUMENT and, more
+ // importantly, CHARACTERS.
+ synchronized (nsSequences) {
+ nsSequences[nsIndex] =
+ ++nsSequences[nsIndex] & nsSeqMasks[nsIndex];
+ return new XMLEvent(this, nsSequences[nsIndex], nsIndex);
+ }
+ case XSLNSpaceIndex :
+ // Make an FoXMLEvent
+ synchronized (nsSequences) {
+ nsSequences[nsIndex] =
+ ++nsSequences[nsIndex] & nsSeqMasks[nsIndex];
+ return new FoXMLEvent(this, nsSequences[nsIndex], nsIndex);
+ }
+ case FOXNSpaceIndex :
+ // No FoxXMLEvent defined - don't break, but fall through
+ case SVGNSpaceIndex :
+ // No SvgXMLEvent defined - don't break, but fall through
+ default :
+ // Just produce a raw XMLEvent
+ synchronized (nsSequences) {
+ nsSequences[nsIndex] =
+ ++nsSequences[nsIndex] & nsSeqMasks[nsIndex];
+ return new XMLEvent(this, nsSequences[nsIndex], nsIndex);
+ }
+ }
+ }
+
+ /**
+ * Acquire an event.
+ *
+ * @return an <tt>XMLEvent</tt>.
+ */
+ public XMLEvent acquireXMLEvent(int nsIndex) throws FOPException {
+ if (nsIndex < 0 || nsIndex > uris.length) {
+ throw new FOPException("URI index out of range: " + nsIndex);
+ }
+ XMLEvent ev;
+ if ((ev = pools[nsIndex].acquireXMLEvent()) != null) {
+ return ev;
+ }
+ ev = makeXMLEvent(nsIndex);
+ return ev;
+ }
+
+ /**
+ * Surrender an event. This method selects the appropriate pool
+ * according to the event namespace index, and passes the request to
+ * the pool.
+ * @param event to surrender
+ */
+ public void surrenderEvent(XMLEvent event) {
+ pools[event.uriIndex].surrenderPoolable(event);
+ }
+
+ /**
+ * Acquire a <code>UriLocalName</code> from the pool, or null if no
+ * pooled names exist.
+ *
+ * @return a <tt>UriLocalName</tt> or null.
+ */
+ public UriLocalName acquireUriLocalName() {
+ return uriLocalNamePool.acquireUriLocalName();
+ }
+
+ /**
+ * Surrender a <code>UriLocalName</code>.
+ * The name is returned to the pool.
+ * @param uriName to surrender
+ */
+ public void surrenderUriLocalName(UriLocalName uriName) {
+ uriLocalNamePool.surrenderPoolable(uriName);
+ }
+
+ /**
+ * Get the size of the event pool for a given namespace.
+ *
+ * @param nsIndex
+ * the index of the namespace
+ * @return pool size.
+ */
+ public int getNSPoolSize(int nsIndex) {
+ return pools[nsIndex].getPoolSize();
+ }
+
+}
* Maintains an index of namespace URIs. These can then be referred to
* by an <tt>int</tt> index.
*/
- private XMLNamespaces namespaces;
+ private Namespaces namespaces;
/**
* No-argument constructor sets up a buffer with the default number of
throws IllegalArgumentException
{
super();
- namespaces = new XMLNamespaces();
+ namespaces = new Namespaces();
}
/**
throws IllegalArgumentException
{
super(size);
- namespaces = new XMLNamespaces();
+ namespaces = new Namespaces();
}
/**
- * Get the <tt>XMLNamespaces</tt> from this buffer.
+ * Get the <tt>Namespaces</tt> from this buffer.
* @return - the namespaces object.
*/
- public XMLNamespaces getNamespaces() { return namespaces; }
+ public Namespaces getNamespaces() { return namespaces; }
/**
* @return next event from the SyncedCircularBuffer
* Discard intervening events.
* @param eventType the SAX event type.
* @param uriIndex the URI index maintained in the
- * <tt>XMLNamespaces</tt> object.
+ * <tt>Namespaces</tt> object.
* @param localName of the required element.
* @return an event of the given type.
* @exception FOPException if buffer errors or interrupts occur.
while (ev != null) {
if (ev.type == eventType && ev.uriIndex == uriIndex) {
switch (uriIndex) {
- case XMLNamespaces.DefAttrNSIndex:
+ case Namespaces.DefAttrNSIndex:
throw new NoSuchElementException
("No special types for default attribute namespace");
- case XMLNamespaces.XSLNSpaceIndex:
+ case Namespaces.XSLNSpaceIndex:
// The FO namespace
if (ev.getFoType() == nsType) {
return ev;
}
break;
- case XMLNamespaces.FOXNSpaceIndex:
+ case Namespaces.FOXNSpaceIndex:
// The FOX namespace
if (ev.getFoxType() == nsType) {
return ev;
}
break;
- case XMLNamespaces.SVGNSpaceIndex:
+ case Namespaces.SVGNSpaceIndex:
// The SVG namespace
if (ev.getSvgType() == nsType) {
return ev;
throws FOPException
{
return getSaxUriTypedEvent(
- eventType, XMLNamespaces.XSLNSpaceIndex, foType);
+ eventType, Namespaces.XSLNSpaceIndex, foType);
}
/**
}
if (ev != null && ev.type == eventType) {
switch (uriIndex) {
- case XMLNamespaces.DefAttrNSIndex:
+ case Namespaces.DefAttrNSIndex:
throw new NoSuchElementException
("No special types for default attribute namespace");
- case XMLNamespaces.XSLNSpaceIndex:
+ case Namespaces.XSLNSpaceIndex:
// The FO namespace
if (ev.getFoType() == nsType) {
return ev;
}
break;
- case XMLNamespaces.FOXNSpaceIndex:
+ case Namespaces.FOXNSpaceIndex:
// The FOX namespace
if (ev.getFoxType() == nsType) {
return ev;
}
break;
- case XMLNamespaces.SVGNSpaceIndex:
+ case Namespaces.SVGNSpaceIndex:
// The SVG namespace
if (ev.getSvgType() == nsType) {
return ev;
throws FOPException
{
return expectSaxUriTypedEvent(
- eventType, XMLNamespaces.XSLNSpaceIndex,
+ eventType, Namespaces.XSLNSpaceIndex,
foType, discardWhiteSpace);
}
/**
* @param uriIndex - the index of the namespace URI maintained in
- * the associated <tt>XMLNamespaces</tt> object.
+ * the associated <tt>Namespaces</tt> object.
* @param localName - the local name of the event.
*/
public UriLocalName(int uriIndex, String localName, int sequence) {
}
public Poolable clear() {
- uriIndex = XMLNamespaces.NO_NAMESPACE;
+ uriIndex = Namespaces.NO_NAMESPACE;
localName = "";
return this;
}
// the basic XML events are unlikely to change.
protected int type = NOEVENT;
protected String chars;
- protected int uriIndex = XMLNamespaces.DefAttrNSIndex;
+ protected int uriIndex = Namespaces.DefAttrNSIndex;
protected String localName;
protected String qName;
protected AttributesImpl attributes;
- protected XMLNamespaces namespaces;
+ protected Namespaces namespaces;
/**
* The one-argument constructor uses the default initialization values:
* namespace
* @param uriIndex the namespace index
*/
- public XMLEvent (XMLNamespaces namespaces, int sequence, int uriIndex ) {
+ public XMLEvent (Namespaces namespaces, int sequence, int uriIndex ) {
super(sequence);
this.namespaces = namespaces;
this.uriIndex = uriIndex;
* @param attributes the AttributesImpl containing the element
* attributes, if any
*/
- public XMLEvent(XMLNamespaces namespaces, int sequence,
+ public XMLEvent(Namespaces namespaces, int sequence,
int type, String chars, int uriIndex,
String localName, String qName,
AttributesImpl attributes)
* @param chars in this event, if any
* @param namespaces the object maintaing URIs and their indices
*/
- public XMLEvent(XMLNamespaces namespaces, int sequence,
+ public XMLEvent(Namespaces namespaces, int sequence,
int uriIndex, int type, String chars) {
super(sequence);
this.namespaces = namespaces;
}
/**
- * Set the <tt>XMLNamespaces</tt> object associated with this event.
- * @param namespaces the XMLNamespaces
+ * Set the <tt>Namespaces</tt> object associated with this event.
+ * @param namespaces the Namespaces
*/
- public void setNamespaces(XMLNamespaces namespaces) {
+ public void setNamespaces(Namespaces namespaces) {
this.namespaces = namespaces;
}
/**
- * Get the <tt>XMLNamespaces</tt> object associated with this event.
- * @return the <tt>XMLNamespaces</tt> object.
+ * Get the <tt>Namespaces</tt> object associated with this event.
+ * @return the <tt>Namespaces</tt> object.
*/
- public XMLNamespaces getNamespaces() { return namespaces; }
+ public Namespaces getNamespaces() { return namespaces; }
/**
* Illegal operation in superclass
+++ /dev/null
-/*
- * $Id$
- *
- * ============================================================================
- * The Apache Software License, Version 1.1
- * ============================================================================
- *
- * Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modifica-
- * tion, are permitted provided that the following conditions are met:
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The end-user documentation included with the redistribution, if any,
- * must include the following acknowledgment: "This product includes software
- * developed by the Apache Software Foundation (http://www.apache.org/)."
- * Alternately, this acknowledgment may appear in the software itself, if and
- * wherever such third-party acknowledgments normally appear.
- * 4. The names "FOP" and "Apache Software Foundation" must not be used to
- * endorse or promote products derived from this software without prior written
- * permission. For written permission, please contact apache@apache.org.
- * 5. Products derived from this software may not be called "Apache", nor may
- * "Apache" appear in their name, without prior written permission of the
- * Apache Software Foundation.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
- * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * This software consists of voluntary contributions made by many individuals
- * on behalf of the Apache Software Foundation and was originally created by
- * James Tauber <jtauber@jtauber.com> . For more information on the Apache
- * Software Foundation, please see <http://www.apache.org/> .
- *
- * @author <a href="mailto:pbwest@powerup.com.au"> Peter B. West </a>
- *
- * @version $Revision$ $Name$
- */
-package org.apache.fop.xml;
-
-import org.apache.fop.apps.FOPException;
-import org.apache.fop.datastructs.SyncedCircularBuffer;
-import org.apache.fop.pool.*;
-
-/**
- * Maintains the namespaces encountered by an invocation of
- * <tt>XMLSerialHandler</tt>.
- * One instance of <i>XMLNamespaces</i> is maintained across all documents
- * that may be processed in a single invocation of <tt>XMLSerialhandler</tt>.
- * A reference to that instance is kept with every instance of <tt>XMLEvent</tt>.
- * An <code>XMLEventPool</code> pool of event objects is maintained for every
- * namesapce encountered in parsing. The pool for the
- * http://www.w3.org/1999/XSL/Format (XSL_FO) namespace is created immediately;
- * other pools are created only as elements from a particular namespace are
- * encountered.
- */
-
-public class XMLNamespaces {
-
- private static final String tag = "$Name$";
- private static final String revision = "$Revision$";
-
- /**
- * Null namespace, as for attribute default and for use with SAX events
- * without namespaces, e.g. START_DOCUMENT.
- */
- public static final String DefAttrNSpace = "";
- /** The XSL_FO namespace */
- public static final String XSLNamespace =
- "http://www.w3.org/1999/XSL/Format";
- /** The FOP extensions namespace */
- public static final String FOXNamespace =
- "http://xml.apache.org/fop/extensions";
- /** The SVG namespace */
- public static final String SVGNamespace = "http://www.w3.org/2000/svg";
-
- public static final int NO_NAMESPACE = -1;
-
- /**
- * Generic undefined type for namespace-specific event types.
- */
- public static final int NO_NS_TYPE = -1;
-
- /** Index for associated namespace */
- public static final int DefAttrNSIndex = 0
- ,XSLNSpaceIndex = 1
- ,FOXNSpaceIndex = 2
- ,SVGNSpaceIndex = 3
- ;
- /** Highest-numbered namespace index */
- public static final int LAST_NS_INDEX = SVGNSpaceIndex;
-
- private static final int BUFFER_SIZE
- = SyncedCircularBuffer.DEFAULTBUFSIZE;
-
- /** Initial size of pool for associated namespace */
- public static final int
- INITIAL_DEF_ATTR_NS_POOL_SIZE = BUFFER_SIZE / 2
- ,INITIAL_XSL_NS_POOL_SIZE = BUFFER_SIZE
- ,INITIAL_FOX_NS_POOL_SIZE = BUFFER_SIZE / 2
- ,INITIAL_SVG_NS_POOL_SIZE = BUFFER_SIZE / 2
- ;
-
- /**
- * An array of namespace URIs. Effectively, a mapping of an <tt>int</tt>
- * index onto a URI. The array is initialized with the known URIs which FOP
- * is expected to handle.
- */
- private String[] uris =
- { DefAttrNSpace, XSLNamespace, FOXNamespace, SVGNamespace };
-
- /**
- * An array of <code>XMLEventPool</code>s. This ArrayList is indexed by
- * the namespace index used in this <code>XMLNamespaces</code> object.
- * This allows for the maintenance of individual event pools for each
- * namespace active in the current document.
- */
- private XMLEventPool[] pools = new XMLEventPool[LAST_NS_INDEX + 1];
-
- /**
- * The pool for <code>UriLocalName</code> objects.
- */
- private UriLocalNamePool uriLocalNamePool;
-
- /**
- * Sequenced objects for use by <tt>XMLEvent</tt>s. Because an
- * <tt>XMLEvent</tt> object must always be associated with an
- * <i>XMLNamespace</i> object, this namespace object will act as a
- * singleton for <tt>XMLEvent</tt>s. This field provides a counter for
- * those objects. The range of values which may be assigned to
- * <i>nsSequences</i> is restricted by <i>nsSeqMasks</i>.
- */
- private int nsSequences[] = new int[LAST_NS_INDEX + 1];
-
- /**
- * This field is used to provide sequence numbers for
- * <code>Poolable UriLocalName</code> objects.
- */
- private int uriLocalSeq = 0;
-
- /**
- * Number of bits in the nsSequences mask for the associated namespace.
- * This value will determine the number of nsSequences values the pool
- * for the associated namespace will track.
- */
- private static final int DEF_ATTR_SEQ_BITS = 14
- ,FO_SEQ_BITS = 18
- ,FOX_SEQ_BITS = 14
- ,SVG_SEQ_BITS = 16
- ;
-
- /**
- * Masks to restrict the range of values within which the nsSequences value
- * for each namespace may cycle.
- */
- private final int[] nsSeqMasks =
- {
- (1 << DEF_ATTR_SEQ_BITS) - 1
- ,(1 << FO_SEQ_BITS) - 1
- ,(1 << FOX_SEQ_BITS) - 1
- ,(1 << SVG_SEQ_BITS) - 1 };
-
- /**
- * Mask to restrict the range of values within which uriLocalSeq will
- * cycle.
- */
- private final int uriLocalSeqMask = (1 << FO_SEQ_BITS) - 1;
-
- public XMLNamespaces() {
- for (int i = 0; i <= LAST_NS_INDEX; i++) {
- pools[i] = null;
- nsSequences[i] = 0;
- }
- pools[DefAttrNSIndex] =
- new XMLEventPool(INITIAL_DEF_ATTR_NS_POOL_SIZE);
- pools[XSLNSpaceIndex] =
- new XMLEventPool(INITIAL_XSL_NS_POOL_SIZE);
- pools[FOXNSpaceIndex] =
- new XMLEventPool(INITIAL_FOX_NS_POOL_SIZE);
- pools[SVGNSpaceIndex] =
- new XMLEventPool(INITIAL_SVG_NS_POOL_SIZE);
- uriLocalNamePool = new UriLocalNamePool(BUFFER_SIZE);
- }
-
- /**
- * The increment access function for the nsSequences associated with the given
- * URI index.
- *
- * @param nsIndex
- * the namespace index
- * @return the next positive nsSequences number. This number may wrap but is
- * guaranteed to be within the range nsSeqMasks >= nsSequences >= 0.
- * @throws FOPException
- * if the namespace index is out of range
- */
- public int getNextSequence(int nsIndex) throws FOPException {
- if (nsIndex < 0 || nsIndex > LAST_NS_INDEX) {
- throw new FOPException(
- "Namespace index " + nsIndex + " out of range.");
- }
- synchronized (nsSequences) {
- nsSequences[nsIndex] = ++nsSequences[nsIndex] & nsSeqMasks[nsIndex];
- return nsSequences[nsIndex];
- }
- }
-
- /**
- * The access function for the nsSequences associated with the given URI
- * index.
- *
- * @param nsIndex
- * the namespace index
- * @return the current nsSequences number
- * @throws FOPException
- * if the index is out of range
- */
- public int getSequenceValue(int nsIndex) throws FOPException {
- if (nsIndex < 0 || nsIndex > LAST_NS_INDEX) {
- throw new FOPException(
- "Namespace index " + nsIndex + " out of range.");
- }
- return nsSequences[nsIndex];
- }
-
- /**
- * @return size of the <tt>uris</tt> <ttArrayList</tt>.
- */
- public int getUrisLength() {
- return uris.length;
- }
-
- /**
- * Get the index corresponding to the parameter URI.
- *
- * @param uri
- * the namespace uri
- * @return integer index of the namespace URI
- * @throws FOPException
- * if <code>uri</code> not recognized
- */
- public int getURIIndex(String uri) throws FOPException {
- int i;
- for (i = 0; i < uris.length; i++) {
- if (uri.equals(uris[i]))
- return i;
- }
- throw new FOPException("Unknown URI " + uri);
- }
-
- /**
- * @param index
- * the integer index of the namespace URI
- * @return the corresponding namespace URI
- */
- public String getIndexURI(int index) {
- return uris[index];
- }
-
- /**
- * Generate a new XMLEvent, based on the uriIndex argument. The uriIndex
- * must be valid for this XMLNamespaces object; i.e. it must correspond to
- * a namespace being tracked in this object.
- *
- * @param nsIndex
- * the namespace index
- * @return an appropriate <code>XMLEvent</code>
- */
- public XMLEvent makeXMLEvent(int nsIndex) throws FOPException {
- if (nsIndex < 0 | nsIndex >= (uris.length)) {
- throw new FOPException("URI index out or range");
- }
- return newXMLEvent(nsIndex);
- }
-
- /**
- * Generate a new XMLEvent, based on the uriIndex argument. This
- * private method is for interanl use when the <code>nsIndex</code> is
- * known to be in range.
- *
- * @param nsIndex
- * the namespace index
- * @return an appropriate <code>XMLEvent</code>
- */
- private XMLEvent newXMLEvent(int nsIndex) {
- // The only currently known subclass of XMLEvent is FoXMLEvent
- switch (nsIndex) {
- case DefAttrNSIndex :
- // Produce an XMLEvent, e.g. for START_DOCUMENT and, more
- // importantly, CHARACTERS.
- synchronized (nsSequences) {
- nsSequences[nsIndex] =
- ++nsSequences[nsIndex] & nsSeqMasks[nsIndex];
- return new XMLEvent(this, nsSequences[nsIndex], nsIndex);
- }
- case XSLNSpaceIndex :
- // Make an FoXMLEvent
- synchronized (nsSequences) {
- nsSequences[nsIndex] =
- ++nsSequences[nsIndex] & nsSeqMasks[nsIndex];
- return new FoXMLEvent(this, nsSequences[nsIndex], nsIndex);
- }
- case FOXNSpaceIndex :
- // No FoxXMLEvent defined - don't break, but fall through
- case SVGNSpaceIndex :
- // No SvgXMLEvent defined - don't break, but fall through
- default :
- // Just produce a raw XMLEvent
- synchronized (nsSequences) {
- nsSequences[nsIndex] =
- ++nsSequences[nsIndex] & nsSeqMasks[nsIndex];
- return new XMLEvent(this, nsSequences[nsIndex], nsIndex);
- }
- }
- }
-
- /**
- * Acquire an event.
- *
- * @return an <tt>XMLEvent</tt>.
- */
- public XMLEvent acquireXMLEvent(int nsIndex) throws FOPException {
- if (nsIndex < 0 || nsIndex > uris.length) {
- throw new FOPException("URI index out of range: " + nsIndex);
- }
- XMLEvent ev;
- if ((ev = pools[nsIndex].acquireXMLEvent()) != null) {
- return ev;
- }
- ev = makeXMLEvent(nsIndex);
- return ev;
- }
-
- /**
- * Surrender an event. This method selects the appropriate pool
- * according to the event namespace index, and passes the request to
- * the pool.
- * @param event to surrender
- */
- public void surrenderEvent(XMLEvent event) {
- pools[event.uriIndex].surrenderPoolable(event);
- }
-
- /**
- * Acquire a <code>UriLocalName</code> from the pool, or null if no
- * pooled names exist.
- *
- * @return a <tt>UriLocalName</tt> or null.
- */
- public UriLocalName acquireUriLocalName() {
- return uriLocalNamePool.acquireUriLocalName();
- }
-
- /**
- * Surrender a <code>UriLocalName</code>.
- * The name is returned to the pool.
- * @param uriName to surrender
- */
- public void surrenderUriLocalName(UriLocalName uriName) {
- uriLocalNamePool.surrenderPoolable(uriName);
- }
-
- /**
- * Get the size of the event pool for a given namespace.
- *
- * @param nsIndex
- * the index of the namespace
- * @return pool size.
- */
- public int getNSPoolSize(int nsIndex) {
- return pools[nsIndex].getPoolSize();
- }
-
-}