KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > xmlc > metadata > InputDocument


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: InputDocument.java,v 1.3 2005/01/26 08:29:24 jkjome Exp $
22  */

23
24 package org.enhydra.xml.xmlc.metadata;
25
26 import java.io.File JavaDoc;
27
28 import org.enhydra.xml.xmlc.codegen.JavaLang;
29 import org.w3c.dom.Document JavaDoc;
30 import org.xml.sax.InputSource JavaDoc;
31
32 /**
33  * Specifies the document to compile.
34  */

35 public class InputDocument extends Include {
36     /**
37      * Element name.
38      */

39     public static final String JavaDoc TAG_NAME = "inputDocument";
40
41     /**
42      * Attribute names.
43      */

44     private static final String JavaDoc PROCESS_SSI_ATTR = "processSSI";
45     private static final String JavaDoc DOCUMENT_FORMAT_ATTR = "documentFormat";
46     private static final String JavaDoc RECOMPILE_SOURCE_ATTR = "recompileSource";
47
48     // dbr_20020128.2_start
49
private static final String JavaDoc SSI_BASE_ATTR = "SSIBase";
50     // dbr_20020128.2_end
51

52     /**
53      * Constructor.
54      */

55     public InputDocument(Document JavaDoc ownerDoc) {
56         super(ownerDoc, TAG_NAME);
57     }
58
59     /**
60      * Get the input source. Derived from the inputDocument attribute,
61      * plus explictly specified encoding if HTML.
62      */

63     public InputSource JavaDoc getInputSource() {
64         String JavaDoc url = getUrl();
65         if (url == null) {
66             return null;
67         }
68         InputSource JavaDoc inputSource = new InputSource JavaDoc(url);
69         HTMLSection htmlMetaData = getMetaData().getHTMLSection();
70         if (htmlMetaData != null) {
71             String JavaDoc htmlEncoding = htmlMetaData.getEncoding();
72             if (htmlEncoding != null) {
73                 inputSource.setEncoding(htmlEncoding);
74             }
75         }
76         return inputSource;
77     }
78
79     /**
80      * Normalize a file to be a unix path name.
81      */

82     private String JavaDoc normalizeToUnixFile(String JavaDoc name) {
83         return name.replace('\\', '/');
84     }
85
86     /**
87      * Get the processSSI attribute.
88      */

89     public boolean getProcessSSI() {
90         return getBooleanAttribute(PROCESS_SSI_ATTR);
91     }
92
93     /**
94      * Set the processSSI attribute.
95      */

96     public void setProcessSSI(boolean value) {
97         setBooleanAttribute(PROCESS_SSI_ATTR, value);
98     }
99
100     // dbr_20020128.1_start
101
/**
102      * Set the SSIBase attribute.
103      */

104     public void setSSIBase(String JavaDoc value) {
105     setRemoveAttribute(SSI_BASE_ATTR, value);
106     }
107
108     /**
109      * Get the SSIBase attribute.
110      */

111     public String JavaDoc getSSIBase() {
112     return getAttributeNull(SSI_BASE_ATTR);
113     }
114     // dbr_20020128.1_end
115

116     /**
117      * Get the documentFormat attribute.
118      */

119     public DocumentFormat getDocumentFormat() {
120         return DocumentFormat.getType(getAttributeNull(DOCUMENT_FORMAT_ATTR));
121     }
122
123     /**
124      * Set the documentFormat attribute.
125      */

126     public void setDocumentFormat(DocumentFormat docType) {
127         setRemoveAttribute(DOCUMENT_FORMAT_ATTR, docType.getName());
128     }
129
130     /**
131      * Get the default recompile source.
132      */

133     private String JavaDoc getDefaultRecompileSource() {
134         String JavaDoc inputFile = getUrl();
135         if (inputFile == null) {
136             return null; // No name...
137
}
138         String JavaDoc name = new File JavaDoc(inputFile).getName();
139
140         // Add in package name, if available.
141
String JavaDoc packageName = getMetaData().getDocumentClass().getPackageName();
142         if (packageName != null) {
143             name = JavaLang.packageNameToUnixFileName(packageName)
144                 + "/" + name;
145         }
146         return name;
147     }
148
149     /**
150      * Get the recompileSource attribute value. Value is always
151      * normalized to a Unix-style pathname. Returns the default
152      * if the attribute is not specified or null if there is no
153      * default.
154      */

155     public String JavaDoc getRecompileSource() {
156         String JavaDoc name = getAttributeNull(RECOMPILE_SOURCE_ATTR);
157         if (name == null) {
158             name = getDefaultRecompileSource();
159         }
160         if (name != null) {
161             return normalizeToUnixFile(name);
162         } else {
163             return null;
164         }
165     }
166
167     /**
168      * Set the recompileSource attribute value.
169      */

170     public void setRecompileSource(String JavaDoc value) {
171         if (value != null) {
172             value = normalizeToUnixFile(value);
173         }
174         setRemoveAttribute(RECOMPILE_SOURCE_ATTR, value);
175     }
176
177     /**
178      * Determine if the recompileSource attribute is specified.
179      */

180     public boolean isRecompileSourceSpecified() {
181         return isAttributeSpecified(RECOMPILE_SOURCE_ATTR);
182     }
183 }
184
Popular Tags