001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.wicket.markup;
018:
019: import org.slf4j.Logger;
020: import org.slf4j.LoggerFactory;
021:
022: /**
023: * Holds markup as a resource (the stream that the markup came from) and a list
024: * of MarkupElements (the markup itself).
025: *
026: * @see MarkupElement
027: * @see ComponentTag
028: * @see org.apache.wicket.markup.RawMarkup
029: *
030: * @author Jonathan Locke
031: * @author Juergen Donnerstag
032: */
033: public class MarkupResourceData {
034: private static final Logger log = LoggerFactory
035: .getLogger(MarkupResourceData.class);
036:
037: /** Placeholder that indicates no markup */
038: public static final MarkupResourceData NO_MARKUP_RESOURCE_DATA = new MarkupResourceData();
039:
040: /** The markup's resource stream */
041: private MarkupResourceStream resource;
042:
043: /** In case of the inherited markup, the base markup's resource stream */
044: private MarkupResourceData baseMarkupResourceData;
045:
046: /** If found in the markup, the <?xml ...?> string */
047: private String xmlDeclaration;
048:
049: /** The encoding as found in <?xml ... encoding="" ?>. Null, else */
050: private String encoding;
051:
052: /** Wicket namespace: <html xmlns:wicket="http://wicket.apache.org"> */
053: private String wicketNamespace;
054:
055: /** == wicket namespace name + ":id" */
056: private String wicketId;
057:
058: /**
059: * Constructor
060: */
061: MarkupResourceData() {
062: setWicketNamespace(ComponentTag.DEFAULT_WICKET_NAMESPACE);
063: }
064:
065: /**
066: * @return String representation of markup list
067: */
068: public String toString() {
069: if (resource != null) {
070: return resource.toString();
071: } else {
072: return "(unknown resource)";
073: }
074: }
075:
076: /**
077: * Gets the resource that contains this markup
078: *
079: * @return The resource where this markup came from
080: */
081: public MarkupResourceStream getResource() {
082: return resource;
083: }
084:
085: /**
086: * Return the XML declaration string, in case if found in the markup.
087: *
088: * @return Null, if not found.
089: */
090: public String getXmlDeclaration() {
091: return xmlDeclaration;
092: }
093:
094: /**
095: * Gets the markup encoding. A markup encoding may be specified in a markup
096: * file with an XML encoding specifier of the form <?xml ...
097: * encoding="..." ?>.
098: *
099: * @return Encoding, or null if not found.
100: */
101: public String getEncoding() {
102: return encoding;
103: }
104:
105: /**
106: * Get the wicket namespace valid for this specific markup
107: *
108: * @return wicket namespace
109: */
110: public String getWicketNamespace() {
111: return this .wicketNamespace;
112: }
113:
114: /**
115: *
116: * @return usually it is "wicket:id"
117: */
118: final public String getWicketId() {
119: return wicketId;
120: }
121:
122: /**
123: * Sets encoding.
124: *
125: * @param encoding
126: * encoding
127: */
128: final void setEncoding(final String encoding) {
129: this .encoding = encoding;
130: }
131:
132: /**
133: * Sets wicketNamespace.
134: *
135: * @param wicketNamespace
136: * wicketNamespace
137: */
138: public final void setWicketNamespace(final String wicketNamespace) {
139: this .wicketNamespace = wicketNamespace;
140: this .wicketId = wicketNamespace + ":id";
141:
142: if (!ComponentTag.DEFAULT_WICKET_NAMESPACE
143: .equals(wicketNamespace)) {
144: log.info("You are using a non-standard component name: "
145: + wicketNamespace);
146: }
147: }
148:
149: /**
150: * Sets xmlDeclaration.
151: *
152: * @param xmlDeclaration
153: * xmlDeclaration
154: */
155: final void setXmlDeclaration(final String xmlDeclaration) {
156: this .xmlDeclaration = xmlDeclaration;
157: }
158:
159: /**
160: * Sets the resource stream associated with the markup. It is for diagnostic
161: * purposes only.
162: *
163: * @param resource
164: * the markup resource stream
165: */
166: final void setResource(final MarkupResourceStream resource) {
167: this .resource = resource;
168: }
169:
170: /**
171: * Get the resource stream containing the base markup (markup inheritance)
172: *
173: * @return baseMarkupResource Null, if not base markup
174: */
175: public MarkupResourceData getBaseMarkupResourceData() {
176: return this .baseMarkupResourceData;
177: }
178:
179: /**
180: * In case of markup inheritance, the base markup resource.
181: *
182: * @param baseMarkupResourceData
183: * The base markup resource
184: */
185: public void setBaseMarkupResourceData(
186: MarkupResourceData baseMarkupResourceData) {
187: this.baseMarkupResourceData = baseMarkupResourceData;
188: }
189: }
|