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
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.designer.cssengine;
042:
043: import java.net.URL;
044:
045: import org.apache.batik.css.engine.CSSStylableElement;
046: import org.apache.batik.css.engine.StyleMap;
047: import org.w3c.dom.Document;
048: import org.w3c.dom.Node;
049: import org.w3c.dom.NodeList;
050:
051: import org.netbeans.modules.visualweb.designer.html.HtmlAttribute;
052: import org.w3c.dom.Attr;
053: import org.w3c.dom.DOMException;
054: import org.w3c.dom.TypeInfo;
055: import org.w3c.dom.UserDataHandler;
056:
057: // XXX Moved from designer/PreviewElement.java.
058: /**
059: * This class represents a DOM element which can be used for
060: * preview purposes where I want to do layout based on styles but
061: * don't have an associated comment. I can set a stylestring on
062: * the element and then have the CSS lookup routines find these
063: * styles using the standard style interface on the element.
064: * @author Tor Norbye
065: */
066: class PreviewElement implements CSSStylableElement {
067: private final Document document;
068: private StyleMap computedStyleMap;
069: // private XhtmlCssEngine engine;
070: private URL base;
071: private String styles;
072: private static final String NYI = "Not supported for PreviewElement";
073:
074: public PreviewElement(Document document, /*XhtmlCssEngine engine,*/
075: URL base, String styles) {
076: this .document = document;
077: this .base = base;
078: // this.engine = engine;
079: this .styles = styles;
080: }
081:
082: // public CSSEngine getEngine() {
083: //// return engine;
084: // return CssEngineServiceProvider.getDefault().getCssEngine(document);
085: // }
086:
087: /**
088: * Returns the computed style of this element/pseudo-element.
089: */
090: public StyleMap getComputedStyleMap(String pseudoElement) {
091: return computedStyleMap;
092: }
093:
094: /**
095: * Sets the computed style of this element/pseudo-element.
096: */
097: public void setComputedStyleMap(String pseudoElement, StyleMap sm) {
098: computedStyleMap = sm;
099: }
100:
101: /**
102: * Returns the ID of this element.
103: */
104: public String getXMLId() {
105: return "";
106: }
107:
108: /**
109: * Returns the class of this element.
110: */
111: public String getCSSClass() {
112: return "";
113: }
114:
115: /**
116: * Returns the CSS base URL of this element.
117: */
118: public URL getCSSBase() {
119: return base;
120: }
121:
122: /**
123: * Tells whether this element is an instance of the given pseudo
124: * class.
125: */
126: public boolean isPseudoInstanceOf(String pseudoClass) {
127: return false;
128: }
129:
130: public org.w3c.dom.Node appendChild(org.w3c.dom.Node node)
131: throws org.w3c.dom.DOMException {
132: throw new RuntimeException(NYI);
133: }
134:
135: public org.w3c.dom.Node cloneNode(boolean param) {
136: throw new RuntimeException(NYI);
137: }
138:
139: public String getAttribute(String str) {
140: //throw new RuntimeException(NYI);
141: if (HtmlAttribute.STYLE.equals(str)) {
142: return styles;
143: }
144:
145: return "";
146: }
147:
148: public String getAttributeNS(String str, String str1) {
149: //throw new RuntimeException(NYI);
150: if (HtmlAttribute.STYLE.equals(str1)) {
151: return styles;
152: }
153:
154: return "";
155: }
156:
157: public org.w3c.dom.Attr getAttributeNode(String str) {
158: throw new RuntimeException(NYI);
159: }
160:
161: public org.w3c.dom.Attr getAttributeNodeNS(String str, String str1) {
162: throw new RuntimeException(NYI);
163: }
164:
165: public org.w3c.dom.NamedNodeMap getAttributes() {
166: //throw new RuntimeException(NYI);
167: return null;
168: }
169:
170: public org.w3c.dom.NodeList getChildNodes() {
171: return new NodeList() {
172: public int getLength() {
173: return 0;
174: }
175:
176: public Node item(int index) {
177: return null;
178: }
179: };
180: }
181:
182: public org.w3c.dom.NodeList getElementsByTagName(String str) {
183: throw new RuntimeException(NYI);
184: }
185:
186: public org.w3c.dom.NodeList getElementsByTagNameNS(String str,
187: String str1) {
188: throw new RuntimeException(NYI);
189: }
190:
191: public org.w3c.dom.Node getFirstChild() {
192: return null;
193: }
194:
195: public org.w3c.dom.Node getLastChild() {
196: return null;
197: }
198:
199: public String getLocalName() {
200: return "preview";
201: }
202:
203: public String getNamespaceURI() {
204: return "preview";
205: }
206:
207: public org.w3c.dom.Node getNextSibling() {
208: return null;
209: }
210:
211: public String getNodeName() {
212: return getLocalName();
213: }
214:
215: public short getNodeType() {
216: return Node.ELEMENT_NODE;
217: }
218:
219: public String getNodeValue() throws org.w3c.dom.DOMException {
220: throw new RuntimeException(NYI);
221: }
222:
223: public org.w3c.dom.Document getOwnerDocument() {
224: // System.err.println("Warning: Previewelement getOwnerDocument called...");
225: // return null;
226: return document;
227: }
228:
229: public org.w3c.dom.Node getParentNode() {
230: return null;
231: }
232:
233: public String getPrefix() {
234: return "preview";
235: }
236:
237: public org.w3c.dom.Node getPreviousSibling() {
238: return null;
239: }
240:
241: public String getTagName() {
242: return getLocalName();
243: }
244:
245: public boolean hasAttribute(String str) {
246: return false;
247: }
248:
249: public boolean hasAttributeNS(String str, String str1) {
250: return false;
251: }
252:
253: public boolean hasAttributes() {
254: return false;
255: }
256:
257: public boolean hasChildNodes() {
258: return false;
259: }
260:
261: public org.w3c.dom.Node insertBefore(org.w3c.dom.Node node,
262: org.w3c.dom.Node node1) throws org.w3c.dom.DOMException {
263: throw new RuntimeException(NYI);
264: }
265:
266: public boolean isSupported(String str, String str1) {
267: return false;
268: }
269:
270: public void normalize() {
271: }
272:
273: public void removeAttribute(String str)
274: throws org.w3c.dom.DOMException {
275: throw new RuntimeException(NYI);
276: }
277:
278: public void removeAttributeNS(String str, String str1)
279: throws org.w3c.dom.DOMException {
280: throw new RuntimeException(NYI);
281: }
282:
283: public org.w3c.dom.Attr removeAttributeNode(org.w3c.dom.Attr attr)
284: throws org.w3c.dom.DOMException {
285: throw new RuntimeException(NYI);
286: }
287:
288: public org.w3c.dom.Node removeChild(org.w3c.dom.Node node)
289: throws org.w3c.dom.DOMException {
290: throw new RuntimeException(NYI);
291: }
292:
293: public org.w3c.dom.Node replaceChild(org.w3c.dom.Node node,
294: org.w3c.dom.Node node1) throws org.w3c.dom.DOMException {
295: throw new RuntimeException(NYI);
296: }
297:
298: public void setAttribute(String str, String str1)
299: throws org.w3c.dom.DOMException {
300: throw new RuntimeException(NYI);
301: }
302:
303: public void setAttributeNS(String str, String str1, String str2)
304: throws org.w3c.dom.DOMException {
305: throw new RuntimeException(NYI);
306: }
307:
308: public org.w3c.dom.Attr setAttributeNode(org.w3c.dom.Attr attr)
309: throws org.w3c.dom.DOMException {
310: throw new RuntimeException(NYI);
311: }
312:
313: public org.w3c.dom.Attr setAttributeNodeNS(org.w3c.dom.Attr attr)
314: throws org.w3c.dom.DOMException {
315: throw new RuntimeException(NYI);
316: }
317:
318: public void setNodeValue(String str)
319: throws org.w3c.dom.DOMException {
320: throw new RuntimeException(NYI);
321: }
322:
323: public void setPrefix(String str) throws org.w3c.dom.DOMException {
324: throw new RuntimeException(NYI);
325: }
326:
327: // TODO: Implement these methods?
328: public void setIdAttributeNode(Attr idAttr, boolean isId)
329: throws DOMException {
330: throw new RuntimeException(NYI);
331: }
332:
333: public void setIdAttributeNS(String namespaceURI, String localName,
334: boolean isId) throws DOMException {
335: throw new RuntimeException(NYI);
336: }
337:
338: public void setIdAttribute(String name, boolean isId)
339: throws DOMException {
340: throw new RuntimeException(NYI);
341: }
342:
343: public TypeInfo getSchemaTypeInfo() {
344: throw new RuntimeException(NYI);
345: }
346:
347: public Object getUserData(String key) {
348: throw new RuntimeException(NYI);
349: }
350:
351: public Object setUserData(String key, Object data,
352: UserDataHandler handler) {
353: throw new RuntimeException(NYI);
354: }
355:
356: public Object getFeature(String feature, String version) {
357: throw new RuntimeException(NYI);
358: }
359:
360: public boolean isEqualNode(Node arg) {
361: throw new RuntimeException(NYI);
362: }
363:
364: public String lookupNamespaceURI(String prefix) {
365: throw new RuntimeException(NYI);
366: }
367:
368: public boolean isDefaultNamespace(String namespaceURI) {
369: throw new RuntimeException(NYI);
370: }
371:
372: public String lookupPrefix(String namespaceURI) {
373: throw new RuntimeException(NYI);
374: }
375:
376: public boolean isSameNode(Node other) {
377: throw new RuntimeException(NYI);
378: }
379:
380: public void setTextContent(String textContent) {
381: throw new RuntimeException(NYI);
382: }
383:
384: public String getTextContent() {
385: throw new RuntimeException(NYI);
386: }
387:
388: public short compareDocumentPosition(Node other) {
389: throw new RuntimeException(NYI);
390: }
391:
392: public String getBaseURI() {
393: throw new RuntimeException(NYI);
394: }
395: }
|