Source Code Cross Referenced for BinaryFile.java in  » UML » AndroMDA-3.2 » org » andromda » cartridges » jsf » component » 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 » UML » AndroMDA 3.2 » org.andromda.cartridges.jsf.component 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.andromda.cartridges.jsf.component;
002:
003:        import java.io.InputStream;
004:
005:        import java.util.Properties;
006:
007:        import javax.faces.component.UIComponentBase;
008:        import javax.faces.el.ValueBinding;
009:
010:        import org.apache.commons.logging.Log;
011:        import org.apache.commons.logging.LogFactory;
012:
013:        public class BinaryFile extends UIComponentBase {
014:            private static final Log logger = LogFactory
015:                    .getLog(BinaryFile.class);
016:            public static final String COMPONENT_TYPE = BinaryFile.class
017:                    .getName();
018:            public static final String RENDERER_TYPE = "org.andromda.cartridges.jsf.BinaryFile";
019:
020:            public BinaryFile() {
021:                super ();
022:                this .setRendererType(RENDERER_TYPE);
023:            }
024:
025:            /**
026:             * @see javax.faces.component.UIComponent#getFamily()
027:             */
028:            public String getFamily() {
029:                return RENDERER_TYPE;
030:            }
031:
032:            /**
033:             * Stores the name of the attriubte that holds the value.
034:             */
035:            public static final String VALUE_ATTRIBUTE = "value";
036:
037:            /**
038:             * Stores the value of this binary file.
039:             */
040:            private Object value;
041:
042:            /**
043:             * Gets the current value of this binary file.
044:             *
045:             * @return the value of this binary file.
046:             */
047:            public Object getValue() {
048:                if (this .value == null) {
049:                    final ValueBinding binding = this 
050:                            .getValueBinding(VALUE_ATTRIBUTE);
051:                    if (binding != null) {
052:                        this .value = binding.getValue(this .getFacesContext());
053:                    }
054:                }
055:                return this .value;
056:            }
057:
058:            /**
059:             * Stores the name of the attriubte that holds the fileName.
060:             */
061:            public static final String FILE_NAME_ATTRIBUTE = "fileName";
062:
063:            /**
064:             * The name of the file to render.
065:             */
066:            private String fileName;
067:
068:            /**
069:             * Sets the file name for this component.
070:             *
071:             * @param fileName the name of the binary file to be rendered.
072:             */
073:            public void setFileName(final String fileName) {
074:                this .fileName = fileName;
075:            }
076:
077:            /**
078:             * Gets the file name for rending the binary file.
079:             * @return the name of the file to render.
080:             */
081:            public String getFileName() {
082:                if (this .fileName == null) {
083:                    final ValueBinding binding = this 
084:                            .getValueBinding(FILE_NAME_ATTRIBUTE);
085:                    if (binding != null) {
086:                        this .fileName = (String) binding.getValue(this 
087:                                .getFacesContext());
088:                    }
089:                }
090:                return this .fileName;
091:            }
092:
093:            /**
094:             * The name of the attribute that stores the content type.
095:             */
096:            public static final String CONTENT_TYPE_ATTRIBUTE = "contentType";
097:
098:            /**
099:             * The content type to use when rendering the file.
100:             */
101:            private String contentType;
102:
103:            /**
104:             * Gets the explicity content type to render the file in.
105:             *
106:             * @return Returns the contentType.
107:             */
108:            public String getContentType() {
109:                if (this .contentType == null) {
110:                    final ValueBinding binding = this 
111:                            .getValueBinding(CONTENT_TYPE_ATTRIBUTE);
112:                    if (binding != null) {
113:                        this .contentType = (String) binding.getValue(this 
114:                                .getFacesContext());
115:                    }
116:
117:                    // - if the content type is still null, lets guess
118:                    if (this .contentType == null) {
119:                        final String fileName = this .getFileName();
120:                        if (fileName != null && fileName.trim().length() > 0) {
121:                            int lastDotIndex = fileName.lastIndexOf('.');
122:                            if (lastDotIndex != -1) {
123:                                final String extension = fileName.substring(
124:                                        lastDotIndex, fileName.length());
125:                                this .contentType = contentTypes
126:                                        .getProperty(extension);
127:                            }
128:                        }
129:                    }
130:                }
131:                return this .contentType;
132:            }
133:
134:            /**
135:             * Sets the explicit content type in which to render the file.
136:             *
137:             * @param contentType The contentType to set.
138:             */
139:            public void setContentType(final String contentType) {
140:                this .contentType = contentType;
141:            }
142:
143:            /**
144:             * Whether or not we should be prompted to save the file when its rendered.
145:             */
146:            public static final String PROMPT_ATTRIBUTE = "prompt";
147:
148:            /**
149:             * Stores the 'prompt' value.
150:             */
151:            private Boolean prompt;
152:
153:            /**
154:             * Gets whether or not the prompt should be rendered.
155:             *
156:             * @return Returns the prompt.
157:             */
158:            public boolean isPrompt() {
159:                if (this .prompt == null) {
160:                    final ValueBinding binding = this 
161:                            .getValueBinding(CONTENT_TYPE_ATTRIBUTE);
162:                    if (binding != null) {
163:                        this .prompt = (Boolean) binding.getValue(this 
164:                                .getFacesContext());
165:                    }
166:                }
167:                return this .prompt != null ? this .prompt.booleanValue() : false;
168:            }
169:
170:            /**
171:             * Sets whether or not the prompt should be rendered.
172:             *
173:             * @param prompt The prompt to set.
174:             */
175:            public void setPrompt(final boolean prompt) {
176:                this .prompt = Boolean.valueOf(prompt);
177:            }
178:
179:            /**
180:             * Stores the default content types.
181:             */
182:            final static Properties contentTypes = new Properties();
183:
184:            /**
185:             * Load up the default content types
186:             */
187:            static {
188:                final String fileName = "contenttypes.properties";
189:                final InputStream stream = BinaryFile.class
190:                        .getResourceAsStream(fileName);
191:                if (stream == null) {
192:                    logger.error("Could not load file from '" + fileName + "'");
193:                }
194:                try {
195:                    contentTypes.load(stream);
196:                } catch (final Throwable throwable) {
197:                    logger.error(throwable);
198:                }
199:                try {
200:                    stream.close();
201:                } catch (final Throwable throwable) {
202:                    // - ignore
203:                }
204:            }
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.