Statistics
| Revision:

root / tmp / org.txm.core / src / groovy / org / txm / importer / graal / PersonalNamespaceContext.groovy @ 187

History | View | Annotate | Download (3.6 kB)

1
// Copyright © 2010-2013 ENS de Lyon.
2
// Copyright © 2007-2010 ENS de Lyon, CNRS, INRP, University of
3
// Lyon 2, University of Franche-Comté, University of Nice
4
// Sophia Antipolis, University of Paris 3.
5
//
6
// The TXM platform is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation,
9
// either version 2 of the License, or (at your option) any
10
// later version.
11
//
12
// The TXM platform is distributed in the hope that it will be
13
// useful, but WITHOUT ANY WARRANTY; without even the implied
14
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
// PURPOSE. See the GNU General Public License for more
16
// details.
17
//
18
// You should have received a copy of the GNU General
19
// Public License along with the TXM platform. If not, see
20
// http://www.gnu.org/licenses.
21
//
22
//
23
//
24
// $LastChangedDate: 2016-02-01 09:53:38 +0100 (Mon, 01 Feb 2016) $
25
// $LastChangedRevision: 3101 $
26
// $LastChangedBy: mdecorde $
27
//
28
package org.txm.importer.graal
29

    
30
import java.util.Iterator;
31

    
32
import javax.xml.*;
33
import javax.xml.namespace.NamespaceContext;
34

    
35
import org.xml.sax.helpers.NamespaceSupport;
36

    
37
/**
38
 * Instantiates a new personal namespace context.
39
 *
40
 * @author ayepdieu, mdecorde
41
 * 
42
 * do correpondances between namespace and uri
43
 */
44
public class PersonalNamespaceContext implements NamespaceContext {
45
        
46
        public static HashMap<String, String> adress2name = new HashMap<String, String>();
47
        public static HashMap<String, String> name2adress = new HashMap<String, String>();
48
        static {
49
                addNamespace("tei", "http://www.tei-c.org/ns/1.0")
50
                addNamespace("me", "http://www.menota.org/ns/1.0")
51
                addNamespace("bfm", "http://bfm.ens-lsh.fr/ns/1.0")
52
                addNamespace("txm", "http://textometrie.org/1.0")
53
                addNamespace("xi", "http://www.w3.org/2001/XInclude")
54
                addNamespace("fn", "http://www.w3.org/2005/xpath-functions")
55
                addNamespace("xhtml", "http://www.w3.org/1999/xhtml")
56
                addNamespace("svg", "http://www.w3.org/2000/svg")
57
                addNamespace(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI)
58
        }
59
        /*
60
        String TEINS = "http://www.tei-c.org/ns/1.0"
61
        String MENS = "http://www.menota.org/ns/1.0";
62
        String BFMNS = "http://bfm.ens-lsh.fr/ns/1.0";
63
        String TXMNS = "http://textometrie.org/1.0";
64
        String XINS = "http://www.w3.org/2001/XInclude";
65
        String FNNS = "http://www.w3.org/2005/xpath-functions";
66
        String XHTMLNS = "http://www.w3.org/1999/xhtml";
67
        String SVGNS = "http://www.w3.org/2000/svg"
68
        String XMLNS = "http://www.w3.org/XML/1998/namespace"
69

70
        String TEINSNAME = "tei"
71
        String MENSNAME = "me";
72
        String BFMNSNAME = "bfm";
73
        String TXMNSNAME = "txm";
74
        String XINSNAME = "xi";
75
        String FNNSNAME = "fn";
76
        String XHTMLNSNAME = "xhtml";
77
        String SVGNSNAME = "svg"
78
*/
79
        public PersonalNamespaceContext() {
80
                super();
81
        }
82

    
83
        public static void addNamespace(String name, String address) {
84
                adress2name.put(address, name);
85
                name2adress.put(name, address);
86
        }
87
        
88
        /* (non-Javadoc)
89
         * @see javax.xml.namespace.NamespaceContext#getNamespaceURI(java.lang.String)
90
         */
91
        public String getNamespaceURI(String prefix) {
92
                if (!name2adress.containsKey(prefix)) return XMLConstants.NULL_NS_URI;
93
                return name2adress.get(prefix)
94
        }
95

    
96
        private static String NONE = "";
97
        /**
98
         * 
99
         * @param uri the uri
100
         * @return the prefix
101
         */
102
        public String getPrefix(String uri) {
103
                
104
                if (uri == null) return NONE;
105
                if (!adress2name.containsKey(uri)) return NONE;
106
                return adress2name.get(uri)
107
        }
108

    
109
        /**
110
         * This method isn't necessary for XPath processing either.
111
         *
112
         * @param uri the uri
113
         * @return the prefixes
114
         */
115
        public Iterator getPrefixes(String uri) {
116
                throw new UnsupportedOperationException();
117
        }
118
}