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.api.insync;
042:
043: import com.sun.rave.designtime.DesignBean;
044: import com.sun.rave.designtime.DesignContext;
045: import com.sun.rave.designtime.DesignEvent;
046: import com.sun.rave.designtime.DesignProject;
047: import com.sun.rave.designtime.DesignProperty;
048: import com.sun.rave.designtime.markup.MarkupDesignBean;
049: import com.sun.rave.designtime.markup.MarkupMouseRegion;
050: import java.net.URL;
051: import java.util.List;
052: import org.netbeans.api.project.Project;
053: import org.openide.filesystems.FileObject;
054: import org.openide.loaders.DataObject;
055: import org.openide.util.Lookup;
056: import org.w3c.dom.Document;
057: import org.w3c.dom.DocumentFragment;
058: import org.w3c.dom.Element;
059: import org.w3c.dom.Node;
060:
061: /**
062: * <p>
063: * This abstract class exposes services the InSync Source modeller can perform.
064: * The InSync implementation will register an implementation of this interface
065: * in the system file system, so using org.openide.util.Lookup on
066: * InSyncService.class you'll get an instance you can call these
067: * methods on.
068: * </p>
069: *
070: * @author Eric Arseneau
071: */
072: public abstract class InSyncService {
073:
074: // /** Insync extention of MutationEventImpl type (see insyc/MarkupUnit and xerces/MuationEventImpl). */
075: // public static final String DOM_DOCUMENT_REPLACED = "DOMDocumentReplaced"; // NOI18N
076:
077: /** Obtain a default provider of the InSyncService */
078: public static InSyncService getProvider() {
079: return (InSyncService) Lookup.getDefault().lookup(
080: InSyncService.class);
081: }
082:
083: public InSyncService() {
084: }
085:
086: public abstract String getBeanNameForJsp(FileObject fileObject);
087:
088: /**
089: * This is a hack until we get things done correctly with integration of Retouche.
090: * Should only be called from JsfJspDataObject to notify us that toDataObject was created by copying fromDataObject.
091: * Go through and rename the EL expression references to the original page name to the new page name.
092: *
093: * This is NOT the way to fix the problem of copy, however there are too many other issues that get in the way
094: * that prevent us from creating a simple fix that will yield the same results. Since ALL of this code will change
095: * when we properly integrate insync into platform, this is throw away code.
096: *
097: * TODO: Remove
098: *
099: * @param fromDataObject
100: * @param toDataObject
101: */
102: public abstract void copied(JsfJspDataObjectMarker fromDataObject,
103: JsfJspDataObjectMarker toDataObject);
104:
105: /**
106: * Execute the runnable outside of a refactoring Session, this allows most of the refactoring processing
107: * to have occured by the time this runnable will get run.
108: *
109: * @param runnable
110: */
111: public abstract void doOutsideOfRefactoringSession(Runnable runnable);
112:
113: // XXX Hacks, to the top component events. Get rid of them, when
114: // there will be able to parse the files on demand. In any case
115: // the SourceMonitor should be in insync.
116: /** Called when jsp data object TopComponent was activated. */
117: public abstract void jspDataObjectTopComponentActivated(
118: DataObject dobj);
119:
120: /** Called when jsp data object TopComponent was hidden. */
121: public abstract void jspDataObjectTopComponentHidden(DataObject dobj);
122:
123: /** Called when jsp data object TopComponent was shown. */
124: public abstract void jspDataObjectTopComponentShown(DataObject dobj);
125:
126: // <missing_designtime_api> These methods point out missing design time api,
127: // XXX Be aware that not exactly in this form the api is needed, the methods
128: // can by factored out to diff api, important is to satisfy the funcitonality need!
129: // For example there might be provided bean for document, and then the rest for the bean.
130:
131: // <markup_separation> XXX Suspicious API which needs to be revisited,
132: // it comes from the original impl of RaveDocument and etc. markup packages.
133: // TODO Get rid of it, these methods point out the architecural flaws.
134: public abstract void appendParsedString(Document doc, Node node,
135: String xhtml, MarkupDesignBean bean);
136:
137: public abstract FileObject getFileObject(Document doc);
138:
139: public abstract int computeLine(Document document, Element element);
140:
141: public abstract URL getDocumentUrl(Document doc);
142:
143: // </markup_separation>
144:
145: public abstract void setUrl(Document doc, URL url);
146:
147: public abstract URL getUrl(Document doc);
148:
149: // JSF Rendering
150: // public abstract DocumentFragment renderHtml(FileObject markupFile, MarkupDesignBean bean);
151: // public abstract Exception getRenderFailure(FileObject markupFile);
152: // public abstract DesignBean getRenderFailureComponent(FileObject markupFile);
153:
154: // <separation of models>
155: // public abstract Document getJspDomForMarkupFile(FileObject markupFile);
156: // public abstract Document getHtmlDomForMarkupFile(FileObject markupFile);
157: // public abstract DocumentFragment getHtmlDomFragmentForMarkupFile(FileObject markupFile);
158: public abstract Element getHtmlBodyForMarkupFile(
159: FileObject markupFile);
160:
161: // XXX Refresh antipatern.
162: // public abstract void clearHtmlForMarkupFile(FileObject markupFile);
163:
164: // // XXX FIXME It is used only in dnd handling (outside of insync) which shouldn't be there.
165: // public abstract boolean isBraveheartPage(Document dom);
166: // public abstract boolean isWoodstockPage(Document dom);
167:
168: // </separation of models>
169: public abstract DocumentFragment getHtmlDomFragmentForDocument(
170: Document document);
171:
172: // </missing_designtime_api>
173:
174: // <error_handling>
175: // XXX It is not clear whether this should be here or at other more suitable place,
176: // anyway, it is good to have these methods together represented by one interface.
177: public abstract RaveErrorHandler getRaveErrorHandler();
178:
179: public interface RaveErrorHandler {
180: /** Clears document related errors.
181: * @param delayed When set, don't actually clear the errors right now;
182: * it clears the errors next time another error is added. */
183: public void clearErrors(boolean delayed);
184:
185: /** Cause the panel/window within which errors are displayed to come to the front if possible. */
186: public void selectErrors();
187:
188: public void displayError(String message);
189:
190: public void displayErrorForLocation(String message,
191: Object location, int line, int column);
192:
193: public void displayErrorForFileObject(String message,
194: FileObject fileObject, int line, int column);
195: } // End of RaveErrorHandler.
196: // </error_handling>
197:
198: // <service methods>
199: /** Convert the given URL to a path: decode spaces from %20's, etc.
200: * If the url does not begin with "file:" it will not do anything.
201: * @todo Find a better home for this method */
202: public abstract String fromURL(String url);
203:
204: // public abstract Element getCorrespondingSourceElement(Element elem);
205: /** Given a general location object provided from the CSS parser,
206: * compute the correct file name to use. */
207: public abstract String computeFileName(Object location);
208:
209: public abstract int computeLineNumber(Object location, int line);
210:
211: // </service methods>
212:
213: public abstract void copyMarkupMouseRegionForElement(
214: Element fromElement, Element toElement);
215:
216: public abstract MarkupMouseRegion getMarkupMouseRegionForElement(
217: Element element);
218:
219: public abstract void copyMarkupDesignBeanForElement(
220: Element fromElement, Element toElement);
221:
222: public abstract MarkupDesignBean getMarkupDesignBeanForElement(
223: Element element);
224:
225: public abstract void setMarkupDesignBeanForElement(Element element,
226: MarkupDesignBean markupDesignBean);
227:
228: /** Generate the html string from the given node. This will return
229: * an empty string unless the Node is an Element or a DocumentFragment
230: * or a Document. */
231: public abstract String getHtmlStream(Node node);
232:
233: /** Generate the html string from the given element */
234: public abstract String getHtmlStream(Element element);
235:
236: /** Generate the html string from the given document. Does formatting. */
237: public abstract String getHtmlStream(Document document);
238:
239: /** Generate the html string from the given document fragment */
240: public abstract String getHtmlStream(DocumentFragment df);
241:
242: // <from designer-service>
243: // /**
244: // * Return true iff the given file object represents a webform primary file
245: // * (e.g. jsp, etc.)
246: // */
247: // public abstract boolean isWebPage(FileObject fo);
248: /**
249: * Return a List of web pages in the project
250: * @param includePages Iff true, include non-fragment pages in the list
251: * @param includeFragments Iff true, include page fragments in the list
252: * @return A List containing FileObject entries for WebForms in the project
253: */
254: public abstract List getWebPages(Project project,
255: boolean includePages, boolean includeFragments);
256:
257: // /**
258: // * Return an array of String mime types for mime types considered to be webforms
259: // * the designer will edit (and insync will provide models for etc.)
260: // */
261: // public abstract String[] getMimeTypes();
262:
263: /**
264: * <p>
265: * Resolve the given url (which can be relative, context relative or
266: * absolute) to an absolute file URL. For example, let's say you have
267: * a document "/tmp/foo.jsp" which references a stylesheet in "/tmp/css/bar.css"
268: * and in this stylesheet you have a url "baz.png".
269: * In this case the parameters to this method would have "base" pointing to the
270: * css file, the url string would be the png filename, and the document reference
271: * would point to the including jsp document.
272: * </p>
273: * The algorithm used by this method is as follows:
274: * <ul>
275: * <li> If the url string represents its own URL (e.g. starts with a protocol)
276: * then the URL returned is the resulting full URL. </li>
277: * <li> Otherwise, if the url string does NOT start with "/", then a URL is
278: * formed by appending it to the base URL passed in
279: * <li> Otherwise, this is a context relative URL (because it begins with "/")
280: * and the base URL is computed by finding the project associated with
281: * the document parameter, and from the document the WEB root is located.
282: * This is taken as the base and the URL is computed as above.
283: * </ul>
284: *
285: * @param base The URL of the referrer, which the url string will be taken
286: * to be relative to, unless it is an "absolute" (context relative) string,
287: * such as "/resources". In that case it will look up the project associated
288: * with the given document and find its context root from there.
289: * @param document A document related (more distantly than the base) to the
290: * url reference.
291: * @param url A string which represents a relative URL, or a context url, or
292: * even a complete url on its own (http://www.sun.com/jscreator).
293: */
294: public abstract URL resolveUrl(URL base, Document document,
295: String url);
296:
297: // <from designer-service>
298:
299: // XXX used in xhtml
300: // xhtml/TableDesignInfo
301: /** Just a marker interface representing the write lock. */
302: public interface WriteLock {
303: }
304:
305: public abstract WriteLock writeLockContext(
306: DesignContext designContext, String message);
307:
308: public abstract void writeUnlockContext(
309: DesignContext designContext, WriteLock lock);
310:
311: public abstract void addLocalStyleValueForElement(Element element,
312: int style, String value);
313:
314: public abstract void removeLocalStyleValueForElement(
315: Element element, int style);
316:
317: // xhtml/FragmentPanel
318: public abstract Project getProjectForDesignProject(
319: DesignProject designProject);
320:
321: public abstract FileObject getMarkupFileObjectForDesignContext(
322: DesignContext designContext);
323:
324: /** XXX Very suspicious, try to get rid of it. */
325: public abstract void initModelsForWebformFile(Project project,
326: FileObject webformFile);
327:
328: // XXX html entities
329: public abstract String expandHtmlEntities(String html,
330: boolean warn, Node node);
331:
332: public abstract int getExpandedOffset(String unexpanded,
333: int unexpandedOffset);
334:
335: public abstract int getUnexpandedOffset(String unexpanded,
336: int expandedOffset);
337:
338: // Thread.currentThread().getContextClassLoader() stuff
339: public abstract ClassLoader getContextClassLoader(
340: DesignContext designContext);
341:
342: public abstract ClassLoader getContextClassLoader(
343: DesignBean designBean);
344:
345: public abstract ClassLoader getContextClassLoader(
346: DesignProperty designProperty);
347:
348: public abstract ClassLoader getContextClassLoader(
349: DesignEvent designEvent);
350: }
|