1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements.  See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership.  The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License.  You may obtain a copy of the License at
10 *
11 *   http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied.  See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21 
22 package org.apache.openoffice.ooxml.parser;
23 
24 import java.util.HashMap;
25 import java.util.Map;
26 import java.util.Vector;
27 
28 public class NamespaceMap
29 {
30     public class NamespaceDescriptor
31     {
NamespaceDescriptor(final String sPrefix, final int nId)32         NamespaceDescriptor (final String sPrefix, final int nId)
33         {
34             Prefix = sPrefix;
35             Id = nId;
36         }
37         public final String Prefix;
38         public final int Id;
39     }
NamespaceMap(final Vector<String[]> aData)40     NamespaceMap (final Vector<String[]> aData)
41     {
42         maUriToDescriptorMap = new HashMap<>();
43         maIdToDescriptorMap = new HashMap<>();
44 
45         for (final String[] aLine : aData)
46         {
47             final int nId = Integer.parseInt(aLine[2]);
48             final NamespaceDescriptor aDescriptor = new NamespaceDescriptor(aLine[1], nId);
49             maUriToDescriptorMap.put(
50                 aLine[3],
51                 aDescriptor);
52             maIdToDescriptorMap.put(
53                 nId,
54                 aDescriptor);
55         }
56     }
57 
58 
59 
60 
GetDescriptorForURI(final String sURI)61     public NamespaceDescriptor GetDescriptorForURI (final String sURI)
62     {
63         if (sURI == null)
64             throw new RuntimeException("namespace is null");
65         if ( ! maUriToDescriptorMap.containsKey(sURI))
66             throw new RuntimeException("namespace '"+sURI+"' is not known");
67         return maUriToDescriptorMap.get(sURI);
68     }
69 
70 
71 
72 
GetDescriptorForId(final int nId)73     public NamespaceDescriptor GetDescriptorForId (final int nId)
74     {
75         return maIdToDescriptorMap.get(nId);
76     }
77 
78 
79 
80 
GetNamespaceCount()81     public int GetNamespaceCount ()
82     {
83         return maUriToDescriptorMap.size();
84     }
85 
86 
87 
88 
89     private final Map<String,NamespaceDescriptor> maUriToDescriptorMap;
90     private final Map<Integer,NamespaceDescriptor> maIdToDescriptorMap;
91 }
92