Index: overview.html
===================================================================
RCS file: /cvs/projects/projectapi/overview.html,v
retrieving revision 1.4
diff -u -r1.4 overview.html
--- overview.html 14 Oct 2004 17:26:43 -0000 1.4
+++ overview.html 9 Feb 2007 14:31:36 -0000
@@ -4,8 +4,9 @@
Besides the visible Javadoc, this module permits a project to add implementations
-of {@link org.netbeans.spi.queries.FileBuiltQueryImplementation}
-and {@link org.netbeans.spi.queries.SharabilityQueryImplementation}
+of {@link org.netbeans.spi.queries.FileBuiltQueryImplementation},
+{@link org.netbeans.spi.queries.SharabilityQueryImplementation} and
+{link org.netbeans.spi.queries.FileEncodingQueryImplementation}
into the project lookup (rather than global lookup).
The implementations will be consulted only in the case the relevant file
belongs to that project (according to {@link org.netbeans.api.project.FileOwnerQuery}).
Index: src/META-INF/services/org.netbeans.spi.project.FileEncodingQueryImplementation
===================================================================
RCS file: src/META-INF/services/org.netbeans.spi.project.FileEncodingQueryImplementation
diff -N src/META-INF/services/org.netbeans.spi.project.FileEncodingQueryImplementation
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/META-INF/services/org.netbeans.spi.project.FileEncodingQueryImplementation 9 Feb 2007 14:31:36 -0000
@@ -0,0 +1,4 @@
+org.netbeans.modules.projectapi.ProjectFileEncodingQueryImplementation
+#position=200
+org.netbeans.modules.projectapi.DataObjectEncodingQueryImplementation
+#position=100
Index: src/org/netbeans/api/project/Project.java
===================================================================
RCS file: /cvs/projects/projectapi/src/org/netbeans/api/project/Project.java,v
retrieving revision 1.17
diff -u -r1.17 Project.java
--- src/org/netbeans/api/project/Project.java 9 Feb 2007 10:55:10 -0000 1.17
+++ src/org/netbeans/api/project/Project.java 9 Feb 2007 14:31:37 -0000
@@ -79,6 +79,7 @@
*
{@link org.netbeans.spi.project.ProjectConfigurationProvider}
* {@link org.netbeans.spi.queries.FileBuiltQueryImplementation}
* {@link org.netbeans.spi.queries.SharabilityQueryImplementation}
+ * {@link org.netbeans.spi.queries.FileEncodingQueryImplementation}
* ProjectOpenedHook
* RecommendedTemplates
* PrivilegedTemplates
Index: src/org/netbeans/modules/projectapi/DataObjectEncodingQueryImplementation.java
===================================================================
RCS file: src/org/netbeans/modules/projectapi/DataObjectEncodingQueryImplementation.java
diff -N src/org/netbeans/modules/projectapi/DataObjectEncodingQueryImplementation.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/netbeans/modules/projectapi/DataObjectEncodingQueryImplementation.java 9 Feb 2007 14:31:37 -0000
@@ -0,0 +1,53 @@
+/*
+ * The contents of this file are subject to the terms of the Common Development
+ * and Distribution License (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.html
+ * or http://www.netbeans.org/cddl.txt.
+ *
+ * When distributing Covered Code, include this CDDL Header Notice in each file
+ * and include the License file at http://www.netbeans.org/cddl.txt.
+ * If applicable, add the following below the CDDL Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ */
+package org.netbeans.modules.projectapi;
+
+import java.nio.charset.Charset;
+import org.netbeans.spi.queries.FileEncodingQueryImplementation;
+import org.openide.filesystems.FileObject;
+import org.openide.loaders.DataObject;
+import org.openide.loaders.DataObjectNotFoundException;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author Tomas Zezula
+ */
+public class DataObjectEncodingQueryImplementation implements FileEncodingQueryImplementation {
+
+ /** Creates a new instance of DataObjectEncodingQueryImplementation */
+ public DataObjectEncodingQueryImplementation() {
+ }
+
+ public Charset getEncoding(FileObject file) {
+ assert file != null;
+ try {
+ DataObject dobj = DataObject.find(file);
+ FileEncodingQueryImplementation impl = dobj.getLookup().lookup (FileEncodingQueryImplementation.class);
+ if (impl == null) {
+ return null;
+ }
+ return impl.getEncoding(file);
+ } catch (DataObjectNotFoundException donf) {
+ Exceptions.printStackTrace(donf);
+ return null;
+ }
+ }
+
+}
Index: src/org/netbeans/modules/projectapi/ProjectFileEncodingQueryImplementation.java
===================================================================
RCS file: src/org/netbeans/modules/projectapi/ProjectFileEncodingQueryImplementation.java
diff -N src/org/netbeans/modules/projectapi/ProjectFileEncodingQueryImplementation.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/org/netbeans/modules/projectapi/ProjectFileEncodingQueryImplementation.java 9 Feb 2007 14:31:38 -0000
@@ -0,0 +1,52 @@
+/*
+ * The contents of this file are subject to the terms of the Common Development
+ * and Distribution License (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.html
+ * or http://www.netbeans.org/cddl.txt.
+ *
+ * When distributing Covered Code, include this CDDL Header Notice in each file
+ * and include the License file at http://www.netbeans.org/cddl.txt.
+ * If applicable, add the following below the CDDL Header, with the fields
+ * enclosed by brackets [] replaced by your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * The Original Software is NetBeans. The Initial Developer of the Original
+ * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
+ * Microsystems, Inc. All Rights Reserved.
+ */
+package org.netbeans.modules.projectapi;
+
+import java.nio.charset.Charset;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.spi.queries.FileEncodingQueryImplementation;
+import org.openide.filesystems.FileObject;
+
+/**
+ *
+ * @author Tomas Zezula
+ */
+public class ProjectFileEncodingQueryImplementation implements FileEncodingQueryImplementation {
+
+
+ public ProjectFileEncodingQueryImplementation() {
+ }
+
+ public Charset getEncoding(FileObject file) {
+ Project p = FileOwnerQuery.getOwner(file);
+ if (p == null) {
+ return null;
+ }
+ FileEncodingQueryImplementation delegate = p.getLookup().lookup(FileEncodingQueryImplementation.class);
+ if (delegate == null) {
+ return null;
+ }
+ return delegate.getEncoding(file);
+ }
+
+
+
+
+}