Source Code Cross Referenced for ImageDaoNet.java in  » ERP-CRM-Financial » Kuali-Financial-System » org » kuali » module » purap » dao » ojb » 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 » ERP CRM Financial » Kuali Financial System » org.kuali.module.purap.dao.ojb 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 The Kuali Foundation.
003:         * 
004:         * Licensed under the Educational Community License, Version 1.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         * http://www.opensource.org/licenses/ecl1.php
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.kuali.module.purap.dao.ojb;
017:
018:        import java.io.BufferedInputStream;
019:        import java.io.BufferedOutputStream;
020:        import java.io.File;
021:        import java.io.FileNotFoundException;
022:        import java.io.FileOutputStream;
023:        import java.io.IOException;
024:        import java.io.InputStream;
025:        import java.io.OutputStream;
026:        import java.net.MalformedURLException;
027:        import java.net.URL;
028:        import java.text.DecimalFormat;
029:        import java.text.NumberFormat;
030:
031:        import org.apache.commons.logging.Log;
032:        import org.apache.commons.logging.LogFactory;
033:        import org.kuali.core.dao.ojb.PlatformAwareDaoBaseOjb;
034:        import org.kuali.core.service.KualiConfigurationService;
035:        import org.kuali.kfs.KFSConstants;
036:        import org.kuali.kfs.service.ParameterService;
037:        import org.kuali.kfs.service.impl.ParameterConstants;
038:        import org.kuali.module.purap.PurapConstants;
039:        import org.kuali.module.purap.dao.ImageDao;
040:        import org.kuali.module.purap.document.AssignContractManagerDocument;
041:        import org.kuali.module.purap.exceptions.PurError;
042:        import org.kuali.module.purap.exceptions.PurapConfigurationException;
043:
044:        /**
045:         * OJB Implementation of ImageDao.
046:         */
047:        public class ImageDaoNet extends PlatformAwareDaoBaseOjb implements 
048:                ImageDao {
049:            private static Log LOG = LogFactory.getLog(ImageDaoNet.class);
050:
051:            private KualiConfigurationService configurationService;
052:            private ParameterService parameterService;
053:
054:            public void setParameterService(ParameterService parameterService) {
055:                this .parameterService = parameterService;
056:            }
057:
058:            public void setConfigurationService(
059:                    KualiConfigurationService configurationService) {
060:                this .configurationService = configurationService;
061:            }
062:
063:            /**
064:             * @see org.kuali.module.purap.dao.ImageDao#getPurchasingDirectorImage(java.lang.String, java.lang.String, java.lang.String)
065:             */
066:            public String getPurchasingDirectorImage(String key,
067:                    String campusCode, String location) {
068:                LOG.debug("getPurchasingDirectorImage() started");
069:
070:                String prefix = parameterService.getParameterValue(
071:                        ParameterConstants.PURCHASING_DOCUMENT.class,
072:                        PurapConstants.PURCHASING_DIRECTOR_IMAGE_PREFIX);
073:                String extension = "."
074:                        + parameterService
075:                                .getParameterValue(
076:                                        ParameterConstants.PURCHASING_DOCUMENT.class,
077:                                        PurapConstants.PURCHASING_DIRECTOR_IMAGE_EXTENSION);
078:                return getFile(prefix, campusCode, key, extension, location);
079:            }
080:
081:            /**
082:             * @see org.kuali.module.purap.dao.ImageDao#getContractManagerImage(java.lang.String, java.lang.Integer, java.lang.String)
083:             */
084:            public String getContractManagerImage(String key,
085:                    Integer contractManagerId, String location) {
086:                LOG.debug("getContractManagerImage() started");
087:
088:                NumberFormat formatter = new DecimalFormat("00");
089:                String cm = formatter.format(contractManagerId);
090:
091:                String prefix = parameterService.getParameterValue(
092:                        AssignContractManagerDocument.class,
093:                        PurapConstants.CONTRACT_MANAGER_IMAGE_PREFIX);
094:                String extension = "."
095:                        + parameterService
096:                                .getParameterValue(
097:                                        AssignContractManagerDocument.class,
098:                                        PurapConstants.CONTRACT_MANAGER_IMAGE_EXTENSION);
099:                return getFile(prefix, cm, key, extension, location);
100:            }
101:
102:            /**
103:             * @see org.kuali.module.purap.dao.ImageDao#getLogo(java.lang.String, java.lang.String, java.lang.String)
104:             */
105:            public String getLogo(String key, String campusCode, String location) {
106:                LOG.debug("getLogo() started. key is " + key
107:                        + ". campusCode is " + campusCode);
108:
109:                String prefix = parameterService.getParameterValue(
110:                        ParameterConstants.PURCHASING_DOCUMENT.class,
111:                        PurapConstants.LOGO_IMAGE_PREFIX);
112:                String extension = "."
113:                        + parameterService.getParameterValue(
114:                                ParameterConstants.PURCHASING_DOCUMENT.class,
115:                                PurapConstants.LOGO_IMAGE_EXTENSION);
116:                return getFile(prefix, campusCode, key, extension, location);
117:            }
118:
119:            /**
120:             * Copy a file from a web location to the local system.
121:             * 
122:             * @param prefix - Prefix for the file name
123:             * @param fileKey - File key for file
124:             * @param key - Unique key for the file
125:             * @param location - location of file
126:             * @return - location to copied file
127:             */
128:            private String getFile(String prefix, String fileKey, String key,
129:                    String extension, String location) {
130:                LOG.debug("getFile() started");
131:
132:                String externalizableUrlSettingName = "externalizable.images.url";
133:                String externalizableUrl = configurationService
134:                        .getPropertyString(KFSConstants.EXTERNALIZABLE_IMAGES_URL_KEY);
135:                if (externalizableUrl == null) {
136:                    throw new PurapConfigurationException(
137:                            "Application Setting "
138:                                    + externalizableUrlSettingName
139:                                    + " is missing");
140:                }
141:                if (location == null) {
142:                    throw new PurapConfigurationException(
143:                            "Valid location to store temp image files was null");
144:                }
145:
146:                String completeUrl = externalizableUrl + prefix + "_"
147:                        + fileKey.toLowerCase() + extension;
148:                String completeFile = location + key.toLowerCase() + prefix
149:                        + extension;
150:
151:                LOG.debug("getFile() URL = " + completeUrl);
152:                LOG.debug("getFile() File = " + completeFile);
153:
154:                OutputStream out = null;
155:                BufferedOutputStream bufOut = null;
156:                InputStream in = null;
157:                BufferedInputStream bufIn = null;
158:
159:                try {
160:                    out = new FileOutputStream(completeFile);
161:                    bufOut = new BufferedOutputStream(out);
162:
163:                    URL url = new URL(completeUrl);
164:                    in = url.openStream();
165:                    bufIn = new BufferedInputStream(in);
166:
167:                    // Repeat until end of file
168:                    while (true) {
169:                        int data = bufIn.read();
170:
171:                        // Check for EOF
172:                        if (data == -1) {
173:                            break;
174:                        } else {
175:                            bufOut.write(data);
176:                        }
177:                    }
178:                } catch (FileNotFoundException fnfe) {
179:                    LOG.error("getFile() File not found: " + completeUrl, fnfe);
180:                    throw new PurapConfigurationException(
181:                            "getFile() File not found: " + completeUrl);
182:                } catch (MalformedURLException mue) {
183:                    LOG.error("getFile() Unable to get URL: " + completeUrl,
184:                            mue);
185:                    throw new IllegalAccessError(mue.getMessage());
186:                } catch (IOException ioe) {
187:                    LOG.error(
188:                            "getFile() Unable to write file: " + completeFile,
189:                            ioe);
190:                    throw new IllegalAccessError(ioe.getMessage());
191:                } finally {
192:                    if (bufIn != null) {
193:                        try {
194:                            bufIn.close();
195:                        } catch (IOException e) {
196:                        }
197:                    }
198:                    if (in != null) {
199:                        try {
200:                            in.close();
201:                        } catch (IOException e) {
202:                        }
203:                    }
204:                    if (bufOut != null) {
205:                        try {
206:                            bufOut.close();
207:                        } catch (IOException e) {
208:                        }
209:                    }
210:                    if (out != null) {
211:                        try {
212:                            out.close();
213:                        } catch (IOException e) {
214:                        }
215:                    }
216:                }
217:                return completeFile;
218:            }
219:
220:            /**
221:             * @see org.kuali.module.purap.dao.ImageDao#removeImages(java.lang.String, java.lang.String)
222:             */
223:            public void removeImages(String key, String location) {
224:                LOG.debug("removeImages() started");
225:                try {
226:                    File dir = new File(location);
227:                    String[] files = dir.list();
228:                    for (int i = 0; i < files.length; i++) {
229:                        String filename = files[i];
230:                        if (filename.startsWith(key.toLowerCase())) {
231:                            LOG.debug("removeImages() removing " + filename);
232:
233:                            File f = new File(location + filename);
234:                            f.delete();
235:                        }
236:                    }
237:                } catch (Exception e) {
238:                    throw new PurError(
239:                            "Caught exception while trying to remove images at "
240:                                    + location, e);
241:                }
242:            }
243:
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.