KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > appclient > jws > StaticContent


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.appclient.jws;
25
26 import java.io.File JavaDoc;
27 import java.net.URI JavaDoc;
28
29 /**
30  *Represents content that does not change from one request for it to the next.
31  *
32  * @author tjquinn
33  */

34 public class StaticContent extends Content {
35
36     /** a URI relative to the install root URI of the app server installation */
37     private URI JavaDoc relativeURI;
38
39     /** indicates if this static content should be marked as the main jar file
40      *in a JNLP document
41      */

42     private boolean isMainJarFile;
43     
44     /**
45      *Returns a new instance of StaticContent
46      *@param origin the ContentOrigin that owns the new static content
47      *@param contentKey content key for storing and retrieving the content
48      *@param path path within the content's subcategory of this content
49      *@param file File object for the physical file corresponding to this static content
50      *@param installRootURI URI specifying the location of the static content file
51      *@return new StaticContent object
52      */

53     public StaticContent(ContentOrigin origin, String JavaDoc contentKey, String JavaDoc path, File JavaDoc file, URI JavaDoc installRootURI, boolean isMainJarFile) {
54         super(origin, contentKey, path);
55         URI JavaDoc fileURI = file.toURI();
56         relativeURI = installRootURI.relativize(fileURI);
57         this.isMainJarFile = isMainJarFile;
58     }
59
60     /**
61      *Retrieves the content's URI relative to the product's installation root.
62      */

63     public URI JavaDoc getRelativeURI() {
64         return relativeURI;
65     }
66
67     /**
68      *Returns a string representation of the StaticContent instance.
69      */

70     public String JavaDoc toString() {
71         String JavaDoc result = super.toString() + ", relative URI=" + getRelativeURI() + ", isMain=" + isMainJarFile;
72         return result;
73     }
74
75     /**
76      *Returns a string expression suitable for use in a JNLP document's <jar>
77      *element for whether this represents the main jar file of the application.
78      */

79     public String JavaDoc getMainExpr() {
80         String JavaDoc result;
81         if (isMainJarFile) {
82             result = " main=\"true\"";
83         } else {
84             result = "";
85         }
86         return result;
87     }
88
89     /**
90      *Returns a string expression suitable for inclusion in a JNLP document
91      *listing this jar file.
92      *@return string of the form <jar HREF="${relative-path-to-virtual-content}"/>
93      */

94     public String JavaDoc asJNLPJarElement() {
95         String JavaDoc fullPath = "${request.scheme}://${request.host}:${request.port}" +
96                 NamingConventions.fullJarPath(getContentKey());
97         
98         return " <jar HREF=\"" + fullPath + "\" " + getMainExpr() + "/>" + lineSep;
99     }
100 }
101
Popular Tags