Index: EncodingQueryImpl.java =================================================================== RCS file: EncodingQueryImpl.java diff -N EncodingQueryImpl.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ EncodingQueryImpl.java 16 Jan 2008 14:03:47 -0000 @@ -0,0 +1,65 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + * + * Portions Copyrighted 2008 Sun Microsystems, Inc. + */ + +package org.netbeans.modules.url; + +import java.nio.charset.Charset; +import org.netbeans.spi.queries.FileEncodingQueryImplementation; +import org.openide.filesystems.FileObject; + +/** + * Implementation of {@code FileEncodingQueryImplementation} that returns + * encoding UTF-8 for every file. + * + * @author Marian Petras + */ +final class EncodingQueryImpl extends FileEncodingQueryImplementation { + + private final Charset charsetUtf8; + + EncodingQueryImpl() { + charsetUtf8 = Charset.forName("UTF-8"); //NOI18N + } + + @Override + public Charset getEncoding(FileObject file) { + return charsetUtf8; + } + +} Index: URLDataLoader.java =================================================================== RCS file: /cvs/utilities/src/org/netbeans/modules/url/URLDataLoader.java,v retrieving revision 1.25 diff -u -r1.25 URLDataLoader.java --- URLDataLoader.java 10 Jan 2008 11:26:43 -0000 1.25 +++ URLDataLoader.java 16 Jan 2008 14:03:47 -0000 @@ -24,7 +24,7 @@ * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL @@ -42,6 +42,7 @@ package org.netbeans.modules.url; import java.io.IOException; +import org.netbeans.spi.queries.FileEncodingQueryImplementation; import org.openide.filesystems.FileObject; import org.openide.loaders.DataObjectExistsException; import org.openide.loaders.ExtensionList; @@ -60,6 +61,9 @@ static final long serialVersionUID =-7407252842873642582L; /** MIME-type of URL files */ private static final String URL_MIME_TYPE = "text/url"; //NOI18N + /** */ + private static final String PROP_ENCODING_QUERY_IMPL + = "org.netbeans.modules.url.encoding"; //NOI18N /** Creates a new URLDataLoader without the extension. */ @@ -67,6 +71,17 @@ super("org.netbeans.modules.url.URLDataObject"); //NOI18N } + /** + * Returns an instance of {@code FileEncodingQueryImplementation} + * representing encoding to be used by {@code URLDataObject}s. + * + * @return an instance of {@code FileEncodingQueryImplementation}, + * or {@code null} if encoding UTF-8 is not supported + */ + FileEncodingQueryImplementation getEncoding() { + return (FileEncodingQueryImplementation) + getProperty(PROP_ENCODING_QUERY_IMPL); + } /** * Initializes this loader. This method is called only once the first time @@ -80,6 +95,13 @@ ext.addMimeType(URL_MIME_TYPE); ext.addMimeType("text/x-url"); //NOI18N setExtensions(ext); + + try { + putProperty(PROP_ENCODING_QUERY_IMPL, new EncodingQueryImpl()); + } catch (IllegalArgumentException ex) { + assert false; //this should not happen + /* UTF-8 is not supported - use the project's default encoding */ + } } /** */ Index: URLDataObject.java =================================================================== RCS file: /cvs/utilities/src/org/netbeans/modules/url/URLDataObject.java,v retrieving revision 1.44 diff -u -r1.44 URLDataObject.java --- URLDataObject.java 10 Jan 2008 11:22:13 -0000 1.44 +++ URLDataObject.java 16 Jan 2008 14:03:47 -0000 @@ -24,7 +24,7 @@ * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun * Microsystems, Inc. All Rights Reserved. * * If you wish your version of this file to be governed by only the CDDL @@ -51,6 +51,7 @@ import java.io.OutputStream; import java.net.MalformedURLException; import java.net.URL; +import org.netbeans.spi.queries.FileEncodingQueryImplementation; import org.openide.DialogDisplayer; import org.openide.cookies.InstanceCookie; import org.openide.cookies.OpenCookie; @@ -62,7 +63,9 @@ import org.openide.NotifyDescriptor; import org.openide.ErrorManager; import org.openide.util.HelpCtx; +import org.openide.util.Lookup; import org.openide.util.NbBundle; +import org.openide.util.lookup.Lookups; /** Data object that represents one bookmark, one .url file containing url. @@ -78,8 +81,10 @@ /** Generated serial version UID. */ static final long serialVersionUID = 6829522922370124627L; - + /** */ + private Lookup lookup; + /** * Constructs a new URL data object. * @@ -91,6 +96,18 @@ throws DataObjectExistsException { super(file, loader); getCookieSet().add(this); + } + + @Override + public Lookup getLookup() { + if (lookup == null) { + FileEncodingQueryImplementation encodingImpl + = ((URLDataLoader) getLoader()).getEncoding(); + lookup = (encodingImpl != null) + ? Lookups.fixed(this, encodingImpl) + : Lookups.singleton(this); + } + return lookup; } /*