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:
042: package org.netbeans.modules.visualweb.api.designer.cssengine;
043:
044: import java.net.URL;
045: import java.util.Collection;
046: import java.util.List;
047: import java.util.Map;
048: import org.apache.batik.css.engine.StyleSheet;
049: import org.w3c.dom.Document;
050: import org.w3c.dom.Element;
051: import org.w3c.dom.Node;
052:
053: /**
054: * Interface to the CSS engine services.
055: * <p>
056: * <b><font color="red"><em>Important note: Do not provide implementation of this interface, use the provider to access it!</em></font></b>
057: * </p>
058: *
059: * @author Peter Zavadsky
060: */
061: public interface CssEngineService {
062:
063: // /** XXX Temporary, engine should be hidden. */
064: // public XhtmlCssEngine getCssEngine(Document document);
065: // /** XXX Temporary, engine should be hidden. */
066: // public void setCssEngine(Document document, XhtmlCssEngine engine);
067:
068: /** Creates a css engine for specified <code>Document</code> and stores it internally. */
069: public void createCssEngineForDocument(Document document, URL url);
070:
071: /** Removes the css engine for specified <code>Document</code> if there was one created before. */
072: public void removeCssEngineForDocument(Document document);
073:
074: /** Reuses the css engine instance for the specified <code>document</code> if there already
075: * exist one for the <code>originalDocument</code> instance. */
076: public void reuseCssEngineForDocument(Document document,
077: Document originalDocument);
078:
079: /** Gets collection of style classes for specific document, if there is corresponding css engine available
080: * otherwise it returns an empty collection. */
081: public Collection getCssStyleClassesForDocument(Document document);
082:
083: /** Parse the given style declaration and return a map of properties
084: * stored in it. The Map will have String keys which correspond to
085: * property names, and String values which correspond to CSS
086: * raw text for the values.
087: * </p>
088: * If there is no css engine created, it returns an empty map. */
089: public Map getStyleMapFromStringForDocument(Document document,
090: String style);
091:
092: /** Given a Map of style properties, serialize the set and compress
093: * properties into shorthands, when possible. See styleToMap.
094: * <p/>
095: * If there is no css engine created, it returns an empty map. */
096: public String getStringFromStyleMapForDocument(Document document,
097: Map<String, String> styleMap);
098:
099: /** Adding a node which represents style sheet node for specified <code>Document</code>,
100: * into the corresponding css engine, if there is one. */
101: public void addTransientStyleSheetNodeForDocument(
102: Document document, Node styleSheetNode);
103:
104: /** Clears the stylesheet nodes for the specified document, from the corresponding css engine,
105: * if there is one. */
106: public void clearTransientStyleSheetNodesForDocument(
107: Document document);
108:
109: /** Gets the local styles string for a specified <code>Element</code> if there is corresponding css engine.
110: * First any style settings in the set parameter array are applied, then any properties
111: * pointed to by the remove array are applied.
112: * @return The new style string */
113: public String getUpdatedLocalStyleValuesForElement(Element element,
114: StyleData[] stylesToSet, StyleData[] stylesToRemove)
115: throws Exception;
116:
117: /** Sets style attribute in specified <code>Element</code> if there is corresponding css engine. */
118: public void setStyleAttributeForElement(Element element,
119: String value);
120:
121: // /** XXX Active modification (via the design bean/property).
122: // * Updates local style value for specified <code>Element</code>. */
123: // public void updateLocalStyleValuesForElement(Element element, StyleData[] stylesToSet, StyleData[] stylesToRemove);
124: // /** XXX Active modification (via the design bean/property).
125: // * Adds local style value for specified <code>Element</code>. */
126: // public void addLocalStyleValueForElement(Element element, int style, String value);
127: // /** XXX Active modification (via the design bean/property).
128: // * Removes local style value for specified <code>Element</code>. */
129: // public void removeLocalStyleValueForElement(Element element, int style);
130:
131: /** Clears computed styles for specified <code>Element</code> if there is corresponding css engine. */
132: public void clearComputedStylesForElement(Element element);
133:
134: /** Sets silent error handler for specified <code>Document</code> if there is corresponding css engine. */
135: public void setSilentErrorHandlerForDocument(Document document);
136:
137: /** Sets null error handler for specified <code>Document</code> if there is corresponding css engine. */
138: public void setNullErrorHandlerForDocument(Document document);
139:
140: // /** Sets error handler for specified <code>Document</code> if there is corresponding css engine. */
141: // public void setErrorHandlerForDocument(Document document, ErrorHandler errorHandler);
142: /** Returns true if was inherited, as opposed to referenced directly by some rule.
143: * for a specified <code>Element</code> if there is corresponsing css engine. */
144: public boolean isInheritedStyleValueForElement(Element element,
145: int propIndex);
146:
147: /** Returns true if the value is default,
148: * for a specified <code>Element</code> if there is corresponsing css engine. */
149: public boolean isDefaultStyleValueForElement(Element element,
150: String pseudo, int propIndex);
151:
152: /** Refreshes all styles for specified <code>Document</code> if corresponding css engine exists. */
153: public void refreshStylesForDocument(Document document);
154:
155: /** If the given property for an element has been computed, remove
156: * its computed state so that it gets recomputed for the next
157: * getComputedStyle call, for specified <code>Document</code> if corresponding
158: * css engine exists.
159: * XXX TODO it sounds horrible, revise. */
160: public void uncomputeValueForElement(Element element, int propIndex);
161:
162: public int getXhtmlPropertyIndex(String property);
163:
164: // public int getXhtmlShorthandIndex(String property);
165:
166: /** Creates a 'preview' element. */
167: public Element createPreviewElementForDocument(Document document,
168: URL base, String styles);
169:
170: // Convenience method
171: /** Returns <code>URL</code> of background image relative to the specified base <code>URL</code>. */
172: public URL getBackgroundImageUrlForElement(Element element,
173: URL baseUrl);
174:
175: ////////////////////////////////////////////////////////////////////////////
176: // <methods needed to be replaced>
177: /** XXX FIXME Get rid of this method, it uses batik classes, which is not acceptable.
178: * Gets computed value for specified <code>Element</code> index if the corresponding css engine exists. */
179: public CssValue getComputedValueForElement(Element element,
180: int propIndex);
181:
182: // /** XXX FIXME Get rid of this method, it uses batik classes, which is not acceptable. */
183: // public boolean isMediaMatchingForDocument(Document document, SACMediaList mediaList);
184: // /** XXX FIXME Get rid of this method, it uses batik classes, which is not acceptable. */
185: // public StyleDeclaration parseStyleDeclarationForElement(Element element, String value);
186: // /** XXX FIXME Get rid of this method, it uses batik classes, which is not acceptable. */
187: // public StyleSheet parseStyleSheetForDocument(Document document, InputSource inputSource, URL uri, String media, Object location);
188: /** XXX FIXME Get rid of this method, it uses batik classes, which is not acceptable. */
189: public StyleSheet parseStyleSheetForDocument(Document document,
190: String rules, URL uri, String media, Object location);
191:
192: /** XXX FIXME Get rid of this method, it uses batik classes, which is not acceptable. */
193: public StyleSheet parseStyleSheetForDocument(Document document,
194: URL uri, String media, Object location);
195:
196: // /** XXX FIXME Get rid of this method, it uses batik classes, which is not acceptable. */
197: // public ValueManager[] getXhtmlValueManagers();
198: // </methods needed to be replaced>
199: ////////////////////////////////////////////////////////////////////////////
200:
201: ////////////////////////////////////////////////////////////////////////////
202: // XXX TODO Move to some other (non engine) interface.
203: // <Non engine methods, might be separated>
204:
205: /** Returns true if the given CSS property for the given element
206: * is set by an inline property setting.
207: * TODO move to some other non css engine interface */
208: public boolean isInlineStyleValue(Element element, int propIndex);
209:
210: // </Non engine methods, might be separated>
211: ////////////////////////////////////////////////////////////////////////////
212:
213: ////////////////////////////////////////////////////////////////////////////
214: // XXX Some utility methods used probably in DOMInspector only
215: // TODO Revise what to do with them
216: // <dominspector?>
217: public String getAllStylesForElement(Element element);
218:
219: public String getAllComputedStylesForElement(Element element);
220:
221: public String getAllRulesForElement(Element element);
222:
223: // </dominspector?>
224: ////////////////////////////////////////////////////////////////////////////
225:
226: // XXX Debugging only
227: public void clearEngineStyleLookupCount();
228:
229: public int getEngineStyleLookupCount();
230:
231: // XXX Stylesheet cache
232: public void flushStyleSheetCache();
233:
234: public String[] getCssIdentifiers(String propertyName);
235:
236: public String[] getCssProperties();
237:
238: public void setStyleParentForElement(Element element,
239: Element styleParent);
240:
241: public Element getStyleParentForElement(Element element);
242:
243: /** Gets url strings. */
244: public String[] getStyleResourcesForElement(Element element,
245: String rules, Document doc, URL docUrl, int[] indexesToMatch);
246:
247: /** Gets style resources data. */
248: public ResourceData[] getStyleResourcesForRules(String rules,
249: Document doc, URL docUrl, URL base, int[] indexesToMatch);
250:
251: /** Gets style resources data. */
252: public ResourceData[] getStyleResourcesForUrl(URL url,
253: Document doc, URL docUrl, int[] indexesToMatch);
254:
255: /** Parse the given document, gets the info about syntax errors.
256: * @param document The document to be parsed */
257: public CssSyntaxErrorInfo[] parseCss(
258: javax.swing.text.Document document);
259:
260: /** XXX Interface describing css syntax error.
261: * <p>
262: * <b><font color="red"><em>Important note: Do not provide implementation of this interface, use the service method to access it!</em></font></b>
263: * </p>
264: * @see CssEngineService#parseCss */
265: public interface CssSyntaxErrorInfo {
266: public int getLineNumber();
267:
268: public String getLocalizedMessage();
269: } // End of CssSyntaxErrorInfo.
270: }
|