View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript-XML: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2006 Open World Ltd, Kevin Rogers
4   //
5   // This file is part of MillScript-XML.
6   //
7   // MillScript-XML is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript-XML is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript-XML; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.commons.xml.tokenizer;
22  
23  import org.millscript.commons.util.IMap;
24  import org.millscript.commons.util.IMapDefault;
25  import org.millscript.commons.util.defaults.ChainedMapDefault;
26  import org.millscript.commons.util.defaults.ConstantMapDefault;
27  import org.millscript.commons.util.map.IArrayMap;
28  import org.millscript.commons.xml.api.Name;
29  
30  /**
31   * This interface represents the namespaces that are currently in scope, it is
32   * a mapping from a prefix to it's IRI for the current scope.
33   */
34  public class PrefixToNamespaceMap extends IArrayMap< String, String > {
35  
36      /**
37       * This is the ID from the release 0.3.0 for future compatibility.
38       */
39      private static final long serialVersionUID = -2468263354341428509L;
40  
41      public static final IMapDefault< String, String > NAMESPACE_MAP_DEFAULT = new ConstantMapDefault< String, String >( "" );
42  
43      /**
44       * Constructs a new namespace to prefix map with the initial
45       * <code>xml</code> and <code>xmlns</code> prefixes declared.
46       */
47      public PrefixToNamespaceMap() {
48          super(
49              new String[] {
50                  "", "",
51                  "xml", Name.XML,
52                  "xmlns", Name.XMLNS
53              },
54              true
55          );
56          this.setDefault( NAMESPACE_MAP_DEFAULT );
57      }
58  
59      /**
60       * Constructs a new namespace to prefix map with the specified parent
61       * mapping and the given key-value pair array of mappings. If a given
62       * prefix is not found in the given array, a lookup will be performed on
63       * the parent map.
64       *
65       * @param parent    the map in which to lookup missing keys
66       * @param store the array of key-value pairs for this mapping
67       */
68      public PrefixToNamespaceMap( final IMap< String, String > parent, final String[] store ) {
69          super( store, true );
70          this.setDefault(
71              new ChainedMapDefault< String, String >( parent )
72          );
73      }
74  
75  }