Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
NamespaceBuilder |
|
| 0.0;0 |
1 | /** |
|
2 | * |
|
3 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
4 | * contributor license agreements. See the NOTICE file distributed with |
|
5 | * this work for additional information regarding copyright ownership. |
|
6 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
7 | * (the "License"); you may not use this file except in compliance with |
|
8 | * 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, software |
|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | * See the License for the specific language governing permissions and |
|
16 | * limitations under the License. |
|
17 | */ |
|
18 | package org.apache.camel.builder.xml; |
|
19 | ||
20 | import java.util.Map; |
|
21 | import java.util.HashMap; |
|
22 | import java.util.Set; |
|
23 | ||
24 | /** |
|
25 | * A helper class for creating namespaces which can then be used to create XPath expressions |
|
26 | * |
|
27 | * @version $Revision: 1.1 $ |
|
28 | */ |
|
29 | 2 | public class NamespaceBuilder { |
30 | 2 | private Map<String,String> namespaces = new HashMap<String, String>(); |
31 | ||
32 | public static NamespaceBuilder namespaceContext() { |
|
33 | 0 | return new NamespaceBuilder(); |
34 | } |
|
35 | ||
36 | public static NamespaceBuilder namespaceContext(String prefix, String uri) { |
|
37 | 2 | return new NamespaceBuilder().namespace(prefix, uri); |
38 | } |
|
39 | ||
40 | public NamespaceBuilder namespace(String prefix, String uri) { |
|
41 | 4 | namespaces.put(prefix, uri); |
42 | 4 | return this; |
43 | } |
|
44 | ||
45 | /** |
|
46 | * Creates a new XPath expression using the current namespaces |
|
47 | * |
|
48 | * @param xpath the XPath expression |
|
49 | * @return a new XPath expression |
|
50 | */ |
|
51 | public XPathBuilder xpath(String xpath) { |
|
52 | 2 | XPathBuilder answer = XPathBuilder.xpath(xpath); |
53 | 2 | Set<Map.Entry<String,String>> entries = namespaces.entrySet(); |
54 | 2 | for (Map.Entry<String, String> entry : entries) { |
55 | 4 | answer.namespace(entry.getKey(), entry.getValue()); |
56 | 4 | } |
57 | 2 | return answer; |
58 | } |
|
59 | } |