Source Code Cross Referenced for JbiArchiveValidationHandler.java in  » ESB » open-esb » com » sun » jbi » jsf » handlers » 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 » ESB » open esb » com.sun.jbi.jsf.handlers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         * 
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         * 
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common Development
008:         * and Distribution License("CDDL") (collectively, the "License").  You
009:         * may not use this file except in compliance with the License. You can obtain
010:         * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011:         * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
012:         * language governing permissions and limitations under the License.
013:         * 
014:         * When distributing the software, include this License Header Notice in each
015:         * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016:         * Sun designates this particular file as subject to the "Classpath" exception
017:         * as provided by Sun in the GPL Version 2 section of the License file that
018:         * accompanied this code.  If applicable, add the following below the License
019:         * Header, with the fields enclosed by brackets [] replaced by your own
020:         * identifying information: "Portions Copyrighted [year]
021:         * [name of copyright owner]"
022:         * 
023:         * Contributor(s):
024:         * 
025:         * If you wish your version of this file to be governed by only the CDDL or
026:         * only the GPL Version 2, indicate your decision by adding "[Contributor]
027:         * elects to include this software in this distribution under the [CDDL or GPL
028:         * Version 2] license."  If you don't indicate a single choice of license, a
029:         * recipient has the option to distribute your version of this file under
030:         * either the CDDL, the GPL Version 2 or to extend the choice of license to
031:         * its licensees as provided above.  However, if you add GPL Version 2 code
032:         * and therefore, elected the GPL Version 2 license, then the option applies
033:         * only if the new code is made subject to such option by the copyright
034:         * holder.
035:         */
036:
037:        /*
038:         * JbiArchiveValidationHandler.java
039:         *
040:         */
041:
042:        package com.sun.jbi.jsf.handlers;
043:
044:        import com.sun.enterprise.tools.admingui.util.FileUtil;
045:        import com.sun.jbi.jsf.bean.InstallationBean;
046:        import com.sun.jbi.jsf.bean.ArchiveBean;
047:        import com.sun.jbi.jsf.bean.UploadCopyRadioBean;
048:        import com.sun.jbi.jsf.util.BeanUtilities;
049:        import com.sun.jbi.jsf.util.I18nUtilities;
050:        import com.sun.jbi.jsf.util.JBIConstants;
051:        import com.sun.jbi.jsf.util.JBILogger;
052:        import com.sun.jbi.jsf.util.ValidationUtilities;
053:        import com.sun.jsftemplating.annotation.Handler;
054:        import com.sun.jsftemplating.annotation.HandlerInput;
055:        import com.sun.jsftemplating.annotation.HandlerOutput;
056:        import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
057:        import com.sun.webui.jsf.model.UploadedFile;
058:        import java.io.File;
059:        import java.util.logging.Level;
060:        import java.util.logging.Logger;
061:        import org.w3c.dom.Document;
062:
063:        public class JbiArchiveValidationHandler {
064:            public final static String JBI_TYPE_COMP = "component"; //not i18n
065:
066:            //Get Logger to log fine mesages for debugging
067:            private static Logger sLog = JBILogger.getInstance();
068:
069:            /**
070:             *  <p> This method return the temporary location of the uploaded file </p>
071:             *  <p> after uploading the file to local disk</p>
072:             *  <p> Input value: "file" -- Type: <code>com.sun.webui.jsf.model.UploadedFile</code></p>
073:             *  <p> Output value: "uploadedLoc" -- Type: <code>java.lang.String</code></p>
074:             *  @param  context The HandlerContext.
075:             */
076:            @Handler(id="getUploadedFileLocation",input={@HandlerInput(name="file",type=UploadedFile.class,required=true)},output={@HandlerOutput(name="uploadedLoc",type=String.class)})
077:            public static void getUploadedFileLocation(HandlerContext handlerCtx) {
078:                final String WIN_CLIENT_SEPARATOR = "\\"; // cannot use File.separator when server not on Windows
079:
080:                ArchiveBean archiveBean = BeanUtilities.getArchiveBean();
081:                UploadedFile uploadedFile = (UploadedFile) handlerCtx
082:                        .getInputValue("file");
083:                String suffix = null;
084:                String prefix = null;
085:
086:                if (uploadedFile != null) {
087:                    String name = uploadedFile.getOriginalName();
088:                    sLog
089:                            .fine("JbiArchiveValidationHandler.getUploadedFileLocation()"
090:                                    + " original name=" + name);
091:
092:                    // fix for  bug# 6498910, 6520070, 6520475
093:                    // in IE, getOriginalName() returns the full path, including the drive.
094:                    //for any other browser, it just returns the file name.
095:
096:                    int lastIndex = name.lastIndexOf(WIN_CLIENT_SEPARATOR);
097:                    if (lastIndex != -1) {
098:                        name = name.substring(lastIndex + 1, name.length());
099:                        sLog
100:                                .fine("JbiArchiveValidationHandler.getUploadedFileLocation()"
101:                                        + " truncated name=" + name);
102:                    }
103:                    archiveBean.setArchiveDisplayName(name);
104:                    if (name.length() != 0) {
105:                        suffix = name.substring(name.indexOf("."));
106:                        prefix = name.substring(0, name.indexOf("."));
107:                        try {
108:                            String tmpFolder = FileUtil.getTempDirPath();
109:                            File tmpFile = File.createTempFile(prefix, suffix,
110:                                    new File(tmpFolder));
111:                            uploadedFile.write(tmpFile);
112:                            sLog
113:                                    .fine("JbiArchiveValidationHandler.getUploadedFileLocation()"
114:                                            + "tmpFile="
115:                                            + tmpFile.getAbsolutePath());
116:                            handlerCtx.setOutputValue("uploadedLoc", tmpFile
117:                                    .getCanonicalPath());
118:                            archiveBean.setArchiveAbsolutePath(tmpFile
119:                                    .getAbsolutePath());
120:                        } catch (Exception ex) {
121:                            sLog
122:                                    .log(
123:                                            Level.FINE,
124:                                            ("JbiArchiveValidationHandler.getUploadedFileLocation(...)"
125:                                                    + ", while saving uploaded file, caught ex="),
126:                                            ex);
127:                            handlerCtx.setOutputValue("uploadedLoc", "");
128:                            archiveBean.setArchiveAbsolutePath("");
129:                        }
130:                    } else {
131:                        handlerCtx.setOutputValue("uploadedLoc", "");
132:                        archiveBean.setArchiveAbsolutePath("");
133:                    }
134:
135:                }
136:            }
137:
138:            /**
139:             *  <p> This method returns the value of user selected file path </p>
140:             *  <p> checks for non-null values form upload and copy paths and returns that</p>
141:             *  <p> Input value: "copyFilePath" -- Type: <code>java.lang.String</code></p>
142:             ** <p> Input value: "uploadFilePath" -- Type: <code>java.lang.String</code></p>
143:             *  <p> Output value: "archiveFilePath" -- Type: <code>java.lang.String</code></p>
144:             *  @param  context The HandlerContext.
145:             */
146:            @Handler(id="getArchivePath",input={@HandlerInput(name="filePath",type=String.class,required=true),@HandlerInput(name="uploadRadio",type=boolean.class,required=true)},output={@HandlerOutput(name="archiveFilePath",type=String.class)})
147:            public static void getArchivePath(HandlerContext handlerCtx) {
148:                InstallationBean installBean = BeanUtilities
149:                        .getInstallationBean();
150:                String filePath = (String) handlerCtx.getInputValue("filePath");
151:                boolean uploadChecked = (Boolean) handlerCtx
152:                        .getInputValue("uploadRadio");
153:                sLog.fine("JbiArchiveValidationHandler.getArchivePath(...)"
154:                        + ", filePath=" + filePath + ", uploadChecked="
155:                        + uploadChecked);
156:
157:                if (uploadChecked) {
158:                    //set to enable deleting temporary uploaded files
159:                    //upload path selected
160:                    installBean.setUploadPathSelected(true);
161:                } else {
162:                    //copy path selected
163:                    installBean.setUploadPathSelected(false);
164:                    ArchiveBean archiveBean = BeanUtilities.getArchiveBean();
165:                    archiveBean.setArchiveAbsolutePath(filePath);
166:                    archiveBean.setArchiveDisplayName(filePath);
167:
168:                }
169:                handlerCtx.setOutputValue("archiveFilePath", filePath);
170:                sLog.fine("JbiArchiveValidationHandler.getArchivePath(...)"
171:                        + ", filePath=" + filePath);
172:            }
173:
174:            /**
175:             *  <p> This handler returns true if archive is valid  </p>
176:             *
177:             * <p> Input value: "archivePath" -- Type: <code>java.lang.String</code> archive path</p>
178:             * <p> Input value: "compType" -- Type: <code>java.lang.String</code> Component Type</p>
179:             * <p> Input value: "navValid" -- Type: <code>java.lang.String</code> navigation page if valid</p>
180:             * <p> Input value: "navValid" -- Type: <code>java.lang.String</code> navigation page if invalid</p>
181:             *  <p> Output value: "isValid" -- Type: <code>Boolean</code></p>
182:             *  <p> Output value: "alertSummaryMsg" -- Type: <code>String</code></p>
183:             **  <p> Output value: "alertDetailMsg" -- Type: <code>String</code></p>
184:             *  <p> Output value: "navLoc" -- Type: <code>String</code></p>
185:             *  @param  context The HandlerContext.
186:             */
187:            @Handler(id="isValidArchive",input={@HandlerInput(name="archivePath",type=String.class,required=true),@HandlerInput(name="compType",type=String.class,required=true),@HandlerInput(name="navValid",type=String.class,required=true),@HandlerInput(name="navInvalid",type=String.class,required=true)},output={@HandlerOutput(name="isValid",type=Boolean.class),@HandlerOutput(name="isAlertNeeded",type=Boolean.class),@HandlerOutput(name="alertSummaryMsg",type=String.class),@HandlerOutput(name="alertDetailMsg",type=String.class),@HandlerOutput(name="navLoc",type=String.class)})
188:            public static void isValidArchive(HandlerContext handlerContext) {
189:
190:                ArchiveBean archiveBean = BeanUtilities.getArchiveBean();
191:                UploadCopyRadioBean uploadCpBean = BeanUtilities
192:                        .getUploadCopyRadioBean();
193:                String pathToFile = (String) handlerContext
194:                        .getInputValue("archivePath");
195:                String compType = (String) handlerContext
196:                        .getInputValue("compType");
197:
198:                String navValid = (String) handlerContext
199:                        .getInputValue("navValid");
200:                uploadCpBean.setNavDestValid(navValid);
201:                String navInvalid = (String) handlerContext
202:                        .getInputValue("navInvalid");
203:                uploadCpBean.setNavDestInvalid(navInvalid);
204:
205:                sLog
206:                        .fine("JbiArchiveValidationHandler.isValidArchive(), archivePath="
207:                                + pathToFile
208:                                + ", compType="
209:                                + compType
210:                                + ", navValid="
211:                                + navValid
212:                                + ", navInvalid="
213:                                + navInvalid);
214:
215:                Document jbiMetadataDoc = ValidationUtilities.getJbiDocument();
216:                String componentType = ValidationUtilities
217:                        .getJbiType(jbiMetadataDoc);
218:                sLog
219:                        .fine("JbiArchiveValidationHandler.isValidArchive(), jbiMetadataDoc="
220:                                + jbiMetadataDoc
221:                                + ", componentType="
222:                                + componentType);
223:
224:                String invalidAlertDetail = checkValidArchive(pathToFile,
225:                        compType);
226:                if (!"".equals(invalidAlertDetail)) {
227:                    sLog
228:                            .fine("JbiArchiveValidationHandler.isValidArchive(), invalidAlertDetail="
229:                                    + invalidAlertDetail);
230:                    setOutputInvalidAlertValue(invalidAlertDetail,
231:                            handlerContext);
232:                } else {
233:                    String navLoc = uploadCpBean.getNavDestValid();
234:                    sLog.fine("JbiArchiveValidationHandler.isValidArchive()"
235:                            + ", isValid=true, isAlertNeeded=false"
236:                            + ", navLoc=" + navLoc + ", componentType="
237:                            + componentType);
238:                    handlerContext.setOutputValue("isValid", "true");
239:                    handlerContext.setOutputValue("isAlertNeeded", "false");
240:                    handlerContext.setOutputValue("navLoc", navLoc);
241:                    archiveBean.setJbiType(componentType);
242:                }
243:            }
244:
245:            /**
246:             * <p> Deletes the invalid archives which were uploaded to temporary location on disk
247:             * <p> Input  value: "archiveStatus" -- Type: <code>Boolean</code></p>
248:             ** <p> Input  value: "archivePath" -- Type: <code>String</code></p>
249:             ** <p> Input  value: "uploadSelected" -- Type: <code>Boolean</code></p>
250:             * @param  handlerCtx <code>HandlerContext</code> provides inputs and outputs.
251:             */
252:            @Handler(id="deleteInvalidatedUploadedArchive",input={@HandlerInput(name="archiveStatus",type=Boolean.class,required=true),@HandlerInput(name="archivePath",type=String.class,required=true),@HandlerInput(name="uploadSelected",type=Boolean.class,required=true)})
253:            public static void deleteInvalidatedUploadedArchive(
254:                    HandlerContext handlerContext) {
255:                String uploadedFileLoc = (String) handlerContext
256:                        .getInputValue("archivePath");
257:                Boolean isValid = (Boolean) handlerContext
258:                        .getInputValue("archiveStatus");
259:                Boolean isUpload = (Boolean) handlerContext
260:                        .getInputValue("uploadSelected");
261:
262:                sLog
263:                        .fine("JbiArchiveValidationHandler.deleteInvalidatedUploadedArchive(...)"
264:                                + ", archivePath(uploadedFileLoc)="
265:                                + uploadedFileLoc
266:                                + ", archiveStatus(isValid)="
267:                                + isValid
268:                                + ", uploadSelected(isUpload)="
269:                                + isUpload);
270:
271:                try {
272:                    if ((isUpload) && (!isValid) && (null != uploadedFileLoc)
273:                            && (!"".equals(uploadedFileLoc))) {
274:                        sLog
275:                                .fine("JbiArchiveValidationHandler.deleteInvalidatedUploadedArchive(...)"
276:                                        + ", deleting uploadedFileLoc="
277:                                        + uploadedFileLoc);
278:                        FileUtil.delete(uploadedFileLoc);
279:                    }
280:                } catch (Exception ex) {
281:                    sLog
282:                            .log(
283:                                    Level.FINE,
284:                                    ("JbiArchiveValidationHandler.deleteInvalidatedUploadedArchive(...)"
285:                                            + ", while deleting uploadedFileLoc="
286:                                            + uploadedFileLoc + ", caught ex="),
287:                                    ex);
288:                }
289:            }
290:
291:            /**
292:             * Set the outputValue of the isValidArchive handler
293:             * @param alertDetail is the alert's detail  message
294:             */
295:            private static void setOutputInvalidAlertValue(String aAlertDetail,
296:                    HandlerContext aHandlerCtxt) {
297:                UploadCopyRadioBean uploadCpBean = BeanUtilities
298:                        .getUploadCopyRadioBean();
299:                String navDestIfInvalid = uploadCpBean.getNavDestInValid();
300:                String alertSummary = I18nUtilities
301:                        .getResourceString("jbi.install.wizard.invalid.alertsummary.text");
302:                aHandlerCtxt.setOutputValue("isValid", "false");
303:                aHandlerCtxt.setOutputValue("isAlertNeeded", "true");
304:                aHandlerCtxt.setOutputValue("alertSummaryMsg", alertSummary);
305:                aHandlerCtxt.setOutputValue("alertDetailMsg", aAlertDetail);
306:                aHandlerCtxt.setOutputValue("navLoc", navDestIfInvalid);
307:                sLog
308:                        .fine("JbiArchiveValidationHandler.setOutputInvalidAlertValue(...)"
309:                                + ", isValid=false, isAlertNeeded=true, alertSummary="
310:                                + alertSummary
311:                                + ", aAlertDetail="
312:                                + aAlertDetail + ", navLoc=" + navDestIfInvalid);
313:                //If upload path was chosen cleanup the uploaded file
314:                //From templocation
315:                //FileUtil.delete (getArchiveAbsolutePath ());
316:            }
317:
318:            /**
319:             *  This method is used for validating JBI archive in the admin-console
320:             *  for installtion and upgrade wizard
321:             *
322:             *@param aPathToFile Path to the archive file as selected in 
323:             *                      copy or upload step of installation/upgrade wizard
324:             *@param aCompType   The type of the chosen archive. 
325:             *                      Valid values are component(For binding-component & service engine)
326:             *                               shared-library and service-assembly
327:             *@return            Alert Detail msg to be displayed after validation fails                      
328:             */
329:            public static String checkValidArchive(String aPathToFile,
330:                    String aCompType) {
331:                ArchiveBean archiveBean = BeanUtilities.getArchiveBean();
332:                archiveBean.setArchiveAbsolutePath(aPathToFile);
333:                String jbiType = "";
334:                resetValidationParameters();
335:
336:                String alertDetailNotWellFormed = I18nUtilities
337:                        .getResourceString("jbi.install.wizard.invalid.notwellformed.text");
338:                String alertDetailNotFound = I18nUtilities
339:                        .getResourceString("jbi.install.wizard.invalid.filenotfound.text");
340:                String alertDetailMissingJbi = I18nUtilities
341:                        .getResourceString("jbi.install.wizard.invalid.missingjbixml.text");
342:                String alertDetailNotSchemaValid = I18nUtilities
343:                        .getResourceString("jbi.install.wizard.invalid.notschemavalid.text");
344:                String alertDetailMismatchArchiveWizard = I18nUtilities
345:                        .getResourceString("jbi.install.wizard.invalid.mismatcharchivewizard.text");
346:
347:                int count = 0;
348:
349:                boolean zipError = archiveBean.getZipFileReadError();
350:                boolean fileError = archiveBean.getFileReadError();
351:                boolean emptyInvalid = ValidationUtilities
352:                        .isArchiveEmptyOrInValid();
353:
354:                if (emptyInvalid || zipError || fileError) {
355:                    return alertDetailNotFound;
356:                } else {
357:                    //also will set if jbi xml present or not
358:                    ValidationUtilities.getMetaDataEntry();
359:
360:                    if (!archiveBean.getHasJbiXml()) {
361:                        return alertDetailMissingJbi;
362:                    } else if (!ValidationUtilities.isJbiXmlWellformed()) {
363:                        return alertDetailNotWellFormed;
364:                    }
365:                    /*
366:                     * Disabling schema validation check :fix for CR 6504700
367:                     * Schema validation apis at console and management level
368:                     * differ in handling validation of xml files with elements
369:                     * having namespace prefixes from several namespaces.
370:                     * JBI Runtime uses JAXB for schema validation and console used javax.xml.validation apis
371:                     *
372:                     else if ( !ValidationUtilities.isJbiXmlSchemaValid () )
373:                    {
374:                        setOutputInvalidAlertValue (alertDetailNotSchemaValid);
375:                    }*/
376:                    else {
377:                        String componentType = ValidationUtilities
378:                                .getJbiType(ValidationUtilities
379:                                        .getJbiDocument());
380:                        if (componentType
381:                                .equals(JBIConstants.JBI_BINDING_COMPONENT_TYPE)
382:                                || componentType
383:                                        .equals(JBIConstants.JBI_SERVICE_ENGINE_TYPE)) {
384:                            jbiType = JBI_TYPE_COMP;
385:                        } else {
386:                            jbiType = componentType;
387:                        }
388:
389:                        if (!jbiType.equals(aCompType)) {
390:                            return alertDetailMismatchArchiveWizard;
391:                        } else {
392:                            return ""; //No AlertDetails since the archive is valid
393:                        }
394:                    }
395:                }
396:            }
397:
398:            /**
399:             * Reset the validation parameters as set by previous archive
400:             */
401:
402:            private static void resetValidationParameters() {
403:                ArchiveBean archiveBean = BeanUtilities.getArchiveBean();
404:                archiveBean.setHasJbiXml(true);
405:                archiveBean.setZipFileReadError(false);
406:                archiveBean.setFileReadError(false);
407:            }
408:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.