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