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 42638
Collapse All | Expand All

(-)overview.html (-2 / +3 lines)
Lines 4-11 Link Here
4
4
5
<p>
5
<p>
6
Besides the visible Javadoc, this module permits a project to add implementations
6
Besides the visible Javadoc, this module permits a project to add implementations
7
of {@link org.netbeans.spi.queries.FileBuiltQueryImplementation}
7
of {@link org.netbeans.spi.queries.FileBuiltQueryImplementation},
8
and {@link org.netbeans.spi.queries.SharabilityQueryImplementation}
8
{@link org.netbeans.spi.queries.SharabilityQueryImplementation} and
9
{link org.netbeans.spi.queries.FileEncodingQueryImplementation}
9
into the project lookup (rather than global lookup).
10
into the project lookup (rather than global lookup).
10
The implementations will be consulted only in the case the relevant file
11
The implementations will be consulted only in the case the relevant file
11
belongs to that project (according to {@link org.netbeans.api.project.FileOwnerQuery}).
12
belongs to that project (according to {@link org.netbeans.api.project.FileOwnerQuery}).
(-)src/META-INF/services/org.netbeans.spi.project.FileEncodingQueryImplementation (+4 lines)
Added Link Here
1
org.netbeans.modules.projectapi.ProjectFileEncodingQueryImplementation
2
#position=200
3
org.netbeans.modules.projectapi.DataObjectEncodingQueryImplementation
4
#position=100
(-)src/org/netbeans/api/project/Project.java (+1 lines)
Lines 79-84 Link Here
79
     * <li>{@link org.netbeans.spi.project.ProjectConfigurationProvider}</li>
79
     * <li>{@link org.netbeans.spi.project.ProjectConfigurationProvider}</li>
80
     * <li>{@link org.netbeans.spi.queries.FileBuiltQueryImplementation}</li>
80
     * <li>{@link org.netbeans.spi.queries.FileBuiltQueryImplementation}</li>
81
     * <li>{@link org.netbeans.spi.queries.SharabilityQueryImplementation}</li>
81
     * <li>{@link org.netbeans.spi.queries.SharabilityQueryImplementation}</li>
82
     * <li>{@link org.netbeans.spi.queries.FileEncodingQueryImplementation}</li>
82
     * <li><a href="@org-netbeans-modules-projectuiapi@/org/netbeans/spi/project/ui/ProjectOpenedHook.html"><code>ProjectOpenedHook</code></a></li>
83
     * <li><a href="@org-netbeans-modules-projectuiapi@/org/netbeans/spi/project/ui/ProjectOpenedHook.html"><code>ProjectOpenedHook</code></a></li>
83
     * <li><a href="@org-netbeans-modules-projectuiapi@/org/netbeans/spi/project/ui/RecommendedTemplates.html"><code>RecommendedTemplates</code></a></li>
84
     * <li><a href="@org-netbeans-modules-projectuiapi@/org/netbeans/spi/project/ui/RecommendedTemplates.html"><code>RecommendedTemplates</code></a></li>
84
     * <li><a href="@org-netbeans-modules-projectuiapi@/org/netbeans/spi/project/ui/PrivilegedTemplates.html"><code>PrivilegedTemplates</code></a></li>
85
     * <li><a href="@org-netbeans-modules-projectuiapi@/org/netbeans/spi/project/ui/PrivilegedTemplates.html"><code>PrivilegedTemplates</code></a></li>
(-)src/org/netbeans/modules/projectapi/DataObjectEncodingQueryImplementation.java (+53 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
package org.netbeans.modules.projectapi;
20
21
import java.nio.charset.Charset;
22
import org.netbeans.spi.queries.FileEncodingQueryImplementation;
23
import org.openide.filesystems.FileObject;
24
import org.openide.loaders.DataObject;
25
import org.openide.loaders.DataObjectNotFoundException;
26
import org.openide.util.Exceptions;
27
28
/**
29
 *
30
 * @author Tomas Zezula
31
 */
32
public class DataObjectEncodingQueryImplementation implements FileEncodingQueryImplementation {
33
    
34
    /** Creates a new instance of DataObjectEncodingQueryImplementation */
35
    public DataObjectEncodingQueryImplementation() {
36
    }
37
    
38
    public Charset getEncoding(FileObject file) {
39
        assert file != null;
40
        try {
41
            DataObject dobj = DataObject.find(file);
42
            FileEncodingQueryImplementation impl = dobj.getLookup().lookup (FileEncodingQueryImplementation.class);
43
            if (impl == null)  {
44
                return null;
45
            }
46
            return impl.getEncoding(file);
47
        } catch (DataObjectNotFoundException donf) {
48
            Exceptions.printStackTrace(donf);
49
            return null;
50
        }
51
    }
52
53
}
(-)src/org/netbeans/modules/projectapi/ProjectFileEncodingQueryImplementation.java (+52 lines)
Added Link Here
1
/*
2
 * The contents of this file are subject to the terms of the Common Development
3
 * and Distribution License (the License). You may not use this file except in
4
 * compliance with the License.
5
 *
6
 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7
 * or http://www.netbeans.org/cddl.txt.
8
 *
9
 * When distributing Covered Code, include this CDDL Header Notice in each file
10
 * and include the License file at http://www.netbeans.org/cddl.txt.
11
 * If applicable, add the following below the CDDL Header, with the fields
12
 * enclosed by brackets [] replaced by your own identifying information:
13
 * "Portions Copyrighted [year] [name of copyright owner]"
14
 *
15
 * The Original Software is NetBeans. The Initial Developer of the Original
16
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17
 * Microsystems, Inc. All Rights Reserved.
18
 */
19
package org.netbeans.modules.projectapi;
20
21
import java.nio.charset.Charset;
22
import org.netbeans.api.project.FileOwnerQuery;
23
import org.netbeans.api.project.Project;
24
import org.netbeans.spi.queries.FileEncodingQueryImplementation;
25
import org.openide.filesystems.FileObject;
26
27
/**
28
 *
29
 * @author Tomas Zezula
30
 */
31
public class ProjectFileEncodingQueryImplementation implements FileEncodingQueryImplementation {
32
    
33
    
34
    public ProjectFileEncodingQueryImplementation() {
35
    }
36
    
37
    public Charset getEncoding(FileObject file) {
38
        Project p = FileOwnerQuery.getOwner(file);
39
        if (p == null) {
40
            return null;
41
        }
42
        FileEncodingQueryImplementation delegate = p.getLookup().lookup(FileEncodingQueryImplementation.class);
43
        if (delegate == null) {
44
            return null;
45
        }
46
        return delegate.getEncoding(file);
47
    }
48
49
    
50
    
51
    
52
}

Return to bug 42638