Source Code Cross Referenced for NamespaceMap.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » lenya » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » apache lenya 2.0 » org.apache.lenya.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:
019:        /* $Id: NamespaceMap.java 473861 2006-11-12 03:51:14Z gregor $  */
020:
021:        package org.apache.lenya.util;
022:
023:        import java.util.HashMap;
024:        import java.util.Iterator;
025:        import java.util.Map;
026:        import java.util.Set;
027:
028:        /**
029:         * An object of this class provides an easy way to access
030:         * Strings in a Map that are prefixed like "prefix.foo".
031:         * The actual map wrapped by this object can contain more
032:         * key-value-pairs, but you can access only the prefixed keys
033:         * through the mapper.
034:         */
035:        public class NamespaceMap {
036:            /**
037:             * <code>SEPARATOR</code> The seperator character
038:             */
039:            public static final String SEPARATOR = ".";
040:            private Map map;
041:            private String prefix;
042:
043:            /**
044:             * Creates a new NamespaceMap object.
045:             * @param _prefix The prefix.
046:             */
047:            public NamespaceMap(String _prefix) {
048:                this (new HashMap(), _prefix);
049:            }
050:
051:            /**
052:             * Creates a new NamespaceMap.
053:             * @param _map A map containing the prefixed key-value-pairs.
054:             * @param _prefix The prefix.
055:             */
056:            public NamespaceMap(Map _map, String _prefix) {
057:                this .map = _map;
058:                this .prefix = _prefix;
059:            }
060:
061:            /**
062:             * Returns the prefix.
063:             * @return A string.
064:             */
065:            public String getPrefix() {
066:                return this .prefix;
067:            }
068:
069:            /**
070:             * Returns the namespace prefix.
071:             * @return The namespace prefix.
072:             */
073:            protected Map getMapObject() {
074:                return this .map;
075:            }
076:
077:            /**
078:             * Returns a map that contains only the un-prefixed key-value-pairs.
079:             * @return The map.
080:             */
081:            public Map getMap() {
082:                Map resultMap = new HashMap();
083:
084:                Set keys = getMapObject().keySet();
085:
086:                for (Iterator i = keys.iterator(); i.hasNext();) {
087:                    Object key = i.next();
088:
089:                    if (key instanceof  String) {
090:                        String keyString = (String) key;
091:
092:                        if (keyString.startsWith(getPrefix() + SEPARATOR)) {
093:                            resultMap.put(getShortName(getPrefix(), keyString),
094:                                    getMapObject().get(key));
095:                        }
096:                    }
097:                }
098:
099:                return resultMap;
100:            }
101:
102:            /**
103:             * Puts a value for prefixed key into the map.
104:             * @param key The key without prefix.
105:             * @param value The value.
106:             */
107:            public void put(String key, Object value) {
108:                getMapObject().put(getFullName(getPrefix(), key), value);
109:            }
110:
111:            /**
112:             * Returns the value for a prefixed key.
113:             * @param key The key without prefix.
114:             * @return The value.
115:             */
116:            public Object get(String key) {
117:                return getMap().get(key);
118:            }
119:
120:            /**
121:             * Returns the full (prefixed) key for a short (un-prefixed) key.
122:             * @param prefix The prefix.
123:             * @param key The un-prefixed key.
124:             * @return A string (prefix + {@link #SEPARATOR} + key).
125:             */
126:            public static String getFullName(String prefix, String key) {
127:                return prefix + SEPARATOR + key;
128:            }
129:
130:            /**
131:             * Returns the short (un-prefixed) key for a full (prefixed) key.
132:             * @param prefix The prefix.
133:             * @param key The full (prefixed) key.
134:             * @return A string.
135:             */
136:            public static String getShortName(String prefix, String key) {
137:                return key.substring(prefix.length() + SEPARATOR.length());
138:            }
139:
140:            /**
141:             * Puts all prefixed key-value-pairs of map into this map.
142:             * @param _map A map.
143:             */
144:            public void putAll(Map _map) {
145:                for (Iterator i = _map.keySet().iterator(); i.hasNext();) {
146:                    String key = (String) i.next();
147:                    put(key, _map.get(key));
148:                }
149:            }
150:
151:            /**
152:             * Returns a map with prefixed keys.
153:             * @return A map.
154:             */
155:            public Map getPrefixedMap() {
156:                return new HashMap(getMapObject());
157:            }
158:
159:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.