From: Peter Bernard West Date: Tue, 1 Oct 2002 16:34:44 +0000 (+0000) Subject: Added foAttrKeys[] sorted key array. X-Git-Tag: Alt-Design_pre_Properties_split~77 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3c477c871b13c3456347c6d6db18a4ab8597c82f;p=xmlgraphics-fop.git Added foAttrKeys[] sorted key array. Obtain DefAttrNSIndex from XMLNamespaces. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@195255 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/fo/FOAttributes.java b/src/org/apache/fop/fo/FOAttributes.java index b177411dc..3d1db408d 100644 --- a/src/org/apache/fop/fo/FOAttributes.java +++ b/src/org/apache/fop/fo/FOAttributes.java @@ -16,6 +16,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Collections; +import java.util.Arrays; /* * FOAttributes.java @@ -63,7 +64,18 @@ public class FOAttributes { */ private HashMap foAttrMap = new HashMap(0); - private int DefAttrNSIndex = XMLNamespaces.DefAttrNSIndex; + /** + * An sorted array of the keys (property indices) of the values in + * foAttrMap. + */ + private Integer[] foAttrKeys = null; + + /** + * A static array of Integer as a template for the generation + * of the foAttrKeys array. + */ + private static Integer[] integerArray + = new Integer[] { Ints.consts.get(0) }; private FONode foNode; @@ -105,7 +117,7 @@ public class FOAttributes { int attrUriIndex = foNode.namespaces.getURIIndex(attrUri); //System.out.println("FONode:" + event); - if (attrUriIndex == DefAttrNSIndex) { + if (attrUriIndex == XMLNamespaces.DefAttrNSIndex) { // Standard FO namespace // Catch default namespace declaration here. This seems to // be a kludge. Should 'xmlns' come through here? @@ -130,7 +142,7 @@ public class FOAttributes { System.out.println("Creating nSpaceAttrMaps"); nSpaceAttrMaps = new ArrayList(attrUriIndex + 1); // Add the fo list - for (j = 0; j < DefAttrNSIndex; j++) + for (j = 0; j < XMLNamespaces.DefAttrNSIndex; j++) nSpaceAttrMaps.add(new HashMap(0)); System.out.println("Adding foAttrMap"); @@ -151,9 +163,17 @@ public class FOAttributes { tmpHash.put(attrLocalname, attrValue); } } + // Set up the sorted array of the foAttr keys, if foAttrMap has + // any entries. + if (foAttrMap.size() > 0) { + foAttrKeys = (Integer[])(foAttrMap.keySet().toArray(integerArray)); + Arrays.sort(foAttrKeys); + } } /** + * Get the default namespace attribute values as an unmodifiable + * Map. * @return a unmodifiable Map containing the the attribute * values for all of the default attribute namespace attributes in this * attribute list, indexed by the property name index from @@ -164,6 +184,7 @@ public class FOAttributes { } /** + * Get the HashMap of all default namespace attributes. * @return HashMap foAttrMap containing the the attribute * values for all of the default attribute namespace attributes in this * attribute list, indexed by the property name index from @@ -174,6 +195,19 @@ public class FOAttributes { return foAttrMap; } + /** + * Get the sorted array of property index keys for the default namespace + * attributes. + * @return Integer[] foAttrKeys containing the the + * sorted keys (the property indices from PropNames) of the + * attribute values for all of the default attribute namespace attributes + * in this attribute list. + * Warning: This array may be changed by the calling process. + */ + public Integer[] getFoAttrKeys() { + return foAttrKeys; + } + /** * A convenience method for accessing attribute values from the default * attribute namespace. @@ -199,6 +233,8 @@ public class FOAttributes { } /** + * Get an unmodifiable Map of the attribute values for a + * particular namespace. * @param uriIndex an int containing the index of the attribute * values namespace, maintained in an XMLEvent static * array. @@ -208,7 +244,7 @@ public class FOAttributes { * derived from the one maintained in nSpaceAttrMaps. */ public Map getAttrMap(int uriIndex) { - if (uriIndex == DefAttrNSIndex) + if (uriIndex == XMLNamespaces.DefAttrNSIndex) return Collections.unmodifiableMap((Map)foAttrMap); if (nSpaceAttrMaps != null) { if (uriIndex >= nSpaceAttrMaps.size()) return null; @@ -220,6 +256,7 @@ public class FOAttributes { } /** + * Get the value of an attribute in a particular namespace. * @param uriIndex an int index of the URIs maintained * by XMLEvent. * @param localName a String with the local name of the @@ -230,7 +267,7 @@ public class FOAttributes { public String getUriAttrValue(int uriIndex, String localName) throws PropertyException { - if (uriIndex == DefAttrNSIndex) + if (uriIndex == XMLNamespaces.DefAttrNSIndex) return getFoAttrValue(PropertyConsts.getPropertyIndex(localName)); return (String) (((HashMap)nSpaceAttrMaps.get(uriIndex)).get(localName)); @@ -281,7 +318,7 @@ public class FOAttributes { // the entries from the merging foAttrs for (int i = 0; i < attrLen; i++) { // skip foAttrMap - if (i == DefAttrNSIndex) continue; + if (i == XMLNamespaces.DefAttrNSIndex) continue; ((HashMap) nSpaceAttrMaps.get(i)) .putAll(foAttrs.getAttrMap(i)); }