Source Code Cross Referenced for StringResource.java in  » Build » ANT » org » apache » tools » ant » types » resources » 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 » Build » ANT » org.apache.tools.ant.types.resources 
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:        package org.apache.tools.ant.types.resources;
020:
021:        import java.io.IOException;
022:        import java.io.InputStream;
023:        import java.io.OutputStream;
024:        import java.io.FilterOutputStream;
025:        import java.io.ByteArrayInputStream;
026:        import java.io.ByteArrayOutputStream;
027:
028:        import org.apache.tools.ant.BuildException;
029:        import org.apache.tools.ant.types.Resource;
030:        import org.apache.tools.ant.types.Reference;
031:
032:        /**
033:         * Exposes a string as a Resource.
034:         * @since Ant 1.7
035:         */
036:        public class StringResource extends Resource {
037:
038:            /** Magic number */
039:            private static final int STRING_MAGIC = Resource
040:                    .getMagicNumber("StringResource".getBytes());
041:
042:            private String encoding = null;
043:
044:            /**
045:             * Default constructor.
046:             */
047:            public StringResource() {
048:            }
049:
050:            /**
051:             * Construct a StringResource with the supplied value.
052:             * @param value the value of this StringResource.
053:             */
054:            public StringResource(String value) {
055:                setValue(value);
056:            }
057:
058:            /**
059:             * Enforce String immutability.
060:             * @param s the new name/value for this StringResource.
061:             */
062:            public synchronized void setName(String s) {
063:                if (getName() != null) {
064:                    throw new BuildException(new ImmutableResourceException());
065:                }
066:                super .setName(s);
067:            }
068:
069:            /**
070:             * The value attribute is a semantically superior alias for the name attribute.
071:             * @param s the String's value.
072:             */
073:            public synchronized void setValue(String s) {
074:                setName(s);
075:            }
076:
077:            /**
078:             * Synchronize access.
079:             * @return the name/value of this StringResource.
080:             */
081:            public synchronized String getName() {
082:                return super .getName();
083:            }
084:
085:            /**
086:             * Get the value of this StringResource.
087:             * @return the represented String.
088:             */
089:            public synchronized String getValue() {
090:                return getName();
091:            }
092:
093:            /**
094:             * Set the encoding to be used for this StringResource.
095:             * @param s the encoding name.
096:             */
097:            public synchronized void setEncoding(String s) {
098:                encoding = s;
099:            }
100:
101:            /**
102:             * Get the encoding used by this StringResource.
103:             * @return the encoding name.
104:             */
105:            public synchronized String getEncoding() {
106:                return encoding;
107:            }
108:
109:            /**
110:             * Get the size of this Resource.
111:             * @return the size, as a long, 0 if the Resource does not exist (for
112:             *         compatibility with java.io.File), or UNKNOWN_SIZE if not known.
113:             */
114:            public synchronized long getSize() {
115:                return isReference() ? ((Resource) getCheckedRef()).getSize()
116:                        : (long) getContent().length();
117:            }
118:
119:            /**
120:             * Get the hash code for this Resource.
121:             * @return hash code as int.
122:             */
123:            public synchronized int hashCode() {
124:                if (isReference()) {
125:                    return getCheckedRef().hashCode();
126:                }
127:                return super .hashCode() * STRING_MAGIC;
128:            }
129:
130:            /**
131:             * Get the string.
132:             *
133:             * @return the string contents of the resource.
134:             * @since Ant 1.7
135:             */
136:            public String toString() {
137:                if (isReference()) {
138:                    return getCheckedRef().toString();
139:                }
140:                return String.valueOf(getContent());
141:            }
142:
143:            /**
144:             * Get an InputStream for the Resource.
145:             * @return an InputStream containing this Resource's content.
146:             * @throws IOException if unable to provide the content of this
147:             *         Resource as a stream.
148:             * @throws UnsupportedOperationException if InputStreams are not
149:             *         supported for this Resource type.
150:             */
151:            public synchronized InputStream getInputStream() throws IOException {
152:                if (isReference()) {
153:                    return ((Resource) getCheckedRef()).getInputStream();
154:                }
155:                //I can't get my head around this; is encoding treatment needed here?
156:                return
157:                //new oata.util.ReaderInputStream(new InputStreamReader(
158:                new ByteArrayInputStream(getContent().getBytes());
159:                //, encoding), encoding);
160:            }
161:
162:            /**
163:             * Get an OutputStream for the Resource.
164:             * @return an OutputStream to which content can be written.
165:             * @throws IOException if unable to provide the content of this
166:             *         Resource as a stream.
167:             * @throws UnsupportedOperationException if OutputStreams are not
168:             *         supported for this Resource type.
169:             */
170:            public synchronized OutputStream getOutputStream()
171:                    throws IOException {
172:                if (isReference()) {
173:                    return ((Resource) getCheckedRef()).getOutputStream();
174:                }
175:                if (getValue() != null) {
176:                    throw new ImmutableResourceException();
177:                }
178:                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
179:                return new FilterOutputStream(baos) {
180:                    public void close() throws IOException {
181:                        super .close();
182:                        StringResource.this .setValue(encoding == null ? baos
183:                                .toString() : baos.toString(encoding));
184:                    }
185:                };
186:            }
187:
188:            /**
189:             * Overrides the super version.
190:             * @param r the Reference to set.
191:             */
192:            public void setRefid(Reference r) {
193:                if (encoding != null) {
194:                    throw tooManyAttributes();
195:                }
196:                super .setRefid(r);
197:            }
198:
199:            /**
200:             * Get the content of this StringResource.
201:             * @return a String; if the Project has been set properties
202:             *         replacement will be attempted.
203:             */
204:            protected synchronized String getContent() {
205:                if (isReference()) {
206:                    return ((StringResource) getCheckedRef()).getContent();
207:                }
208:                String value = getValue();
209:                if (value == null) {
210:                    return value;
211:                }
212:                return getProject() == null ? value : getProject()
213:                        .replaceProperties(value);
214:            }
215:
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.