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.markup;
043:
044: import org.netbeans.modules.visualweb.designer.markup.MarkupServiceImpl;
045: import javax.xml.parsers.DocumentBuilder;
046: import javax.xml.parsers.ParserConfigurationException;
047: import org.w3c.dom.Document;
048: import org.w3c.dom.DocumentFragment;
049: import org.w3c.dom.Element;
050: import org.w3c.dom.Node;
051: import org.w3c.dom.Text;
052:
053: /**
054: * <code>MarkupService</code> implementation.
055: *
056: * @author Peter Zavadsky
057: */
058: public final class MarkupService {
059:
060: private MarkupService() {
061: }
062:
063: // public static String expandHtmlEntities(String html) {
064: // return expandHtmlEntities(html, true, null);
065: // }
066: //
067: // public static String expandHtmlEntities(String html, boolean warn) {
068: // return expandHtmlEntities(html, warn, null);
069: // }
070: //
071: // public static String expandHtmlEntities(String html, boolean warn, Node node) {
072: // return MarkupServiceImpl.expandHtmlEntities(html, warn, node);
073: // }
074: //
075: // public static int getUnexpandedOffset(String unexpanded, int expandedOffset) {
076: // return MarkupServiceImpl.getUnexpandedOffset(unexpanded, expandedOffset);
077: // }
078: //
079: // public static int getExpandedOffset(String unexpanded, int unexpandedOffset) {
080: // return MarkupServiceImpl.getExpandedOffset(unexpanded, unexpandedOffset);
081: // }
082:
083: // // <utilities methods>
084: // public static URL getCascadedXMLBase(Element elt) {
085: // return MarkupServiceImpl.getCascadedXMLBase(elt);
086: // }
087:
088: // // XXX From org.netbeans.modules.visualweb.insync.Util.
089: // /**
090: // * Given an element which may be in a rendered DocumentFragment, return the corresponding JSF
091: // * element in the source.
092: // */
093: // public static Element getCorrespondingSourceElement(Element element) {
094: // return MarkupServiceImpl.getCorrespondingSourceElement(element);
095: // }
096:
097: // <markup_separation> copied from insync/Util
098: // XXX This should be separate utility api, openide extension or what.
099: // /**
100: // * Show the given line in a particular file.
101: // *
102: // * @param filename The full path to the file
103: // * @param lineno The line number
104: // * @param openFirst Usually you'll want to pass false. When set to true, this will first open
105: // * the file, then request the given line number; this works around certain bugs for
106: // * some editor types like CSS files.
107: // */
108: // public static void show(String filename, int lineno, int column, boolean openFirst) {
109: // MarkupServiceImpl.show(filename, lineno, column, openFirst);
110: // }
111: //
112: // /**
113: // * Show the given line in a particular file.
114: // *
115: // * @param fileObject The FileObject for the file
116: // * @param lineno The line number
117: // * @param openFirst Usually you'll want to pass false. When set to true, this will first open
118: // * the file, then request the given line number; this works around certain bugs for
119: // * some editor types like CSS files.
120: // */
121: // public static void show(FileObject fileObject, int lineno, int column, boolean openFirst) {
122: // MarkupServiceImpl.show(fileObject, lineno, column, openFirst);
123: // }
124:
125: // // <markup_separation> moved from insync/MarkupUnit
126: // /** Convert the given URL to a path: decode spaces from %20's, etc.
127: // * If the url does not begin with "file:" it will not do anything.
128: // * @todo Find a better home for this method
129: // */
130: // public static String fromURL(String url) {
131: // return MarkupServiceImpl.fromURL(url);
132: // }
133: // // </markup_separation>
134:
135: //// <error_handling> Moved from RaveDocument.
136: //// XXX These methods are suspicoius, they deal with openide output window.
137: // // and there may not be any knowing about it from this impls.
138: // /** Clear document related errors.
139: // * @param delayed When set, don't actually clear the errors right now;
140: // * it clears the errors next time another error is added. */
141: // public static void clearErrors(boolean delayed) {
142: // MarkupServiceImpl.clearErrors(delayed);
143: // }
144: //
145: //// /**
146: //// * Display the given error message to the user. The optional listener argument
147: //// * (pass in null if not applicable) will make the line hyperlinked and the
148: //// * listener is invoked to process any user clicks.
149: //// * @param message The string to be displayed to the user
150: //// * @param listener null, or a listener to be notified when the user clicks
151: //// * the linked message
152: //// */
153: //// public static void displayError(String message, OutputListener listener) {
154: //// MarkupServiceImpl.displayError(message, listener);
155: //// }
156: //
157: // /**
158: // * Cause the panel/window within which errors are displayed to come to the front if possible.
159: // *
160: // */
161: // public static void selectErrors() {
162: // MarkupServiceImpl.selectErrors();
163: // }
164: //
165: // public static void displayError(String message) {
166: // MarkupServiceImpl.displayError(message);
167: // }
168: //
169: // public static void displayErrorForLocation(String message, Object location, int line, int column) {
170: // MarkupServiceImpl.displayErrorForLocation(message, location, line, column);
171: // }
172: //
173: // public static void displayErrorForFileObject(String message, FileObject fileObject, int line, int column) {
174: // MarkupServiceImpl.displayErrorForFileObject(message, fileObject, line, column);
175: // }
176: //
177: // /** Given a general location object provided from the CSS parser,
178: // * compute the correct file name to use. */
179: // public static String computeFilename(Object location) {
180: // return MarkupServiceImpl.computeFilename(location);
181: // }
182: // /** Given a general location object provided from the CSS parser,
183: // * compute the correct line number to use. */
184: // public static int computeLineNumber(Object location, int line) {
185: // return MarkupServiceImpl.computeLineNumber(location, line);
186: // }
187: //// </error_handling>
188:
189: // // XXX Moved from DesignerService.
190: // /**
191: // * Return an InputStream for the given CSS URI, if the corresponding CSS
192: // * file is open and edited. Otherwise return null.
193: // *
194: // * @param uri The URI to the CSS file. <b>MUST</b> be an absolute file url!
195: // * @return An InputStream for the live edited CSS
196: // */
197: // public static InputStream getOpenCssStream(String uriString) {
198: // return MarkupServiceImpl.getOpenCssStream(uriString);
199: // }
200: // // </utilities methods>
201:
202: // /**
203: // * Generate the html string from the given node. This will return
204: // * an empty string unless the Node is an Element or a DocumentFragment
205: // * or a Document.
206: // */
207: // public static String getHtmlStream(Node node) {
208: // return MarkupServiceImpl.getHtmlStream(node);
209: // }
210: //
211: // /** Generate the html string from the given element */
212: // public static String getHtmlStream(Element element) {
213: // return MarkupServiceImpl.getHtmlStream(element);
214: // }
215: //
216: // /** Generate the html string from the given document. Does formatting. */
217: // public static String getHtmlStream(Document document) {
218: // return MarkupServiceImpl.getHtmlStream(document);
219: // }
220: //
221: // /** Generate the html string from the given document fragment */
222: // public static String getHtmlStream(DocumentFragment df) {
223: // return MarkupServiceImpl.getHtmlStream(df);
224: // }
225:
226: public static DocumentBuilder createRaveSourceDocumentBuilder(
227: boolean useCss) throws ParserConfigurationException {
228: return MarkupServiceImpl
229: .createRaveSourceDocumentBuilder(useCss);
230: }
231:
232: public static DocumentBuilder createRaveRenderedDocumentBuilder(
233: boolean useCss) throws ParserConfigurationException {
234: return MarkupServiceImpl
235: .createRaveRenderedDocumentBuilder(useCss);
236: }
237:
238: public static void markRendered(Node src, Node dst) {
239: MarkupServiceImpl.markRendered(src, dst);
240: }
241:
242: /** Mark all nodes in a node tree as rendered HTML nodes, and point back to the
243: * source nodes in the JSP DOM. For nodes that all point to the same source
244: * node I want only the topmost nodes to point to the source.
245: */
246: public static void markRenderedNodes(Node node) {
247: MarkupServiceImpl.markRenderedNodes(null, node);
248: }
249:
250: /** Recursively mark all text nodes in the given node subtree as
251: * being jspx nodes
252: */
253: public static void markJspxSource(Node node) {
254: MarkupServiceImpl.markJspxSource(node);
255: }
256:
257: public static void setInputEncodingForDocument(Document document,
258: String inputEncoding) {
259: MarkupServiceImpl.setInputEncodingForDocument(document,
260: inputEncoding);
261: }
262:
263: /** Get the text or comment text children of this element, which
264: * should correspond to style rules.
265: */
266: public static String getStyleText(Element element) {
267: return MarkupServiceImpl.getStyleText(element);
268: }
269:
270: /**
271: * Given an element which may be in a rendered DocumentFragment, return the corresponding JSF
272: * element in the source.
273: */
274: public static Element getCorrespondingSourceElement(Element element) {
275: return MarkupServiceImpl.getCorrespondingSourceElement(element);
276: }
277:
278: // public static boolean isRenderedNode(Node node) {
279: // return MarkupServiceImpl.isRenderedNode(node);
280: // }
281:
282: public static Node getRenderedNodeForNode(Node node) {
283: return MarkupServiceImpl.getRenderedNodeForNode(node);
284: }
285:
286: public static Node getSourceNodeForNode(Node node) {
287: return MarkupServiceImpl.getSourceNodeForNode(node);
288: }
289:
290: /** XXX Get rid of this, it seems only RaveText uses it. */
291: public static boolean isJspxNode(Node node) {
292: return MarkupServiceImpl.isJspxNode(node);
293: }
294:
295: public static void setJspxNode(Node node, boolean jspx) {
296: MarkupServiceImpl.setJspxNode(node, jspx);
297: }
298:
299: public static Element getRenderedElementForElement(Element element) {
300: return MarkupServiceImpl.getRenderedElementForElement(element);
301: }
302:
303: public static void setRenderedElementForElement(Element element,
304: Element renderedElement) {
305: MarkupServiceImpl.setRenderedElementForElement(element,
306: renderedElement);
307: }
308:
309: public static Element getSourceElementForElement(Element element) {
310: return MarkupServiceImpl.getSourceElementForElement(element);
311: }
312:
313: public static Text getRenderedTextForText(Text text) {
314: return MarkupServiceImpl.getRenderedTextForText(text);
315: }
316:
317: public static Text getSourceTextForText(Text text) {
318: return MarkupServiceImpl.getSourceTextForText(text);
319: }
320:
321: public static void setSourceTextForText(Text text, Text sourceText) {
322: MarkupServiceImpl.setSourceTextForText(text, sourceText);
323: }
324:
325: public static Element getTBodyElementForTableElement(
326: Element tableElement) {
327: return MarkupServiceImpl
328: .getTBodyElementForTableElement(tableElement);
329: }
330: }
|