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 org.apache.batik.css.engine.CSSEngine;
044: import org.apache.batik.css.engine.value.AbstractValueManager;
045: import org.apache.batik.css.engine.value.URIValue;
046: import org.apache.batik.css.engine.value.Value;
047: import org.w3c.css.sac.LexicalUnit;
048: import org.w3c.dom.DOMException;
049:
050: /**
051: * This class provides support for the "background-image" property.
052: *
053: * @author Tor Norbye
054: */
055: public class BackgroundImageManager extends AbstractValueManager {
056:
057: public boolean isInheritedProperty() {
058: return false;
059: }
060:
061: public String getPropertyName() {
062: return CssConstants.CSS_BACKGROUND_IMAGE_PROPERTY;
063: }
064:
065: public Value getDefaultValue() {
066: return CssValueConstants.NONE_VALUE;
067: }
068:
069: public Value createValue(LexicalUnit lu, CSSEngine engine)
070: throws DOMException {
071: switch (lu.getLexicalUnitType()) {
072: case LexicalUnit.SAC_INHERIT:
073: return CssValueConstants.INHERIT_VALUE;
074:
075: case LexicalUnit.SAC_URI:
076: String stringValue = lu.getStringValue();
077:
078: java.net.URL docUrl = null;
079:
080: if (stringValue.length() > 1 && stringValue.startsWith("/")) {
081: // XXX #6336303 If the value starts with '/', it is context-relative,
082: // therefore this hack chops it off to assure resolution of the URI.
083: // TODO Check if it is correct to provide base URI ending with '/'.
084: stringValue = stringValue.substring(1);
085:
086: // org.w3c.dom.Document doc = engine.getDocument();
087: //// if(doc instanceof RaveDocument) {
088: //// RaveDocument rDoc = (RaveDocument)doc;
089: // // <markup_separation>
090: //// DesignProject designProject = rDoc.getRoot().getDesignBean().getDesignContext().getProject();
091: //// if(designProject instanceof FacesModelSet) {
092: //// FacesModelSet fModelSet = (FacesModelSet)designProject;
093: //// FileObject documentRoot = JsfProjectHelper.getDocumentRoot(fModelSet.getProject());
094: //// try {
095: //// docUrl = documentRoot.getURL();
096: //// } catch(FileStateInvalidException fsie) {
097: //// ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, fsie);
098: //// }
099: //// }
100: // // ====
101: // docUrl = InSyncService.getProvider().getDocumentUrl(doc);
102: if (engine instanceof XhtmlCssEngine) {
103: docUrl = ((XhtmlCssEngine) engine).getDocumentUrl();
104: }
105: // </markup_separation>
106: // }
107: }
108: // else {
109: // TODO It is not context-relative, but relative to the page location.
110: // }
111:
112: if (docUrl != null) {
113: return new URIValue(lu.getStringValue(), resolveURI(
114: docUrl, stringValue));
115: } else {
116: return new URIValue(lu.getStringValue(), resolveURI(
117: engine.getCSSBaseURI(), stringValue));
118: }
119: case LexicalUnit.SAC_IDENT:
120: String s = lu.getStringValue().toLowerCase().intern();
121: if (s == CssConstants.CSS_NONE_VALUE) {
122: return CssValueConstants.NONE_VALUE;
123: }
124: throw createInvalidIdentifierDOMException(lu
125: .getStringValue(), engine);
126: }
127: throw createInvalidLexicalUnitDOMException(lu
128: .getLexicalUnitType(), engine);
129: }
130: }
|