%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.jetspeed.container.namespace.JetspeedNamespaceMapperImpl |
|
|
1 | /* |
|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 | * contributor license agreements. See the NOTICE file distributed with |
|
4 | * this work for additional information regarding copyright ownership. |
|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 | * (the "License"); you may not use this file except in compliance with |
|
7 | * the License. You may obtain a copy of the License at |
|
8 | * |
|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 | * |
|
11 | * Unless required by applicable law or agreed to in writing, software |
|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 | * See the License for the specific language governing permissions and |
|
15 | * limitations under the License. |
|
16 | */ |
|
17 | package org.apache.jetspeed.container.namespace; |
|
18 | ||
19 | import org.apache.pluto.om.common.ObjectID; |
|
20 | ||
21 | ||
22 | /** |
|
23 | * Jetspeed implementation of Name space mapping for creating named attributes. |
|
24 | * |
|
25 | * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a> |
|
26 | * @author <a href="mailto:ate@douma.nu">Ate Douma</a> |
|
27 | * @version $Id: JetspeedNamespaceMapperImpl.java 551860 2007-06-29 11:56:23Z ate $ |
|
28 | */ |
|
29 | public class JetspeedNamespaceMapperImpl implements JetspeedNamespaceMapper |
|
30 | { |
|
31 | private String prefix; |
|
32 | ||
33 | public JetspeedNamespaceMapperImpl(String prefix) |
|
34 | 0 | { |
35 | 0 | this.prefix = prefix; |
36 | 0 | if ( this.prefix == null ) |
37 | { |
|
38 | 0 | this.prefix = DEFAULT_PREFIX; |
39 | } |
|
40 | 0 | } |
41 | ||
42 | public JetspeedNamespaceMapperImpl() |
|
43 | { |
|
44 | 0 | this(null); |
45 | 0 | } |
46 | ||
47 | public String getPrefix() |
|
48 | { |
|
49 | 0 | return prefix; |
50 | } |
|
51 | ||
52 | public String encode(String ns, String name) |
|
53 | { |
|
54 | 0 | return join(prefix,ns,"_",name,null,class="keyword">null); |
55 | } |
|
56 | ||
57 | public String encode(String ns1, String ns2, String name) |
|
58 | { |
|
59 | 0 | return join(prefix,ns1,"_",ns2,"_",name); |
60 | } |
|
61 | ||
62 | public String decode(String ns, String name) |
|
63 | { |
|
64 | 0 | if (!name.startsWith(prefix)) return null; |
65 | 0 | String tmp = join(prefix,ns,"_",null,class="keyword">null,class="keyword">null); |
66 | 0 | if (!name.startsWith(tmp)) return null; |
67 | 0 | return name.substring(tmp.length()); |
68 | } |
|
69 | ||
70 | public String encode(long id, String name) |
|
71 | { |
|
72 | 0 | return encode(new Long(id).toString(),name); |
73 | } |
|
74 | ||
75 | /* (non-Javadoc) |
|
76 | * @see org.apache.pluto.util.NamespaceMapper#encode(org.apache.pluto.om.common.ObjectID, java.lang.String) |
|
77 | */ |
|
78 | public String encode(ObjectID ns, String name) |
|
79 | { |
|
80 | 0 | return encode(ns.toString(),name); |
81 | } |
|
82 | ||
83 | /* (non-Javadoc) |
|
84 | * @see org.apache.pluto.util.NamespaceMapper#encode(org.apache.pluto.om.common.ObjectID, org.apache.pluto.om.common.ObjectID, java.lang.String) |
|
85 | */ |
|
86 | public String encode(ObjectID ns1, ObjectID ns2, String name) |
|
87 | { |
|
88 | 0 | return encode(ns1.toString(),ns2.toString(),name); |
89 | } |
|
90 | ||
91 | /* (non-Javadoc) |
|
92 | * @see org.apache.pluto.util.NamespaceMapper#decode(org.apache.pluto.om.common.ObjectID, java.lang.String) |
|
93 | */ |
|
94 | public String decode(ObjectID ns, String name) |
|
95 | { |
|
96 | 0 | return decode(ns.toString(),name); |
97 | } |
|
98 | ||
99 | private static String join(String s1, String s2, String s3, String s4, String s5, String s6) |
|
100 | { |
|
101 | 0 | int len = 0; |
102 | 0 | if (s1 != null) |
103 | { |
|
104 | 0 | len+=s1.length(); |
105 | 0 | if (s2 != null) |
106 | { |
|
107 | 0 | len+=s2.length(); |
108 | 0 | if (s3 != null) |
109 | { |
|
110 | 0 | len+=s3.length(); |
111 | 0 | if (s4 != null) |
112 | { |
|
113 | 0 | len+=s4.length(); |
114 | 0 | if (s5 != null) |
115 | { |
|
116 | 0 | len+=s5.length(); |
117 | 0 | if (s6 != null) |
118 | { |
|
119 | 0 | len+=s6.length(); |
120 | } |
|
121 | } |
|
122 | } |
|
123 | } |
|
124 | } |
|
125 | } |
|
126 | 0 | char[] buffer = new class="keyword">char[len]; |
127 | 0 | int index = 0; |
128 | 0 | if (s1 != null) |
129 | { |
|
130 | 0 | len = s1.length(); |
131 | 0 | s1.getChars(0,len,buffer,index); |
132 | 0 | index+= len; |
133 | 0 | if (s2 != null) |
134 | { |
|
135 | 0 | len = s2.length(); |
136 | 0 | s2.getChars(0,len,buffer,index); |
137 | 0 | index+= len; |
138 | 0 | if (s3 != null) |
139 | { |
|
140 | 0 | len = s3.length(); |
141 | 0 | s3.getChars(0,len,buffer,index); |
142 | 0 | index+= len; |
143 | 0 | if (s4 != null) |
144 | { |
|
145 | 0 | len = s4.length(); |
146 | 0 | s4.getChars(0,len,buffer,index); |
147 | 0 | index+= len; |
148 | 0 | if (s5 != null) |
149 | { |
|
150 | 0 | len = s5.length(); |
151 | 0 | s5.getChars(0,len,buffer,index); |
152 | 0 | index+= len; |
153 | 0 | if (s6 != null) |
154 | { |
|
155 | 0 | len = s6.length(); |
156 | 0 | s6.getChars(0,len,buffer,index); |
157 | } |
|
158 | } |
|
159 | } |
|
160 | } |
|
161 | } |
|
162 | } |
|
163 | 0 | return new String(buffer); |
164 | } |
|
165 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |