Source Code Cross Referenced for VariableAttributes.java in  » XML » digester » org » apache » commons » digester » substitution » 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 » XML » digester » org.apache.commons.digester.substitution 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* $Id: VariableAttributes.java 471661 2006-11-06 08:09:25Z skitching $
002:         *
003:         * Licensed to the Apache Software Foundation (ASF) under one or more
004:         * contributor license agreements.  See the NOTICE file distributed with
005:         * this work for additional information regarding copyright ownership.
006:         * The ASF licenses this file to You under the Apache License, Version 2.0
007:         * (the "License"); you may not use this file except in compliance with
008:         * the License.  You may obtain a copy of the License at
009:         * 
010:         *      http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         */
018:
019:        package org.apache.commons.digester.substitution;
020:
021:        import org.xml.sax.Attributes;
022:
023:        import java.util.ArrayList;
024:
025:        /**
026:         * <p>Wrapper for an org.xml.sax.Attributes object which expands any 
027:         * "variables" referenced in the attribute value via ${foo} or similar. 
028:         * This is only done when something actually asks for the attribute value, 
029:         * thereby imposing no performance penalty if the attribute is not used.</p>
030:         *
031:         * @since 1.6
032:         */
033:
034:        public class VariableAttributes implements  Attributes {
035:
036:            // list of mapped attributes.
037:            private ArrayList values = new ArrayList(10);
038:
039:            private Attributes attrs;
040:            private VariableExpander expander;
041:
042:            // ------------------- Public Methods
043:
044:            /**
045:             * Specify which attributes class this object is a proxy for.
046:             */
047:            public void init(Attributes attrs, VariableExpander expander) {
048:                this .attrs = attrs;
049:                this .expander = expander;
050:
051:                // I hope this doesn't release the memory for this array; for 
052:                // efficiency, this should just mark the array as being size 0.
053:                values.clear();
054:            }
055:
056:            public String getValue(int index) {
057:                if (index >= values.size()) {
058:                    // Expand the values array with null elements, so the later
059:                    // call to set(index, s) works ok.
060:                    //
061:                    // Unfortunately, there is no easy way to set the size of
062:                    // an arraylist; we must repeatedly add null elements to it..
063:                    values.ensureCapacity(index + 1);
064:                    for (int i = values.size(); i <= index; ++i) {
065:                        values.add(null);
066:                    }
067:                }
068:
069:                String s = (String) values.get(index);
070:
071:                if (s == null) {
072:                    // we have never been asked for this value before.
073:                    // get the real attribute value and perform substitution
074:                    // on it.
075:                    s = attrs.getValue(index);
076:                    if (s != null) {
077:                        s = expander.expand(s);
078:                        values.set(index, s);
079:                    }
080:                }
081:
082:                return s;
083:            }
084:
085:            public String getValue(String qname) {
086:                int index = attrs.getIndex(qname);
087:                if (index == -1) {
088:                    return null;
089:                }
090:                return getValue(index);
091:            }
092:
093:            public String getValue(String uri, String localname) {
094:                int index = attrs.getIndex(uri, localname);
095:                if (index == -1) {
096:                    return null;
097:                }
098:                return getValue(index);
099:            }
100:
101:            // plain proxy methods follow : nothing interesting :-)
102:            public int getIndex(String qname) {
103:                return attrs.getIndex(qname);
104:            }
105:
106:            public int getIndex(String uri, String localpart) {
107:                return attrs.getIndex(uri, localpart);
108:            }
109:
110:            public int getLength() {
111:                return attrs.getLength();
112:            }
113:
114:            public String getLocalName(int index) {
115:                return attrs.getLocalName(index);
116:            }
117:
118:            public String getQName(int index) {
119:                return attrs.getQName(index);
120:            }
121:
122:            public String getType(int index) {
123:                return attrs.getType(index);
124:            }
125:
126:            public String getType(String qname) {
127:                return attrs.getType(qname);
128:            }
129:
130:            public String getType(String uri, String localname) {
131:                return attrs.getType(uri, localname);
132:            }
133:
134:            public String getURI(int index) {
135:                return attrs.getURI(index);
136:            }
137:
138:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.