Issue #138846: move the implementation of declarative MIME resolvers to the Filesystems API. diff --git a/o.n.core/test/unit/src/org/netbeans/core/filesystems/ArchiveURLMapperTest.java b/core.startup/test/unit/src/org/netbeans/core/startup/layers/ArchiveURLMapperTest.java rename from o.n.core/test/unit/src/org/netbeans/core/filesystems/ArchiveURLMapperTest.java rename to core.startup/test/unit/src/org/netbeans/core/startup/layers/ArchiveURLMapperTest.java --- a/o.n.core/test/unit/src/org/netbeans/core/filesystems/ArchiveURLMapperTest.java +++ b/core.startup/test/unit/src/org/netbeans/core/startup/layers/ArchiveURLMapperTest.java @@ -39,7 +39,7 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.core.filesystems; +package org.netbeans.core.startup.layers; import java.io.File; import java.io.FileOutputStream; diff --git a/o.n.core/test/unit/src/org/netbeans/core/filesystems/NbinstURLMapperTest.java b/core.startup/test/unit/src/org/netbeans/core/startup/layers/NbinstURLMapperTest.java rename from o.n.core/test/unit/src/org/netbeans/core/filesystems/NbinstURLMapperTest.java rename to core.startup/test/unit/src/org/netbeans/core/startup/layers/NbinstURLMapperTest.java --- a/o.n.core/test/unit/src/org/netbeans/core/filesystems/NbinstURLMapperTest.java +++ b/core.startup/test/unit/src/org/netbeans/core/startup/layers/NbinstURLMapperTest.java @@ -39,7 +39,7 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.core.filesystems; +package org.netbeans.core.startup.layers; import java.io.BufferedReader; import java.io.File; @@ -51,11 +51,8 @@ import java.net.URL; import java.net.URLConnection; import java.util.StringTokenizer; -import org.netbeans.core.startup.layers.NbinstURLMapper; -import org.netbeans.core.startup.layers.NbinstURLStreamHandlerFactory; import org.netbeans.junit.MockServices; import org.netbeans.junit.NbTestCase; -import org.netbeans.modules.masterfs.MasterURLMapper; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.URLMapper; @@ -74,14 +71,14 @@ super (testName); } + @Override protected void setUp() throws Exception { super.setUp(); MockServices.setServices( TestInstalledFileLocator.class, NbinstURLStreamHandlerFactory.class, - NbinstURLMapper.class, - MasterURLMapper.class); + NbinstURLMapper.class); org.netbeans.core.startup.Main.initializeURLFactory (); diff --git a/core.ui/src/org/netbeans/core/ui/options/filetypes/FileAssociationsModel.java b/core.ui/src/org/netbeans/core/ui/options/filetypes/FileAssociationsModel.java --- a/core.ui/src/org/netbeans/core/ui/options/filetypes/FileAssociationsModel.java +++ b/core.ui/src/org/netbeans/core/ui/options/filetypes/FileAssociationsModel.java @@ -50,7 +50,6 @@ import java.util.TreeSet; import java.util.logging.Level; import java.util.logging.Logger; -import org.netbeans.core.LoaderPoolNode; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; import org.openide.filesystems.FileUtil; @@ -303,7 +302,8 @@ if (userDefined) { userDefinedResolverFO = mimeResolverFO; } - ArrayList extAndMimePairs = LoaderPoolNode.getExtensionsAndMIMETypes(mimeResolverFO); + assert mimeResolverFO.getPath().startsWith("Services/MIMEResolver"); //NOI18N + ArrayList extAndMimePairs = MIMEResolver.getExtensionsAndMIMETypes(mimeResolverFO); Iterator iter = extAndMimePairs.iterator(); while (iter.hasNext()) { String[] pair = iter.next(); diff --git a/o.n.core/src/org/netbeans/core/Bundle.properties b/o.n.core/src/org/netbeans/core/Bundle.properties --- a/o.n.core/src/org/netbeans/core/Bundle.properties +++ b/o.n.core/src/org/netbeans/core/Bundle.properties @@ -45,8 +45,6 @@ This module provides the central infrastructure \ that lets NetBeans-based applications run. \ It cannot be disabled. - -Services/MIMEResolver=File Types #DataSystem dataSystemName=All Files diff --git a/o.n.core/src/org/netbeans/core/LoaderPoolNode.java b/o.n.core/src/org/netbeans/core/LoaderPoolNode.java --- a/o.n.core/src/org/netbeans/core/LoaderPoolNode.java +++ b/o.n.core/src/org/netbeans/core/LoaderPoolNode.java @@ -64,7 +64,6 @@ import javax.swing.Action; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import org.netbeans.core.filesystems.MIMEResolverImpl; import org.netbeans.core.startup.ManifestSection; import org.openide.actions.MoveDownAction; import org.openide.actions.MoveUpAction; @@ -90,6 +89,7 @@ import org.openide.util.LookupEvent; import org.openide.util.LookupListener; import org.openide.util.NbBundle; +import org.openide.util.NotImplementedException; import org.openide.util.RequestProcessor; import org.openide.util.TopologicalSortException; import org.openide.util.Utilities; @@ -739,17 +739,6 @@ } private static NbLoaderPool nbLoaderPool = null; - /** Returns list of extension and MIME type pairs for given MIMEResolver - * FileObject. The list can contain duplicates and also [null, MIME] pairs. - * @param fo MIMEResolver FileObject - * @return list of extension and MIME type pairs. The list can contain - * duplicates and also [null, MIME] pairs. - * @since 3.9 - */ - public static ArrayList getExtensionsAndMIMETypes(FileObject fo) { - return MIMEResolverImpl.getExtensionsAndMIMETypes(fo); - } - /***** Inner classes **************/ /** Node representing one loader in Loader Pool */ diff --git a/o.n.core/src/org/netbeans/core/filesystems/XMLEnvironmentProvider.java b/o.n.core/src/org/netbeans/core/filesystems/XMLEnvironmentProvider.java deleted file mode 100644 --- a/o.n.core/src/org/netbeans/core/filesystems/XMLEnvironmentProvider.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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]" - * - * Contributor(s): - * - * The Original Software is NetBeans. The Initial Developer of the Original - * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun - * Microsystems, Inc. All Rights Reserved. - * - * 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. - */ - -package org.netbeans.core.filesystems; - -import java.io.*; -import java.util.*; - -import org.xml.sax.*; -import org.xml.sax.helpers.*; - -import org.openide.cookies.InstanceCookie; -import org.openide.loaders.*; -import org.openide.filesystems.*; -import org.openide.util.*; -import org.openide.util.lookup.*; -import org.openide.xml.*; -import org.openide.*; - -/** - * Default implementation providing Environment for XMLDataObject according to its - * public ID. - * - *

