| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| NamespaceSet |
|
| 0.0;0 |
| 1 | /* | |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one | |
| 3 | * or more contributor license agreements. See the NOTICE file | |
| 4 | * distributed with this work for additional information | |
| 5 | * regarding copyright ownership. The ASF licenses this file | |
| 6 | * to you under the Apache License, Version 2.0 (the | |
| 7 | * "License"); you may not use this file except in compliance | |
| 8 | * with the License. You may obtain a copy of the License at | |
| 9 | * | |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 11 | * | |
| 12 | * Unless required by applicable law or agreed to in writing, | |
| 13 | * software distributed under the License is distributed on an | |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 15 | * KIND, either express or implied. See the License for the | |
| 16 | * specific language governing permissions and limitations under the License. | |
| 17 | */ | |
| 18 | package org.apache.shindig.social.core.util.xstream; | |
| 19 | ||
| 20 | import com.google.common.collect.Maps; | |
| 21 | ||
| 22 | import java.util.HashMap; | |
| 23 | import java.util.Map; | |
| 24 | import java.util.Set; | |
| 25 | import java.util.Map.Entry; | |
| 26 | ||
| 27 | /** | |
| 28 | * A container class that defines namespaces and subsequent element named for an | |
| 29 | * element in the output stack. A set of active namespaces are defined by | |
| 30 | * addNamespace and a name to prefixed name translation is specified by | |
| 31 | * addPrefixedElement. | |
| 32 | */ | |
| 33 | 2 | public class NamespaceSet { |
| 34 | ||
| 35 | /** | |
| 36 | * A map namespace attributes to the namespace uri. | |
| 37 | */ | |
| 38 | 2 | private Map<String, String> namespaces = Maps.newHashMap(); |
| 39 | /** | |
| 40 | * A map of localElement names to prefixed element names. | |
| 41 | */ | |
| 42 | 2 | private Map<String, String> elementNames = Maps.newHashMap(); |
| 43 | ||
| 44 | /** | |
| 45 | * Add a namespace to the list. | |
| 46 | * | |
| 47 | * @param nsAttribute | |
| 48 | * the attribute to be used to specify the namespace | |
| 49 | * @param namespace | |
| 50 | * the namespace URI | |
| 51 | */ | |
| 52 | public void addNamespace(String nsAttribute, String namespace) { | |
| 53 | 3 | namespaces.put(nsAttribute, namespace); |
| 54 | 3 | } |
| 55 | ||
| 56 | /** | |
| 57 | * Add a localname translation. | |
| 58 | * | |
| 59 | * @param elementName | |
| 60 | * the local name of the element | |
| 61 | * @param namespacedElementName | |
| 62 | * the final name of the element with prefix. | |
| 63 | */ | |
| 64 | public void addPrefixedElement(String elementName, | |
| 65 | String namespacedElementName) { | |
| 66 | 3 | elementNames.put(elementName, namespacedElementName); |
| 67 | 3 | } |
| 68 | ||
| 69 | /** | |
| 70 | * Convert an element name, if necessary. | |
| 71 | * | |
| 72 | * @param name | |
| 73 | * the name to be converted. | |
| 74 | * @return the converted name, left as is if no conversion was required. | |
| 75 | */ | |
| 76 | public String getElementName(String name) { | |
| 77 | 469 | String namespacedName = elementNames.get(name); |
| 78 | 469 | if (namespacedName != null) { |
| 79 | 24 | return namespacedName; |
| 80 | } | |
| 81 | 445 | return name; |
| 82 | } | |
| 83 | ||
| 84 | /** | |
| 85 | * @return an Set of entries containing the namespace attributes and uris, | |
| 86 | * attributes in the key, uri's in the value or each entry. | |
| 87 | */ | |
| 88 | public Set<Entry<String, String>> nameSpaceEntrySet() { | |
| 89 | 41 | return namespaces.entrySet(); |
| 90 | } | |
| 91 | ||
| 92 | } |