source: trunk/docx4j/src/main/java/org/docx4j/jaxb/NamespacePrefixMapperSunInternal.java @ 883

Revision 883, 4.6 KB checked in by jharrop, 3 years ago (diff)

NamespacePrefixMappings? stores the mappings in a single location, and is sufficient for xpath.

Line 
1/*
2 *  Copyright 2007-2008, Plutext Pty Ltd.
3 *   
4 *  This file is part of docx4j.
5
6    docx4j is licensed under the Apache License, Version 2.0 (the "License");
7    you may not use this file except in compliance with the License.
8
9    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, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18
19 */
20
21package org.docx4j.jaxb;
22
23import java.util.Iterator;
24
25import javax.xml.XMLConstants;
26import javax.xml.namespace.NamespaceContext;
27
28import org.docx4j.openpackaging.parts.relationships.Namespaces;
29
30public class NamespacePrefixMapperSunInternal extends com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper 
31        {
32        // Must use 'internal' for Java 6
33
34       
35    /**
36     * Returns a preferred prefix for the given namespace URI.
37     *
38     * This method is intended to be overrided by a derived class.
39     *
40     * @param namespaceUri
41     *      The namespace URI for which the prefix needs to be found.
42     *      Never be null. "" is used to denote the default namespace.
43     * @param suggestion
44     *      When the content tree has a suggestion for the prefix
45     *      to the given namespaceUri, that suggestion is passed as a
46     *      parameter. Typically this value comes from QName.getPrefix()
47     *      to show the preference of the content tree. This parameter
48     *      may be null, and this parameter may represent an already
49     *      occupied prefix.
50     * @param requirePrefix
51     *      If this method is expected to return non-empty prefix.
52     *      When this flag is true, it means that the given namespace URI
53     *      cannot be set as the default namespace.
54     *
55     * @return
56     *      null if there's no preferred prefix for the namespace URI.
57     *      In this case, the system will generate a prefix for you.
58     *
59     *      Otherwise the system will try to use the returned prefix,
60     *      but generally there's no guarantee if the prefix will be
61     *      actually used or not.
62     *
63     *      return "" to map this namespace URI to the default namespace.
64     *      Again, there's no guarantee that this preference will be
65     *      honored.
66     *
67     *      If this method returns "" when requirePrefix=true, the return
68     *      value will be ignored and the system will generate one.
69     */
70    public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {   
71       
72        return NamespacePrefixMappings.getPreferredPrefixStatic(namespaceUri, suggestion, requirePrefix);
73
74    }
75   
76       
77   
78    /**
79     * Returns a list of namespace URIs that should be declared
80     * at the root element.
81     * <p>
82     * By default, the JAXB RI produces namespace declarations only when
83     * they are necessary, only at where they are used. Because of this
84     * lack of look-ahead, sometimes the marshaller produces a lot of
85     * namespace declarations that look redundant to human eyes. For example,
86     * <pre><xmp>
87     * <?xml version="1.0"?>
88     * <root>
89     *   <ns1:child xmlns:ns1="urn:foo"> ... </ns1:child>
90     *   <ns2:child xmlns:ns2="urn:foo"> ... </ns2:child>
91     *   <ns3:child xmlns:ns3="urn:foo"> ... </ns3:child>
92     *   ...
93     * </root>
94     * <xmp></pre>
95     * <p>
96     * If you know in advance that you are going to use a certain set of
97     * namespace URIs, you can override this method and have the marshaller
98     * declare those namespace URIs at the root element.
99     * <p>
100     * For example, by returning <code>new String[]{"urn:foo"}</code>,
101     * the marshaller will produce:
102     * <pre><xmp>
103     * <?xml version="1.0"?>
104     * <root xmlns:ns1="urn:foo">
105     *   <ns1:child> ... </ns1:child>
106     *   <ns1:child> ... </ns1:child>
107     *   <ns1:child> ... </ns1:child>
108     *   ...
109     * </root>
110     * <xmp></pre>
111     * <p>
112     * To control prefixes assigned to those namespace URIs, use the
113     * {@link #getPreferredPrefix} method.
114     *
115     * @return
116     *      A list of namespace URIs as an array of {@link String}s.
117     *      This method can return a length-zero array but not null.
118     *      None of the array component can be null. To represent
119     *      the empty namespace, use the empty string <code>""</code>.
120     *
121     * @since
122     *      JAXB RI 1.0.2
123     */
124//    public String[] getPreDeclaredNamespaceUris() {
125//        return new String[] { "urn:abc", "urn:def" };
126//    }
127
128   
129}
Note: See TracBrowser for help on using the repository browser.