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-2006 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.xsl;
042:
043: import org.xml.sax.InputSource;
044: import javax.xml.transform.Source;
045: import org.openide.loaders.*;
046: import org.openide.filesystems.FileObject;
047: import org.openide.util.HelpCtx;
048: import org.openide.nodes.Node;
049: import org.openide.nodes.Children;
050: import org.openide.nodes.CookieSet;
051: import org.openide.util.Lookup;
052: import org.openide.util.lookup.Lookups;
053: import org.netbeans.spi.xml.cookies.*;
054: import org.netbeans.modules.xml.XMLDataObjectLook;
055: import org.netbeans.modules.xml.text.TextEditorSupport;
056: import org.netbeans.modules.xml.sync.*;
057: import org.netbeans.modules.xml.cookies.*;
058: import org.netbeans.modules.xml.api.XmlFileEncodingQueryImpl;
059: import org.netbeans.modules.xml.text.syntax.XMLKit;
060: import org.netbeans.modules.xsl.cookies.ValidateXSLSupport;
061: import org.openide.util.NbBundle;
062:
063: /**
064: * XSL owner.
065: *
066: * @author Libor Kramolis
067: * @author asgeir@dimonsoftware.com
068: */
069: public final class XSLDataObject extends MultiDataObject implements
070: XMLDataObjectLook {
071: /** Serial Version UID */
072: private static final long serialVersionUID = -3523066651187749549L;
073: /** XSLT Mime Type. */
074: public static final String MIME_TYPE = "application/xslt+xml"; // NOI18N
075: private static final String XSL_ICON_BASE = "org/netbeans/modules/xsl/resources/xslObject"; // NOI18N
076: private transient final DataObjectCookieManager cookieManager;
077: private transient Synchronizator synchronizator;
078:
079: public XSLDataObject(final FileObject obj,
080: final UniFileLoader loader)
081: throws DataObjectExistsException {
082: super (obj, loader);
083:
084: CookieSet set = getCookieSet();
085: cookieManager = new DataObjectCookieManager(this , set);
086: set.add(cookieManager);
087:
088: // add check and validate cookies
089: InputSource is = DataObjectAdapters.inputSource(this );
090: set.add(new CheckXMLSupport(is));
091: set.add(new ValidateXSLSupport(is));
092:
093: // add TransformableCookie
094: Source source = DataObjectAdapters.source(this );
095: set.add(new TransformableSupport(source));
096:
097: // editor support defines MIME type understood by EditorKits registry
098: TextEditorSupport.TextEditorSupportFactory editorFactory = new TextEditorSupport.TextEditorSupportFactory(
099: this , XMLKit.MIME_TYPE);
100: editorFactory.registerCookies(set);
101:
102: }
103:
104: public final Lookup getLookup() {
105: return Lookups.fixed(new Object[] { super .getLookup(), this ,
106: XmlFileEncodingQueryImpl.singleton() });
107: }
108:
109: /**
110: */
111: protected Node createNodeDelegate() {
112: return new XSLDataNode(this );
113: }
114:
115: /**
116: */
117: public HelpCtx getHelpCtx() {
118: //return new HelpCtx (XSLDataObject.class);
119: return HelpCtx.DEFAULT_HELP;
120: }
121:
122: // XMLDataObjectLook to be deprecated ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123:
124: public DataObjectCookieManager getCookieManager() {
125: return cookieManager;
126: }
127:
128: public synchronized Synchronizator getSyncInterface() {
129: if (synchronizator == null) {
130: synchronizator = new DataObjectSyncSupport(
131: XSLDataObject.this );
132: }
133: return synchronizator;
134: }
135:
136: /**
137: * Redefine icon and help.
138: */
139: private static class XSLDataNode extends DataNode {
140:
141: /** Create new XSLDataNode. */
142: public XSLDataNode(XSLDataObject obj) {
143: super (obj, Children.LEAF);
144: setIconBase(XSL_ICON_BASE);
145: setShortDescription(NbBundle.getMessage(
146: XSLDataObject.class, "PROP_XSLDataNode_desc"));
147: }
148:
149: /**
150: */
151: public HelpCtx getHelpCtx() {
152: //return new HelpCtx (XSLDataObject.class);
153: return HelpCtx.DEFAULT_HELP;
154: }
155:
156: }
157:
158: }
|