This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 123115
Collapse All | Expand All

(-)EncodingQueryImpl.java (+65 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5
 * 
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 * 
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 * 
35
 * Contributor(s):
36
 * 
37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
38
 */
39
40
package org.netbeans.modules.url;
41
42
import java.nio.charset.Charset;
43
import org.netbeans.spi.queries.FileEncodingQueryImplementation;
44
import org.openide.filesystems.FileObject;
45
46
/**
47
 * Implementation of {@code FileEncodingQueryImplementation} that returns
48
 * encoding UTF-8 for every file.
49
 *
50
 * @author  Marian Petras
51
 */
52
final class EncodingQueryImpl extends FileEncodingQueryImplementation {
53
54
    private final Charset charsetUtf8;
55
56
    EncodingQueryImpl() {
57
        charsetUtf8 = Charset.forName("UTF-8");                         //NOI18N
58
    }
59
60
    @Override
61
    public Charset getEncoding(FileObject file) {
62
        return charsetUtf8;
63
    }
64
65
}
(-)URLDataLoader.java (-1 / +23 lines)
Lines 24-30 Link Here
24
 * Contributor(s):
24
 * Contributor(s):
25
 *
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
28
 * Microsystems, Inc. All Rights Reserved.
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
30
 * If you wish your version of this file to be governed by only the CDDL
Lines 42-47 Link Here
42
package org.netbeans.modules.url;
42
package org.netbeans.modules.url;
43
43
44
import java.io.IOException;
44
import java.io.IOException;
45
import org.netbeans.spi.queries.FileEncodingQueryImplementation;
45
import org.openide.filesystems.FileObject;
46
import org.openide.filesystems.FileObject;
46
import org.openide.loaders.DataObjectExistsException;
47
import org.openide.loaders.DataObjectExistsException;
47
import org.openide.loaders.ExtensionList;
48
import org.openide.loaders.ExtensionList;
Lines 60-65 Link Here
60
    static final long serialVersionUID =-7407252842873642582L;
61
    static final long serialVersionUID =-7407252842873642582L;
61
    /** MIME-type of URL files */
62
    /** MIME-type of URL files */
62
    private static final String URL_MIME_TYPE = "text/url";             //NOI18N
63
    private static final String URL_MIME_TYPE = "text/url";             //NOI18N
64
    /** */
65
    private static final String PROP_ENCODING_QUERY_IMPL
66
                                = "org.netbeans.modules.url.encoding";  //NOI18N
63
    
67
    
64
    
68
    
65
    /** Creates a new URLDataLoader without the extension. */
69
    /** Creates a new URLDataLoader without the extension. */
Lines 67-72 Link Here
67
        super("org.netbeans.modules.url.URLDataObject");                //NOI18N
71
        super("org.netbeans.modules.url.URLDataObject");                //NOI18N
68
    }
72
    }
69
73
74
    /**
75
     * Returns an instance of {@code FileEncodingQueryImplementation}
76
     * representing encoding to be used by {@code URLDataObject}s.
77
     * 
78
     * @return  an instance of {@code FileEncodingQueryImplementation},
79
     *          or {@code null} if encoding UTF-8 is not supported
80
     */
81
    FileEncodingQueryImplementation getEncoding() {
82
        return (FileEncodingQueryImplementation)
83
               getProperty(PROP_ENCODING_QUERY_IMPL);
84
    }
70
    
85
    
71
    /**
86
    /**
72
     * Initializes this loader. This method is called only once the first time
87
     * Initializes this loader. This method is called only once the first time
Lines 80-85 Link Here
80
        ext.addMimeType(URL_MIME_TYPE);
95
        ext.addMimeType(URL_MIME_TYPE);
81
        ext.addMimeType("text/x-url");                                  //NOI18N
96
        ext.addMimeType("text/x-url");                                  //NOI18N
82
        setExtensions(ext);
97
        setExtensions(ext);
98
99
        try {
100
            putProperty(PROP_ENCODING_QUERY_IMPL, new EncodingQueryImpl());
101
        } catch (IllegalArgumentException ex) {
102
            assert false;   //this should not happen
103
            /* UTF-8 is not supported - use the project's default encoding */
104
        }
83
    }
105
    }
84
106
85
    /** */
107
    /** */
(-)URLDataObject.java (-2 / +19 lines)
Lines 24-30 Link Here
24
 * Contributor(s):
24
 * Contributor(s):
25
 *
25
 *
26
 * The Original Software is NetBeans. The Initial Developer of the Original
26
 * The Original Software is NetBeans. The Initial Developer of the Original
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
27
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
28
 * Microsystems, Inc. All Rights Reserved.
28
 * Microsystems, Inc. All Rights Reserved.
29
 *
29
 *
30
 * If you wish your version of this file to be governed by only the CDDL
30
 * If you wish your version of this file to be governed by only the CDDL
Lines 51-56 Link Here
51
import java.io.OutputStream;
51
import java.io.OutputStream;
52
import java.net.MalformedURLException;
52
import java.net.MalformedURLException;
53
import java.net.URL;
53
import java.net.URL;
54
import org.netbeans.spi.queries.FileEncodingQueryImplementation;
54
import org.openide.DialogDisplayer;
55
import org.openide.DialogDisplayer;
55
import org.openide.cookies.InstanceCookie;
56
import org.openide.cookies.InstanceCookie;
56
import org.openide.cookies.OpenCookie;
57
import org.openide.cookies.OpenCookie;
Lines 62-68 Link Here
62
import org.openide.NotifyDescriptor;
63
import org.openide.NotifyDescriptor;
63
import org.openide.ErrorManager;
64
import org.openide.ErrorManager;
64
import org.openide.util.HelpCtx;
65
import org.openide.util.HelpCtx;
66
import org.openide.util.Lookup;
65
import org.openide.util.NbBundle;
67
import org.openide.util.NbBundle;
68
import org.openide.util.lookup.Lookups;
66
69
67
70
68
/** Data object that represents one bookmark, one .url file containing url.
71
/** Data object that represents one bookmark, one .url file containing url.
Lines 78-85 Link Here
78
    
81
    
79
    /** Generated serial version UID. */
82
    /** Generated serial version UID. */
80
    static final long serialVersionUID = 6829522922370124627L;
83
    static final long serialVersionUID = 6829522922370124627L;
81
82
    
84
    
85
    /** */
86
    private Lookup lookup;
87
83
    /**
88
    /**
84
     * Constructs a new URL data object.
89
     * Constructs a new URL data object.
85
     *
90
     *
Lines 91-96 Link Here
91
            throws DataObjectExistsException {
96
            throws DataObjectExistsException {
92
        super(file, loader);
97
        super(file, loader);
93
        getCookieSet().add(this);
98
        getCookieSet().add(this);
99
    }
100
    
101
    @Override
102
    public Lookup getLookup() {
103
        if (lookup == null) {
104
            FileEncodingQueryImplementation encodingImpl
105
                    = ((URLDataLoader) getLoader()).getEncoding();
106
            lookup = (encodingImpl != null)
107
                     ? Lookups.fixed(this, encodingImpl)
108
                     : Lookups.singleton(this);
109
        }
110
        return lookup;
94
    }
111
    }
95
    
112
    
96
    /*
113
    /*

Return to bug 123115