- * Subclass instance of this must be registered as FileEntityResolver - * dictates and must implement Environment.Provider interface. - * - *

- * It forever caches provided environment! - * - * @see org.netbeans.core.xml.FileEntityResolver - * @author Petr Kuzel - * @version - */ -class XMLEnvironmentProvider extends SharedClassObject { - - private static final long serialVersionUID = 18947L; - - private static transient Map envs = new HashMap(11); // 11 expected number of modules using this - - // Environment.Provider ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - /** Returns a lookup that represents environment. - * @return the lookup - */ - public final Lookup getEnvironment(DataObject obj){ - - // the obj check is done by core FileEntityResolver that calls us - - // we want to create just one instance per FileObject - - FileObject file = obj.getPrimaryFile(); - Lookup lookup = envs.get(file); - if (lookup == null) { - lookup = createLookup(obj); - envs.put(file, lookup); - } - return lookup; - - } - - /** - * It is called exactly once per DataObject. - * - * @return content of assigned Lookup - */ - protected InstanceContent createInstanceContent(DataObject obj) { - return new InstanceContent(); - } - - /** - * It is called exactly once per DataObject. - * - * @return Lookup containing createInstanceContent() - */ - protected Lookup createLookup(DataObject obj) { - InstanceContent ic = createInstanceContent(obj); - Lookup lookup = new AbstractLookup(ic); - if (lookup.lookup(InstanceCookie.class) == null) { - Exceptions.printStackTrace(new IllegalStateException()); // instance cookie required - } - return lookup; - } - -} diff --git a/o.n.core/src/org/netbeans/core/resources/mf-layer.xml b/o.n.core/src/org/netbeans/core/resources/mf-layer.xml --- a/o.n.core/src/org/netbeans/core/resources/mf-layer.xml +++ b/o.n.core/src/org/netbeans/core/resources/mf-layer.xml @@ -53,12 +53,6 @@ - - - - - - @@ -106,11 +100,11 @@ - + - + @@ -126,12 +120,6 @@ - - - - - - diff --git a/o.n.core/src/org/netbeans/core/resources/mime.gif b/o.n.core/src/org/netbeans/core/resources/mime.gif deleted file mode 100644 Binary file o.n.core/src/org/netbeans/core/resources/mime.gif has changed diff --git a/o.n.core/test/unit/src/org/netbeans/core/filesystems/FileEntityResolverTest.java b/o.n.core/test/unit/src/org/netbeans/core/LoaderPoolNodeResolverChangeTest.java rename from o.n.core/test/unit/src/org/netbeans/core/filesystems/FileEntityResolverTest.java rename to o.n.core/test/unit/src/org/netbeans/core/LoaderPoolNodeResolverChangeTest.java --- a/o.n.core/test/unit/src/org/netbeans/core/filesystems/FileEntityResolverTest.java +++ b/o.n.core/test/unit/src/org/netbeans/core/LoaderPoolNodeResolverChangeTest.java @@ -39,7 +39,7 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.core.filesystems; +package org.netbeans.core; import java.io.IOException; import java.io.OutputStream; @@ -50,7 +50,6 @@ import java.util.jar.Attributes; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; -import org.netbeans.core.LoaderPoolNode; import org.netbeans.core.startup.ManifestSection; import org.openide.ErrorManager; import org.openide.filesystems.FileObject; @@ -71,7 +70,7 @@ * * @author Jaroslav Tulach */ -public class FileEntityResolverTest extends org.netbeans.core.LoggingTestCaseHid +public class LoaderPoolNodeResolverChangeTest extends org.netbeans.core.LoggingTestCaseHid implements LookupListener, ChangeListener { private FileObject fo; private Lenka loader; @@ -81,7 +80,7 @@ private int poolChange; private static ErrorManager err; - public FileEntityResolverTest(String testName) { + public LoaderPoolNodeResolverChangeTest(String testName) { super(testName); } diff --git a/openide.filesystems/src/org/openide/filesystems/MIMEResolver.java b/openide.filesystems/src/org/openide/filesystems/MIMEResolver.java --- a/openide.filesystems/src/org/openide/filesystems/MIMEResolver.java +++ b/openide.filesystems/src/org/openide/filesystems/MIMEResolver.java @@ -41,6 +41,7 @@ package org.openide.filesystems; import java.util.*; +import org.openide.filesystems.declmime.MIMEResolverImpl; /** @@ -63,4 +64,17 @@ * @return recognized MIME type or null if not recognized */ public abstract String findMIMEType(FileObject fo); + + /** + * Returns list of extension and MIME type pairs for given declarative (XML) MIME resolver. + * The list can contain duplicates and also [null, MIME] pairs. + * @param fo XML file matching the DTD + * @return list of extension and MIME type pairs. The list can contain + * duplicates and also [null, MIME] pairs. + * @since XXX + */ + public static ArrayList getExtensionsAndMIMETypes(FileObject fo) { + return MIMEResolverImpl.getExtensionsAndMIMETypes(fo); + } + } diff --git a/openide.filesystems/src/org/openide/filesystems/MIMESupport.java b/openide.filesystems/src/org/openide/filesystems/MIMESupport.java --- a/openide.filesystems/src/org/openide/filesystems/MIMESupport.java +++ b/openide.filesystems/src/org/openide/filesystems/MIMESupport.java @@ -47,10 +47,14 @@ import java.io.OutputStream; import java.lang.ref.Reference; import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Enumeration; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.logging.Logger; +import org.openide.filesystems.declmime.MIMEResolverImpl; import org.openide.util.Lookup; import org.openide.util.LookupEvent; import org.openide.util.LookupListener; @@ -194,8 +198,20 @@ } ERR.fine("Computing resolvers"); // NOI18N - - MIMEResolver[] toRet = result.allInstances().toArray(new MIMEResolver[0]); + + List all = new ArrayList(result.allInstances()); + + FileObject declarativeFolder = Repository.getDefault().getDefaultFileSystem().findResource("Services/MIMEResolver"); // NOI18N + if (declarativeFolder != null) { + for (FileObject f : Ordering.getOrder(Arrays.asList(declarativeFolder.getChildren()), true)) { + if (f.hasExt("xml")) { // NOI18N + // For now, just assume it has the right DTD. Could check this if desired. + all.add(new MIMEResolverImpl(f)); + } + } + } + + MIMEResolver[] toRet = all.toArray(new MIMEResolver[all.size()]); ERR.fine("Resolvers computed"); // NOI18N diff --git a/o.n.core/src/org/netbeans/core/filesystems/Bundle.properties b/openide.filesystems/src/org/openide/filesystems/declmime/Bundle.properties rename from o.n.core/src/org/netbeans/core/filesystems/Bundle.properties rename to openide.filesystems/src/org/openide/filesystems/declmime/Bundle.properties diff --git a/o.n.core/src/org/netbeans/core/filesystems/DefaultParser.java b/openide.filesystems/src/org/openide/filesystems/declmime/DefaultParser.java rename from o.n.core/src/org/netbeans/core/filesystems/DefaultParser.java rename to openide.filesystems/src/org/openide/filesystems/declmime/DefaultParser.java --- a/o.n.core/src/org/netbeans/core/filesystems/DefaultParser.java +++ b/openide.filesystems/src/org/openide/filesystems/declmime/DefaultParser.java @@ -39,7 +39,7 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.core.filesystems; +package org.openide.filesystems.declmime; import java.io.*; import java.util.logging.Level; diff --git a/o.n.core/src/org/netbeans/core/filesystems/FileObjectFilter.java b/openide.filesystems/src/org/openide/filesystems/declmime/FileObjectFilter.java rename from o.n.core/src/org/netbeans/core/filesystems/FileObjectFilter.java rename to openide.filesystems/src/org/openide/filesystems/declmime/FileObjectFilter.java --- a/o.n.core/src/org/netbeans/core/filesystems/FileObjectFilter.java +++ b/openide.filesystems/src/org/openide/filesystems/declmime/FileObjectFilter.java @@ -39,7 +39,7 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.core.filesystems; +package org.openide.filesystems.declmime; import org.openide.filesystems.*; diff --git a/o.n.core/src/org/netbeans/core/filesystems/MIMEComponent.java b/openide.filesystems/src/org/openide/filesystems/declmime/MIMEComponent.java rename from o.n.core/src/org/netbeans/core/filesystems/MIMEComponent.java rename to openide.filesystems/src/org/openide/filesystems/declmime/MIMEComponent.java --- a/o.n.core/src/org/netbeans/core/filesystems/MIMEComponent.java +++ b/openide.filesystems/src/org/openide/filesystems/declmime/MIMEComponent.java @@ -39,7 +39,7 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.core.filesystems; +package org.openide.filesystems.declmime; import org.xml.sax.ContentHandler; diff --git a/o.n.core/src/org/netbeans/core/filesystems/MIMEResolverImpl.java b/openide.filesystems/src/org/openide/filesystems/declmime/MIMEResolverImpl.java rename from o.n.core/src/org/netbeans/core/filesystems/MIMEResolverImpl.java rename to openide.filesystems/src/org/openide/filesystems/declmime/MIMEResolverImpl.java --- a/o.n.core/src/org/netbeans/core/filesystems/MIMEResolverImpl.java +++ b/openide.filesystems/src/org/openide/filesystems/declmime/MIMEResolverImpl.java @@ -39,7 +39,7 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.core.filesystems; +package org.openide.filesystems.declmime; import java.io.FileNotFoundException; import java.io.IOException; @@ -47,14 +47,10 @@ import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; -import org.openide.cookies.InstanceCookie; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.filesystems.MIMEResolver; -import org.openide.loaders.DataObject; -import org.openide.loaders.Environment; import org.openide.util.Utilities; -import org.openide.util.lookup.InstanceContent; import org.openide.xml.XMLUtil; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -63,20 +59,9 @@ * MIMEResolver implementation driven by an XML document instance * following PUBLIC "-//NetBeans//DTD MIME Resolver 1.0//EN". * - *

- * 1. It provides Environment for XMLDataObjects with above public ID. - *

- * 2. Provided environment returns (InstanceCookie) Impl instance. - *

- * 3. [Instance]Lookup return that Impl instance. - *

- * 4. MIMEResolver's findMIMEType() parses description file and applies checks on passed files. - *

- * Note: It is public to be accessible by XML layer. - * * @author Petr Kuzel */ -public final class MIMEResolverImpl extends XMLEnvironmentProvider implements Environment.Provider { +public final class MIMEResolverImpl extends MIMEResolver { private static final long serialVersionUID = 18975L; @@ -86,25 +71,9 @@ private static final boolean CASE_INSENSITIVE = Utilities.isWindows() || Utilities.getOperatingSystem() == Utilities.OS_VMS; - // DefaultEnvironmentProvider~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - protected InstanceContent createInstanceContent(DataObject obj) { - FileObject fo = obj.getPrimaryFile(); - InstanceContent ic = new InstanceContent(); - ic.add(new Impl(fo)); - return ic; - } - - /** Returns list of extension and MIME type pairs for given MIMEResolver - * FileObject. The list can contain duplicates and also [null, MIME] pairs. - * @param fo MIMEResolver FileObject - * @return list of extension and MIME type pairs. The list can contain - * duplicates and also [null, MIME] pairs. - */ public static ArrayList getExtensionsAndMIMETypes(FileObject fo) { - assert fo.getPath().startsWith("Services/MIMEResolver"); //NOI18N ArrayList result = new ArrayList(); - Impl impl = new Impl(fo); + MIMEResolverImpl impl = new MIMEResolverImpl(fo); impl.parseDesc(); FileElement[] elements = impl.smell; if(elements != null) { @@ -124,100 +93,80 @@ return result; } - // MIMEResolver ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // This file object describes rules that drive ths instance + private final FileObject data; - // - // It implements InstanceCookie because it is added to environment of XML document. - // The cookie return itself i.e. MIMEResolver to be searchable by Lookup. - // - static class Impl extends MIMEResolver implements InstanceCookie { - // This file object describes rules that drive ths instance - private final FileObject data; + // Resolvers in reverse order + private FileElement[] smell = null; - // Resolvers in reverse order - private FileElement[] smell = null; - - private short state = DescParser.INIT; - - Impl(FileObject obj) { - if (ERR.isLoggable(Level.FINE)) ERR.fine("MIMEResolverImpl.Impl.(" + obj + ")"); // NOI18N - data = obj; + private short state = DescParser.INIT; + + public MIMEResolverImpl(FileObject obj) { + if (ERR.isLoggable(Level.FINE)) { + ERR.fine("MIMEResolverImpl.(" + obj + ")"); // NOI18N } - - /** - * Resolves FileObject and returns recognized MIME type - * @param fo is FileObject which should be resolved - * @return recognized MIME type or null if not recognized - */ - public String findMIMEType(FileObject fo) { + data = obj; + } - synchronized (this) { // lazy init + /** + * Resolves FileObject and returns recognized MIME type + * @param fo is FileObject which should be resolved + * @return recognized MIME type or null if not recognized + */ + public String findMIMEType(FileObject fo) { - if (state == DescParser.INIT) { - state = parseDesc(); - } - - if (state == DescParser.ERROR) { - return null; - } + synchronized (this) { // lazy init + + if (state == DescParser.INIT) { + state = parseDesc(); } - // smell is filled in reverse order - - for (int i = smell.length-1; i>=0; i--) { - String s = smell[i].resolve(fo); - if (s != null) { - if (ERR.isLoggable(Level.FINE)) ERR.fine("MIMEResolverImpl.findMIMEType(" + fo + ")=" + s); // NOI18N - return s; - } + if (state == DescParser.ERROR) { + return null; } - - return null; } - // description document is parsed in the same thread - private short parseDesc() { - smell = new FileElement[0]; - DescParser parser = new DescParser(data); - parser.parse(); - smell = (parser.template != null) ? parser.template : smell; - if (ERR.isLoggable(Level.FINE)) { - if (parser.state == DescParser.ERROR) { - ERR.fine("MIMEResolverImpl.Impl parsing error!"); - } else { - StringBuffer buf = new StringBuffer(); - buf.append("Parse: "); - for (int i = 0; i= 0; i--) { + String s = smell[i].resolve(fo); + if (s != null) { + if (ERR.isLoggable(Level.FINE)) { + ERR.fine("MIMEResolverImpl.findMIMEType(" + fo + ")=" + s); // NOI18N } + return s; } - return parser.state; - } - - // InstanceCookie ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - public Object instanceCreate() { - return this; - } - - public Class instanceClass() { - return this.getClass(); - } - - public String instanceName() { - return this.getClass().getName(); } - /** For debug purposes. */ - public String toString() { - return "MIMEResolverImpl.Impl[" + data + ", " + smell + "]"; // NOI18N - } - - + return null; } - + // description document is parsed in the same thread + private short parseDesc() { + smell = new FileElement[0]; + DescParser parser = new DescParser(data); + parser.parse(); + smell = (parser.template != null) ? parser.template : smell; + if (ERR.isLoggable(Level.FINE)) { + if (parser.state == DescParser.ERROR) { + ERR.fine("MIMEResolverImpl parsing error!"); + } else { + StringBuffer buf = new StringBuffer(); + buf.append("Parse: "); + for (int i = 0; i < smell.length; i++) { + buf.append('\n').append(smell[i]); + } + ERR.fine(buf.toString()); + } + } + return parser.state; + } + + /** For debug purposes. */ + public String toString() { + return "MIMEResolverImpl[" + data + ", " + smell + "]"; // NOI18N + } + // XML -> memory representation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /** diff --git a/o.n.core/src/org/netbeans/core/filesystems/Util.java b/openide.filesystems/src/org/openide/filesystems/declmime/Util.java rename from o.n.core/src/org/netbeans/core/filesystems/Util.java rename to openide.filesystems/src/org/openide/filesystems/declmime/Util.java --- a/o.n.core/src/org/netbeans/core/filesystems/Util.java +++ b/openide.filesystems/src/org/openide/filesystems/declmime/Util.java @@ -39,7 +39,7 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.core.filesystems; +package org.openide.filesystems.declmime; import org.openide.util.Utilities; diff --git a/o.n.core/src/org/netbeans/core/filesystems/XMLMIMEComponent.java b/openide.filesystems/src/org/openide/filesystems/declmime/XMLMIMEComponent.java rename from o.n.core/src/org/netbeans/core/filesystems/XMLMIMEComponent.java rename to openide.filesystems/src/org/openide/filesystems/declmime/XMLMIMEComponent.java --- a/o.n.core/src/org/netbeans/core/filesystems/XMLMIMEComponent.java +++ b/openide.filesystems/src/org/openide/filesystems/declmime/XMLMIMEComponent.java @@ -39,7 +39,7 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.core.filesystems; +package org.openide.filesystems.declmime; import java.lang.ref.WeakReference; import java.util.logging.Level; @@ -337,7 +337,7 @@ // it may be caused by wrong user XML documents, notify only in debug mode // also see #16484 if the error message makes no sense - Logger emgr = Logger.getLogger("org.netbeans.core.filesystems.XMLMIMEComponent"); // NOI18N + Logger emgr = Logger.getLogger(XMLMIMEComponent.class.getName()); if (emgr.isLoggable(Level.FINE)) { emgr.fine("[while parsing " + fo + "] " + exception.getSystemId() + ":" + exception.getLineNumber() + ":" + exception.getColumnNumber() + ": " + exception.getMessage()); // NOI18N } diff --git a/o.n.core/src/org/netbeans/core/filesystems/resolver.dtd b/openide.filesystems/src/org/openide/filesystems/declmime/resolver.dtd rename from o.n.core/src/org/netbeans/core/filesystems/resolver.dtd rename to openide.filesystems/src/org/openide/filesystems/declmime/resolver.dtd diff --git a/o.n.core/src/org/netbeans/core/filesystems/xml-rules.dtd b/openide.filesystems/src/org/openide/filesystems/declmime/xml-rules.dtd rename from o.n.core/src/org/netbeans/core/filesystems/xml-rules.dtd rename to openide.filesystems/src/org/openide/filesystems/declmime/xml-rules.dtd diff --git a/openide.filesystems/test/unit/src/org/openide/filesystems/MIMESupportTest.java b/openide.filesystems/test/unit/src/org/openide/filesystems/MIMESupportTest.java --- a/openide.filesystems/test/unit/src/org/openide/filesystems/MIMESupportTest.java +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/MIMESupportTest.java @@ -45,6 +45,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.io.PrintStream; import java.lang.ref.WeakReference; import java.util.Date; import java.util.Enumeration; @@ -196,6 +197,22 @@ } } + public void testDeclarativeMIMEResolvers() throws Exception { + FileObject resolver = FileUtil.createData(Repository.getDefault().getDefaultFileSystem().getRoot(), "Services/MIMEResolver/r.xml"); + OutputStream os = resolver.getOutputStream(); + PrintStream ps = new PrintStream(os); + ps.println(""); + ps.println(""); + ps.println(" "); + ps.println(" "); + ps.println(" "); + ps.println(" "); + ps.println(""); + os.close(); + FileObject foo = FileUtil.createMemoryFileSystem().getRoot().createData("x.foo"); + assertEquals("text/x-foo", foo.getMIMEType()); + } + public static class TestLookup extends ProxyLookup { public TestLookup() { super(); diff --git a/o.n.core/test/unit/src/org/netbeans/core/filesystems/MIMEResolverImplTest.java b/openide.filesystems/test/unit/src/org/openide/filesystems/declmime/MIMEResolverImplTest.java rename from o.n.core/test/unit/src/org/netbeans/core/filesystems/MIMEResolverImplTest.java rename to openide.filesystems/test/unit/src/org/openide/filesystems/declmime/MIMEResolverImplTest.java --- a/o.n.core/test/unit/src/org/netbeans/core/filesystems/MIMEResolverImplTest.java +++ b/openide.filesystems/test/unit/src/org/openide/filesystems/declmime/MIMEResolverImplTest.java @@ -39,19 +39,17 @@ * made subject to such option by the copyright holder. */ -package org.netbeans.core.filesystems; +package org.openide.filesystems.declmime; -import java.io.*; -import java.util.*; import java.net.URL; -import org.xml.sax.*; -import org.openide.loaders.*; -import org.openide.filesystems.*; -import org.openide.util.*; -import org.openide.util.lookup.*; -import org.openide.xml.*; -import org.openide.*; -import org.netbeans.junit.*; +import java.util.ArrayList; +import java.util.List; +import org.netbeans.junit.NbTestCase; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileUtil; +import org.openide.filesystems.MIMEResolver; +import org.openide.filesystems.XMLFileSystem; public class MIMEResolverImplTest extends NbTestCase { List resolvers; @@ -62,11 +60,8 @@ } @SuppressWarnings("deprecation") + @Override protected void setUp() throws Exception { -/* - URL u = getClass().getProtectionDomain().getCodeSource().getLocation(); - u = new URL(u, "org/netbeans/core/filesystems/code-fs.xml"); -*/ URL u = this.getClass().getResource ("code-fs.xml"); FileSystem fs = new XMLFileSystem(u); @@ -79,10 +74,6 @@ resolvers.add(createResolver(fos[i])); } -/* - u = getClass().getProtectionDomain().getCodeSource().getLocation(); - u = new URL(u, "org/netbeans/core/filesystems/data-fs.xml"); -*/ u = this.getClass().getResource ("data-fs.xml"); fs = new XMLFileSystem(u); @@ -91,33 +82,20 @@ FileUtil.setMIMEType("txt2", "text/plain; charset=us-ascii"); } - public static void main(java.lang.String[] args) { - junit.textui.TestRunner.run(suite()); - } - - public static NbTest suite() { - NbTestSuite suite = new NbTestSuite(MIMEResolverImplTest.class); - - return suite; - } - - private static MIMEResolver createResolver(FileObject fo) throws Exception { if (fo == null) throw new NullPointerException(); - return new MIMEResolverImpl.Impl(fo); + return new MIMEResolverImpl(fo); } private String resolve(FileObject fo) { - Iterator it = resolvers.iterator(); - while (it.hasNext()) { - MIMEResolver r = (MIMEResolver) it.next(); + for (MIMEResolver r : resolvers) { String s = r.findMIMEType(fo); if (s != null) return s; } return null; } - public void testDeclarativeMIME() throws Exception { + public void testMultithreading() throws Exception { Object tl1 = new Object(); Object tl2 = new Object(); @@ -144,13 +122,14 @@ private class TestThread extends Thread { - Object lock; + final Object lock; String fail; private TestThread(Object lock) { this.lock = lock; } + @Override public void run() { String s; FileObject fo = null; @@ -210,5 +189,5 @@ public void testIllegalXMLEncoding() { assertEquals("illegal-encoding.xml recognized as a XML file", "text/x-springconfig+xml", resolve(root.getFileObject("illegal-encoding", "xml"))); } - + } diff --git a/o.n.core/test/unit/src/org/netbeans/core/filesystems/code-fs.xml b/openide.filesystems/test/unit/src/org/openide/filesystems/declmime/code-fs.xml rename from o.n.core/test/unit/src/org/netbeans/core/filesystems/code-fs.xml rename to openide.filesystems/test/unit/src/org/openide/filesystems/declmime/code-fs.xml diff --git a/o.n.core/test/unit/src/org/netbeans/core/filesystems/data-fs.xml b/openide.filesystems/test/unit/src/org/openide/filesystems/declmime/data-fs.xml rename from o.n.core/test/unit/src/org/netbeans/core/filesystems/data-fs.xml rename to openide.filesystems/test/unit/src/org/openide/filesystems/declmime/data-fs.xml