source: trunk/docx4j/src/main/java/org/docx4j/jaxb/NamespacePrefixMapperRelationshipsPart.java @ 871

Revision 871, 5.6 KB checked in by jharrop, 3 years ago (diff)

Get rid of System.out.println (mostly).

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
23public class NamespacePrefixMapperRelationshipsPart extends com.sun.xml.bind.marshaller.NamespacePrefixMapper {
24       
25    /**
26     * Returns a preferred prefix for the given namespace URI;
27     * this one is used *only* when we marshal the relationships part.
28     *
29     * This method is intended to be overrided by a derived class.
30     *
31     * @param namespaceUri
32     *      The namespace URI for which the prefix needs to be found.
33     *      Never be null. "" is used to denote the default namespace.
34     * @param suggestion
35     *      When the content tree has a suggestion for the prefix
36     *      to the given namespaceUri, that suggestion is passed as a
37     *      parameter. Typically this value comes from QName.getPrefix()
38     *      to show the preference of the content tree. This parameter
39     *      may be null, and this parameter may represent an already
40     *      occupied prefix.
41     * @param requirePrefix
42     *      If this method is expected to return non-empty prefix.
43     *      When this flag is true, it means that the given namespace URI
44     *      cannot be set as the default namespace.
45     *
46     * @return
47     *      null if there's no preferred prefix for the namespace URI.
48     *      In this case, the system will generate a prefix for you.
49     *
50     *      Otherwise the system will try to use the returned prefix,
51     *      but generally there's no guarantee if the prefix will be
52     *      actually used or not.
53     *
54     *      return "" to map this namespace URI to the default namespace.
55     *      Again, there's no guarantee that this preference will be
56     *      honored.
57     *
58     *      If this method returns "" when requirePrefix=true, the return
59     *      value will be ignored and the system will generate one.
60     */
61    public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) 
62    // Implement the interface   
63    {
64
65        return getPreferredPrefixStatic( namespaceUri,  suggestion,  requirePrefix);
66    }
67   
68    protected static String getPreferredPrefixStatic(String namespaceUri, String suggestion, boolean requirePrefix) {
69   
70//      if (namespaceUri.equals("http://schemas.openxmlformats.org/wordprocessingml/2006/main")) {
71//              return "w";
72//      }
73//      if (namespaceUri.equals("http://schemas.microsoft.com/office/2006/xmlPackage")) {
74//              return "pkg";
75//      }
76//     
77//      if (namespaceUri.equals("http://schemas.openxmlformats.org/officeDocument/2006/custom-properties")) {
78//              return "prop";
79//      }
80//     
81//      if (namespaceUri.equals("http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes")) {
82//              return "vt";
83//      }
84               
85        if (namespaceUri.equals("http://schemas.openxmlformats.org/package/2006/relationships")) {
86                return ""; // Make it the default namespace
87        }
88       
89//      if (namespaceUri.equals("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing")) {
90//              return "wp";
91//      }
92//     
93//      if (namespaceUri.equals("http://schemas.openxmlformats.org/drawingml/2006/main")) {
94//              return "a";
95//      }
96//     
97//      if (namespaceUri.equals("http://schemas.openxmlformats.org/drawingml/2006/picture")) {
98//              return "pic";
99//      }
100       
101        return suggestion;
102    }
103   
104    /**
105     * Returns a list of namespace URIs that should be declared
106     * at the root element.
107     * <p>
108     * By default, the JAXB RI produces namespace declarations only when
109     * they are necessary, only at where they are used. Because of this
110     * lack of look-ahead, sometimes the marshaller produces a lot of
111     * namespace declarations that look redundant to human eyes. For example,
112     * <pre><xmp>
113     * <?xml version="1.0"?>
114     * <root>
115     *   <ns1:child xmlns:ns1="urn:foo"> ... </ns1:child>
116     *   <ns2:child xmlns:ns2="urn:foo"> ... </ns2:child>
117     *   <ns3:child xmlns:ns3="urn:foo"> ... </ns3:child>
118     *   ...
119     * </root>
120     * <xmp></pre>
121     * <p>
122     * If you know in advance that you are going to use a certain set of
123     * namespace URIs, you can override this method and have the marshaller
124     * declare those namespace URIs at the root element.
125     * <p>
126     * For example, by returning <code>new String[]{"urn:foo"}</code>,
127     * the marshaller will produce:
128     * <pre><xmp>
129     * <?xml version="1.0"?>
130     * <root xmlns:ns1="urn:foo">
131     *   <ns1:child> ... </ns1:child>
132     *   <ns1:child> ... </ns1:child>
133     *   <ns1:child> ... </ns1:child>
134     *   ...
135     * </root>
136     * <xmp></pre>
137     * <p>
138     * To control prefixes assigned to those namespace URIs, use the
139     * {@link #getPreferredPrefix} method.
140     *
141     * @return
142     *      A list of namespace URIs as an array of {@link String}s.
143     *      This method can return a length-zero array but not null.
144     *      None of the array component can be null. To represent
145     *      the empty namespace, use the empty string <code>""</code>.
146     *
147     * @since
148     *      JAXB RI 1.0.2
149     */
150//    public String[] getPreDeclaredNamespaceUris() {
151//        return new String[] { "urn:abc", "urn:def" };
152//    }
153
154   
155}
Note: See TracBrowser for help on using the repository browser.