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-2008 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.url;
043:
044: import java.io.IOException;
045: import org.netbeans.spi.queries.FileEncodingQueryImplementation;
046: import org.openide.filesystems.FileObject;
047: import org.openide.loaders.DataObjectExistsException;
048: import org.openide.loaders.ExtensionList;
049: import org.openide.loaders.MultiDataObject;
050: import org.openide.loaders.UniFileLoader;
051: import org.openide.util.NbBundle;
052:
053: /**
054: * Data loader which recognizes URL files.
055: *
056: * @author Ian Formanek
057: */
058: public class URLDataLoader extends UniFileLoader {
059:
060: /** Generated serial version UID. */
061: static final long serialVersionUID = -7407252842873642582L;
062: /** MIME-type of URL files */
063: private static final String URL_MIME_TYPE = "text/url"; //NOI18N
064: /** */
065: private static final String PROP_ENCODING_QUERY_IMPL = "org.netbeans.modules.url.encoding"; //NOI18N
066:
067: /** Creates a new URLDataLoader without the extension. */
068: public URLDataLoader() {
069: super ("org.netbeans.modules.url.URLDataObject"); //NOI18N
070: }
071:
072: /**
073: * Returns an instance of {@code FileEncodingQueryImplementation}
074: * representing encoding to be used by {@code URLDataObject}s.
075: *
076: * @return an instance of {@code FileEncodingQueryImplementation},
077: * or {@code null} if encoding UTF-8 is not supported
078: */
079: FileEncodingQueryImplementation getEncoding() {
080: return (FileEncodingQueryImplementation) getProperty(PROP_ENCODING_QUERY_IMPL);
081: }
082:
083: /**
084: * Initializes this loader. This method is called only once the first time
085: * this loader is used (not for each instance).
086: */
087: @Override
088: protected void initialize() {
089: super .initialize();
090:
091: ExtensionList ext = new ExtensionList();
092: ext.addMimeType(URL_MIME_TYPE);
093: ext.addMimeType("text/x-url"); //NOI18N
094: setExtensions(ext);
095:
096: try {
097: putProperty(PROP_ENCODING_QUERY_IMPL,
098: new EncodingQueryImpl());
099: } catch (IllegalArgumentException ex) {
100: assert false; //this should not happen
101: /* UTF-8 is not supported - use the project's default encoding */
102: }
103: }
104:
105: /** */
106: @Override
107: protected String defaultDisplayName() {
108: return NbBundle.getMessage(URLDataLoader.class,
109: "PROP_URLLoader_Name"); //NOI18N
110: }
111:
112: /**
113: * This methods uses the layer action context so it returns
114: * a non-<code>null</code> value.
115: *
116: * @return name of the context on layer files to read/write actions to
117: */
118: @Override
119: protected String actionsContext() {
120: return "Loaders/text/url/Actions/"; //NOI18N
121: }
122:
123: /**
124: * @return <code>URLDataObject</code> for the specified file
125: */
126: protected MultiDataObject createMultiObject(FileObject primaryFile)
127: throws DataObjectExistsException, IOException {
128: return new URLDataObject(primaryFile, this);
129: }
130:
131: }
|