diff -r dc440cc77d77 apisupport.project/nbproject/project.properties --- a/apisupport.project/nbproject/project.properties Mon Sep 22 22:08:43 2008 -0500 +++ b/apisupport.project/nbproject/project.properties Tue Sep 23 16:17:22 2008 -0500 @@ -39,7 +39,7 @@ javac.compilerargs=-Xlint -Xlint:-serial javac.source=1.5 -spec.version.base=1.23.0 +spec.version.base=1.24 javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml diff -r dc440cc77d77 apisupport.project/nbproject/project.xml --- a/apisupport.project/nbproject/project.xml Mon Sep 22 22:08:43 2008 -0500 +++ b/apisupport.project/nbproject/project.xml Tue Sep 23 16:17:22 2008 -0500 @@ -230,7 +230,7 @@ 2 - + 1.16 diff -r dc440cc77d77 xml.schema/manifest.mf --- a/xml.schema/manifest.mf Mon Sep 22 22:08:43 2008 -0500 +++ b/xml.schema/manifest.mf Tue Sep 23 16:17:22 2008 -0500 @@ -3,3 +3,4 @@ OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/xml/schema/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/xml/schema/resources/mf-layer.xml AutoUpdate-Show-In-Client: false +OpenIDE-Module-Specification-Version: 1.16 diff -r dc440cc77d77 xml.schema/nbproject/project.properties --- a/xml.schema/nbproject/project.properties Mon Sep 22 22:08:43 2008 -0500 +++ b/xml.schema/nbproject/project.properties Tue Sep 23 16:17:22 2008 -0500 @@ -40,7 +40,6 @@ javac.compilerargs=-Xlint -Xlint:-serial javac.source=1.5 -spec.version.base=1.15.0 javahelp.base=org/netbeans/modules/xml/schema javahelp.hs=xmltools-javahelp.hs diff -r dc440cc77d77 xml.schema/nbproject/project.xml --- a/xml.schema/nbproject/project.xml Mon Sep 22 22:08:43 2008 -0500 +++ b/xml.schema/nbproject/project.xml Tue Sep 23 16:17:22 2008 -0500 @@ -130,7 +130,7 @@ - + 1.2 diff -r dc440cc77d77 xml.schema/src/org/netbeans/modules/xml/schema/actions/GenerateXMLAction.java --- a/xml.schema/src/org/netbeans/modules/xml/schema/actions/GenerateXMLAction.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml.schema/src/org/netbeans/modules/xml/schema/actions/GenerateXMLAction.java Tue Sep 23 16:17:22 2008 -0500 @@ -7,12 +7,12 @@ import org.netbeans.modules.xml.schema.SchemaDataObject; import org.netbeans.modules.xml.schema.ui.basic.SchemaModelCookie; import org.netbeans.modules.xml.schema.wizard.SampleXMLGeneratorWizardIterator; +import org.netbeans.modules.xml.wizard.SchemaParser; import org.openide.DialogDisplayer; import org.openide.nodes.Node; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.util.actions.CookieAction; -import org.netbeans.modules.xml.lib.Util; import org.openide.NotifyDescriptor; public final class GenerateXMLAction extends CookieAction { @@ -31,7 +31,7 @@ if(sdo == null) return; - if(Util.getRootElements(sdo.getPrimaryFile()).roots.size() == 0) { + if(SchemaParser.getRootElements(sdo.getPrimaryFile()).roots.size() == 0) { //no root elements; cannot generate XML NotifyDescriptor desc = new NotifyDescriptor.Message (NbBundle.getMessage(GenerateXMLAction.class, "MSG_cannot_generate_XML_file"), NotifyDescriptor.ERROR_MESSAGE); diff -r dc440cc77d77 xml.schema/src/org/netbeans/modules/xml/schema/wizard/SampleXMLGeneratorWizardIterator.java --- a/xml.schema/src/org/netbeans/modules/xml/schema/wizard/SampleXMLGeneratorWizardIterator.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml.schema/src/org/netbeans/modules/xml/schema/wizard/SampleXMLGeneratorWizardIterator.java Tue Sep 23 16:17:22 2008 -0500 @@ -8,11 +8,9 @@ import java.awt.Dialog; import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; -import java.io.StringWriter; import java.io.Writer; import java.net.URI; import java.net.URISyntaxException; @@ -38,11 +36,12 @@ import org.netbeans.api.project.Project; import org.netbeans.editor.BaseDocument; import org.netbeans.modules.xml.api.EncodingUtil; +import org.netbeans.modules.xml.lib.GuiUtil; import org.netbeans.modules.xml.schema.SchemaDataObject; import org.netbeans.modules.xml.text.TextEditorSupport; import org.netbeans.modules.xml.wizard.AbstractPanel; import org.netbeans.modules.xml.wizard.DocumentModel; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.wizard.SchemaParser; import org.netbeans.modules.xml.wizard.XMLContentPanel; import org.netbeans.modules.xml.wizard.XMLGeneratorVisitor; import org.openide.DialogDisplayer; @@ -202,7 +201,7 @@ Set set = new HashSet(1); DataObject createdObject = DataObject.find(fileObject[0]); - Util.performDefaultAction(createdObject); + GuiUtil.performDefaultAction(createdObject); set.add(createdObject); formatXML(fileObject[0]); @@ -237,7 +236,7 @@ xmlPanel.setObject(model); model.setPrefix(PREFIX); - String ns = Util.getNamespace(schemaFileObject); + String ns = SchemaParser.getNamespace(schemaFileObject); model.setNamespace(ns); } diff -r dc440cc77d77 xml.tax/manifest.mf --- a/xml.tax/manifest.mf Mon Sep 22 22:08:43 2008 -0500 +++ b/xml.tax/manifest.mf Tue Sep 23 16:17:22 2008 -0500 @@ -2,7 +2,7 @@ OpenIDE-Module: org.netbeans.modules.xml.tax/2 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/xml/tax/resources/Bundle.properties OpenIDE-Module-Install: org/netbeans/modules/xml/tax/TAXModuleInstall.class -OpenIDE-Module-Implementation-Version: 4 OpenIDE-Module-Layer: org/netbeans/modules/xml/tax/resources/mf-layer.xml OpenIDE-Module-Requires: org.openide.modules.InstalledFileLocator +OpenIDE-Module-Specification-Version: 1.16 diff -r dc440cc77d77 xml.tax/nbproject/project.properties --- a/xml.tax/nbproject/project.properties Mon Sep 22 22:08:43 2008 -0500 +++ b/xml.tax/nbproject/project.properties Tue Sep 23 16:17:22 2008 -0500 @@ -37,7 +37,6 @@ # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. -spec.version.base=1.15.0 extra.module.files=modules/ext/org-netbeans-tax.jar is.autoload=true # Apache's XNI API - parser implementation used internally by module diff -r dc440cc77d77 xml.tax/nbproject/project.xml --- a/xml.tax/nbproject/project.xml Mon Sep 22 22:08:43 2008 -0500 +++ b/xml.tax/nbproject/project.xml Tue Sep 23 16:17:22 2008 -0500 @@ -69,7 +69,7 @@ - + 1.2 @@ -145,7 +145,17 @@ - + + org.netbeans.modules.apisupport.project + org.netbeans.modules.xml.tools + org.netbeans.modules.xml.tools.java + org.netbeans.tax + org.netbeans.tax.io + org.netbeans.tax.decl + org.netbeans.tax.event + org.netbeans.modules.xml.tax.cookies + org.netbeans.modules.xml.tax.parser + ext/org-netbeans-tax.jar diff -r dc440cc77d77 xml.tax/src/org/netbeans/modules/xml/tax/cookies/TreeEditorCookieImpl.java --- a/xml.tax/src/org/netbeans/modules/xml/tax/cookies/TreeEditorCookieImpl.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml.tax/src/org/netbeans/modules/xml/tax/cookies/TreeEditorCookieImpl.java Tue Sep 23 16:17:22 2008 -0500 @@ -41,10 +41,7 @@ package org.netbeans.modules.xml.tax.cookies; import java.io.IOException; -import java.util.Enumeration; -import java.lang.ref.SoftReference; import java.lang.ref.WeakReference; -import java.lang.ref.ReferenceQueue; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeSupport; @@ -52,25 +49,17 @@ import org.xml.sax.InputSource; -import org.openide.loaders.OpenSupport; -import org.openide.loaders.DataObject; -import org.openide.loaders.MultiDataObject; -import org.openide.nodes.CookieSet; import org.openide.nodes.Node; import org.openide.util.Task; import org.openide.util.RequestProcessor; import org.openide.*; -import org.openide.cookies.*; import org.netbeans.tax.*; import org.netbeans.tax.event.TreeEvent; import org.netbeans.modules.xml.*; -import org.netbeans.modules.xml.tree.*; import org.netbeans.modules.xml.cookies.*; -import org.netbeans.modules.xml.text.*; import org.netbeans.modules.xml.sync.*; -import org.netbeans.modules.xml.tax.*; import org.netbeans.modules.xml.tax.parser.DTDParsingSupport; import org.netbeans.modules.xml.tax.parser.ParsingSupport; import org.netbeans.modules.xml.tax.parser.XMLParsingSupport; diff -r dc440cc77d77 xml.tools.java/manifest.mf --- a/xml.tools.java/manifest.mf Mon Sep 22 22:08:43 2008 -0500 +++ b/xml.tools.java/manifest.mf Tue Sep 23 16:17:22 2008 -0500 @@ -2,7 +2,7 @@ OpenIDE-Module: org.netbeans.modules.xml.tools.java OpenIDE-Module-Layer: org/netbeans/modules/xml/tools/java/resources/mf-layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/xml/tools/java/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 1.1 +OpenIDE-Module-Specification-Version: 1.2 diff -r dc440cc77d77 xml.tools.java/nbproject/project.xml --- a/xml.tools.java/nbproject/project.xml Mon Sep 22 22:08:43 2008 -0500 +++ b/xml.tools.java/nbproject/project.xml Tue Sep 23 16:17:22 2008 -0500 @@ -71,7 +71,7 @@ - + 1.2 @@ -89,7 +89,7 @@ 2 - + 1.16 diff -r dc440cc77d77 xml.tools/manifest.mf --- a/xml.tools/manifest.mf Mon Sep 22 22:08:43 2008 -0500 +++ b/xml.tools/manifest.mf Tue Sep 23 16:17:22 2008 -0500 @@ -1,7 +1,7 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.xml.tools/2 -OpenIDE-Module-Implementation-Version: 4 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/xml/tools/resources/Bundle.properties OpenIDE-Module-Layer: org/netbeans/modules/xml/tools/resources/mf-layer.xml AutoUpdate-Show-In-Client: false +OpenIDE-Module-Specification-Version: 1.16 diff -r dc440cc77d77 xml.tools/nbproject/project.properties --- a/xml.tools/nbproject/project.properties Mon Sep 22 22:08:43 2008 -0500 +++ b/xml.tools/nbproject/project.properties Tue Sep 23 16:17:22 2008 -0500 @@ -37,5 +37,4 @@ # Version 2 license, then the option applies only if the new code is # made subject to such option by the copyright holder. -spec.version.base=1.15.0 disable.qa-functional.tests=true diff -r dc440cc77d77 xml.tools/nbproject/project.xml --- a/xml.tools/nbproject/project.xml Mon Sep 22 22:08:43 2008 -0500 +++ b/xml.tools/nbproject/project.xml Tue Sep 23 16:17:22 2008 -0500 @@ -60,7 +60,7 @@ - + 1.2 @@ -136,7 +136,11 @@ - + + org.netbeans.modules.xml.tools.java + org.netbeans.modules.xml.tools.actions + org.netbeans.modules.xml.tools.generator + diff -r dc440cc77d77 xml/manifest.mf --- a/xml/manifest.mf Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/manifest.mf Tue Sep 23 16:17:22 2008 -0500 @@ -1,8 +1,7 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.xml -OpenIDE-Module-Implementation-Version: 1 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/xml/resources/Bundle.properties OpenIDE-Module-Install: org/netbeans/modules/xml/CoreModuleInstall.class OpenIDE-Module-Layer: org/netbeans/modules/xml/resources/mf-layer.xml AutoUpdate-Show-In-Client: false -OpenIDE-Module-Specification-Version: 1.1 +OpenIDE-Module-Specification-Version: 1.2 diff -r dc440cc77d77 xml/nbproject/project.xml --- a/xml/nbproject/project.xml Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/nbproject/project.xml Tue Sep 23 16:17:22 2008 -0500 @@ -299,7 +299,21 @@ - + + org.netbeans.modules.xml.schema + org.netbeans.modules.xml.tax + org.netbeans.modules.xml.tools + org.netbeans.modules.xml.tools.java + org.netbeans.modules.xsl + org.netbeans.modules.xslt.core + org.netbeans.modules.xml + org.netbeans.modules.xml.actions + org.netbeans.modules.xml.cookies + org.netbeans.modules.xml.lib + org.netbeans.modules.xml.sync + org.netbeans.modules.xml.text + org.netbeans.modules.xml.wizard + diff -r dc440cc77d77 xml/src/META-INF/services/org.netbeans.spi.queries.FileEncodingQueryImplementation --- a/xml/src/META-INF/services/org.netbeans.spi.queries.FileEncodingQueryImplementation Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/META-INF/services/org.netbeans.spi.queries.FileEncodingQueryImplementation Tue Sep 23 16:17:22 2008 -0500 @@ -1,3 +1,3 @@ -org.netbeans.modules.xml.DefaultXmlFileEncodingQueryImpl +org.netbeans.modules.xml.util.DefaultXmlFileEncodingQueryImpl #position=105 diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/DTDDataLoader.java --- a/xml/src/org/netbeans/modules/xml/DTDDataLoader.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/DTDDataLoader.java Tue Sep 23 16:17:22 2008 -0500 @@ -41,7 +41,7 @@ package org.netbeans.modules.xml; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.netbeans.modules.xml.text.syntax.DTDKit; import org.openide.loaders.*; import org.openide.filesystems.FileObject; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/DTDDataLoaderBeanInfo.java --- a/xml/src/org/netbeans/modules/xml/DTDDataLoaderBeanInfo.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/DTDDataLoaderBeanInfo.java Tue Sep 23 16:17:22 2008 -0500 @@ -42,7 +42,7 @@ import java.beans.*; import java.awt.Image; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.openide.util.Exceptions; import org.openide.util.Utilities; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/DTDDataObject.java --- a/xml/src/org/netbeans/modules/xml/DTDDataObject.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/DTDDataObject.java Tue Sep 23 16:17:22 2008 -0500 @@ -52,7 +52,7 @@ import org.netbeans.modules.xml.text.TextEditorSupport; import org.netbeans.modules.xml.sync.*; import org.netbeans.modules.xml.cookies.*; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.netbeans.modules.xml.text.syntax.DTDKit; import org.netbeans.spi.xml.cookies.*; import org.xml.sax.InputSource; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/DefaultXmlFileEncodingQueryImpl.java --- a/xml/src/org/netbeans/modules/xml/DefaultXmlFileEncodingQueryImpl.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +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): - * - * Portions Copyrighted 2007 Sun Microsystems, Inc. - */ -package org.netbeans.modules.xml; - -import java.nio.charset.Charset; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.netbeans.modules.xml.api.XmlFileEncodingQueryImpl; -import org.netbeans.spi.queries.FileEncodingQueryImplementation; -import org.openide.filesystems.FileObject; - -/** - * - * @author nam - */ -public class DefaultXmlFileEncodingQueryImpl extends FileEncodingQueryImplementation { - - public Charset getEncoding(FileObject f) { - try { - if (f.getMIMEType().endsWith("xml")) { - return XmlFileEncodingQueryImpl.singleton().getEncoding(f); - } - } catch (Exception ex) { - Logger.getLogger(getClass().getName()).log(Level.FINE, ex.getLocalizedMessage(), ex); - } - return null; - } - -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/EntityDataLoader.java --- a/xml/src/org/netbeans/modules/xml/EntityDataLoader.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/EntityDataLoader.java Tue Sep 23 16:17:22 2008 -0500 @@ -41,7 +41,7 @@ package org.netbeans.modules.xml; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.openide.loaders.UniFileLoader; import org.openide.loaders.MultiDataObject; import org.openide.loaders.DataObjectExistsException; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/EntityDataLoaderBeanInfo.java --- a/xml/src/org/netbeans/modules/xml/EntityDataLoaderBeanInfo.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/EntityDataLoaderBeanInfo.java Tue Sep 23 16:17:22 2008 -0500 @@ -42,7 +42,7 @@ import java.beans.*; import java.awt.Image; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.openide.util.Utilities; import org.openide.loaders.MultiFileLoader; import org.openide.util.Exceptions; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/EntityDataObject.java --- a/xml/src/org/netbeans/modules/xml/EntityDataObject.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/EntityDataObject.java Tue Sep 23 16:17:22 2008 -0500 @@ -54,7 +54,7 @@ import org.netbeans.modules.xml.sync.*; import org.netbeans.modules.xml.cookies.*; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.netbeans.spi.xml.cookies.*; import org.openide.util.Lookup; import org.xml.sax.InputSource; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/XMLDataLoader.java --- a/xml/src/org/netbeans/modules/xml/XMLDataLoader.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/XMLDataLoader.java Tue Sep 23 16:17:22 2008 -0500 @@ -44,7 +44,7 @@ import java.util.*; import java.text.DateFormat; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.netbeans.modules.xml.text.syntax.XMLKit; import org.openide.filesystems.*; import org.openide.loaders.*; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/XMLDataLoaderBeanInfo.java --- a/xml/src/org/netbeans/modules/xml/XMLDataLoaderBeanInfo.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/XMLDataLoaderBeanInfo.java Tue Sep 23 16:17:22 2008 -0500 @@ -42,7 +42,7 @@ import java.beans.*; import java.awt.Image; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.openide.util.Exceptions; import org.openide.util.Utilities; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/XMLDataObject.java --- a/xml/src/org/netbeans/modules/xml/XMLDataObject.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/XMLDataObject.java Tue Sep 23 16:17:22 2008 -0500 @@ -56,7 +56,7 @@ import org.netbeans.modules.xml.text.TextEditorSupport; import org.netbeans.modules.xml.sync.*; import org.netbeans.modules.xml.cookies.*; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.netbeans.modules.xml.text.syntax.XMLKit; import org.netbeans.spi.xml.cookies.*; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/actions/CheckEntityAction.java --- a/xml/src/org/netbeans/modules/xml/actions/CheckEntityAction.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/actions/CheckEntityAction.java Tue Sep 23 16:17:22 2008 -0500 @@ -47,7 +47,7 @@ import org.netbeans.modules.xml.actions.CollectXMLAction; import org.netbeans.api.xml.cookies.*; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; /** * Checks well-formess of XML entity sending results to output window. diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/actions/CollectDTDAction.java --- a/xml/src/org/netbeans/modules/xml/actions/CollectDTDAction.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/actions/CollectDTDAction.java Tue Sep 23 16:17:22 2008 -0500 @@ -40,7 +40,7 @@ */ package org.netbeans.modules.xml.actions; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.openide.util.HelpCtx; /** diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/actions/CollectSystemAction.java --- a/xml/src/org/netbeans/modules/xml/actions/CollectSystemAction.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/actions/CollectSystemAction.java Tue Sep 23 16:17:22 2008 -0500 @@ -46,7 +46,7 @@ import javax.swing.JMenuItem; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.openide.awt.JInlineMenu; import org.openide.windows.TopComponent.Registry; import org.openide.windows.WindowManager; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/actions/CollectXMLAction.java --- a/xml/src/org/netbeans/modules/xml/actions/CollectXMLAction.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/actions/CollectXMLAction.java Tue Sep 23 16:17:22 2008 -0500 @@ -40,7 +40,7 @@ */ package org.netbeans.modules.xml.actions; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.openide.util.HelpCtx; /** diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/actions/InputOutputReporter.java --- a/xml/src/org/netbeans/modules/xml/actions/InputOutputReporter.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/actions/InputOutputReporter.java Tue Sep 23 16:17:22 2008 -0500 @@ -60,7 +60,7 @@ import org.netbeans.api.xml.cookies.*; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.openide.text.Annotatable; import org.openide.text.Annotation; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/actions/XMLUpdateDocumentAction.java --- a/xml/src/org/netbeans/modules/xml/actions/XMLUpdateDocumentAction.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/actions/XMLUpdateDocumentAction.java Tue Sep 23 16:17:22 2008 -0500 @@ -43,7 +43,7 @@ import java.util.Iterator; import org.netbeans.modules.xml.cookies.UpdateDocumentCookie; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.openide.nodes.Node; import org.openide.util.HelpCtx; import org.openide.util.Lookup; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/cookies/CookieManager.java --- a/xml/src/org/netbeans/modules/xml/cookies/CookieManager.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/cookies/CookieManager.java Tue Sep 23 16:17:22 2008 -0500 @@ -48,7 +48,7 @@ import org.openide.nodes.CookieSet; import org.openide.loaders.DataObject; -import org.netbeans.modules.xml.lib.LookupManager; +import org.netbeans.modules.xml.util.LookupManager; /** * @author Libor Kramolis diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/cookies/DataObjectCookieManager.java --- a/xml/src/org/netbeans/modules/xml/cookies/DataObjectCookieManager.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/cookies/DataObjectCookieManager.java Tue Sep 23 16:17:22 2008 -0500 @@ -40,7 +40,7 @@ */ package org.netbeans.modules.xml.cookies; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.openide.nodes.*; import org.openide.loaders.*; import org.openide.cookies.*; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/lib/AbstractUtil.java --- a/xml/src/org/netbeans/modules/xml/lib/AbstractUtil.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,214 +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.modules.xml.lib; - -import org.openide.ErrorManager; -import org.openide.util.Lookup; -import org.openide.util.NbBundle; - -import java.awt.*; -import java.util.StringTokenizer; -import java.util.MissingResourceException; - -/** - * This provides package scope utilities for debugging and code - * internationalization. It is designed to have a subclass, - * ErrorManager instance and bundle in each client's package. - *

- * It ensures localized strings will be loaded from Bundle.properties - * (branded) in same package as subclass belongs. - *

- * Debugging methods use {@link org.openide.ErrorManager} to log messages. - * ErrorManager instance also belongs to sub-class's package. - * - * @author Libor Kramolis - */ -public abstract class AbstractUtil { - /** Instance package ErrorManager. */ - private ErrorManager packageErrorManager; - /** Default debug severity used with ErrorManager. */ - private static final int DEBUG_SEVERITY = ErrorManager.INFORMATIONAL; - - // - // String localizing purposes - // - - - /** - * Get localized string from package bundle. - * @param key Key identifing localized value. - * @return localized value. - */ - public final String getString (Class clazz, String key) { - if (key == null) throw new NullPointerException(); - return NbBundle.getMessage (clazz, key); - } - - /** - * Get localized string from package bundle. - * @param key Key identifing localized value (MessageFormat). - * @param param An argument {0} used for message parametrization. - * @return localized value. - */ - public final String getString (Class clazz, String key, Object param) { - if (key == null) throw new NullPointerException(); - return NbBundle.getMessage (clazz, key, param); - } - - /** - * Get localized string from package bundle. - * @param key Key identifing localized value (MessageFormat). - * @param param1 An argument {0} used for message parametrization. - * @param param2 An argument {1} used for message parametrization. - * @return Localized value. - */ - public final String getString (Class clazz, String key, Object param1, Object param2) { - if (key == null) throw new NullPointerException(); - return NbBundle.getMessage (clazz, key, param1, param2); - } - - /** - * Get localized character from package bundle. Usually used on mnemonic. - * @param key Key identifing localized value. - * @return localized value. - */ - public final char getChar (Class clazz, String key) { - if (key == null) throw new NullPointerException(); - return NbBundle.getMessage (clazz, key).charAt (0); - } - - - /** - * Loads branded color. Parses syntax given by to Color(int,int,int) constructor: - * e.g.: 0,255,128. - * @return color or null if bundle contains null literal - * (masking) or of entry miss at all. - * @throws MissingResourceException on invalid color syntax - */ - public final Color getColor(String key) { - String raw = null; - try { - raw = getString(AbstractUtil.class, key); - } catch (MissingResourceException e) { - return null; - } - StringTokenizer tokenizer = new StringTokenizer(raw, ", \t"); // NOI18N - if (tokenizer.countTokens() < 3) { - if (tokenizer.countTokens() == 1) { - if ("null".equals(tokenizer.nextToken())) return null; // NOI18N - } - throw new MissingResourceException("Invalid color format: " + raw, getClass().getName(), key); // NOI18N - } - - String red = tokenizer.nextToken(); - String green = tokenizer.nextToken(); - String blue = tokenizer.nextToken(); - int r = Integer.parseInt(red); - if (r<0 || r>255) throw new MissingResourceException("Invalid color format: " + raw, getClass().getName(), key); // NOI18N - int g = Integer.parseInt(green); - if (g<0 || g>255) throw new MissingResourceException("Invalid color format: " + raw, getClass().getName(), key); // NOI18N - int b = Integer.parseInt(blue); - if (b<0 || b>255) throw new MissingResourceException("Invalid color format: " + raw, getClass().getName(), key); // NOI18N - // ignore remainig tokens, possibly alpha in future - - return new Color(r, g, b); - } - - // - // Debugging purposes - // - - /** - * Check whether running at loggable level. - * @return true if debug (...) will log something. - */ - public final boolean isLoggable () { - return getErrorManager().isLoggable (DEBUG_SEVERITY); - } - - /** - * Log a message if package log level passes. - * @param message Message to log down. null is allowed - * but is not logged. - */ - public final void debug (String message) { - if (message == null) return; - getErrorManager().log (DEBUG_SEVERITY, message); - } - - /** - * Always log a exception. - * @param ex Exception to log down. null is allowed - * but is not logged. - */ - public final void debug (Throwable ex) { - if (ex == null) return; - getErrorManager().notify (DEBUG_SEVERITY, ex); - } - - /** - * Always log an annotated exception. - * @param message Message used for exception annotation or null. - * @param ex Exception to log down. null is allowed - * but is not logged. - */ - public final void debug (String message, Throwable ex) { - if (ex == null) return; - if (message != null) { - ex = getErrorManager().annotate(ex, DEBUG_SEVERITY, message, null, null, null); - } - debug (ex); - } - - /** - * Provide an ErrorManager instance named per subclass package. - * @return ErrorManager which is default for package where is class - * declared . - */ - public final synchronized ErrorManager getErrorManager () { - if ( packageErrorManager == null ) { - String pack = "org.netbeans.modules.xml.core.lib"; // NOI18N - packageErrorManager = ErrorManager.getDefault().getInstance(pack); - } - return packageErrorManager; - } - -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/lib/Bundle.properties --- a/xml/src/org/netbeans/modules/xml/lib/Bundle.properties Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/lib/Bundle.properties Tue Sep 23 16:17:22 2008 -0500 @@ -41,40 +41,3 @@ ## FileUtilities # {0} - file name including extension PROP_replaceMsg=File {0} already exists.\nDo you want to replace it? - -## StreamFileSystem.java -PROP_StreamFileSystem=StreamFileSystem - - -## Convertors.java -# Encoding display names taken from TAx library -NAME_ISO-8859-1=ISO-8859-1 (Latin 1) -NAME_IBM870=IBM870 -NAME_ISO-2022-JP=ISO-2022-JP -NAME_ISO-8859-3=ISO-8859-3 -NAME_IBM424=IBM424 -NAME_KOI8-R=KOI8-R (Russian) -NAME_IBM280=IBM280 -NAME_ISO-8859-4=ISO-8859-4 -NAME_IBM285=IBM285 -NAME_EUC-JP=EUC-JP -NAME_UTF-8=UTF-8 (recommended) -NAME_IBM297=IBM297 -NAME_ASCII=ASCII (7-bit) -NAME_ISO-8859-2=ISO-8859-2 -NAME_UTF-16=UTF-16 (recommended) -NAME_IBM500=IBM500 -NAME_IBM277=IBM277 -NAME_GB2312=GB2312 -NAME_ISO-8859-9=ISO-8859-9 -NAME_IBM871=IBM871 -NAME_ISO-8859-7=ISO-8859-7 -NAME_IBM037=IBM037 -NAME_IBM918=IBM918 -NAME_IBM284=IBM284 -NAME_ISO-2022-KR=ISO-2022-KR -NAME_EUC-KR=EUC-KR -NAME_ISO-8859-6=ISO-8859-6 -NAME_ISO-8859-8=ISO-8859-8 -NAME_BIG5=BIG5 -NAME_ISO-8859-5=ISO-8859-5 diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/lib/Convertors.java --- a/xml/src/org/netbeans/modules/xml/lib/Convertors.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,158 +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.modules.xml.lib; - -import java.io.Reader; -import java.io.StringReader; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.EOFException; - -import javax.swing.text.Document; - -import org.xml.sax.InputSource; - -import org.netbeans.modules.xml.text.TextEditorSupport; -import org.openide.ErrorManager; -import org.openide.util.Lookup; -import java.net.URL; - -import org.openide.filesystems.FileObject; -import org.openide.loaders.DataObject; - -/** - * Set of static methods converting misc data representations. - * - * @author Petr Kuzel - * @version 0.9 - */ -public final class Convertors { - - - /** - * @return current state of Document as string - */ - public static String documentToString(final Document doc) { - - if (doc == null) throw new NullPointerException(); - - final String[] str = new String[1]; - - // safely take the text from the document - Runnable run = new Runnable() { - public void run () { - try { - str[0] = doc.getText(0, doc.getLength()); - } catch (javax.swing.text.BadLocationException e) { - // impossible - e.printStackTrace(); - } - } - }; - - doc.render(run); - return str[0]; - - } - - /** - * @return InputSource, a callie SHOULD set systemId if available - */ - public static InputSource documentToInputSource(Document doc) { - - if (doc == null) throw new NullPointerException(); - - String text = documentToString(doc); - Reader reader = new StringReader(text); - - // our specifics property - String system = (String) doc.getProperty(TextEditorSupport.PROP_DOCUMENT_URL); - - // try Swing general property - if (system == null) { - Object obj = doc.getProperty(Document.StreamDescriptionProperty); - if (obj instanceof DataObject) { - try { - DataObject dobj = (DataObject) obj; - FileObject fo = dobj.getPrimaryFile(); - URL url = fo.getURL(); - system = url.toExternalForm(); - } catch (IOException io) { - ErrorManager emgr = Lookup.getDefault().lookup(ErrorManager.class); - emgr.notify(io); - } - } else { - ErrorManager emgr = Lookup.getDefault().lookup(ErrorManager.class); - emgr.log("XML:Convertors:Unknown stream description:" + obj); - } - } - - // set something, some parsers are nervous if no system id - if (system == null) { - system = "XML/Convertors/documentToInputSource()"; //NOI18N - } - - InputSource in = new InputSource(system); // NOI18N - in.setCharacterStream(reader); - return in; - } - - - /** - * Wrap reader into buffered one and start reading returning - * String as a EOF is reached. - */ - public static String readerToString(Reader reader) throws IOException { - - BufferedReader fastReader = new BufferedReader(reader); - StringBuffer buf = new StringBuffer(1024); - try { - for (int i = fastReader.read(); i >= 0; i = fastReader.read()) { - buf.append((char)i); - } - } catch (EOFException eof) { - //expected - } - - return buf.toString(); - } - -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/lib/FileUtilities.java --- a/xml/src/org/netbeans/modules/xml/lib/FileUtilities.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/lib/FileUtilities.java Tue Sep 23 16:17:22 2008 -0500 @@ -40,6 +40,7 @@ */ package org.netbeans.modules.xml.lib; +import org.netbeans.modules.xml.util.Util; import java.io.IOException; import org.openide.loaders.DataObject; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/lib/GuiUtil.java --- a/xml/src/org/netbeans/modules/xml/lib/GuiUtil.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/lib/GuiUtil.java Tue Sep 23 16:17:22 2008 -0500 @@ -40,6 +40,7 @@ */ package org.netbeans.modules.xml.lib; +import org.netbeans.modules.xml.util.Util; import java.awt.event.ActionEvent; import javax.swing.Action; import javax.swing.SwingUtilities; @@ -47,12 +48,15 @@ import org.openide.ErrorManager; import org.openide.NotifyDescriptor; import org.openide.DialogDisplayer; +import org.openide.actions.ActionManager; import org.openide.awt.StatusDisplayer; import org.openide.filesystems.FileObject; import org.openide.nodes.Node; import org.openide.loaders.DataObject; import org.openide.loaders.DataObjectNotFoundException; +import org.openide.util.Lookup; import org.openide.util.Mutex; +import org.openide.util.actions.SystemAction; /** * @author Libor Kramolis @@ -61,6 +65,20 @@ private GuiUtil() {} + /** + * Perform default action on specified data object. + */ + public static void performDefaultAction (DataObject dataObject) { + + Node node = dataObject.getNodeDelegate(); + SystemAction action = node.getDefaultAction(); + + if (action != null) { + ActionManager manager = (ActionManager) Lookup.getDefault().lookup(ActionManager.class); + manager.invokeAction(action, new ActionEvent (node, ActionEvent.ACTION_PERFORMED, "")); // NOI18N + } + } + /** * Try to perform default action on specified file object. */ diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/lib/LookupManager.java --- a/xml/src/org/netbeans/modules/xml/lib/LookupManager.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,198 +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.modules.xml.lib; - -import java.util.*; - -import org.openide.util.*; - -/** - * - * @author Libor Kramolis, Jesse Glick - * @version 0.2 - */ -public abstract class LookupManager { - /** */ - private static final Map handles = new WeakHashMap(); - - /** */ - private Handle handle = null; - - - // - // init - // - - /** - * Create new LookupManager. Call register() when ready. - */ - public LookupManager () { - } - - - /** To be called when it is fully initialized and ready to receive events. - * Subclasses may wish to call addedToResult (getResults()) immediately. - */ - protected final void register (Class clazz) { - if ( handle != null ) { - throw new IllegalStateException(); - } - synchronized (handles) { - handle = (Handle)handles.get (clazz); - if ( handle == null ) { - handles.put (clazz, handle = new Handle (clazz)); - } - } - handle.register (this); - } - - - // - // itself - // - - /** - */ - protected final Collection getResult() { - return handle.getInstances(); - } - - - /** - */ - protected abstract void removedFromResult (Collection removed); - - /** - */ - protected abstract void addedToResult (Collection added); - - - // - // class Handle - // - - /** - * - */ - private static final class Handle implements LookupListener { - - private final Class clazz; - private Lookup.Result lookupResult = null; - private Collection lastResult = null; - private final Set lms = new WeakSet(300); - - // - // init - // - - /** - */ - private Handle (Class clazz) { - this.clazz = clazz; - } - - /** - */ - public void register (LookupManager lm) { - synchronized (lms) { - lms.add (lm); - } - } - - - // - // itself - // - - /** - */ - private Lookup.Result getLookupResult () { - if ( lookupResult == null ) { - lookupResult = (Lookup.getDefault()).lookup (new Lookup.Template (clazz)); - lookupResult.addLookupListener (this); - } - return lookupResult; - } - - /** - */ - public void resultChanged (LookupEvent evt) { - Collection currentResult = getLookupResult().allInstances(); - - Collection removed = new HashSet (lastResult); - removed.removeAll (currentResult); - Collection added = new HashSet (currentResult); - added.removeAll (lastResult); - - if ( ( removed.isEmpty() == false ) || - ( added.isEmpty() == false ) ) { - synchronized (lms) { - Iterator it = lms.iterator(); - while (it.hasNext()) { - LookupManager lm = (LookupManager)it.next(); - if ( removed.isEmpty() == false ) { - lm.removedFromResult(removed); - } - if ( added.isEmpty() == false ) { - lm.addedToResult(added); - } - } - } - } - - lastResult = currentResult; - } - - /** - */ - public Collection getInstances() { - //!!! can we use caching? I'm affraid we cannot because - // lookup callbakcs are asynchronous so we can miss some - // registrations (it may be crucuial for cookies) - if (lastResult == null) { - lastResult = getLookupResult().allInstances(); - } - return lastResult; - } - - } // end: class Handle - -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/lib/StreamFileObject.java --- a/xml/src/org/netbeans/modules/xml/lib/StreamFileObject.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,191 +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.modules.xml.lib; - -import java.io.*; -import java.util.*; - -import org.openide.filesystems.*; -import org.openide.filesystems.FileSystem; - -/** - * This file object represents an InputStream. - * - * @author Petr Kuzel - * @version untested draft - */ -public class StreamFileObject extends FileObject { - - /** Serial Version UID */ - private static final long serialVersionUID =8966806836211837503L; - - - private org.openide.filesystems.FileObject[] files; //kids - - private boolean isRoot; //does it represent folder (root); - - private InputStream peer; //wrapped input stream - - private FileSystem fs; - - - //my filesystem - - /** Creates new StreamFileObject */ - public StreamFileObject(InputStream in) { - this(in, false); - } - - public StreamFileObject(InputStream in, boolean isRoot) { - this.isRoot = isRoot; - peer = in; - if (isRoot) { - files = new org.openide.filesystems.FileObject[] { - new StreamFileObject(in) - }; - } else { - files = new org.openide.filesystems.FileObject[0]; - } - fs = new StreamFileSystem(this); - } - - public org.openide.filesystems.FileObject[] getChildren() { - return files; - } - - public void removeFileChangeListener(org.openide.filesystems.FileChangeListener fileChangeListener) { - } - - public org.openide.filesystems.FileLock lock() throws java.io.IOException { - return FileLock.NONE; - } - - public java.lang.Object getAttribute(java.lang.String str) { - return null; - } - - public java.util.Date lastModified() { - return new Date(0L); - } - - public java.lang.String getExt() { - return "InputStream"; // NOI18N - } - - @Deprecated - public boolean isReadOnly() { - return true; - } - - public org.openide.filesystems.FileObject createData(java.lang.String str, java.lang.String str1) throws java.io.IOException { - return null; - } - - public void delete(org.openide.filesystems.FileLock fileLock) throws java.io.IOException { - } - - public org.openide.filesystems.FileObject createFolder(java.lang.String str) throws java.io.IOException { - return null; - } - - public void rename(org.openide.filesystems.FileLock fileLock, java.lang.String str, java.lang.String str2) throws java.io.IOException { - } - - public boolean isData() { - return isRoot == false; - } - - public java.io.OutputStream getOutputStream(org.openide.filesystems.FileLock fileLock) throws java.io.IOException { - throw new IOException("r/o"); // NOI18N - } - - public java.io.InputStream getInputStream() throws java.io.FileNotFoundException { - return peer; - } - - public boolean isValid() { - return true; - } - - public java.util.Enumeration getAttributes() { - return org.openide.util.Enumerations.empty(); - } - - public java.lang.String getName() { - return "StreamFileObject"; // NOI18N - } - - @Deprecated - public void setImportant(boolean param) { - } - - public boolean isFolder() { - return isRoot; - } - - public void setAttribute(java.lang.String str, java.lang.Object obj) throws java.io.IOException { - } - - public void addFileChangeListener(org.openide.filesystems.FileChangeListener fileChangeListener) { - } - - public long getSize() { - return 766; //!!! - } - - public org.openide.filesystems.FileObject getParent() { - if (isRoot) return null; - return fs.getRoot(); - } - - public boolean isRoot() { - return isRoot; - } - - public org.openide.filesystems.FileObject getFileObject(java.lang.String str, java.lang.String str1) { - return null; - } - - public org.openide.filesystems.FileSystem getFileSystem() throws org.openide.filesystems.FileStateInvalidException { - return fs; - } - -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/lib/StreamFileSystem.java --- a/xml/src/org/netbeans/modules/xml/lib/StreamFileSystem.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +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.modules.xml.lib; - -import org.openide.filesystems.*; - -/** - * It represents r/o filesystem given by an InputStream. - * Such filesystem contains just one StreamFileObject. - * - * @author Petr Kuzel - * @version untested draft - */ -class StreamFileSystem extends FileSystem { - - /** Serial Version UID */ - private static final long serialVersionUID =2822790916118072639L; - - private FileObject root; - - // == StreamFileObject - - /** Creates new StreamFileSystem */ - public StreamFileSystem(StreamFileObject root) { - this.root = root; - } - - public org.openide.filesystems.FileObject getRoot() { - return root; - } - - public org.openide.filesystems.FileObject findResource(java.lang.String str) { - return null; - } - - public org.openide.util.actions.SystemAction[] getActions() { - return new org.openide.util.actions.SystemAction[0]; - } - - public boolean isReadOnly() { - return true; - } - - public java.lang.String getDisplayName() { - return Util.THIS.getString ( - StreamFileSystem.class, "PROP_StreamFileSystem"); - } - -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/lib/Util.java --- a/xml/src/org/netbeans/modules/xml/lib/Util.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,426 +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.modules.xml.lib; - -import java.awt.event.ActionEvent; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.TreeSet; - -import javax.swing.JFileChooser; -import javax.swing.filechooser.FileFilter; - -import org.openide.NotifyDescriptor; -import org.openide.DialogDisplayer; -import org.openide.actions.ActionManager; -import org.openide.windows.WindowManager; - -import org.netbeans.api.xml.services.UserCatalog; - -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.loaders.DataObject; -import org.openide.util.Lookup; -import org.openide.util.actions.SystemAction; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathFactory; -import javax.xml.namespace.NamespaceContext; -import org.netbeans.modules.xml.wizard.SchemaParser; -import org.openide.nodes.Node; -import org.xml.sax.InputSource; -import org.w3c.dom.NodeList; - - -/** - * Collection of static support methods. - * - * @author Petr Kuzel - */ -public class Util extends AbstractUtil { - - // last catalog directory - private static File lastDirectory; - - /** Default and only one instance of this class. */ - public static final Util THIS = new Util(); - public static final String NO_NAME_SPACE = "NO_NAME_SPACE"; //NOI18N - - /** Nobody can create instance of it, just me. */ - private Util () { - } - - /** - * Prompts user for a Schema file. - * @param extensions a space separated list of file extensions - * @return filename or null if operation was cancelled. - */ - public static File selectSchemaFile(final String extensions) { - JFileChooser chooser = new JFileChooser(); - - chooser.setFileFilter(new FileFilter() { - public boolean accept(File f) { - if (f.isDirectory()) return true; - StringTokenizer token = new StringTokenizer(extensions, " "); // NOI18N - while (token.hasMoreElements()) { - if (f.getName().endsWith(token.nextToken())) return true; - } - return false; - } - public String getDescription() { - return Util.THIS.getString(Util.class, "PROP_schema_mask"); // NOI18N - } - }); - - if (lastDirectory != null) { - chooser.setCurrentDirectory(lastDirectory); - } - - chooser.setDialogTitle(Util.THIS.getString(Util.class, "PROP_schema_dialog_name")); - while (chooser.showDialog(WindowManager.getDefault().getMainWindow(), - Util.THIS.getString(Util.class, "PROP_schema_select_button")) - == JFileChooser.APPROVE_OPTION) - { - File f = chooser.getSelectedFile(); - lastDirectory = chooser.getCurrentDirectory(); - if (f != null && f.isFile()) { - StringTokenizer token = new StringTokenizer(extensions, " "); // NOI18N - while (token.hasMoreElements()) { - if (f.getName().endsWith(token.nextToken())) return f; - } - } - - DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( - Util.THIS.getString(Util.class, "MSG_inValidFile"), NotifyDescriptor.WARNING_MESSAGE)); - } - return null; - } - - /** - * Obtain all known DTD public IDs. - */ - public static String[] getKnownDTDPublicIDs() { - UserCatalog catalog = UserCatalog.getDefault(); - if (catalog != null) { - Set idSet = new TreeSet(); - for (Iterator it = catalog.getPublicIDs(); it.hasNext(); ) { - String next = (String) it.next(); - // exclude schema publicIDs - String nextLowerCase = next.toLowerCase(); - if (!nextLowerCase.startsWith("schema:") && !nextLowerCase.endsWith(".xsd")) { // NOI18N - idSet.add(next); - } - } - return (String[]) idSet.toArray(new String[idSet.size()]); - } else { - Util.THIS.debug("Note SourceResolver not found!"); // NOI18N - return new String[0]; - } - } - - /** - * Perform default action on specified data object. - */ - public static void performDefaultAction (DataObject dataObject) { - - Node node = dataObject.getNodeDelegate(); - SystemAction action = node.getDefaultAction(); - - if (action != null) { - ActionManager manager = (ActionManager) Lookup.getDefault().lookup(ActionManager.class); - manager.invokeAction(action, new ActionEvent (node, ActionEvent.ACTION_PERFORMED, "")); // NOI18N - } - } - - public static String getDocumentType() { - return "xsd"; - } - - public static Map getFiles2NSMappingInProj(File rootFile, String docType){ - List fileList = getFilesWithExtension(rootFile, docType, new ArrayList()); - Map result = new HashMap(); - String xpathQuery = "//xsd:schema/@targetNamespace"; - - for(int i=0; i < fileList.size();i++){ - File file = (File)fileList.get(i); - - if(Thread.currentThread().isInterrupted()) - //if interrupted by the client dump the result and immediately return - break; - List targetNSList = null; - try { - targetNSList = runXPathQuery(file, xpathQuery); - String targetNS = null; - FileObject fobj = FileUtil.toFileObject(file); - if(targetNSList.size() > 0){ - //just take the first and ignore rest - targetNS = (String)targetNSList.get(0); - } else{ - targetNS = NO_NAME_SPACE; - } - if( (targetNS == NO_NAME_SPACE)) - //this is wsdl and it must have NS so ignore this file - continue; - result.put(fobj, targetNS); - } catch (Exception ex) { - //ex.printStackTrace(); - //ignore this route - } - } - return result; - } - - public static List getFilesWithExtension(File startFile, String fileExtension, List curList) { - if(Thread.currentThread().isInterrupted()) - //if interrupted by the client dump the result and immediately return - return curList; - if(curList == null) - curList = new ArrayList(); - if(startFile.isFile()){ - int index = startFile.getName().lastIndexOf("."); - if(index != -1){ - String extn = startFile.getName().substring(index+1); - if((extn != null) && (extn.equalsIgnoreCase(fileExtension))) - curList.add(startFile); - } - } - if(startFile.isDirectory()){ - File[] children = startFile.listFiles(); - if(children != null){ - for(int i=0; i < children.length; i++ ){ - File child = (File) children[i]; - getFilesWithExtension(child, fileExtension, curList); - } - } - } - return curList; - } - - public static List runXPathQuery(File parsedFile, String xpathExpr) throws Exception{ - List result = new ArrayList(); - XPath xpath = XPathFactory.newInstance().newXPath(); - xpath.setNamespaceContext(getNamespaceContext()); - - InputSource inputSource = new InputSource(new FileInputStream(parsedFile)); - NodeList nodes = (NodeList) xpath.evaluate(xpathExpr, inputSource, XPathConstants.NODESET); - if((nodes != null) && (nodes.getLength() > 0)){ - for(int i=0; i e : namespaces.entrySet()) { - Entry e = (Entry)it.next(); - prefixes.put(e.getValue(), e.getKey()); - } - } - - public HashNamespaceResolver(Map namespaces, Map prefixes) { - this.namespaces = namespaces; - this.prefixes = prefixes; - } - - public Iterator getPrefixes(String namespaceURI) { - return Collections.singletonList(getPrefix(namespaceURI)).iterator(); - } - - public String getPrefix(String namespaceURI) { - return (String)prefixes.get(namespaceURI); - } - - public String getNamespaceURI(String prefix) { - return (String)namespaces.get(prefix); - } - } - -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/sync/DataObjectSyncSupport.java --- a/xml/src/org/netbeans/modules/xml/sync/DataObjectSyncSupport.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/sync/DataObjectSyncSupport.java Tue Sep 23 16:17:22 2008 -0500 @@ -48,7 +48,7 @@ import org.netbeans.modules.xml.XMLDataObjectLook; import org.netbeans.modules.xml.cookies.CookieManagerCookie; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.openide.cookies.EditorCookie; import org.openide.filesystems.FileObject; import org.openide.loaders.DataObject; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/sync/FileRepresentation.java --- a/xml/src/org/netbeans/modules/xml/sync/FileRepresentation.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/sync/FileRepresentation.java Tue Sep 23 16:17:22 2008 -0500 @@ -40,6 +40,7 @@ */ package org.netbeans.modules.xml.sync; +import org.netbeans.modules.xml.util.Util; import java.util.Date; import java.io.*; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/sync/SyncSupport.java --- a/xml/src/org/netbeans/modules/xml/sync/SyncSupport.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/sync/SyncSupport.java Tue Sep 23 16:17:22 2008 -0500 @@ -45,7 +45,7 @@ import org.openide.nodes.*; import java.util.Vector; import java.util.Arrays; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; /** * A generic support for synchronizing text, tree and file representation diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/text/TextEditorComponent.java --- a/xml/src/org/netbeans/modules/xml/text/TextEditorComponent.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/text/TextEditorComponent.java Tue Sep 23 16:17:22 2008 -0500 @@ -48,7 +48,7 @@ import javax.swing.event.CaretEvent; import javax.swing.event.CaretListener; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.openide.windows.Workspace; import org.openide.windows.Mode; import org.openide.windows.WindowManager; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/text/TextEditorSupport.java --- a/xml/src/org/netbeans/modules/xml/text/TextEditorSupport.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/text/TextEditorSupport.java Tue Sep 23 16:17:22 2008 -0500 @@ -40,6 +40,7 @@ */ package org.netbeans.modules.xml.text; +import org.netbeans.modules.xml.util.Util; import java.io.*; import java.text.*; import java.util.Enumeration; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/text/TextRepresentation.java --- a/xml/src/org/netbeans/modules/xml/text/TextRepresentation.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/text/TextRepresentation.java Tue Sep 23 16:17:22 2008 -0500 @@ -40,6 +40,8 @@ */ package org.netbeans.modules.xml.text; +import org.netbeans.modules.xml.util.Util; +import org.netbeans.modules.xml.util.Convertors; import java.io.Reader; import java.io.StringReader; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/text/XMLTextRepresentation.java --- a/xml/src/org/netbeans/modules/xml/text/XMLTextRepresentation.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/text/XMLTextRepresentation.java Tue Sep 23 16:17:22 2008 -0500 @@ -47,7 +47,7 @@ import javax.swing.JViewport; import javax.swing.text.StyledDocument; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.openide.*; import org.openide.cookies.*; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/util/AbstractUtil.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/util/AbstractUtil.java Tue Sep 23 16:17:22 2008 -0500 @@ -0,0 +1,214 @@ +/* + * 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.modules.xml.util; + +import org.openide.ErrorManager; +import org.openide.util.Lookup; +import org.openide.util.NbBundle; + +import java.awt.*; +import java.util.StringTokenizer; +import java.util.MissingResourceException; + +/** + * This provides package scope utilities for debugging and code + * internationalization. It is designed to have a subclass, + * ErrorManager instance and bundle in each client's package. + *

+ * It ensures localized strings will be loaded from Bundle.properties + * (branded) in same package as subclass belongs. + *

+ * Debugging methods use {@link org.openide.ErrorManager} to log messages. + * ErrorManager instance also belongs to sub-class's package. + * + * @author Libor Kramolis + */ +public abstract class AbstractUtil { + /** Instance package ErrorManager. */ + private ErrorManager packageErrorManager; + /** Default debug severity used with ErrorManager. */ + private static final int DEBUG_SEVERITY = ErrorManager.INFORMATIONAL; + + // + // String localizing purposes + // + + + /** + * Get localized string from package bundle. + * @param key Key identifing localized value. + * @return localized value. + */ + public final String getString (Class clazz, String key) { + if (key == null) throw new NullPointerException(); + return NbBundle.getMessage (clazz, key); + } + + /** + * Get localized string from package bundle. + * @param key Key identifing localized value (MessageFormat). + * @param param An argument {0} used for message parametrization. + * @return localized value. + */ + public final String getString (Class clazz, String key, Object param) { + if (key == null) throw new NullPointerException(); + return NbBundle.getMessage (clazz, key, param); + } + + /** + * Get localized string from package bundle. + * @param key Key identifing localized value (MessageFormat). + * @param param1 An argument {0} used for message parametrization. + * @param param2 An argument {1} used for message parametrization. + * @return Localized value. + */ + public final String getString (Class clazz, String key, Object param1, Object param2) { + if (key == null) throw new NullPointerException(); + return NbBundle.getMessage (clazz, key, param1, param2); + } + + /** + * Get localized character from package bundle. Usually used on mnemonic. + * @param key Key identifing localized value. + * @return localized value. + */ + public final char getChar (Class clazz, String key) { + if (key == null) throw new NullPointerException(); + return NbBundle.getMessage (clazz, key).charAt (0); + } + + + /** + * Loads branded color. Parses syntax given by to Color(int,int,int) constructor: + * e.g.: 0,255,128. + * @return color or null if bundle contains null literal + * (masking) or of entry miss at all. + * @throws MissingResourceException on invalid color syntax + */ + public final Color getColor(String key) { + String raw = null; + try { + raw = getString(AbstractUtil.class, key); + } catch (MissingResourceException e) { + return null; + } + StringTokenizer tokenizer = new StringTokenizer(raw, ", \t"); // NOI18N + if (tokenizer.countTokens() < 3) { + if (tokenizer.countTokens() == 1) { + if ("null".equals(tokenizer.nextToken())) return null; // NOI18N + } + throw new MissingResourceException("Invalid color format: " + raw, getClass().getName(), key); // NOI18N + } + + String red = tokenizer.nextToken(); + String green = tokenizer.nextToken(); + String blue = tokenizer.nextToken(); + int r = Integer.parseInt(red); + if (r<0 || r>255) throw new MissingResourceException("Invalid color format: " + raw, getClass().getName(), key); // NOI18N + int g = Integer.parseInt(green); + if (g<0 || g>255) throw new MissingResourceException("Invalid color format: " + raw, getClass().getName(), key); // NOI18N + int b = Integer.parseInt(blue); + if (b<0 || b>255) throw new MissingResourceException("Invalid color format: " + raw, getClass().getName(), key); // NOI18N + // ignore remainig tokens, possibly alpha in future + + return new Color(r, g, b); + } + + // + // Debugging purposes + // + + /** + * Check whether running at loggable level. + * @return true if debug (...) will log something. + */ + public final boolean isLoggable () { + return getErrorManager().isLoggable (DEBUG_SEVERITY); + } + + /** + * Log a message if package log level passes. + * @param message Message to log down. null is allowed + * but is not logged. + */ + public final void debug (String message) { + if (message == null) return; + getErrorManager().log (DEBUG_SEVERITY, message); + } + + /** + * Always log a exception. + * @param ex Exception to log down. null is allowed + * but is not logged. + */ + public final void debug (Throwable ex) { + if (ex == null) return; + getErrorManager().notify (DEBUG_SEVERITY, ex); + } + + /** + * Always log an annotated exception. + * @param message Message used for exception annotation or null. + * @param ex Exception to log down. null is allowed + * but is not logged. + */ + public final void debug (String message, Throwable ex) { + if (ex == null) return; + if (message != null) { + ex = getErrorManager().annotate(ex, DEBUG_SEVERITY, message, null, null, null); + } + debug (ex); + } + + /** + * Provide an ErrorManager instance named per subclass package. + * @return ErrorManager which is default for package where is class + * declared . + */ + public final synchronized ErrorManager getErrorManager () { + if ( packageErrorManager == null ) { + String pack = "org.netbeans.modules.xml.core.lib"; // NOI18N + packageErrorManager = ErrorManager.getDefault().getInstance(pack); + } + return packageErrorManager; + } + +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/util/Convertors.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/util/Convertors.java Tue Sep 23 16:17:22 2008 -0500 @@ -0,0 +1,158 @@ +/* + * 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.modules.xml.util; + +import java.io.Reader; +import java.io.StringReader; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.EOFException; + +import javax.swing.text.Document; + +import org.xml.sax.InputSource; + +import org.netbeans.modules.xml.text.TextEditorSupport; +import org.openide.ErrorManager; +import org.openide.util.Lookup; +import java.net.URL; + +import org.openide.filesystems.FileObject; +import org.openide.loaders.DataObject; + +/** + * Set of static methods converting misc data representations. + * + * @author Petr Kuzel + * @version 0.9 + */ +public final class Convertors { + + + /** + * @return current state of Document as string + */ + public static String documentToString(final Document doc) { + + if (doc == null) throw new NullPointerException(); + + final String[] str = new String[1]; + + // safely take the text from the document + Runnable run = new Runnable() { + public void run () { + try { + str[0] = doc.getText(0, doc.getLength()); + } catch (javax.swing.text.BadLocationException e) { + // impossible + e.printStackTrace(); + } + } + }; + + doc.render(run); + return str[0]; + + } + + /** + * @return InputSource, a callie SHOULD set systemId if available + */ + public static InputSource documentToInputSource(Document doc) { + + if (doc == null) throw new NullPointerException(); + + String text = documentToString(doc); + Reader reader = new StringReader(text); + + // our specifics property + String system = (String) doc.getProperty(TextEditorSupport.PROP_DOCUMENT_URL); + + // try Swing general property + if (system == null) { + Object obj = doc.getProperty(Document.StreamDescriptionProperty); + if (obj instanceof DataObject) { + try { + DataObject dobj = (DataObject) obj; + FileObject fo = dobj.getPrimaryFile(); + URL url = fo.getURL(); + system = url.toExternalForm(); + } catch (IOException io) { + ErrorManager emgr = Lookup.getDefault().lookup(ErrorManager.class); + emgr.notify(io); + } + } else { + ErrorManager emgr = Lookup.getDefault().lookup(ErrorManager.class); + emgr.log("XML:Convertors:Unknown stream description:" + obj); + } + } + + // set something, some parsers are nervous if no system id + if (system == null) { + system = "XML/Convertors/documentToInputSource()"; //NOI18N + } + + InputSource in = new InputSource(system); // NOI18N + in.setCharacterStream(reader); + return in; + } + + + /** + * Wrap reader into buffered one and start reading returning + * String as a EOF is reached. + */ + public static String readerToString(Reader reader) throws IOException { + + BufferedReader fastReader = new BufferedReader(reader); + StringBuffer buf = new StringBuffer(1024); + try { + for (int i = fastReader.read(); i >= 0; i = fastReader.read()) { + buf.append((char)i); + } + } catch (EOFException eof) { + //expected + } + + return buf.toString(); + } + +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/util/DefaultXmlFileEncodingQueryImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/util/DefaultXmlFileEncodingQueryImpl.java Tue Sep 23 16:17:22 2008 -0500 @@ -0,0 +1,54 @@ +/* + * 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): + * + * Portions Copyrighted 2007 Sun Microsystems, Inc. + */ +package org.netbeans.modules.xml.util; + +import java.nio.charset.Charset; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.netbeans.modules.xml.api.XmlFileEncodingQueryImpl; +import org.netbeans.spi.queries.FileEncodingQueryImplementation; +import org.openide.filesystems.FileObject; + +/** + * + * @author nam + */ +public class DefaultXmlFileEncodingQueryImpl extends FileEncodingQueryImplementation { + + public Charset getEncoding(FileObject f) { + try { + if (f.getMIMEType().endsWith("xml")) { + return XmlFileEncodingQueryImpl.singleton().getEncoding(f); + } + } catch (Exception ex) { + Logger.getLogger(getClass().getName()).log(Level.FINE, ex.getLocalizedMessage(), ex); + } + return null; + } + +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/util/LookupManager.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/util/LookupManager.java Tue Sep 23 16:17:22 2008 -0500 @@ -0,0 +1,198 @@ +/* + * 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.modules.xml.util; + +import java.util.*; + +import org.openide.util.*; + +/** + * + * @author Libor Kramolis, Jesse Glick + * @version 0.2 + */ +public abstract class LookupManager { + /** */ + private static final Map handles = new WeakHashMap(); + + /** */ + private Handle handle = null; + + + // + // init + // + + /** + * Create new LookupManager. Call register() when ready. + */ + public LookupManager () { + } + + + /** To be called when it is fully initialized and ready to receive events. + * Subclasses may wish to call addedToResult (getResults()) immediately. + */ + protected final void register (Class clazz) { + if ( handle != null ) { + throw new IllegalStateException(); + } + synchronized (handles) { + handle = (Handle)handles.get (clazz); + if ( handle == null ) { + handles.put (clazz, handle = new Handle (clazz)); + } + } + handle.register (this); + } + + + // + // itself + // + + /** + */ + protected final Collection getResult() { + return handle.getInstances(); + } + + + /** + */ + protected abstract void removedFromResult (Collection removed); + + /** + */ + protected abstract void addedToResult (Collection added); + + + // + // class Handle + // + + /** + * + */ + private static final class Handle implements LookupListener { + + private final Class clazz; + private Lookup.Result lookupResult = null; + private Collection lastResult = null; + private final Set lms = new WeakSet(300); + + // + // init + // + + /** + */ + private Handle (Class clazz) { + this.clazz = clazz; + } + + /** + */ + public void register (LookupManager lm) { + synchronized (lms) { + lms.add (lm); + } + } + + + // + // itself + // + + /** + */ + private Lookup.Result getLookupResult () { + if ( lookupResult == null ) { + lookupResult = (Lookup.getDefault()).lookup (new Lookup.Template (clazz)); + lookupResult.addLookupListener (this); + } + return lookupResult; + } + + /** + */ + public void resultChanged (LookupEvent evt) { + Collection currentResult = getLookupResult().allInstances(); + + Collection removed = new HashSet (lastResult); + removed.removeAll (currentResult); + Collection added = new HashSet (currentResult); + added.removeAll (lastResult); + + if ( ( removed.isEmpty() == false ) || + ( added.isEmpty() == false ) ) { + synchronized (lms) { + Iterator it = lms.iterator(); + while (it.hasNext()) { + LookupManager lm = (LookupManager)it.next(); + if ( removed.isEmpty() == false ) { + lm.removedFromResult(removed); + } + if ( added.isEmpty() == false ) { + lm.addedToResult(added); + } + } + } + } + + lastResult = currentResult; + } + + /** + */ + public Collection getInstances() { + //!!! can we use caching? I'm affraid we cannot because + // lookup callbakcs are asynchronous so we can miss some + // registrations (it may be crucuial for cookies) + if (lastResult == null) { + lastResult = getLookupResult().allInstances(); + } + return lastResult; + } + + } // end: class Handle + +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/util/StreamFileObject.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/util/StreamFileObject.java Tue Sep 23 16:17:22 2008 -0500 @@ -0,0 +1,191 @@ +/* + * 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.modules.xml.util; + +import java.io.*; +import java.util.*; + +import org.openide.filesystems.*; +import org.openide.filesystems.FileSystem; + +/** + * This file object represents an InputStream. + * + * @author Petr Kuzel + * @version untested draft + */ +public class StreamFileObject extends FileObject { + + /** Serial Version UID */ + private static final long serialVersionUID =8966806836211837503L; + + + private org.openide.filesystems.FileObject[] files; //kids + + private boolean isRoot; //does it represent folder (root); + + private InputStream peer; //wrapped input stream + + private FileSystem fs; + + + //my filesystem + + /** Creates new StreamFileObject */ + public StreamFileObject(InputStream in) { + this(in, false); + } + + public StreamFileObject(InputStream in, boolean isRoot) { + this.isRoot = isRoot; + peer = in; + if (isRoot) { + files = new org.openide.filesystems.FileObject[] { + new StreamFileObject(in) + }; + } else { + files = new org.openide.filesystems.FileObject[0]; + } + fs = new StreamFileSystem(this); + } + + public org.openide.filesystems.FileObject[] getChildren() { + return files; + } + + public void removeFileChangeListener(org.openide.filesystems.FileChangeListener fileChangeListener) { + } + + public org.openide.filesystems.FileLock lock() throws java.io.IOException { + return FileLock.NONE; + } + + public java.lang.Object getAttribute(java.lang.String str) { + return null; + } + + public java.util.Date lastModified() { + return new Date(0L); + } + + public java.lang.String getExt() { + return "InputStream"; // NOI18N + } + + @Deprecated + public boolean isReadOnly() { + return true; + } + + public org.openide.filesystems.FileObject createData(java.lang.String str, java.lang.String str1) throws java.io.IOException { + return null; + } + + public void delete(org.openide.filesystems.FileLock fileLock) throws java.io.IOException { + } + + public org.openide.filesystems.FileObject createFolder(java.lang.String str) throws java.io.IOException { + return null; + } + + public void rename(org.openide.filesystems.FileLock fileLock, java.lang.String str, java.lang.String str2) throws java.io.IOException { + } + + public boolean isData() { + return isRoot == false; + } + + public java.io.OutputStream getOutputStream(org.openide.filesystems.FileLock fileLock) throws java.io.IOException { + throw new IOException("r/o"); // NOI18N + } + + public java.io.InputStream getInputStream() throws java.io.FileNotFoundException { + return peer; + } + + public boolean isValid() { + return true; + } + + public java.util.Enumeration getAttributes() { + return org.openide.util.Enumerations.empty(); + } + + public java.lang.String getName() { + return "StreamFileObject"; // NOI18N + } + + @Deprecated + public void setImportant(boolean param) { + } + + public boolean isFolder() { + return isRoot; + } + + public void setAttribute(java.lang.String str, java.lang.Object obj) throws java.io.IOException { + } + + public void addFileChangeListener(org.openide.filesystems.FileChangeListener fileChangeListener) { + } + + public long getSize() { + return 766; //!!! + } + + public org.openide.filesystems.FileObject getParent() { + if (isRoot) return null; + return fs.getRoot(); + } + + public boolean isRoot() { + return isRoot; + } + + public org.openide.filesystems.FileObject getFileObject(java.lang.String str, java.lang.String str1) { + return null; + } + + public org.openide.filesystems.FileSystem getFileSystem() throws org.openide.filesystems.FileStateInvalidException { + return fs; + } + +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/util/StreamFileSystem.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/util/StreamFileSystem.java Tue Sep 23 16:17:22 2008 -0500 @@ -0,0 +1,88 @@ +/* + * 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.modules.xml.util; + +import org.netbeans.modules.xml.lib.*; +import org.openide.filesystems.*; + +/** + * It represents r/o filesystem given by an InputStream. + * Such filesystem contains just one StreamFileObject. + * + * @author Petr Kuzel + * @version untested draft + */ +class StreamFileSystem extends FileSystem { + + /** Serial Version UID */ + private static final long serialVersionUID =2822790916118072639L; + + private FileObject root; + + // == StreamFileObject + + /** Creates new StreamFileSystem */ + public StreamFileSystem(StreamFileObject root) { + this.root = root; + } + + public org.openide.filesystems.FileObject getRoot() { + return root; + } + + public org.openide.filesystems.FileObject findResource(java.lang.String str) { + return null; + } + + public org.openide.util.actions.SystemAction[] getActions() { + return new org.openide.util.actions.SystemAction[0]; + } + + public boolean isReadOnly() { + return true; + } + + public java.lang.String getDisplayName() { + return Util.THIS.getString ( + StreamFileSystem.class, "PROP_StreamFileSystem"); + } + +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/util/Util.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/util/Util.java Tue Sep 23 16:17:22 2008 -0500 @@ -0,0 +1,360 @@ +/* + * 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.modules.xml.util; + +import java.awt.event.ActionEvent; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.TreeSet; + +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileFilter; + +import org.openide.NotifyDescriptor; +import org.openide.DialogDisplayer; +import org.openide.actions.ActionManager; +import org.openide.windows.WindowManager; + +import org.netbeans.api.xml.services.UserCatalog; + +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.loaders.DataObject; +import org.openide.util.Lookup; +import org.openide.util.actions.SystemAction; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathFactory; +import javax.xml.namespace.NamespaceContext; +import org.netbeans.modules.xml.wizard.SchemaParser; +import org.openide.nodes.Node; +import org.xml.sax.InputSource; +import org.w3c.dom.NodeList; + + +/** + * Collection of static support methods. + * + * @author Petr Kuzel + */ +public class Util extends AbstractUtil { + + // last catalog directory + private static File lastDirectory; + + /** Default and only one instance of this class. */ + public static final Util THIS = new Util(); + public static final String NO_NAME_SPACE = "NO_NAME_SPACE"; //NOI18N + + /** Nobody can create instance of it, just me. */ + private Util () { + } + + /** + * Prompts user for a Schema file. + * @param extensions a space separated list of file extensions + * @return filename or null if operation was cancelled. + */ + public static File selectSchemaFile(final String extensions) { + JFileChooser chooser = new JFileChooser(); + + chooser.setFileFilter(new FileFilter() { + public boolean accept(File f) { + if (f.isDirectory()) return true; + StringTokenizer token = new StringTokenizer(extensions, " "); // NOI18N + while (token.hasMoreElements()) { + if (f.getName().endsWith(token.nextToken())) return true; + } + return false; + } + public String getDescription() { + return Util.THIS.getString(Util.class, "PROP_schema_mask"); // NOI18N + } + }); + + if (lastDirectory != null) { + chooser.setCurrentDirectory(lastDirectory); + } + + chooser.setDialogTitle(Util.THIS.getString(Util.class, "PROP_schema_dialog_name")); + while (chooser.showDialog(WindowManager.getDefault().getMainWindow(), + Util.THIS.getString(Util.class, "PROP_schema_select_button")) + == JFileChooser.APPROVE_OPTION) + { + File f = chooser.getSelectedFile(); + lastDirectory = chooser.getCurrentDirectory(); + if (f != null && f.isFile()) { + StringTokenizer token = new StringTokenizer(extensions, " "); // NOI18N + while (token.hasMoreElements()) { + if (f.getName().endsWith(token.nextToken())) return f; + } + } + + DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( + Util.THIS.getString(Util.class, "MSG_inValidFile"), NotifyDescriptor.WARNING_MESSAGE)); + } + return null; + } + + /** + * Obtain all known DTD public IDs. + */ + public static String[] getKnownDTDPublicIDs() { + UserCatalog catalog = UserCatalog.getDefault(); + if (catalog != null) { + Set idSet = new TreeSet(); + for (Iterator it = catalog.getPublicIDs(); it.hasNext(); ) { + String next = (String) it.next(); + // exclude schema publicIDs + String nextLowerCase = next.toLowerCase(); + if (!nextLowerCase.startsWith("schema:") && !nextLowerCase.endsWith(".xsd")) { // NOI18N + idSet.add(next); + } + } + return (String[]) idSet.toArray(new String[idSet.size()]); + } else { + Util.THIS.debug("Note SourceResolver not found!"); // NOI18N + return new String[0]; + } + } + + public static String getDocumentType() { + return "xsd"; + } + + public static Map getFiles2NSMappingInProj(File rootFile, String docType){ + List fileList = getFilesWithExtension(rootFile, docType, new ArrayList()); + Map result = new HashMap(); + String xpathQuery = "//xsd:schema/@targetNamespace"; + + for(int i=0; i < fileList.size();i++){ + File file = (File)fileList.get(i); + + if(Thread.currentThread().isInterrupted()) + //if interrupted by the client dump the result and immediately return + break; + List targetNSList = null; + try { + targetNSList = runXPathQuery(file, xpathQuery); + String targetNS = null; + FileObject fobj = FileUtil.toFileObject(file); + if(targetNSList.size() > 0){ + //just take the first and ignore rest + targetNS = (String)targetNSList.get(0); + } else{ + targetNS = NO_NAME_SPACE; + } + if( (targetNS == NO_NAME_SPACE)) + //this is wsdl and it must have NS so ignore this file + continue; + result.put(fobj, targetNS); + } catch (Exception ex) { + //ex.printStackTrace(); + //ignore this route + } + } + return result; + } + + public static List getFilesWithExtension(File startFile, String fileExtension, List curList) { + if(Thread.currentThread().isInterrupted()) + //if interrupted by the client dump the result and immediately return + return curList; + if(curList == null) + curList = new ArrayList(); + if(startFile.isFile()){ + int index = startFile.getName().lastIndexOf("."); + if(index != -1){ + String extn = startFile.getName().substring(index+1); + if((extn != null) && (extn.equalsIgnoreCase(fileExtension))) + curList.add(startFile); + } + } + if(startFile.isDirectory()){ + File[] children = startFile.listFiles(); + if(children != null){ + for(int i=0; i < children.length; i++ ){ + File child = (File) children[i]; + getFilesWithExtension(child, fileExtension, curList); + } + } + } + return curList; + } + + public static List runXPathQuery(File parsedFile, String xpathExpr) throws Exception{ + List result = new ArrayList(); + XPath xpath = XPathFactory.newInstance().newXPath(); + xpath.setNamespaceContext(getNamespaceContext()); + + InputSource inputSource = new InputSource(new FileInputStream(parsedFile)); + NodeList nodes = (NodeList) xpath.evaluate(xpathExpr, inputSource, XPathConstants.NODESET); + if((nodes != null) && (nodes.getLength() > 0)){ + for(int i=0; i e : namespaces.entrySet()) { + Entry e = (Entry)it.next(); + prefixes.put(e.getValue(), e.getKey()); + } + } + + public HashNamespaceResolver(Map namespaces, Map prefixes) { + this.namespaces = namespaces; + this.prefixes = prefixes; + } + + public Iterator getPrefixes(String namespaceURI) { + return Collections.singletonList(getPrefix(namespaceURI)).iterator(); + } + + public String getPrefix(String namespaceURI) { + return (String)prefixes.get(namespaceURI); + } + + public String getNamespaceURI(String prefix) { + return (String)namespaces.get(prefix); + } + } + +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/AbstractPanel.java --- a/xml/src/org/netbeans/modules/xml/wizard/AbstractPanel.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/wizard/AbstractPanel.java Tue Sep 23 16:17:22 2008 -0500 @@ -40,6 +40,7 @@ */ package org.netbeans.modules.xml.wizard; +import org.netbeans.modules.xml.wizard.impl.SchemaPanel; import java.util.*; import java.beans.*; @@ -48,7 +49,6 @@ import org.openide.*; import org.openide.util.HelpCtx; -import java.net.URL; import javax.swing.event.ChangeListener; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/Bundle.properties --- a/xml/src/org/netbeans/modules/xml/wizard/Bundle.properties Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,149 +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. - -TITLE_x_of_y={0} of {1} -PROP_schema_panel_name=Schema Options -MSG_schema_wizard_desc=Specify the schema location and the namespace of \ -your document's root element. -LBL_schema_location=Schema URI: -PROP_schema_locationLabel_desc=Schema Location Name or Address -PROP_schema_locationLabel_mne=S -PROP_schema_locationTextField_desc=Enter Schema URI or use Browse button to select file. -LBL_browse=Browse... -PROP_schema_locationButton_desc=Select local XML Schema file. -PROP_schema_locationButton_mne=o -LBL_root_namespace=Document Namespace: -PROP_schema_nsLabel_desc=Document Root Element Namespace -PROP_schema_nsLabel_mne=N -PROP_schema_nsComboBox_desc=Use Schema target namespace or enter your own. -PROP_schema_root_name=Root Element: -PROP_schema_rootLabel_desc=Document Root Element Name -PROP_schema_rootLabel_mne=R -PROP_schema_rootComboBox_desc=Use offered name or enter your own root name. -IMG_FolderNode_Closed = org/netbeans/modules/xml/wizard/folder_closed.png -IMG_FolderNode_Opened = org/netbeans/modules/xml/wizard/folder_opened.png -LBL_WaitNode_Wait = Please wait... -CTL_SchemaPanel_Column_Name_name = File -CTL_SchemaPanel_Column_Desc_name = External reference name. -CTL_SchemaPanel_Column_Name_selected = Select -CTL_SchemaPanel_Column_Desc_selected = Select to import/include. -CTL_SchemaPanel_Column_Name_prefix = Prefix -CTL_SchemaPanel_Column_Desc_prefix = Namespace prefix value. -LBL_SchemaPanel_InvalidPrefix = Unique prefix must be specified. -TIP_SchemaPanel_Location=Select an external reference. -LBL_SchemaPanel_Location=Select one or more files\: -LBL_SchemaPanel_Namespace=Namespace\: -TIP_SchemaPanel_Namespace=Namespace of external reference. -LBL_SchemaPanel_Primary_Schema=Primary Schema\: -TIP_SchemaPanel_Primary_Schema=Use this as Primary Schema -LBL_SchemaPanel_Root_Element=Root Element\: -TIP_SchemaPanel_Root_Element=Root Element -LBL_SchemaPanel_Category_By_File = By File -LBL_SchemaPanel_Category_By_Namespace = By Namespace -PROP_schema_checkbox_mne=U -LBL_SchemaDetailPanel_Header=Schema Details -MSG_SchemaPanel_No_Root_Element=No root elements or unable to retrieve the root elements. -LBL_SchemaPanel_ImportCreator_Type=Import -LBL_Browser=Schema Browser -DSC_Browser=Select Schema by File, or by Namespace -PROP_doc_panel_name=Select Document Type -MSG_document_panel_desc=Select the type of XML document you want to create based on your document structure, data types, and namespace requirements. -PROP_wellformed_name=Well-formed Document -PROP_doc_wellformedRadioButton_mne=W -PROP_doc_wellformedRadioButton_desc=Structure constraints of this type of document are hidden to processors. -PROP_dtd_doc_name=DTD-Constrained Document -PROP_doc_dtdConstrainedRadioButton_mne=D -PROP_doc_dtdConstrainedRadioButton_desc=DTD constraint exposes document structure to validating processors. -PROP_schema_doc_name=XML Schema-Constrained Document -PROP_doc_schemaConstrainedRadioButton_mne=S -PROP_doc_schemaConstrainedRadioButton_desc=Schema exposes document structure and data types to XML Schema-aware processors. -PROP_other_doc_name=Other: -PROP_dtd_panel_name=DTD Options -MSG_dtd_panel_desc=Specify the following DTD options for your document: -PROP_dtd_pid_name=DTD Public ID: -PROP_dtd_pidLable_desc=Unique Standardized DTD Public ID -PROP_dtd_pidLabel_mne=P -PROP_dtd_catalog_name=Catalog -PROP_dtd_catalog_desc=Allows to manage entity catalogs. -PROP_dtd_catalog_mne=C -PROP_dtd_sid_name=DTD System ID: -PROP_dtd_sidLabel_desc=Typically HTTP URL to Standardized Location -PROP_dtd_sidLabel_mne=S -PROP_dtd_root_name=Document Root: -PROP_dtd_rootLabel_desc=Root Element of XML Document -PROP_dtd_rootLabel_mne=R -PROP_dtd_pidComboBox_desc=Select public ID from mounted entity catalog or enter your own. -PROP_dtd_sidComboBox_desc=Select recent system ID or enter new one. -PROP_dtd_rootComboBox_desc=Select offered root name or enter your own. - -## XMLWizardIterator.java -MSG_unknown=... - -## Util.java -PROP_schema_select_button=OK -MSG_inValidFile=Invalid file! -PROP_schema_dialog_name=Select XML Schema -PROP_schema_mask=XML Schemas -XMLContentPanel.titleLabel.text=Select options for including optional content in the XML document -XMLContentPanel.jLabel1.text=Content Options -XMLContentPanel.attributes.text=Generate Optional Attributes -XMLContentPanel.attributes.mne=A -XMLContentPanel.elements.text=Generate Optional Elements -XMLContentPanel.elements.mne=E -XMLContentPanel.jLabel2.text=Repeating Elements -XMLContentPanel.jLabel3.text=Preferred occurences: -XMLContentPanel.jLabel4.text=Value to user when "preferred > minOccurs" and "preferred < maxOccurs". -XMLContentPanel.jLabel5.text=Recursion depth: -XMLContentPanel.jLabel6.text=Depth to which self-referencing elements in the XML document should recurse -PROP_xml_content_panel_name=XML Model Generation Options - -LBL_PRIMARY_COL=Primary -LBL_SCHEMA_COL=Schema -LBL_ROOT_COL=Root -LBL_PREIFX_COL=Prefix -LBL_TABLE_SCHEMA_PROMPT= -TIP_PREFIX_COL=Select a schema as a Primary schema -TIP_COMBO_COL=Click for combo box -MSG_SchemaPanel_Incorrect_Primary=Please select a schema that has root elements as Primary. -LBL_No_Root_Elements= -LBL_Schema_table=Schema Table -LBL_BrowseButton=Browse -LBL_BrowseButton_mme=B -LBL_RemoveButton=Remove -LBL_RemoveButton_mne=R diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/DTDPanel.form --- a/xml/src/org/netbeans/modules/xml/wizard/DTDPanel.form Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,173 +0,0 @@ - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/DTDPanel.java --- a/xml/src/org/netbeans/modules/xml/wizard/DTDPanel.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,393 +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.modules.xml.wizard; - -import java.awt.*; -import java.awt.event.*; -import java.net.MalformedURLException; -import java.net.URL; - -import java.util.Iterator; -import java.util.Set; -import java.util.Vector; - -import javax.swing.DefaultComboBoxModel; -import javax.swing.text.JTextComponent; - -import org.netbeans.modules.xml.lib.Util; -import org.openide.nodes.Node; -import org.openide.nodes.NodeOperation; - -import org.xml.sax.*; - -/** - * Gathers data for DTD driven XML document instantionation. - * - * @author Petr Kuzel - * @version it does not work well, no PIDs no roots, ... - */ -public class DTDPanel extends AbstractPanel { - /** Serial Version UID */ - private static final long serialVersionUID = 5310047495162425192L; - - - /** Creates new form DTDPanel */ - public DTDPanel() { - initComponents(); - initAccessibility(); - - // attach focus listener to editor directly - Component editor = pidComboBox.getEditor().getEditorComponent(); - editor.addFocusListener(new FocusAdapter() { - public void focusLost(FocusEvent e) { - if (existsPID()) updatePossibilities(); - } - }); - - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { - java.awt.GridBagConstraints gridBagConstraints; - - descTextArea = new javax.swing.JTextArea(); - pidLabel = new javax.swing.JLabel(); - pidComboBox = new javax.swing.JComboBox(); - catalogButton = new javax.swing.JButton(); - sidLabel = new javax.swing.JLabel(); - sidComboBox = new javax.swing.JComboBox(); - rootLabel = new javax.swing.JLabel(); - rootComboBox = new javax.swing.JComboBox(); - fillPanel = new javax.swing.JPanel(); - - setName(Util.THIS.getString(DTDPanel.class, "PROP_dtd_panel_name")); // NOI18N - setLayout(new java.awt.GridBagLayout()); - - descTextArea.setEditable(false); - descTextArea.setLineWrap(true); - descTextArea.setText(Util.THIS.getString(DTDPanel.class, "MSG_dtd_panel_desc")); // NOI18N - descTextArea.setWrapStyleWord(true); - descTextArea.setDisabledTextColor(descTextArea.getForeground()); - descTextArea.setEnabled(false); - descTextArea.setOpaque(false); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); - add(descTextArea, gridBagConstraints); - - pidLabel.setLabelFor(pidComboBox); - pidLabel.setText(Util.THIS.getString(DTDPanel.class, "PROP_dtd_pid_name")); // NOI18N - pidLabel.setToolTipText("null"); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 12); - add(pidLabel, gridBagConstraints); - - pidComboBox.setEditable(true); - pidComboBox.setToolTipText("null"); - pidComboBox.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - pidComboBoxActionPerformed(evt); - } - }); - pidComboBox.addFocusListener(new java.awt.event.FocusAdapter() { - public void focusLost(java.awt.event.FocusEvent evt) { - pidComboBoxFocusLost(evt); - } - }); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); - add(pidComboBox, gridBagConstraints); - - catalogButton.setText(Util.THIS.getString(DTDPanel.class, "PROP_dtd_catalog_name")); // NOI18N - catalogButton.setToolTipText("null"); - catalogButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - catalogButtonActionPerformed(evt); - } - }); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); - add(catalogButton, gridBagConstraints); - - sidLabel.setLabelFor(sidComboBox); - sidLabel.setText(Util.THIS.getString(DTDPanel.class, "PROP_dtd_sid_name")); // NOI18N - sidLabel.setToolTipText("null"); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 12); - add(sidLabel, gridBagConstraints); - - sidComboBox.setEditable(true); - sidComboBox.setToolTipText("null"); - sidComboBox.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - sidComboBoxActionPerformed(evt); - } - }); - sidComboBox.addFocusListener(new java.awt.event.FocusAdapter() { - public void focusLost(java.awt.event.FocusEvent evt) { - sidComboBoxFocusLost(evt); - } - }); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); - add(sidComboBox, gridBagConstraints); - - rootLabel.setLabelFor(rootComboBox); - rootLabel.setText(Util.THIS.getString(DTDPanel.class, "PROP_dtd_root_name")); // NOI18N - rootLabel.setToolTipText("null"); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 12); - add(rootLabel, gridBagConstraints); - - rootComboBox.setEditable(true); - rootComboBox.setToolTipText("null"); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); - add(rootComboBox, gridBagConstraints); - - fillPanel.setLayout(null); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.weighty = 1.0; - add(fillPanel, gridBagConstraints); - }// //GEN-END:initComponents - - private void catalogButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_catalogButtonActionPerformed - Node catalog = getCatalogNode(); - if (catalog == null) return; - NodeOperation.getDefault().explore(catalog); - }//GEN-LAST:event_catalogButtonActionPerformed - - private void initAccessibility() { - - Util util = Util.THIS; - rootLabel.setDisplayedMnemonic(util.getChar(DTDPanel.class, "PROP_dtd_rootLabel_mne")); - pidLabel.setDisplayedMnemonic(util.getChar(DTDPanel.class, "PROP_dtd_pidLabel_mne")); - sidLabel.setDisplayedMnemonic(util.getChar(DTDPanel.class, "PROP_dtd_sidLabel_mne")); - catalogButton.setMnemonic(util.getChar(DTDPanel.class, "PROP_dtd_catalog_mne")); - getAccessibleContext().setAccessibleDescription(descTextArea.getText()); - } - - private void sidComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sidComboBoxActionPerformed - // ignore listing - if (sidComboBox.isPopupVisible()) return; - if (existsPID() == false) updatePossibilities(); - }//GEN-LAST:event_sidComboBoxActionPerformed - - private void pidComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pidComboBoxActionPerformed - // ignore listing - if (pidComboBox.isPopupVisible()) return; - - if (existsPID()) updatePossibilities(); - }//GEN-LAST:event_pidComboBoxActionPerformed - - private void pidComboBoxFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_pidComboBoxFocusLost - if (existsPID()) updatePossibilities(); - }//GEN-LAST:event_pidComboBoxFocusLost - - private void sidComboBoxFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_sidComboBoxFocusLost - if (existsPID() == false) updatePossibilities(); - }//GEN-LAST:event_sidComboBoxFocusLost - - /** - * Try to access catalog management node or null. - */ - private Node getCatalogNode() { - -// TopManager top = TopManager.getDefault(); -// Node runtime = top.getPlaces().nodes().environment(); -// Children children = runtime.getChildren(); -// Enumeration en = children.nodes(); -// -// while (en.hasMoreElements()) { -// Node next = (Node) en.nextElement(); -// //!!! it is undeclared dependency on catalog module -// if ("XML-CATALOG".equals(next.getName())) { // NOI18N -// return new FilterNode(next); -// } -// } - - return null; - } - - // does user entered a PID - private boolean existsPID() { - Object pid = pidModel.getSelectedItem(); - return (pid != null) && (pid instanceof String) - && (((String)pid).trim().equals("") == false); - } - - private void updatePossibilities() { - //??? we are in AWT parse in separate task - - Util.THIS.debug("Updating possible roots (DTD)..."); - - InputSource in = new InputSource(); - - Object sid = sidModel.getSelectedItem(); - String systemId = null; - try { - if (sid != null) { - systemId = sid.toString(); - URL context = model.getTargetFolderURL(); - if (context != null) { - systemId = new URL(context, systemId).toExternalForm(); - } - } - } catch (MalformedURLException ex) { - // ignore it use one passes by user - } - in.setSystemId(systemId); - - Object pid = pidModel.getSelectedItem(); - in.setPublicId( pid == null ? null : pid.toString() ); - - Util.THIS.debug("PID: " + pid + ", SID:" + sid); - Set roots = new DTDParser().parse(in); - - if (roots.size() > 0) { - rootModel.removeAllElements(); - Iterator it = roots.iterator(); - while (it.hasNext()) { - String next = (String) it.next(); - rootModel.addElement(next); - } - } - - // select suggested text (do not focus it) - Component editor = rootComboBox.getEditor().getEditorComponent(); - if (editor instanceof JTextComponent) { - ((JTextComponent)editor).selectAll(); - } - } - - /** User just entered the panel, init view by model values - */ - protected void initView() { - - // fetch catalogs etc. - String[] pids = Util.getKnownDTDPublicIDs(); - pidModel = new DefaultComboBoxModel(pids); - sidModel = new DefaultComboBoxModel(recentSIDs); - rootModel = new DefaultComboBoxModel(); - - pidComboBox.setModel(pidModel); - pidComboBox.getEditor().selectAll(); - - if (true /* #23966 */ || getCatalogNode() == null) { - catalogButton.setVisible(false); - // !!! gridwith mus be set somehow to remaider! - } - - // set models - rootComboBox.setModel(rootModel); - - sidComboBox.setModel(sidModel); - - } - - /** User just leaved the panel, update model - */ - protected void updateModel() { - Object pid = pidModel.getSelectedItem(); - model.setPublicID( pid == null ? null : pid.toString() ); - - Object sid = sidModel.getSelectedItem(); - model.setSystemID(sid == null ? null : sid.toString()); - - Object root = rootModel.getSelectedItem(); - model.setRoot(root == null ? null : root.toString()); - - Util.THIS.debug("Model updated PID: " + pid + " SID: " + sid + " root: " + root); - - // update recent - - if (recentSIDs.contains(sid) == false) { - recentSIDs.add(sid); - } - } - - /** User just reentered the panel. - */ - protected void updateView() { - } - - private DefaultComboBoxModel rootModel; - private DefaultComboBoxModel pidModel; - private DefaultComboBoxModel sidModel; - - private static Vector recentSIDs = new Vector(); - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton catalogButton; - private javax.swing.JTextArea descTextArea; - private javax.swing.JPanel fillPanel; - private javax.swing.JComboBox pidComboBox; - private javax.swing.JLabel pidLabel; - private javax.swing.JComboBox rootComboBox; - private javax.swing.JLabel rootLabel; - private javax.swing.JComboBox sidComboBox; - private javax.swing.JLabel sidLabel; - // End of variables declaration//GEN-END:variables - -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/DTDParser.java --- a/xml/src/org/netbeans/modules/xml/wizard/DTDParser.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,148 +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.modules.xml.wizard; - -import java.io.*; -import java.util.*; - -import org.xml.sax.*; -import org.xml.sax.ext.*; -import org.xml.sax.helpers.*; - -import org.openide.xml.*; - -import org.netbeans.api.xml.services.UserCatalog; -import org.netbeans.api.xml.parsers.SAXEntityParser; -import org.netbeans.modules.xml.lib.Util; - -/** - * Silently produces Set of roots from passed SAX declaration handler events. - * - * @author Petr Kuzel - */ -final class DTDParser extends DefaultHandler implements DeclHandler { - - static final String SAX_PROPERTY = "http://xml.org/sax/properties/"; // NOI18N - static final String DECL_HANDLER = "declaration-handler"; // NOI18N - - private final Set roots = new TreeSet(); - - /** Creates new DTDParser */ - public DTDParser() { - } - - /** - * @param in if filled only SID and PID the entity catalog "normalization" is used - */ - public Set parse(InputSource in) { - - Util.THIS.debug("DTDParser started."); - - try { - // we do not want Crimson, it does not understand relative SYSTEM ids - XMLReader parser = XMLUtil.createXMLReader(true); - parser.setContentHandler(this); - parser.setErrorHandler(this); - parser.setProperty(SAX_PROPERTY + DECL_HANDLER, this); - - // provide fake entity resolver and source - - UserCatalog catalog = UserCatalog.getDefault(); - EntityResolver res = (catalog == null ? null : catalog.getEntityResolver()); - - if (res != null) parser.setEntityResolver(res); - - SAXEntityParser dtdParser = new SAXEntityParser(parser, false); - dtdParser.parse(in); - - throw new IllegalStateException("How we can get here?"); // NOI18N - } catch (Stop stop) { - return roots; // expected - } catch (SAXException ex) { - Util.THIS.debug("Ignoring SAX ex. while parsing DTD:", ex); // NOI18N - if (ex.getException() instanceof RuntimeException) { - Util.THIS.debug("Nested exception:", ex.getException()); // NOI18N - } - return roots; // better partial result than nothing - } catch (IOException ex) { - Util.THIS.debug("Ignoring I/O ex. while parsing DTD:", ex); // NOI18N - return roots; // better partial result than nothing - } finally { - Util.THIS.debug("DTDParser stopped."); // NOI18N - } - } - - public void elementDecl(String name, String model) throws SAXException { - Util.THIS.debug("\telementDecl(" + name + ",...)"); // NOI18N - roots.add(name); - } - - public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException { - } - - public void attributeDecl(String eName, String aName, String type, String valueDefault, String value) throws SAXException { - } - - public void internalEntityDecl(String name, String value) throws SAXException { - } - - public void notationDecl (String name, String publicId, String systemId) throws SAXException { - } - - public void startElement (String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { - Util.THIS.debug("\tstopping parser!"); // NOI18N - throw new Stop(); - } - - private class Stop extends SAXException { - - private static final long serialVersionUID = -64662796017444980L; - - Stop() { - super("STOP"); //NOI18N - } - - public Throwable fillInStackTrace() { - return this; - } - } -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/DTDWizardIterator.java --- a/xml/src/org/netbeans/modules/xml/wizard/DTDWizardIterator.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,311 +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-2007 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.modules.xml.wizard; - -//java imports -import java.awt.Component; -import java.io.IOException; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.NoSuchElementException; -import java.util.Set; -import javax.swing.JComponent; -import javax.swing.event.ChangeListener; -import javax.swing.event.ChangeEvent; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import org.netbeans.api.project.Project; -import org.netbeans.api.project.ProjectUtils; -import org.netbeans.api.project.SourceGroup; -import org.netbeans.api.project.Sources; -import org.netbeans.modules.xml.api.EncodingUtil; -import org.openide.WizardDescriptor; -import org.openide.filesystems.FileObject; -import org.openide.loaders.DataFolder; -import org.openide.loaders.DataObject; -import org.openide.util.Exceptions; -import org.openide.util.NbBundle; -import org.openide.cookies.EditCookie; -import org.openide.loaders.TemplateWizard; -import org.netbeans.spi.project.ui.templates.support.Templates; -import org.openide.cookies.EditorCookie; -import org.openide.cookies.SaveCookie; - -/** - * Sample schema wizard iterator. See layer.xml for template declaration. - * - * @author Samaresh (Samaresh.Panda@Sun.Com) - */ -public class DTDWizardIterator extends Object implements TemplateWizard.Iterator { - - private static final long serialVersionUID = 1L; - private int index; - private final Set changeListeners = new HashSet(); - protected transient WizardDescriptor.Panel[] panels; - protected String encoding; //project's encoding - - /** - * You should define what panels you want to use here: - */ - protected WizardDescriptor.Panel[] createPanels (Project project, - final TemplateWizard wizard) { - DataFolder df = null; - Sources sources = ProjectUtils.getSources(project); - SourceGroup[] folders = sources.getSourceGroups("java"); //NOI18N - if (folders == null || folders.length == 0) { - folders = sources.getSourceGroups(Sources.TYPE_GENERIC); - } - try { - df = wizard.getTargetFolder(); - } catch (IOException ex) { - //just catch - } - if (df != null) { - wizard.setTargetFolder(df); - org.openide.WizardDescriptor.Panel panel = Templates.createSimpleTargetChooser(project, folders); - return new org.openide.WizardDescriptor.Panel[]{panel}; - } - - //make the first one as the default target folder. IZ: 98643 - if (folders != null && folders.length != 0) { - df = DataFolder.findFolder(folders[0].getRootFolder()); - wizard.setTargetFolder(df); - } - WizardDescriptor.Panel panel = Templates.createSimpleTargetChooser(project, folders); - return new WizardDescriptor.Panel[] {panel}; - } - - /** - * Initialization of the wizard iterator. - */ - public void initialize(TemplateWizard wizard) { - index = 0; - Project project = Templates.getProject( wizard ); - panels = createPanels (project, wizard); - - // Creating steps. - Object prop = wizard.getProperty (WizardDescriptor.PROP_CONTENT_DATA); // NOI18N - String[] beforeSteps = null; - if (prop instanceof String[]) { - beforeSteps = (String[])prop; - } - String[] steps = createSteps (beforeSteps, panels); - - for (int i = 0; i < panels.length; i++) { - Component c = panels[i].getComponent (); - if (steps[i] == null) { - // Default step name to component name of panel. - // Mainly useful for getting the name of the target - // chooser to appear in the list of steps. - steps[i] = c.getName (); - } - if (c instanceof JComponent) { // assume Swing components - JComponent jc = (JComponent) c; - // Step #. - jc.putClientProperty (WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, Integer.valueOf(i)); // NOI18N - // Step name (actually the whole list for reference). - jc.putClientProperty (WizardDescriptor.PROP_CONTENT_DATA, steps); // NOI18N - } - } - } - - /** - * Cleanup. - */ - public void uninitialize (TemplateWizard wiz) { - panels = null; - } - - /** - * This is where, the schema gets instantiated from the template. - */ - public Set instantiate (TemplateWizard wizard) throws IOException { - FileObject dir = Templates.getTargetFolder( wizard ); - DataFolder df = DataFolder.findFolder( dir ); - FileObject template = Templates.getTemplate( wizard ); - DataObject dTemplate = DataObject.find( template ); - DataObject dobj = dTemplate.createFromTemplate(df, Templates.getTargetName(wizard)); - if (dobj == null) - return Collections.emptySet(); - - encoding = EncodingUtil.getProjectEncoding(df.getPrimaryFile()); - if(!EncodingUtil.isValidEncoding(encoding)) - encoding = "UTF-8"; //NOI18N - EditCookie edit = dobj.getCookie(EditCookie.class); - if (edit != null) { - EditorCookie editorCookie = dobj.getCookie(EditorCookie.class); - Document doc = (Document)editorCookie.openDocument(); - fixEncoding(doc, encoding); - SaveCookie save = dobj.getCookie(SaveCookie.class); - if (save!=null) save.save(); - } - - return Collections.singleton(dobj.getPrimaryFile()); - } - - /** - * - */ - public void addChangeListener(ChangeListener listener) { - changeListeners.add(listener); - } - - /** - * - * - */ - public void removeChangeListener(ChangeListener listener) { - changeListeners.remove(listener); - } - - /** - * - */ - public void fireStateChanged() { - ChangeEvent event = new ChangeEvent(this); - - Iterator i = changeListeners.iterator(); - while (i.hasNext()) { - try { - i.next().stateChanged(event); - } catch (Exception e) { - //Debug.debugNotify(e); - } - } - } - - /** - * - */ - public String name () { - return NbBundle.getMessage(DTDWizardIterator.class, "TITLE_x_of_y", - Integer.valueOf(index + 1), Integer.valueOf(panels.length)); - } - - /** - * - */ - public boolean hasNext () { - return index < panels.length - 1; - } - - /** - * - */ - public boolean hasPrevious () { - return index > 0; - } - - /** - * - */ - public void nextPanel () { - if (! hasNext ()) throw new NoSuchElementException (); - index++; - } - - /** - * - */ - public void previousPanel () { - if (! hasPrevious ()) throw new NoSuchElementException (); - index--; - } - - /** - * Returns the current panel. - */ - public WizardDescriptor.Panel current () { - return panels[index]; - } - - /** - * Create steps. - */ - private String[] createSteps(String[] before, WizardDescriptor.Panel[] panels) { - //assert panels != null; - // hack to use the steps set before this panel processed - int diff = 0; - if (before == null) { - before = new String[0]; - } else if (before.length > 0) { - diff = ("...".equals (before[before.length - 1])) ? 1 : 0; // NOI18N - } - String[] res = new String[ (before.length - diff) + panels.length]; - for (int i = 0; i < res.length; i++) { - if (i < (before.length - diff)) { - res[i] = before[i]; - } else { - res[i] = panels[i - before.length + diff].getComponent ().getName (); - } - } - return res; - } - - /** - * Utility method to replace text in document. - */ - void replaceInDocument(javax.swing.text.Document document, String replaceFrom, String replaceTo) { - javax.swing.text.AbstractDocument doc = (javax.swing.text.AbstractDocument)document; - int len = replaceFrom.length(); - try { - String content = doc.getText(0,doc.getLength()); - int index = content.lastIndexOf(replaceFrom); - while (index>=0) { - doc.replace(index,len,replaceTo,null); - content=content.substring(0,index); - index = content.lastIndexOf(replaceFrom); - } - } catch (javax.swing.text.BadLocationException ex){} - } - - void fixEncoding(javax.swing.text.Document document, String encoding) { - if(encoding == null) - encoding = "UTF-8"; //NOI18N - try { - document.insertString(19, " encoding=\""+encoding+"\"", null); - } catch (BadLocationException ex) { - Exceptions.printStackTrace(ex); - } - } - -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/DocumentModel.java --- a/xml/src/org/netbeans/modules/xml/wizard/DocumentModel.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/wizard/DocumentModel.java Tue Sep 23 16:17:23 2008 -0500 @@ -40,15 +40,11 @@ */ package org.netbeans.modules.xml.wizard; +import org.netbeans.modules.xml.wizard.XMLContentAttributes; import java.beans.PropertyChangeSupport; import java.beans.PropertyChangeListener; import java.net.URL; -import java.util.ArrayList; -import java.util.Iterator; import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import org.openide.nodes.Node; /** * Holds state of new document wizard. diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/DocumentPanel.form --- a/xml/src/org/netbeans/modules/xml/wizard/DocumentPanel.form Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/DocumentPanel.java --- a/xml/src/org/netbeans/modules/xml/wizard/DocumentPanel.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,244 +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.modules.xml.wizard; - -import org.netbeans.modules.xml.lib.Util; - -/** - * - * @author Petr Kuzel - */ -public class DocumentPanel extends AbstractPanel { - /** Serial Version UID */ - private static final long serialVersionUID = 3793605846188902177L; - - - /** Creates new form DocumentPanel */ - public DocumentPanel() { - initComponents(); - initAccessibility(); - - // switch off extensibity point - not implemented - otherRadioButton.setVisible(false); - otherComboBox.setVisible(false); - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { - java.awt.GridBagConstraints gridBagConstraints; - - buttonGroup = new javax.swing.ButtonGroup(); - descTextArea = new javax.swing.JTextArea(); - wellformedRadioButton = new javax.swing.JRadioButton(); - dtdConstrainedRadioButton = new javax.swing.JRadioButton(); - schemaConstrainedRadioButton = new javax.swing.JRadioButton(); - otherRadioButton = new javax.swing.JRadioButton(); - otherComboBox = new javax.swing.JComboBox(); - fillPanel = new javax.swing.JPanel(); - - setName(Util.THIS.getString(DocumentPanel.class, "PROP_doc_panel_name")); // NOI18N - setLayout(new java.awt.GridBagLayout()); - - descTextArea.setEditable(false); - descTextArea.setLineWrap(true); - descTextArea.setText(Util.THIS.getString(DocumentPanel.class, "MSG_document_panel_desc")); // NOI18N - descTextArea.setWrapStyleWord(true); - descTextArea.setDisabledTextColor(descTextArea.getForeground()); - descTextArea.setEnabled(false); - descTextArea.setOpaque(false); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); - add(descTextArea, gridBagConstraints); - - buttonGroup.add(wellformedRadioButton); - wellformedRadioButton.setText(Util.THIS.getString(DocumentPanel.class, "PROP_wellformed_name")); // NOI18N - wellformedRadioButton.setToolTipText("null"); - wellformedRadioButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - wellformedRadioButtonActionPerformed(evt); - } - }); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; - gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 0); - add(wellformedRadioButton, gridBagConstraints); - - buttonGroup.add(dtdConstrainedRadioButton); - dtdConstrainedRadioButton.setText(Util.THIS.getString(DocumentPanel.class, "PROP_dtd_doc_name")); // NOI18N - dtdConstrainedRadioButton.setToolTipText("null"); - dtdConstrainedRadioButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - dtdConstrainedRadioButtonActionPerformed(evt); - } - }); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; - gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 0); - add(dtdConstrainedRadioButton, gridBagConstraints); - - buttonGroup.add(schemaConstrainedRadioButton); - schemaConstrainedRadioButton.setText(Util.THIS.getString(DocumentPanel.class, "PROP_schema_doc_name")); // NOI18N - schemaConstrainedRadioButton.setToolTipText("null"); - schemaConstrainedRadioButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - schemaConstrainedRadioButtonActionPerformed(evt); - } - }); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; - gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 0); - add(schemaConstrainedRadioButton, gridBagConstraints); - - buttonGroup.add(otherRadioButton); - otherRadioButton.setText(Util.THIS.getString(DocumentPanel.class, "PROP_other_doc_name")); // NOI18N - otherRadioButton.setEnabled(false); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 12); - add(otherRadioButton, gridBagConstraints); - - otherComboBox.setEnabled(false); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.weightx = 1.0; - add(otherComboBox, gridBagConstraints); - - fillPanel.setLayout(null); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.weighty = 1.0; - add(fillPanel, gridBagConstraints); - }// //GEN-END:initComponents - - private void initAccessibility() { - - Util util = Util.THIS; - wellformedRadioButton.setMnemonic(util.getChar( - DocumentPanel.class, "PROP_doc_wellformedRadioButton_mne")); - schemaConstrainedRadioButton.setMnemonic(util.getChar( - DocumentPanel.class, "PROP_doc_schemaConstrainedRadioButton_mne")); - dtdConstrainedRadioButton.setMnemonic(util.getChar( - DocumentPanel.class, "PROP_doc_dtdConstrainedRadioButton_mne")); - getAccessibleContext().setAccessibleDescription(descTextArea.getText()); - } - - private void schemaConstrainedRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_schemaConstrainedRadioButtonActionPerformed - updateModel(); - }//GEN-LAST:event_schemaConstrainedRadioButtonActionPerformed - - private void dtdConstrainedRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dtdConstrainedRadioButtonActionPerformed - updateModel(); - }//GEN-LAST:event_dtdConstrainedRadioButtonActionPerformed - - private void wellformedRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wellformedRadioButtonActionPerformed - updateModel(); - }//GEN-LAST:event_wellformedRadioButtonActionPerformed - - /** User just entered the panel, init view by model values - */ - protected void initView() { - int type = model.getType(); - switch (type) { - case DocumentModel.NONE: - wellformedRadioButton.setSelected(true); - break; - case DocumentModel.DTD: - dtdConstrainedRadioButton.setSelected(true); - break; - case DocumentModel.SCHEMA: - schemaConstrainedRadioButton.setSelected(true); - break; - case DocumentModel.OTHER: - otherRadioButton.setSelected(true); - break; - default: - throw new IllegalStateException(); - } - } - - /** User just leaved the panel, update model - */ - protected void updateModel() { - if (wellformedRadioButton.isSelected()) { - model.setType(model.NONE); - } else if (dtdConstrainedRadioButton.isSelected()) { - model.setType(model.DTD); - } else if (schemaConstrainedRadioButton.isSelected()) { - model.setType(model.SCHEMA); - } else { - model.setType(model.OTHER); - } - } - - /** User just reentered the panel. - */ - protected void updateView() { - // no dynamic update needed - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.ButtonGroup buttonGroup; - private javax.swing.JTextArea descTextArea; - private javax.swing.JRadioButton dtdConstrainedRadioButton; - private javax.swing.JPanel fillPanel; - private javax.swing.JComboBox otherComboBox; - private javax.swing.JRadioButton otherRadioButton; - private javax.swing.JRadioButton schemaConstrainedRadioButton; - private javax.swing.JRadioButton wellformedRadioButton; - // End of variables declaration//GEN-END:variables - -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/ExternalReferenceDataNode.java --- a/xml/src/org/netbeans/modules/xml/wizard/ExternalReferenceDataNode.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,291 +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-2007 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.modules.xml.wizard; - -import java.io.File; -import java.net.URI; -import java.net.URISyntaxException; -import org.netbeans.modules.xml.lib.Util; -import org.openide.loaders.DataObject; -import org.openide.nodes.FilterNode; -import org.openide.nodes.Node; -import org.openide.ErrorManager; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.nodes.Node.Property; -import org.openide.nodes.PropertySupport.Reflection; -import org.openide.nodes.Sheet; -import org.openide.nodes.Sheet.Set; -import org.openide.util.NbBundle; - -/** - * Represents a collection of external references, or a single file. - * - * @author Ajit Bhate - * @author Nathan Fiedler - */ -public class ExternalReferenceDataNode extends FilterNode { - /** Name of the 'selected' property. */ - public static final String PROP_SELECTED = "selected"; - /** Name of the 'prefix' property. */ - public static final String PROP_PREFIX = "prefix"; - /** Set of PropertySets. */ - private Sheet sheet; - /** True if selected, false otherwise. */ - private boolean selected; - /** The namespace prefix, if specified. */ - private String prefix=null; - private static int counter=0; - private ExternalReferenceDecorator decorator; - - /** - * Creates a new instance of ExternalReferenceDataNode. - * - * @param original the delegate Node. - * @param decorator the external reference decorator. - */ - public ExternalReferenceDataNode(Node original,ExternalReferenceDecorator dec) { - super(original, new Children(original, dec)); - this.decorator=dec; - - } - - public boolean canRename() { - // Disable rename as it serves no purpose here and makes the - // single-click-select-toggle difficult to use. - return false; - } - - /** - * Indicates if this node allows setting it selected. - * - * @return true if this node can be selected, false otherwise. - */ - public boolean canSelect() { - DataObject dobj = (DataObject) getLookup().lookup(DataObject.class); - return dobj != null && !dobj.getPrimaryFile().isFolder() ; - } - - /** - * Creates a node property of the given key (same as the column keys) - * and specific getter/setter methods on the given object. - * - * @param key property name (same as matching column). - * @param type Class of the property (e.g. String.class). - * @param inst object on which to reflect. - * @param getter name of getter method for property value. - * @param setter name of setter method for property value (may be null). - * @return new property. - */ - private Node.Property createProperty(String key, Class type, Object inst, - String getter, String setter) { - Property prop = null; - try { - prop = new Reflection(inst, type, getter, setter); - prop.setName(key); - prop.setDisplayName(NbBundle.getMessage( - ExternalReferenceDataNode.class, - "CTL_SchemaPanel_Column_Name_" + key)); - prop.setShortDescription(NbBundle.getMessage( - ExternalReferenceDataNode.class, - "CTL_SchemaPanel_Column_Desc_" + key)); - } catch (NoSuchMethodException nsme) { - ErrorManager.getDefault().notify(nsme); - } - return prop; - } - - protected Sheet createSheet() { - Sheet sheet = Sheet.createDefault(); - Set set = sheet.get(Sheet.PROPERTIES); - set.put(createProperty(PROP_NAME, String.class, this, - "getHtmlDisplayName", null)); - if (canSelect()) { - set.put(createProperty(PROP_SELECTED, Boolean.TYPE, this, - "isSelected", "setSelected")); - // Node.Property prop = createProperty(PROP_PREFIX, String.class, - // this, "getPrefix", "setPrefix"); - // Suppress the [...] button because it is not needed. - // prop.setValue("suppressCustomEditor", Boolean.TRUE); - // set.put(prop); - } /*else { - // Do not include this property so the checkbox is not shown. - //set.put(createProperty(PROP_SELECTED, Boolean.TYPE, this, - // "isSelected", null)); - Node.Property prop = createProperty(PROP_PREFIX, String.class, - this, "getPrefix", null); - // Suppress the [...] button because it is not needed. - prop.setValue("suppressCustomEditor", Boolean.TRUE); - set.put(prop); - }*/ - return sheet; - } - - protected final synchronized Sheet getSheet() { - if (sheet != null) { - return sheet; - } - sheet = createSheet(); - firePropertySetsChange(null, null); - return sheet; - } - - public PropertySet[] getPropertySets() { - Sheet s = getSheet(); - return s.toArray(); - } - - public String getHtmlDisplayName() { - String name = getOriginal().getHtmlDisplayName(); - return name; - } - - public String getPrefix() { - - if (prefix == null) { - DataObject dobj = (DataObject) getLookup().lookup(DataObject.class); - if( dobj !=null && !(dobj.getPrimaryFile().isFolder()) ) - prefix = decorator.generatePrefix(prefix, dobj); - else - prefix =""; - } - return prefix; - } - - public boolean isSelected() { - return selected; - } - - - public void setDisplayName(String s) { - super.disableDelegation(DELEGATE_GET_DISPLAY_NAME|DELEGATE_SET_DISPLAY_NAME); - super.setDisplayName(s); - } - - /** - * Set the namespace prefix for this node. - * - * @param prefix new namespace prefix. - */ - public void setPrefix(String prefix) { - String old = this.prefix; - this.prefix = prefix; - firePropertyChange(PROP_PREFIX, old, prefix); - } - - /** - * Mark this node as selected. - * - * @param selected true to select, false to unselect. - */ - public void setSelected(boolean selected) { - if (!canSelect()) { - throw new IllegalStateException("node cannot be selected"); - } - boolean old = this.selected; - this.selected = selected; - firePropertyChange(PROP_SELECTED, new Boolean(old), new Boolean(selected)); - } - - public String getNamespace() { - DataObject dobj = (DataObject) getLookup().lookup(DataObject.class); - if (dobj != null) { - FileObject fobj = dobj.getPrimaryFile(); - return Util.getNamespace(fobj); - } - return null; - } - - public String getSchemaFileName(){ - DataObject dobj = (DataObject) getLookup().lookup(DataObject.class); - if (dobj != null) { - FileObject fobj = dobj.getPrimaryFile(); - File file = FileUtil.toFile(fobj); - String uri = file.getPath(); - if (uri != null) { - try { - // escape the non-ASCII characters - uri = new URI(uri).toASCIIString(); - } catch (URISyntaxException e) { - // the specified uri is not valid, it is too late to fix it now - } - } - return uri; - } - - return null; - - } - - private static class Children extends FilterNode.Children { - /** Controls the appearance of child nodes. */ - ExternalReferenceDecorator decorator; - - public Children(Node original, ExternalReferenceDecorator dec) { - super(original); - this.decorator=dec; - } - - protected Node[] createNodes(Node n) { - DataObject dobj = (DataObject) n.getLookup().lookup(DataObject.class); - if (dobj != null) { - FileObject fobj = dobj.getPrimaryFile(); - if (fobj.isFolder() && fobj.getNameExt().equals("nbproject") && - fobj.getFileObject("project.xml") != null) { - // It is the NetBeans project folder, ignore it. - return new Node[0]; - } - String fname = fobj.getNameExt(); - String ext = decorator.getDocumentType(); - if (fobj.isFolder() || fname.endsWith(ext)) { - return super.createNodes(n); - } - } - return new Node[0]; - } - - protected Node copyNode(Node node) { - return decorator.createExternalReferenceNode(node); - } - - } -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/ExternalReferenceDecorator.java --- a/xml/src/org/netbeans/modules/xml/wizard/ExternalReferenceDecorator.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,112 +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-2007 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.modules.xml.wizard; - - -import java.util.HashMap; -import java.util.Map; -import org.openide.loaders.DataObject; -import org.openide.nodes.Node; - -/** - * An ExternalReferenceDecorator is used to control the appearance of the - * nodes in the ExternalReferenceCustomizer. - * - * @author Nathan Fiedler - */ -public class ExternalReferenceDecorator { - - private SchemaImportGUI panel; - private static String SCHEMA = "xsd"; - private static int counter = 0; - /** Prefix for the namespace prefix values (e.g. "ns"). */ - private static final String PREFIX_PREFIX = "ns"; // NOI18N - /** Hashmap to keep track of prefixes */ - private Map prefixMap = new HashMap(); - - public ExternalReferenceDecorator(SchemaImportGUI panel){ - this.panel = panel; - } - /** - * Create an ExternalReferenceNode with the given delegate node. - * Implementors may wish to delegate to the customizer. - * - * @param node delegate Node. - * @return new ExternalReferenceNode. - */ - ExternalReferenceDataNode createExternalReferenceNode(Node original){ - return panel.createExternalReferenceNode(original); - } - - - /** - * Generate a unique prefix value for the document containing the - * customized component. The selected node is provided, which permits - * customizing the prefix based on the model represented by the node. - * - * @param prefix the desired prefix for the namespace prefix; - * if null, a default of "ns" will be used. - * @param dobj DataObject for which to find unique prefix. - * @return unique prefix value (e.g. "ns1"); must not be null. - */ - String generatePrefix(String prefix, DataObject dobj){ - String prefixStr = prefix == null ? PREFIX_PREFIX : prefix; - String existPrefix = (String)prefixMap.get(dobj); - if(existPrefix != null) - return existPrefix; - - String generated = prefixStr + counter++; - prefixMap.put(dobj, generated); - return generated; - } - - /** - * Return the document type that this decorator wants to show in the - * file chooser. - * - * @return the desired document type. - */ - String getDocumentType(){ - return SCHEMA; - } - - } diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/FolderNode.java --- a/xml/src/org/netbeans/modules/xml/wizard/FolderNode.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,99 +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-2007 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.modules.xml.wizard; - -import java.awt.Image; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.Repository; -import org.openide.loaders.DataObject; -import org.openide.loaders.DataObjectNotFoundException; -import org.openide.nodes.AbstractNode; -import org.openide.nodes.Children; -import org.openide.nodes.Node; -import org.openide.util.NbBundle; - -/** - * An abstract node that uses a file folder icon. Ideally the icon is - * taken from the Node delegate of DataFolder, if it is available. - * Otherwise a default icon is used. - * - * @author Nathan Fiedler - */ -public class FolderNode extends AbstractNode { - /** The source for our folder icons. */ - private static Node iconSource; - - static { - FileObject fobj = Repository.getDefault().getDefaultFileSystem().getRoot(); - try { - DataObject dobj = DataObject.find(fobj); - iconSource = dobj.getNodeDelegate(); - } catch (DataObjectNotFoundException donfe) { - // In this case, we have our default icons, which are not - // platform-conformant, but they are better than nothing. - } - } - - public FolderNode(Children children) { - super(children); - } - - public Image getIcon(int type) { - if (iconSource != null) { - return iconSource.getIcon(type); - } else { - String url = NbBundle.getMessage(FolderNode.class, - "IMG_FolderNode_Closed"); - return org.openide.util.Utilities.loadImage(url); - } - } - - public Image getOpenedIcon(int type) { - if (iconSource != null) { - return iconSource.getOpenedIcon(type); - } else { - String url = NbBundle.getMessage(FolderNode.class, - "IMG_FolderNode_Opened"); - return org.openide.util.Utilities.loadImage(url); - } - } -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/NamespaceChildren.java --- a/xml/src/org/netbeans/modules/xml/wizard/NamespaceChildren.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,172 +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-2007 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.modules.xml.wizard; - -import java.awt.EventQueue; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import org.netbeans.modules.xml.lib.Util; -import org.openide.filesystems.FileObject; -import org.openide.filesystems.FileUtil; -import org.openide.loaders.DataObject; -import org.openide.loaders.DataObjectNotFoundException; -import org.openide.nodes.Children; -import org.openide.nodes.Node; -import org.openide.util.RequestProcessor; - - -/** - * Represents the collection of files belonging to a common namespace. - * - * @author Ajit Bhate - */ -public class NamespaceChildren extends Children.Keys { - /** Map of namespace to a list of files in that namespace. */ - private HashMap nsFilesMap; - /** Set of folders containing referencable files. */ - private FileObject[] rootFolders; - private ExternalReferenceDecorator decorator; - - /** - * Creates a new instance of NamespaceChildren. - * - * @param roots set of root folders. - * @param decorator used to decorate the nodes. - */ - public NamespaceChildren(FileObject[] roots, ExternalReferenceDecorator decorator) { - super(); - rootFolders = roots; - this.decorator=decorator; - nsFilesMap = new HashMap(); - } - - protected Node[] createNodes(Object key) { - if (key == WaitNode.WAIT_KEY) { - return WaitNode.createNode(); - } else if (key instanceof String) { - List fobjs = (List)nsFilesMap.get(key); - if (fobjs != null && !fobjs.isEmpty()) { - Node[] filterNodes = new Node[fobjs.size()]; - int i = 0; - for (int j=0; j < fobjs.size();j++) { - try { - FileObject fobj = (FileObject)fobjs.get(j); - Node node = DataObject.find(fobj).getNodeDelegate(); - filterNodes[i++] = decorator.createExternalReferenceNode(node); - } catch (DataObjectNotFoundException donfe) { - } - } - Children.Array children = new Children.Array(); - children.add(filterNodes); - Node node = new NamespaceNode(children, (String) key); - return new Node[] { node }; - } - } - return new Node[] { }; - } - - protected void addNotify() { - super.addNotify(); - setKeys(WaitNode.getKeys()); - RequestProcessor.getDefault().post(new Runnable() { - public void run() { - for (int i =0; i < rootFolders.length;i++) { - FileObject root = rootFolders[i]; - java.util.Map map =Util.getFiles2NSMappingInProj(FileUtil.toFile(root), Util.getDocumentType()); - java.util.Set set= map.entrySet(); - Iterator it = set.iterator(); - while(it.hasNext()){ - java.util.Map.Entry entry = (java.util.Map.Entry)it.next(); - String ns = (String)entry.getValue(); - List fobjs = (List)nsFilesMap.get(ns); - if (fobjs == null) { - fobjs = new ArrayList(); - } - fobjs.add((FileObject)entry.getKey()); - nsFilesMap.put(ns, fobjs); - } - } - // Set the keys on the EDT to avoid clobbering the JTree - // and causing an AIOOBE (issue 94498). - EventQueue.invokeLater(new Runnable() { - public void run() { - setKeys(nsFilesMap.keySet()); - } - }); - } - }); - } - - - // @Override - protected void removeNotify() { - setKeys(Collections.emptySet()); - } - - private static class NamespaceNode extends FolderNode { - /** Controls the appearance of this node. */ - public static final String NO_NAME_SPACE = "NO_NAME_SPACE"; - - NamespaceNode(Children children, String myNamespace) { - super(children); - setName(myNamespace); - if (NO_NAME_SPACE.equals(myNamespace)) { - setDisplayName("NoTargetNameSpace"); - } - } - - public String getHtmlDisplayName() { - String name = getDisplayName(); - return name; - } - - public String getNamespace() { - // Our name is our namespace. - return getName(); - } - - } - -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/SchemaImportGUI.form --- a/xml/src/org/netbeans/modules/xml/wizard/SchemaImportGUI.form Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/SchemaImportGUI.java --- a/xml/src/org/netbeans/modules/xml/wizard/SchemaImportGUI.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,654 +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.modules.xml.wizard; - - -import java.awt.BorderLayout; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.Iterator; -import javax.swing.DefaultComboBoxModel; -import org.openide.explorer.ExplorerManager; -import org.openide.explorer.view.TreeTableView; -import javax.swing.tree.TreeSelectionModel; -import org.openide.filesystems.FileObject; -import org.openide.loaders.DataObject; -import org.openide.nodes.AbstractNode; -import org.openide.nodes.Children; -import org.openide.nodes.Node; -import org.openide.nodes.PropertySupport; -import java.lang.reflect.InvocationTargetException; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import org.openide.loaders.TemplateWizard; -import org.openide.loaders.DataFolder; -import org.netbeans.api.project.FileOwnerQuery; -import org.netbeans.api.project.Project; -import org.netbeans.spi.project.SubprojectProvider; -import org.netbeans.spi.project.ui.LogicalViewProvider; -import java.util.Set; -import javax.swing.JPanel; -import javax.swing.tree.TreePath; -import org.netbeans.modules.xml.lib.Util; -import org.openide.explorer.view.Visualizer; -import org.openide.util.NbBundle; - - - -/** - * This panel gathers data that are necessary for instantiting of XML - * document conforming to given XML Schema. - *

- * Data allows to create a document that respect restrictions of current parser - * implementations (they use schemaLocation hint specifically). - * - * @author Petr Kuzel - */ -public class SchemaImportGUI extends JPanel implements ExplorerManager.Provider, PropertyChangeListener{ - /** Serial Version UID */ - private static final long serialVersionUID = -7568909683682244030L; - private transient ExplorerManager explorerManager; - private TemplateWizard templateWizard; - private ExternalReferenceDecorator decorator; - /** Map of registered nodes, keyed by their representative DataObject. */ - private Map registeredNodes; - private FileObject primarySchema=null; - private boolean first= false; - private boolean removeFlag=false; - - /** Creates new form SchemaPanel */ - public SchemaImportGUI(TemplateWizard tw) { - initComponents(); - initAccessibility(); - this.templateWizard = tw; - registeredNodes = new HashMap(); - decorator = new ExternalReferenceDecorator(this); - // View for selecting an external reference. - TreeTableView locationView = new LocationView(); - locationView.setDefaultActionAllowed(false); - locationView.setPopupAllowed(false); - locationView.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); - locationView.setRootVisible(false); - locationView.getAccessibleContext().setAccessibleName(locationLabel.getToolTipText()); - locationView.getAccessibleContext().setAccessibleDescription(locationLabel.getToolTipText()); - Node.Property[] columns = new Node.Property[] { - new Column(ExternalReferenceDataNode.PROP_NAME, String.class, true), - new ImportColumn(referenceTypeName()), - //new Column(ExternalReferenceDataNode.PROP_PREFIX, String.class, false), - }; - locationView.setProperties(columns); - locationView.setTreePreferredWidth(200); - locationView.setTableColumnPreferredWidth(0, 25); -// locationView.setTableColumnPreferredWidth(1, 25); - locationPanel.add(locationView, BorderLayout.CENTER); - explorerManager = new ExplorerManager(); - explorerManager.addPropertyChangeListener(this); - explorerManager.setRootContext(createRootNode()); - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { - - locationPanel = new javax.swing.JPanel(); - locationLabel = new javax.swing.JLabel(); - - setName(Util.THIS.getString(SchemaImportGUI.class, "PROP_schema_panel_name")); // NOI18N - - locationPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); - locationPanel.setLayout(new java.awt.BorderLayout()); - - locationLabel.setLabelFor(locationPanel); - locationLabel.setText(org.openide.util.NbBundle.getMessage(SchemaImportGUI.class, "LBL_SchemaPanel_Location")); // NOI18N - locationLabel.setToolTipText(org.openide.util.NbBundle.getMessage(SchemaImportGUI.class, "TIP_SchemaPanel_Location")); // NOI18N - - org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(layout.createSequentialGroup() - .addContainerGap() - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) - .add(org.jdesktop.layout.GroupLayout.LEADING, locationLabel) - .add(locationPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE)) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(layout.createSequentialGroup() - .addContainerGap() - .add(locationLabel) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(locationPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 247, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - ); - }// //GEN-END:initComponents - -private void primarySchemaCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_primarySchemaCheckBoxActionPerformed - // fireChange(); - -}//GEN-LAST:event_primarySchemaCheckBoxActionPerformed - - private void initAccessibility() { - - // memonics - Util util = Util.THIS; - locationLabel.setDisplayedMnemonic(util.getChar( - SchemaImportGUI.class, "PROP_schema_locationLabel_mne")); - - } - - protected class Column extends PropertySupport.ReadOnly { - /** The keyword for this column. */ - private String key; - - /** - * Constructs a new instance of Column. - * - * @param key keyword for this column. - * @param type type of the property (e.g. String.class). - * @param tree true if this is the 'tree' column. - */ - public Column(String key, Class type, boolean tree) { - super(key, type, NbBundle.getMessage(Column.class, - "CTL_SchemaPanel_Column_Name_" + key), - NbBundle.getMessage(Column.class, - "CTL_SchemaPanel_Column_Desc_" + key)); - this.key = key; - setValue("TreeColumnTTV", Boolean.valueOf(tree)); - } - - public Object getValue() - throws IllegalAccessException, InvocationTargetException { - return key; - } - } - - protected class ImportColumn extends PropertySupport.ReadOnly { - /** The keyword for this column. */ - private String key; - - /** - * Creates a new instance of ImportColumn. - * - * @param name the column's name. - */ - public ImportColumn(String name) { - super("selected", Boolean.TYPE, name,NbBundle.getMessage(Column.class, - "CTL_SchemaPanel_Column_Desc_selected")); - this.key = "selected"; - setValue("TreeColumnTTV", Boolean.FALSE); - } - - public Object getValue() - throws IllegalAccessException, InvocationTargetException { - return key; - } - } - - protected Node createRootNode() { - try { - DataFolder folder = templateWizard.getTargetFolder(); - Project project = FileOwnerQuery.getOwner(folder.getPrimaryFile()); - SubprojectProvider provider = (SubprojectProvider)project.getLookup().lookup(SubprojectProvider.class); - Set refProjects= provider.getSubprojects(); - Iterator it = refProjects.iterator(); - - Node[] rootNodes = new Node[1 + (refProjects == null ? 0 : refProjects.size())]; - LogicalViewProvider viewProvider = (LogicalViewProvider) project.getLookup().lookup(LogicalViewProvider.class); - rootNodes[0] = decorator.createExternalReferenceNode(viewProvider.createLogicalView()); - int rootIndex = 1; - - java.util.List projectRoots = new java.util.ArrayList(); - projectRoots.add(project.getProjectDirectory()); - if (refProjects != null) { - while(it.hasNext()){ - // for (Object o : refProjects) { - Object o = it.next(); - Project refPrj = (Project) o; - viewProvider = (LogicalViewProvider) refPrj.getLookup(). - lookup(LogicalViewProvider.class); - rootNodes[rootIndex++] = decorator.createExternalReferenceNode(viewProvider.createLogicalView()); - projectRoots.add(refPrj.getProjectDirectory()); - } - } - FileObject[] roots = (FileObject[])projectRoots.toArray(new FileObject[projectRoots.size()]); - Children fileChildren = new Children.Array(); - fileChildren.add(rootNodes); - Node byFilesNode = new FolderNode(fileChildren); - byFilesNode.setDisplayName(NbBundle.getMessage( - SchemaImportGUI.class, - "LBL_SchemaPanel_Category_By_File")); - - // Construct the By Namespace node. - Children nsChildren = new NamespaceChildren(roots, decorator); - Node byNsNode = new FolderNode(nsChildren); - byNsNode.setDisplayName(NbBundle.getMessage( - SchemaImportGUI.class, - "LBL_SchemaPanel_Category_By_Namespace")); - Children categories = new Children.Array(); - categories.add(new Node[] { byFilesNode, byNsNode }); - Node rootNode = new AbstractNode(categories); - // Surprisingly, this becomes the name and description of the first column. - rootNode.setDisplayName(NbBundle.getMessage(SchemaImportGUI.class, - "CTL_SchemaPanel_Column_Name_name")); - rootNode.setShortDescription(NbBundle.getMessage(SchemaImportGUI.class, - "CTL_SchemaPanel_Column_Desc_name")); - return rootNode; - } catch(Exception e){ - e.printStackTrace(); - } - return null; - } - - public ExplorerManager getExplorerManager() { - return explorerManager; - } - - - public ExternalReferenceDataNode createExternalReferenceNode(Node original) { - DataObject dobj = (DataObject) original.getLookup().lookup(DataObject.class); - NodeSet set = (NodeSet)registeredNodes.get(dobj); - if (set == null) { - set = new NodeSet(this); - registeredNodes.put(dobj, set); - } - ExternalReferenceDataNode erdn = new ExternalReferenceDataNode(original, decorator); - set.add(erdn); - if (set.isSelected() && erdn.canSelect()) { - erdn.setSelected(true); - } - erdn.addPropertyChangeListener(this); - return erdn; - } - - /** - * Manages the state of a set of nodes. - */ - private static class NodeSet { - /** The property change listener for each node. */ - private PropertyChangeListener listener; - /** Nodes in this set. */ - private List nodes; - /** True if this set is selected, false otherwise. */ - private boolean selected; - - /** - * Creates a new instance of NodeSet. - * - * @param listener listens to the Node. - */ - public NodeSet(PropertyChangeListener listener) { - this.listener = listener; - } - - /** - * Add the given node to this set. - * - * @param node node to be added to set. - */ - public void add(ExternalReferenceDataNode node) { - if (nodes == null) { - nodes = new LinkedList(); - } - nodes.add(node); - } - - /** - * Returns the list of nodes in this set. - * - * @return list of nodes. - */ - public List getNodes() { - return nodes; - } - - /** - * Indicates if this set is selected or not. - * - * @return true if selected, false otherwise. - */ - public boolean isSelected() { - return selected; - } - - /** - * Set the prefix for Nodes in this group. - * - * @param prefix new namespace prefix. - */ - public void setPrefix(String prefix) { - for(int i=0; i 0 && nodes[0] instanceof ExternalReferenceDataNode) { - ExternalReferenceDataNode node = (ExternalReferenceDataNode) nodes[0]; - validateInput(node); - } - } else if (pname.equals(ExternalReferenceDataNode.PROP_PREFIX)) { - ExternalReferenceDataNode erdn = (ExternalReferenceDataNode) event.getSource(); - // Look up the node in the map of sets, and ensure they all - // have the same prefix. - String prefix = (String) event.getNewValue(); - DataObject dobj = (DataObject) erdn.getLookup().lookup(DataObject.class); - NodeSet set = (NodeSet)registeredNodes.get(dobj); - // Ideally the set should already exist, but cope gracefully. - assert set != null : "node not created by customizer"; - if (set == null) { - set = new NodeSet(this); - set.add(erdn); - } - set.setPrefix(prefix); - validateInput(erdn); - } else if (pname.equals(ExternalReferenceDataNode.PROP_SELECTED)) { - ExternalReferenceDataNode erdn = (ExternalReferenceDataNode) event.getSource(); - // Look up the node in the map of sets, and ensure they are all - // selected as a unit. - boolean selected = ((Boolean) event.getNewValue()).booleanValue(); - DataObject dobj = (DataObject) erdn.getLookup().lookup(DataObject.class); - NodeSet set = (NodeSet)registeredNodes.get(dobj); - // Ideally the set should already exist, but cope gracefully. - assert set != null : "node not created by customizer"; - if (set == null) { - set = new NodeSet(this); - set.add(erdn); - } - set.setSelected(selected); - //setPrimarySchema(erdn, selected, false); - // Check if the current selection is valid. - validateInput(erdn); - } - } - - /** - * Determine if the user's input is valid or not. This will enable - * or disable the save/reset controls based on the results, as well - * as issue error messages. - * - * @param node selected node. - */ - private void validateInput(ExternalReferenceDataNode erdn) { - String msg = null; - String ep = erdn.getPrefix(); - // Must be a non-empty prefix, that is not already in use, and - // is unique among the selected nodes (and be selected itself). - if (ep.length() == 0 || (!isValidPrefix(erdn) && erdn.isSelected())) { - msg = NbBundle.getMessage(SchemaImportGUI.class, "LBL_SchemaPanel_InvalidPrefix"); - } - - - int selected = countSelectedNodes(); - if(selected < 0 ) - msg = "ERROR MSG"; - // Must have selected nodes, and no error messages. - //setSaveEnabled((allowEmptySelection() || selected > 0) ); - } - - /** - * Check if prefix is unique on UI. - * - * @return true if Prefix is not unique on UI, false otherwise. - */ - private boolean isValidPrefix(ExternalReferenceDataNode node) { - DataObject dobj = (DataObject) node.getLookup().lookup(DataObject.class); - NodeSet nodeSet = (NodeSet)registeredNodes.get(dobj); - Collection sets = registeredNodes.values(); - Iterator it = sets.iterator(); - while(it.hasNext()) { - // Ignore the set which contains the given node, and those - // sets which are not selected. - NodeSet set = (NodeSet)it.next(); - if (!set.equals(nodeSet) && set.isSelected()) { - // Only need to check the first node, as all of them have - // the same prefix (or at least that is the idea). - ExternalReferenceDataNode other = (ExternalReferenceDataNode)set.getNodes().get(0); - if (node.getPrefix().equals(other.getPrefix())) { - return false; - } - } - } - return true; - } - - - /** - * Determine the number of nodes that the user selected, useful for - * knowing if any nodes are selected or not. - * - * @return number of selected nodes. - */ - public int countSelectedNodes() { - int results = 0; - Collection sets = registeredNodes.values(); - Iterator it = sets.iterator(); - while(it.hasNext()){ - NodeSet set = (NodeSet)it.next(); - List nodes = set.getNodes(); - if (nodes.size() > 0) { - results++; - } - } - - return results; - } - - - /** - * A TreeTableView that toggles the selection of the external reference - * data nodes using a single mouse click. - */ - private class LocationView extends TreeTableView { - /** silence compiler warnings */ - private static final long serialVersionUID = 1L; - - /** - * Creates a new instance of LocationView. - */ - public LocationView() { - super(); - tree.addMouseListener(new MouseAdapter() { - public void mouseClicked(MouseEvent e) { - // Invert the selection of the data node, if such a - // node was clicked on. - TreePath path = tree.getPathForLocation(e.getX(), e.getY()); - if (path != null) { - Object comp = path.getLastPathComponent(); - Node node = Visualizer.findNode(comp); - if (node instanceof ExternalReferenceDataNode) { - ExternalReferenceDataNode erdn = - (ExternalReferenceDataNode) node; - if (erdn.canSelect()) { - boolean selected = !erdn.isSelected(); - erdn.setSelected(selected); - //setPrimarySchema(erdn, selected, true); - - } - } - } - } - }); - } - } - - - public boolean isPrimarySchemaSelected() { - if(rootModel.getSize() == 0) - return false; - else - return true; - } - - /** - * Retrieve the list of nodes that the user selected. - * - * @return list of selected nodes (empty if none). - */ - protected List getSelectedNodes() { - List results = new LinkedList(); - Collection sets = registeredNodes.values(); - Iterator it = sets.iterator(); - while(it.hasNext()){ - NodeSet set = (NodeSet)it.next(); - if (set.isSelected()) { - List nodes = set.getNodes(); - if (nodes.size() > 0) { - // Use just one of the corresponding nodes, as the - // others are basically duplicates. - results.add(nodes.get(0)); - } - } - } - return results; - } - - /* private void setPrimarySchema(ExternalReferenceDataNode erdn, boolean selected, boolean fromTreeView) { - String ns = null; - DataObject dobj = (DataObject) erdn.getLookup().lookup(DataObject.class); - FileObject fobj = dobj.getPrimaryFile(); - - //if the schema was selected by clicking in the import column, then we dont need to set this - if(fromTreeView) { - erdn.setSelected(selected); - return; - } - - if (selected) { - // Have to collect the namespace value - // when the node is selected. - if(!fobj.isFolder()) { - ns= erdn.getNamespace(); - String key = fobj.getNameExt() + " (" + ns + ")" ; - removeFlag=false; - namespaceModel.addElement(new SchemaComboItem(key, fobj)); - } - } else { - if(!fobj.isFolder()) { - ns=erdn.getNamespace(); - String key=fobj.getNameExt() + " (" + ns + ")"; - for(int i = 0 ; i - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/SchemaPanel.java --- a/xml/src/org/netbeans/modules/xml/wizard/SchemaPanel.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,774 +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.modules.xml.wizard; - -import java.awt.Component; - -import java.awt.Color; -import java.awt.Dialog; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.net.*; -import java.io.*; -import java.util.Iterator; -import javax.swing.DefaultComboBoxModel; -import org.openide.filesystems.FileObject; -import org.openide.loaders.DataObject; -import java.util.ArrayList; -import java.util.List; -import org.openide.loaders.TemplateWizard; -import java.util.Vector; -import javax.swing.AbstractCellEditor; -import javax.swing.JComboBox; -import javax.swing.JRadioButton; -import javax.swing.JTable; -import javax.swing.SwingUtilities; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableCellEditor; -import javax.swing.table.TableCellRenderer; -import javax.swing.table.TableColumn; -import org.netbeans.modules.xml.lib.Util; -import org.openide.DialogDescriptor; -import org.openide.DialogDisplayer; -import org.openide.WizardDescriptor; -import org.openide.util.NbBundle; - - - -/** - * This panel gathers data that are necessary for instantiting of XML - * document conforming to given XML Schema. - *

- * Data allows to create a document that respect restrictions of current parser - * implementations (they use schemaLocation hint specifically). - * - * @author Petr Kuzel - */ -public class SchemaPanel extends AbstractPanel implements ActionListener, TableModelListener { - /** Serial Version UID */ - private static final long serialVersionUID = -7568909683682244030L; - private TemplateWizard templateWizard; - private FileObject primarySchema=null; - private Vector rows; - private final static int PRIMARY_COL = 0; - private final static int SCHEMA_COL = 1; - private final static int ROOT_COL = 2; - private final static int PREFIX_COL = 3; - private SchemaTableModel tableModel; - private SchemaImportGUI gui; - private static String startString; - /** Prefix for the namespace prefix values (e.g. "ns"). */ - private static final String PREFIX = "ns"; // NOI18N - /** Hashmap to keep track of prefixes */ - private List prefixMap = new ArrayList(); - - - /** Creates new form SchemaPanel */ - public SchemaPanel(TemplateWizard tw) { - this.templateWizard = tw; - rows = new Vector(); - tableModel = new SchemaTableModel(); - initComponents(); - initAccessibility(); - initComp(); - - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { - - locationPanel = new javax.swing.JPanel(); - jScrollPane1 = new javax.swing.JScrollPane(); - schemaTable = new javax.swing.JTable(); - locationLabel = new javax.swing.JLabel(); - browseButton = new javax.swing.JButton(); - browseButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - browseButtonActionPerformed(evt); - } - }); - removeButton = new javax.swing.JButton(); - - setName(Util.THIS.getString(SchemaPanel.class, "PROP_schema_panel_name")); // NOI18N - - locationPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); - locationPanel.setLayout(new java.awt.BorderLayout()); - - schemaTable.setModel(tableModel); - jScrollPane1.setViewportView(schemaTable); - schemaTable.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "LBL_Schema_table")); // NOI18N - schemaTable.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "LBL_Schema_table")); // NOI18N - - locationPanel.add(jScrollPane1, java.awt.BorderLayout.CENTER); - - locationLabel.setLabelFor(locationPanel); - locationLabel.setText(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "LBL_SchemaPanel_Location")); // NOI18N - locationLabel.setToolTipText(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "TIP_SchemaPanel_Location")); // NOI18N - - browseButton.setText(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "LBL_BrowseButton")); // NOI18N - - removeButton.setText(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "LBL_RemoveButton")); // NOI18N - removeButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - removeButtonActionPerformed(evt); - } - }); - - org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); - this.setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(layout.createSequentialGroup() - .addContainerGap() - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(locationPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 582, Short.MAX_VALUE) - .add(locationLabel) - .add(layout.createSequentialGroup() - .add(browseButton) - .add(18, 18, 18) - .add(removeButton))) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(layout.createSequentialGroup() - .addContainerGap() - .add(locationLabel) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(locationPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 268, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) - .add(browseButton) - .add(removeButton)) - .addContainerGap(82, Short.MAX_VALUE)) - ); - - browseButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "LBL_BrowseButton")); // NOI18N - removeButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "LBL_RemoveButton")); // NOI18N - - getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "PROP_schema_panel_name")); // NOI18N - getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "PROP_schema_panel_name")); // NOI18N - }// //GEN-END:initComponents - - private boolean isDuplicate(String schemaFileName) { - if(rows.size() == 1) - return false; - for(int i=0 ; i < rows.size(); i++ ){ - List rowData = (List)rows.get(i); - SchemaObject obj = (SchemaObject)rowData.get(SCHEMA_COL); - if(obj.toString().equals(startString)) - continue; - if(obj.getSchemaFileName().equals(schemaFileName)) - return true; - } - return false; - } - -private void primarySchemaCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_primarySchemaCheckBoxActionPerformed - // fireChange(); - -}//GEN-LAST:event_primarySchemaCheckBoxActionPerformed - -private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed - int row = schemaTable.getSelectedRow(); - //System.out.println("delete row = " + row); - deleteRow(row); -}//GEN-LAST:event_removeButtonActionPerformed - - private void browseButtonActionPerformed(ActionEvent evt){ - gui = new SchemaImportGUI(templateWizard); - final DialogDescriptor descriptor = new DialogDescriptor(gui, - NbBundle.getMessage(SchemaPanel.class,"LBL_Browser"), - true, this); - Dialog dlg = DialogDisplayer.getDefault().createDialog(descriptor); - dlg.getAccessibleContext().setAccessibleDescription("DSC_Browser"); - dlg.setVisible(true); - } - private void initAccessibility() { - - // memonics - Util util = Util.THIS; - locationLabel.setDisplayedMnemonic(util.getChar( - SchemaPanel.class, "PROP_schema_locationLabel_mne")); - browseButton.setMnemonic(util.getChar( - SchemaPanel.class, "LBL_BrowseButton_mme")); - removeButton.setMnemonic(util.getChar( - SchemaPanel.class, "LBL_RemoveButton_mne")); - - } - - /** - * Update namespace and root combo models. - */ - private void updatePossibilities() { - } - - /** User just entered the panel, init view by model values - */ - protected void initView() { - - } - - /** User just leaved the panel, update model - */ - protected void updateModel() { - int numRows = tableModel.getRowCount(); - int numCols = tableModel.getColumnCount(); - String uri = null; - List schemaFiles = new ArrayList(); - for (int i=0; i < numRows; i++) { - List rowData = (List)rows.get(i); - boolean primary= ((Boolean)rowData.get(PRIMARY_COL)).booleanValue(); - String prefix = (String)rowData.get(PREFIX_COL); - SchemaObject obj = (SchemaObject)rowData.get(SCHEMA_COL); - if(obj.toString().equals(startString)) - continue; - //set the prefix since this is the most updated prefix - obj.setPrefix(prefix); - String root = (String)rowData.get(ROOT_COL); - if(primary) { - model.setPrimarySchema(obj.toString()); - model.setNamespace(obj.getNamespace()); - model.setPrefix(prefix); - model.setRoot(root); - File file = new File(obj.toString()); - uri = file.getName(); - if (uri != null) { - // we need to escape spaces, URI does not like them - uri = uri.replaceAll(" ", "%20"); // NOI18N - try { - // escape the non-ASCII characters - uri = new URI(uri).toASCIIString(); - } catch (URISyntaxException e) { - // the specified uri is not valid, it is too late to fix it now - } - } - model.setSystemID(uri == null || uri.length() == 0 ? null : uri); - } - schemaFiles.add(obj); - } - model.setSchemaNodes(schemaFiles); - - } - - /** User just reentered the panel. - */ - protected void updateView() { - } - - private String getStartString() { - return NbBundle.getMessage(SchemaPanel.class, "LBL_TABLE_SCHEMA_PROMPT"); - } - - private void tableKeyPressed(KeyEvent evt) { - if( evt.getKeyCode()==KeyEvent.VK_DELETE ){ - int row = schemaTable.getSelectedRow(); - // System.out.println("delete row = " + row); - deleteRow(row); - } - } - - private void deleteRow(int index) { - if(index!=-1){ - SchemaObject val = (SchemaObject)tableModel.getValueAt(index, SCHEMA_COL); - if(val.toString().equals(startString)) - return; - rows.remove(index); - schemaTable.addNotify(); - fireChange(); - } - - } - - - - - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton browseButton; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JLabel locationLabel; - private javax.swing.JPanel locationPanel; - private javax.swing.JButton removeButton; - private javax.swing.JTable schemaTable; - // End of variables declaration//GEN-END:variables - - public void actionPerformed(ActionEvent evt) { - if (evt.getSource().equals(DialogDescriptor.OK_OPTION)) { - List nodes = gui.getSelectedNodes(); - if(nodes != null){ - String noRoot = NbBundle.getMessage(SchemaPanel.class, "LBL_No_Root_Elements"); - for(int i=0;i < nodes.size(); i++ ){ - List row = new ArrayList(); - ExternalReferenceDataNode erdn = (ExternalReferenceDataNode)nodes.get(i); - DataObject dobj = (DataObject) erdn.getLookup().lookup(DataObject.class); - if(isDuplicate(erdn.getSchemaFileName())) - continue; - FileObject fobj = dobj.getPrimaryFile(); - SchemaObject obj = new SchemaObject(erdn.getSchemaFileName()); - obj.setNamespace(erdn.getNamespace()); - obj.setSchemaFileName(erdn.getSchemaFileName()); - - row.add(false); - row.add(obj); - - SchemaParser.SchemaInfo info = Util.getRootElements(fobj); - if (info != null && info.roots.size() > 0) { - Iterator it = info.roots.iterator(); - String[] rootElements = new String[(info.roots.size())]; - info.roots.toArray(rootElements); - obj.setRootElements(rootElements); - row.add(rootElements[0]); - } else { - //we have to add some dummy element since there are no roots - row.add(noRoot); - } - - String pre = generateUniquePrefix(); - obj.setPrefix(pre); - //keep track of unique prefixes - addPrefix(pre); - row.add(pre); - tableModel.addRow(0,row); - } - schemaTable.addNotify(); - } - } else if(evt.getSource().equals(DialogDescriptor.CANCEL_OPTION)){ - gui.setVisible(false); - } - } - - private List createBlankElement(String val) { - List t = new ArrayList(); - t.add(new Boolean(false)); - t.add(new SchemaObject(val)); - t.add((String) " "); - t.add((String) " "); - return t; - } - - private void addRow(String val) { - List r=createBlankElement(val); - tableModel.addRow(r); - schemaTable.addNotify(); - - } - - private void initComp() { - schemaTable.getModel().addTableModelListener(this); - schemaTable.getTableHeader().setReorderingAllowed( false ); - startString = getStartString(); - - //set key listener to delete rows when user presses del key - schemaTable.addKeyListener(new KeyAdapter() { - public void keyPressed(KeyEvent evt) { - tableKeyPressed(evt); - } - }); - //add the initial row - addRow(startString); - - //set width - TableColumn column = null; - for (int i = 0; i < 4; i++) { - column = schemaTable.getColumnModel().getColumn(i); - if (i == PRIMARY_COL) { - column.setPreferredWidth(40); - } else if(i ==SCHEMA_COL) { - column.setPreferredWidth(250); - } else { - column.setPreferredWidth(80); - } - } - - //set renderer and editor for the first column - schemaTable.getColumnModel().getColumn(PRIMARY_COL).setCellRenderer(new RadioColumnRenderer()); - schemaTable.getColumnModel().getColumn(PRIMARY_COL).setCellEditor(new RadioColumnEditor()); - - //set up rendere/editor for the combo box column - TableColumn rootColumn = schemaTable.getColumnModel().getColumn(ROOT_COL); - rootColumn.setCellEditor(new ComboBoxColumnEditor()); - DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); - renderer.setToolTipText(NbBundle.getMessage(SchemaPanel.class, "TIP_COMBO_COL")); - rootColumn.setCellRenderer(renderer); - - int height = schemaTable.getRowHeight(); - - // Determine highest cell in the row - for (int c=0; c= getRowCount() || col >= getColumnCount()) - return; - if(value == null) - return; - - List rowVector = (List)rows.elementAt(row); - - if (col == PRIMARY_COL && ((Boolean)value).booleanValue() ) { - //only those schemas can be set as primary that have root elements - SchemaObject obj = (SchemaObject)getValueAt(row, SCHEMA_COL); - if(obj.getRootElements() == null || obj.getRootElements().length == 0) { - String errMsg = org.openide.util.NbBundle.getMessage(SchemaPanel.class, "MSG_SchemaPanel_Incorrect_Primary"); - templateWizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, errMsg); - return; - } else - templateWizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, ""); - - for (int i = 0; i < getRowCount(); i++) { - if (i != row) { - setValueAt(new Boolean(false), i, 0); - } - } - rowVector.set(col, value); - - } else if(col == SCHEMA_COL){ - String systemId = (String)value; - - //if the value being set is the same as start string, ignore - //if the value is not a url, ignore - if(systemId.equals(startString)) - return; - try { - File file = new File(systemId); - if( !file.exists() ) { - if( !systemId.startsWith("http") ) - return; - } - URL context = model.getTargetFolderURL(); - if (context != null) { - systemId = new URL(context, systemId).toExternalForm(); - } - } catch (MalformedURLException ex) { - return; - } - - //create a schema object - - SchemaParser parser = new SchemaParser(); - SchemaParser.SchemaInfo info = parser.parse(systemId); - SchemaObject obj = new SchemaObject ((String)value); - if (info.namespace != null) { - obj.setNamespace(info.namespace); - } - if (info != null && info.roots.size() > 0) { - Iterator it = info.roots.iterator(); - String[] rootElements = new String[(info.roots.size())]; - info.roots.toArray(rootElements); - obj.setRootElements(rootElements); - rowVector.set(ROOT_COL, rootElements[0]); - } - obj.setSchemaFileName((String)value); - rowVector.set(col, obj); - - - } else if (col == PREFIX_COL) { - String prefix = (String)value; - if(prefix.trim().length() ==0 ) - return; - if(verifyUniquePrefix( prefix) ) { - addPrefix(prefix); - rowVector.set(col, value); - } - } else { - rowVector.set(col, value); - } - templateWizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, ""); - fireChange(); - fireTableCellUpdated(row, col); - } - - private void addRow(List r) { - rows.add(r); - } - - private void addRow(int i, List row) { - rows.add(i, row); - } - - private void printDebugData() { - int numRows = getRowCount(); - int numCols = getColumnCount(); - - for (int i=0; i < numRows; i++) { - System.out.print(" row " + i + ":"); - for (int j=0; j < numCols; j++) { - // System.out.print(" " + data[i][j]); - } - System.out.println(); - } - System.out.println("--------------------------"); - } - - } - - class RadioColumnEditor extends AbstractCellEditor implements TableCellEditor { - // protected EventListenerList listenerList = new EventListenerList(); - // protected ChangeEvent changeEvent = new ChangeEvent(this); - private JRadioButton theRadioButton; - - public RadioColumnEditor() { - super(); - theRadioButton = new JRadioButton(); - theRadioButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent event) { - fireEditingStopped(); - } - }); - } - public Component getTableCellEditorComponent(JTable table, Object obj, boolean isSelected, int row, int col) { - theRadioButton.setHorizontalAlignment(SwingUtilities.CENTER); - if(obj != null){ - Boolean lValueAsBoolean = (Boolean)obj; - theRadioButton.setSelected(lValueAsBoolean.booleanValue()); - } - return theRadioButton; - } - - public Object getCellEditorValue() { - return new Boolean(theRadioButton.isSelected()); - } - } - - class RadioColumnRenderer extends JRadioButton implements TableCellRenderer { - public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { - this.setBackground(Color.WHITE); - if (value == null){ - this.setSelected(false); - } else{ - Boolean ValueAsBoolean = (Boolean)value; - this.setSelected(ValueAsBoolean.booleanValue()); - } - this.setHorizontalAlignment(SwingUtilities.CENTER); - setToolTipText(NbBundle.getMessage(SchemaPanel.class, "TIP_PREFIX_COL")); - return this; - } - } - - class ComboBoxColumnEditor extends AbstractCellEditor implements TableCellEditor { - private JComboBox comboBox; - - public ComboBoxColumnEditor() { - super(); - } - public Component getTableCellEditorComponent(JTable table, Object obj, boolean isSelected, int row, int col) { - comboBox = new JComboBox(); - comboBox.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent event) { - fireEditingStopped(); - } - }); - DefaultComboBoxModel rootModel = new DefaultComboBoxModel(); - SchemaObject o = (SchemaObject)table.getModel().getValueAt(row, SCHEMA_COL); - - if( !(o.toString().equals(startString))) { - String[] root = o.getRootElements(); - if(root != null && root.length >0) { - for(int i=0; i < root.length; i++) - rootModel.addElement(root[i]); - } - } - comboBox.setModel(rootModel); - return comboBox; - } - - public Object getCellEditorValue() { - return comboBox.getModel().getSelectedItem(); - //return new Boolean(theRadioButton.isSelected()); - } - - - } - - -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/SchemaParser.java --- a/xml/src/org/netbeans/modules/xml/wizard/SchemaParser.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/wizard/SchemaParser.java Tue Sep 23 16:17:23 2008 -0500 @@ -41,11 +41,14 @@ package org.netbeans.modules.xml.wizard; +import java.io.File; import java.io.IOException; import java.util.Set; import java.util.TreeSet; import org.netbeans.api.xml.services.UserCatalog; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; import org.openide.xml.XMLUtil; import org.xml.sax.*; import org.xml.sax.helpers.*; @@ -149,4 +152,21 @@ */ public String namespace; } + + public static String getNamespace(FileObject fobj) { + SchemaParser parser = new SchemaParser(); + File file = FileUtil.toFile(fobj); + SchemaParser.SchemaInfo info = parser.parse(file.toURI().toString()); + if (info == null) return null; + return info.namespace; + } + + public static SchemaParser.SchemaInfo getRootElements(FileObject fobj) { + SchemaParser parser = new SchemaParser(); + File file = FileUtil.toFile(fobj); + SchemaParser.SchemaInfo info = parser.parse(file.toURI().toString()); + if (info == null) return null; + else return info; + } + } diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/WaitNode.java --- a/xml/src/org/netbeans/modules/xml/wizard/WaitNode.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +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-2007 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.modules.xml.wizard; - -import java.util.Collection; -import java.util.Collections; -import org.openide.nodes.AbstractNode; -import org.openide.nodes.Children; -import org.openide.nodes.Node; -import org.openide.util.NbBundle; - -/** - * A placeholder node that displays a "please wait" message while the - * task to generate the final node is performed. - * - * @author Nathan Fiedler - */ -public class WaitNode extends AbstractNode { - /** A child key for this node, to be used with Children.Key.setKeys(). */ - public static final Object WAIT_KEY = new Object(); - - /** - * Creates a new instance of WaitNode. - */ - public WaitNode() { - super(Children.LEAF); - setName(NbBundle.getMessage(WaitNode.class, "LBL_WaitNode_Wait")); - setIconBaseWithExtension("org/netbeans/modules/xml/xam/ui/resources/wait.gif"); - } - - /** - * Convenience method that creates an array with a single WaitNode. - * - * @return array with a WaitNode. - */ - public static Node[] createNode() { - return new Node[] { new WaitNode() }; - } - - /** - * Convenience method that creates a collection with a single child key - * entry, that being the WAIT_KEY value. - * - * @return collection with WAIT_KEY. - */ - public static Collection getKeys() { - return Collections.singletonList(WaitNode.WAIT_KEY); - } -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/XMLContentPanel.java --- a/xml/src/org/netbeans/modules/xml/wizard/XMLContentPanel.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/wizard/XMLContentPanel.java Tue Sep 23 16:17:23 2008 -0500 @@ -6,12 +6,14 @@ package org.netbeans.modules.xml.wizard; +import org.netbeans.modules.xml.wizard.SchemaParser; +import org.netbeans.modules.xml.wizard.XMLContentAttributes; import java.io.File; import java.util.Iterator; import javax.swing.DefaultComboBoxModel; import javax.swing.SpinnerModel; import javax.swing.SpinnerNumberModel; -import org.netbeans.modules.xml.lib.Util; +import org.netbeans.modules.xml.util.Util; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileUtil; import org.openide.util.NbBundle; @@ -293,7 +295,7 @@ return null; } FileObject fobj = FileUtil.toFileObject(f); - schemaInfo = Util.getRootElements(fobj); + schemaInfo = SchemaParser.getRootElements(fobj); return schemaInfo; } diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/XMLGeneratorVisitor.java --- a/xml/src/org/netbeans/modules/xml/wizard/XMLGeneratorVisitor.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/src/org/netbeans/modules/xml/wizard/XMLGeneratorVisitor.java Tue Sep 23 16:17:23 2008 -0500 @@ -40,6 +40,7 @@ */ package org.netbeans.modules.xml.wizard; +import org.netbeans.modules.xml.wizard.XMLContentAttributes; import java.io.File; import java.io.IOException; import java.io.Writer; diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/XMLWizardIterator.java --- a/xml/src/org/netbeans/modules/xml/wizard/XMLWizardIterator.java Mon Sep 22 22:08:43 2008 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,717 +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.modules.xml.wizard; - -import java.io.OutputStream; -import java.io.BufferedOutputStream; -import java.io.Writer; -import java.io.OutputStreamWriter; -import java.util.HashSet; -import java.util.Map; -import java.util.HashMap; -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeEvent; -import java.io.File; -import java.util.Set; -import java.io.IOException; -import java.lang.ref.Reference; -import java.lang.ref.WeakReference; -import java.net.URI; -import java.net.URL; -import java.text.DateFormat; -import java.util.Date; -import java.util.List; - -import javax.swing.event.ChangeListener; -import javax.swing.event.ChangeEvent; -import javax.swing.JComponent; -import org.netbeans.api.project.Project; -import org.netbeans.editor.BaseDocument; -import org.netbeans.modules.xml.api.EncodingUtil; - -import org.netbeans.modules.xml.lib.Util; -import org.netbeans.modules.xml.retriever.RetrieveEntry; -import org.netbeans.modules.xml.retriever.RetrieverEngine; -import org.netbeans.modules.xml.retriever.catalog.Utilities; -import org.netbeans.modules.xml.retriever.catalog.Utilities.DocumentTypesEnum; - -import org.netbeans.modules.xml.text.TextEditorSupport; -import org.netbeans.spi.project.CacheDirectoryProvider; -import org.netbeans.spi.project.ui.templates.support.Templates; -import org.openide.loaders.TemplateWizard; -import org.openide.WizardDescriptor; -import org.openide.cookies.EditCookie; -import org.openide.cookies.EditorCookie; -import org.openide.loaders.DataFolder; -import org.openide.filesystems.FileSystem; -import org.openide.filesystems.FileObject; -import org.openide.loaders.DataObject; -import org.openide.filesystems.FileLock; -import org.openide.filesystems.FileUtil; -import org.openide.util.NbBundle; - - - -/** - * Controls new XML Docuemnt wizard. It is kind of dynamic wizard with - * multiple way of diferent length. - * - * @author Petr Kuzel - */ -public class XMLWizardIterator implements TemplateWizard.Iterator { - /** Serial Version UID */ - private static final long serialVersionUID = 5070430920636117204L; - - - private static final String XML_EXT = "xml"; // NOI18N - - // parent wizard - - private transient TemplateWizard templateWizard; - - // model collecting our data - - private transient DocumentModel model; - - // panels - - private transient int current; - - private static final int TARGET_PANEL = 0; - private transient WizardDescriptor.Panel targetPanel; - - private static final int DOCUMENT_PANEL = 1; - private transient DocumentPanel documentPanel; - - private static final int CONSTRAINT_PANEL = 2; - private transient SchemaPanel schemaPanel; - private transient DTDPanel dtdPanel; - - private static final int CONTENT_PANEL = 3; - private transient XMLContentPanel xmlPanel; - - /** Singleton instance of JavaWizardIterator, should it be ever needed. - */ - private static Reference instance; - - private transient Map listenersMap = new HashMap(2); - private transient String[] beforeSteps; - private transient Object targetSteps; - - - /** Returns JavaWizardIterator singleton instance. This method is used - * for constructing the instance from filesystem.attributes. - */ - public static synchronized XMLWizardIterator singleton() { - XMLWizardIterator it = instance == null ? null : instance.get(); - if (it == null) { - it = new XMLWizardIterator(); - instance = new WeakReference(it); - } - return it; - } - - public void initialize(TemplateWizard templateWizard) { - this.templateWizard = templateWizard; - current = TARGET_PANEL; - URL targetFolderURL = null; - try { - DataFolder folder = templateWizard.getTargetFolder(); - targetFolderURL = folder.getPrimaryFile().getURL(); - //#25604 workaround - if (targetFolderURL.toExternalForm().endsWith("/") == false) { - targetFolderURL = new URL(targetFolderURL.toExternalForm() + "/"); - } - } catch (IOException ignore) { - } - model = new DocumentModel(targetFolderURL); - Object prop = templateWizard.getProperty (WizardDescriptor.PROP_CONTENT_DATA); // NOI18N - if (prop != null && prop instanceof String[]) { - beforeSteps = (String[])prop; - } - } - - public void uninitialize(TemplateWizard templateWizard) { - if (targetPanel!=null) { - ((JComponent)targetPanel.getComponent()).putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, targetSteps); - targetPanel = null; - } - current = -1; - model = null; - templateWizard = null; - schemaPanel = null; - dtdPanel = null; - documentPanel = null; - xmlPanel = null; - } - - public Set instantiate(TemplateWizard templateWizard) throws IOException { - final DataFolder folder = templateWizard.getTargetFolder(); - - final File pobj = FileUtil.toFile(folder.getPrimaryFile()); - - final String extension = XML_EXT; - - // #22812 we do not control validity constrains of target panel - // assure uniquess to "" name - - String targetName = templateWizard.getTargetName(); - if (targetName == null || "null".equals(targetName)) { // NOI18N - targetName = "XMLDocument"; // NOI18N - } - final FileObject targetFolder = folder.getPrimaryFile(); - String uniqueTargetName = targetName; - int i = 2; - - while (targetFolder.getFileObject(uniqueTargetName, extension) != null) { - uniqueTargetName = targetName + i; - i++; - } - - final String name = uniqueTargetName; - String encoding = EncodingUtil.getProjectEncoding(folder.getPrimaryFile()); - if (!EncodingUtil.isValidEncoding(encoding)) - encoding = "UTF-8"; //NOI18N - String nameExt = name + "." + extension; - - // in atomic action create data object and return it - - FileSystem filesystem = targetFolder.getFileSystem(); - final FileObject[] fileObject = new FileObject[1]; - FileSystem.AtomicAction fsAction = new FileSystem.AtomicAction() { - public void run() throws IOException { - // XXX use Freemarker instead of this hardcoded template! - //use the project's encoding if there is one - FileObject fo = targetFolder.createData(name, extension); - fileObject[0] = fo; - - } - }; - - - filesystem.runAtomicAction(fsAction); - - StringBuffer sb = new StringBuffer(); - //write the comment - writeXMLComment(sb, nameExt, encoding); - //write the body - writeXMLFile(sb); - - FileLock lock = null; - try { - lock = fileObject[0].lock(); - OutputStream out = fileObject[0].getOutputStream(lock); - out = new BufferedOutputStream(out, 999); - Writer writer = new OutputStreamWriter(out, encoding); - writer.write(sb.toString()); - writer.flush(); - writer.close(); - lock.releaseLock(); - lock = null; - - } finally { - if (lock != null) { - lock.releaseLock(); - } - } - // perform default action and return - Set set = new HashSet(1); - DataObject createdObject = DataObject.find(fileObject[0]); - Util.performDefaultAction(createdObject); - set.add(createdObject); - - formatXML(fileObject[0]); - return set; - } - - - public WizardDescriptor.Panel current() { - WizardDescriptor.Panel panel = currentComponent(); - if (panel.getComponent() instanceof JComponent) { - ((JComponent)panel.getComponent()).putClientProperty( - WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, // NOI18N - new Integer(current) - ); - } - return panel; - } - - - private WizardDescriptor.Panel currentComponent() { - switch (current) { - case TARGET_PANEL: - return getTargetPanel(); - case DOCUMENT_PANEL: - return getDocumentPanel(); - case CONSTRAINT_PANEL: - switch (model.getType()) { - case DocumentModel.DTD: - return getDTDPanel(); - case DocumentModel.SCHEMA: - return getSchemaPanel(); - default: - throw new IllegalStateException(); - } - case CONTENT_PANEL: - return getXMLContentPanel(); - default: - throw new IllegalStateException(); - } - } - - public boolean hasNext() { - boolean none = model.getType() == model.NONE; - int length = 0; - if(model.getType() == model.SCHEMA) - length = CONTENT_PANEL; - if(model.getType() == model.NONE) - length = DOCUMENT_PANEL; - else if(model.getType() == model.DTD) - length = CONSTRAINT_PANEL; - // int length = none ? DOCUMENT_PANEL : CONSTRAINT_PANEL; - return current < length; - } - - public boolean hasPrevious() { - return current > TARGET_PANEL; - } - - public String name() { - return NbBundle.getMessage(XMLWizardIterator.class, "TITLE_x_of_y", - Integer.valueOf(current + 1), Integer.valueOf(current)); - } - - public void nextPanel() { - current++; - } - - public void previousPanel() { - current--; - } - - // events source ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - // - // To symplify synchronization use bridge listeners delegating to model - // events. We do not need to sample listeners in sync block and then fire - // changes over the sampled listener copies out-of the sync block. - // - - public void removeChangeListener(ChangeListener changeListener) { - if (changeListener == null) return; - synchronized (listenersMap) { - Object bridge = listenersMap.remove(changeListener); - if (bridge == null) return; - if (model == null) return; - model.removePropertyChangeListener((PropertyChangeListener) bridge); - } - } - - public void addChangeListener(final ChangeListener changeListener) { - if (changeListener == null) return; - synchronized (listenersMap) { - PropertyChangeListener listenerBridge = new PropertyChangeListener() { - final ChangeEvent EVENT = new ChangeEvent(XMLWizardIterator.this); - public void propertyChange(PropertyChangeEvent e) { - changeListener.stateChanged(EVENT); - } - }; - - if (listenersMap.put(changeListener, listenerBridge) == null) { - model.addPropertyChangeListener(listenerBridge); - } - } - } - - // implementation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - private WizardDescriptor.Panel getDocumentPanel() { - if (documentPanel == null) { - documentPanel = new DocumentPanel(); - documentPanel.setObject(model); - - String[] steps = new String[3]; - steps[0] = getTargetPanelName(); - steps[1] = getDocumentPanelName(); - steps[2] = Util.THIS.getString(XMLWizardIterator.class, "MSG_unknown"); - String[] newSteps = createSteps(beforeSteps,steps); - documentPanel.putClientProperty( - WizardDescriptor.PROP_CONTENT_DATA, // NOI18N - newSteps - ); - - } - return new AbstractPanel.WizardStep(documentPanel); - } - - private WizardDescriptor.Panel getDTDPanel() { - if (dtdPanel == null) { - dtdPanel = new DTDPanel(); - dtdPanel.setObject(model); - - String[] steps = new String[3]; - steps[0] = getTargetPanelName(); - steps[1] = getDocumentPanelName(); - steps[2] = getDTDPanelName(); - String[] newSteps = createSteps(beforeSteps,steps); - dtdPanel.putClientProperty( - WizardDescriptor.PROP_CONTENT_DATA, // NOI18N - newSteps - ); - - } - return new AbstractPanel.WizardStep(dtdPanel); - } - - private WizardDescriptor.Panel getSchemaPanel() { - if (schemaPanel == null) { - schemaPanel = new SchemaPanel(templateWizard); - schemaPanel.setObject(model); - - String[] steps = new String[4]; - steps[0] = getTargetPanelName(); - steps[1] = getDocumentPanelName(); - steps[2] = getSchemaPanelName(); - steps[3] = getXMLContentPanelName(); - String[] newSteps = createSteps(beforeSteps,steps); - schemaPanel.putClientProperty( - WizardDescriptor.PROP_CONTENT_DATA, // NOI18N - newSteps - ); - } - return new AbstractPanel.WizardStep(schemaPanel); - } - - private WizardDescriptor.Panel getTargetPanel() { - if (targetPanel == null) { - targetPanel = templateWizard.targetChooser(); - // fill component with step hints - if (targetPanel.getComponent() instanceof JComponent) { - JComponent panel = (JComponent) targetPanel.getComponent(); - targetSteps = panel.getClientProperty(WizardDescriptor.PROP_CONTENT_DATA); - String[] steps = new String[3]; - //steps[0] = "Hello"; - steps[0] = getTargetPanelName(); - steps[1] = getDocumentPanelName(); - steps[2] = Util.THIS.getString(XMLWizardIterator.class, "MSG_unknown"); - String[] newSteps = createSteps(beforeSteps,steps); - panel.putClientProperty( - WizardDescriptor.PROP_CONTENT_DATA, // NOI18N - newSteps - ); - } - - } - return targetPanel; - } - - private String getTargetPanelName() { - Object panel = getTargetPanel().getComponent(); - if (panel instanceof JComponent) { - return ((JComponent)panel).getName(); - } else { - return ""; //??? some fallback - } - } - - private String getDocumentPanelName() { - return Util.THIS.getString(XMLWizardIterator.class, "PROP_doc_panel_name"); - } - - private String getDTDPanelName() { - return Util.THIS.getString(XMLWizardIterator.class, "PROP_dtd_panel_name"); - } - - private String getSchemaPanelName() { - return Util.THIS.getString(XMLWizardIterator.class, "PROP_schema_panel_name"); - } - - private static String[] createSteps(String[] before, String[] panelNames) { - //assert panels != null; - // hack to use the steps set before this panel processed - int diff = 0; - if (before == null) { - before = new String[0]; - } else if (before.length > 0) { - diff = ("...".equals (before[before.length - 1])) ? 1 : 0; // NOI18N - } - String[] res = new String[ (before.length - diff) + panelNames.length]; - for (int i = 0; i < res.length; i++) { - if (i < (before.length - diff)) { - res[i] = before[i]; - } else { - res[i] = panelNames[i - before.length + diff]; - } - } - return res; - } - - private WizardDescriptor.Panel getXMLContentPanel() { - if (xmlPanel == null) { - xmlPanel = new XMLContentPanel(); - xmlPanel.setObject(model); - - String[] steps = new String[4]; - steps[0] = getTargetPanelName(); - steps[1] = getDocumentPanelName(); - steps[2] = getSchemaPanelName(); - steps[3] = getXMLContentPanelName(); - String[] newSteps = createSteps(beforeSteps,steps); - xmlPanel.putClientProperty( - WizardDescriptor.PROP_CONTENT_DATA, // NOI18N - newSteps - ); - } - return new AbstractPanel.WizardStep(xmlPanel); - } - - private String getXMLContentPanelName() { - return Util.THIS.getString(XMLWizardIterator.class, "PROP_xml_content_panel_name"); - } - - private void generateXMLBody(DocumentModel model, String root, StringBuffer writer){ - String schemaFileName = model.getPrimarySchema(); - if(model.getPrimarySchema().startsWith("http")) { - schemaFileName = retrieveURLSchema(model.getPrimarySchema()); - } - XMLGeneratorVisitor visitor = new XMLGeneratorVisitor(schemaFileName, model.getXMLContentAttributes(), writer); - visitor.generateXML(root); - } - - private String retrieveURLSchema(String sourceURL) { - try { - Project prj = Templates.getProject(templateWizard); - FileObject prjrtfo = prj.getProjectDirectory(); - // File saveFile = new File(selectedSaveRootFolder.getPath() + File.separator + "nbproject" + File.separator + "private" + File.separator+ schemaFileName); - - File prjrt = FileUtil.toFile(prjrtfo); - URI privateCatalogURI = null; - URI privateCacheURI = null; - //determine the cache dir - CacheDirectoryProvider cdp = (CacheDirectoryProvider) prj.getLookup(). - lookup(CacheDirectoryProvider.class); - String cachestr = Utilities.DEFAULT_PRIVATE_CAHCE_URI_STR; - try{ - if( (cdp != null) && (cdp.getCacheDirectory() != null) ){ - URI prjrturi = prjrt.toURI(); - URI cpduri = FileUtil.toFile(cdp.getCacheDirectory()).toURI(); - String cachedirstr = Utilities.relativize(prjrturi, cpduri); - cachestr = cachedirstr+"/"+Utilities.PRIVATE_CAHCE_URI_STR; - } - privateCacheURI = new URI(cachestr); - }catch(Exception e){ - - } - if(privateCacheURI == null) - return null; - URI cacheURI = prjrt.toURI().resolve(privateCacheURI); - File saveFile = new File(cacheURI ); - if(!saveFile.isDirectory()) - saveFile.mkdirs(); - - RetrieverEngine instance = RetrieverEngine.getRetrieverEngine(saveFile, false); - RetrieveEntry rent =new RetrieveEntry(null, sourceURL, null, null, DocumentTypesEnum.schema, true); - instance.addResourceToRetrieve(rent); - instance.setFileOverwrite(true); - instance.start(); - - //find where the file was downloaded, remove the "http:/" from the url - String returnstr = saveFile.getPath() + sourceURL.substring(6, sourceURL.length()); - return returnstr; - } catch (Exception e) { - //e.printStackTrace(); - return null; - } - } - - private void modifyRootElementAttrs(StringBuffer xmlBuffer) { - Map nsAttrs = model.getXMLContentAttributes().getNamespaceToPrefixMap(); - - if (nsAttrs == null || nsAttrs.size() == 0) { - return; - } - int firstOccur = xmlBuffer.indexOf("xmlns"); - int insertLoc = xmlBuffer.indexOf("xmlns", firstOccur + 1); - - StringBuffer sb = new StringBuffer(); - for (String ns : nsAttrs.keySet()) { - String xmlnsString = "xmlns:" + nsAttrs.get(ns) + "='" + ns + "'"; - if (xmlBuffer.indexOf(xmlnsString) == -1) { - xmlBuffer.insert(insertLoc, xmlnsString + "\n "); - } - - } - xmlBuffer.insert(insertLoc, sb.toString()); - - } - - - private void writeXMLFile(StringBuffer writer) throws IOException { - DataFolder folder = templateWizard.getTargetFolder(); - File pobj = FileUtil.toFile(folder.getPrimaryFile()); - String root = model.getRoot(); - if (root == null) { - root = "root"; - } - String prefix = model.getPrefix(); - - if (model.getType() == model.DTD) { - if (model.getPublicID() == null) { - writer.append("\n"); // NOI18N - - } else { - writer.append("\n"); // NOI18N - - } - writer.append("<" + root + ">\n"); // NOI18N - - } else if (model.getType() == model.SCHEMA) { - String namespace = model.getNamespace(); - List nodes = model.getSchemaNodes(); - - if (prefix == null || "".equals(prefix)) { - writer.append("<" + root + " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"); - } else { - writer.append("<" + prefix + ":" + root + " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"); - } - - - Map nsToPre = new HashMap(); - if (nodes != null) { - for (int i = 0; i < nodes.size(); i++) { - SchemaObject erdn = (SchemaObject) nodes.get(i); - nsToPre.put(erdn.getNamespace(), erdn.getPrefix()); - - if (erdn.getPrefix() == null || "".equals(erdn.getPrefix())) { - writer.append(" xmlns='" + erdn.getNamespace() + "'\n"); - } else { - writer.append(" xmlns:" + erdn.getPrefix() + "='" + erdn.getNamespace() + "'\n"); - } - } - for (int i = 0; i < nodes.size(); i++) { - SchemaObject erdn = (SchemaObject) nodes.get(i); - String relativePath = null; - if (erdn.toString().startsWith("http")) { - relativePath = erdn.toString(); - } else { - relativePath = Util.getRelativePath((new File(erdn.getSchemaFileName())), pobj); - } - if (i == 0) { - if (nodes.size() == 1) { - writer.append(" xsi:schemaLocation='" + erdn.getNamespace() + " " + relativePath + "'>\n"); - } else { - writer.append(" xsi:schemaLocation='" + erdn.getNamespace() + " " + relativePath + "\n"); - } - } else if (i == nodes.size() - 1) { - writer.append(" " + erdn.getNamespace() + " " + relativePath + "'>\n"); - } else { - writer.append(" " + erdn.getNamespace() + " " + relativePath + "\n"); - } - } - - } - model.getXMLContentAttributes().setNamespaceToPrefixMap(nsToPre); - generateXMLBody(model, root, writer); - modifyRootElementAttrs(writer); - } else { - writer.append("<" + root + ">\n"); // NOI18N - - } - - if (prefix == null || "".equals(prefix)) { - writer.append("\n"); // NOI18N - - writer.append("\n"); // NOI18N - - } else { - writer.append("\n"); // NOI18N - - writer.append("\n"); - } - - // writer.flush(); - // writer.close(); - - } - - private void writeXMLComment(StringBuffer writer, String filename, String encoding) throws IOException { - writer.append("\n"); // NOI18N - writer.append("\n"); // NOI18N - // comment - Date now = new Date(); - String currentDate = DateFormat.getDateInstance(DateFormat.LONG).format(now); - String currentTime = DateFormat.getTimeInstance(DateFormat.SHORT).format(now); - String userName = System.getProperty("user.name"); - writer.append("\n"); // NOI18N - writer.append("\n"); - } - - - - private void formatXML(FileObject fobj){ - try { - DataObject dobj = DataObject.find(fobj); - EditorCookie ec = dobj.getCookie(EditorCookie.class); - if (ec == null) { - return; - } - BaseDocument doc = (BaseDocument) ec.getDocument(); - org.netbeans.modules.xml.text.api.XMLFormatUtil.reformat(doc, 0, doc.getLength()); - EditCookie cookie = dobj.getCookie(EditCookie.class); - if (cookie instanceof TextEditorSupport) { - if (cookie != null) { - ((TextEditorSupport) cookie).saveDocument(); - } - } - - } catch (Exception e) { - //if exception , then the file will be informatted - } - - - } -} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/folder_closed.png Binary file xml/src/org/netbeans/modules/xml/wizard/folder_closed.png has changed diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/folder_opened.png Binary file xml/src/org/netbeans/modules/xml/wizard/folder_opened.png has changed diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/Bundle.properties --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/Bundle.properties Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,137 @@ +# 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. + +TITLE_x_of_y={0} of {1} +PROP_schema_panel_name=Schema Options +MSG_schema_wizard_desc=Specify the schema location and the namespace of \ +your document's root element. +LBL_schema_location=Schema URI: +PROP_schema_locationLabel_desc=Schema Location Name or Address +PROP_schema_locationLabel_mne=S +PROP_schema_locationTextField_desc=Enter Schema URI or use Browse button to select file. +LBL_browse=Browse... +PROP_schema_locationButton_desc=Select local XML Schema file. +PROP_schema_locationButton_mne=o +LBL_root_namespace=Document Namespace: +PROP_schema_nsLabel_desc=Document Root Element Namespace +PROP_schema_nsLabel_mne=N +PROP_schema_nsComboBox_desc=Use Schema target namespace or enter your own. +PROP_schema_root_name=Root Element: +PROP_schema_rootLabel_desc=Document Root Element Name +PROP_schema_rootLabel_mne=R +PROP_schema_rootComboBox_desc=Use offered name or enter your own root name. +IMG_FolderNode_Closed = org/netbeans/modules/xml/wizard/impl/folder_closed.png +IMG_FolderNode_Opened = org/netbeans/modules/xml/wizard/impl/folder_opened.png +LBL_WaitNode_Wait = Please wait... +CTL_SchemaPanel_Column_Name_name = File +CTL_SchemaPanel_Column_Desc_name = External reference name. +CTL_SchemaPanel_Column_Name_selected = Select +CTL_SchemaPanel_Column_Desc_selected = Select to import/include. +CTL_SchemaPanel_Column_Name_prefix = Prefix +CTL_SchemaPanel_Column_Desc_prefix = Namespace prefix value. +LBL_SchemaPanel_InvalidPrefix = Unique prefix must be specified. +TIP_SchemaPanel_Location=Select an external reference. +LBL_SchemaPanel_Location=Select one or more files\: +LBL_SchemaPanel_Namespace=Namespace\: +TIP_SchemaPanel_Namespace=Namespace of external reference. +LBL_SchemaPanel_Primary_Schema=Primary Schema\: +TIP_SchemaPanel_Primary_Schema=Use this as Primary Schema +LBL_SchemaPanel_Root_Element=Root Element\: +TIP_SchemaPanel_Root_Element=Root Element +LBL_SchemaPanel_Category_By_File = By File +LBL_SchemaPanel_Category_By_Namespace = By Namespace +PROP_schema_checkbox_mne=U +LBL_SchemaDetailPanel_Header=Schema Details +MSG_SchemaPanel_No_Root_Element=No root elements or unable to retrieve the root elements. +LBL_SchemaPanel_ImportCreator_Type=Import +LBL_Browser=Schema Browser +DSC_Browser=Select Schema by File, or by Namespace +PROP_doc_panel_name=Select Document Type +MSG_document_panel_desc=Select the type of XML document you want to create based on your document structure, data types, and namespace requirements. +PROP_wellformed_name=Well-formed Document +PROP_doc_wellformedRadioButton_mne=W +PROP_doc_wellformedRadioButton_desc=Structure constraints of this type of document are hidden to processors. +PROP_dtd_doc_name=DTD-Constrained Document +PROP_doc_dtdConstrainedRadioButton_mne=D +PROP_doc_dtdConstrainedRadioButton_desc=DTD constraint exposes document structure to validating processors. +PROP_schema_doc_name=XML Schema-Constrained Document +PROP_doc_schemaConstrainedRadioButton_mne=S +PROP_doc_schemaConstrainedRadioButton_desc=Schema exposes document structure and data types to XML Schema-aware processors. +PROP_other_doc_name=Other: +PROP_dtd_panel_name=DTD Options +MSG_dtd_panel_desc=Specify the following DTD options for your document: +PROP_dtd_pid_name=DTD Public ID: +PROP_dtd_pidLable_desc=Unique Standardized DTD Public ID +PROP_dtd_pidLabel_mne=P +PROP_dtd_catalog_name=Catalog +PROP_dtd_catalog_desc=Allows to manage entity catalogs. +PROP_dtd_catalog_mne=C +PROP_dtd_sid_name=DTD System ID: +PROP_dtd_sidLabel_desc=Typically HTTP URL to Standardized Location +PROP_dtd_sidLabel_mne=S +PROP_dtd_root_name=Document Root: +PROP_dtd_rootLabel_desc=Root Element of XML Document +PROP_dtd_rootLabel_mne=R +PROP_dtd_pidComboBox_desc=Select public ID from mounted entity catalog or enter your own. +PROP_dtd_sidComboBox_desc=Select recent system ID or enter new one. +PROP_dtd_rootComboBox_desc=Select offered root name or enter your own. + +## XMLWizardIterator.java +MSG_unknown=... + +## Util.java +PROP_schema_select_button=OK +MSG_inValidFile=Invalid file! +PROP_schema_dialog_name=Select XML Schema +PROP_schema_mask=XML Schemas + +LBL_PRIMARY_COL=Primary +LBL_SCHEMA_COL=Schema +LBL_ROOT_COL=Root +LBL_PREIFX_COL=Prefix +LBL_TABLE_SCHEMA_PROMPT= +TIP_PREFIX_COL=Select a schema as a Primary schema +TIP_COMBO_COL=Click for combo box +MSG_SchemaPanel_Incorrect_Primary=Please select a schema that has root elements as Primary. +LBL_No_Root_Elements= +LBL_Schema_table=Schema Table +LBL_BrowseButton=Browse +LBL_BrowseButton_mme=B +LBL_RemoveButton=Remove +LBL_RemoveButton_mne=R diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/DTDPanel.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/DTDPanel.form Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,173 @@ + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/DTDPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/DTDPanel.java Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,394 @@ +/* + * 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.modules.xml.wizard.impl; + +import org.netbeans.modules.xml.wizard.*; +import java.awt.*; +import java.awt.event.*; +import java.net.MalformedURLException; +import java.net.URL; + +import java.util.Iterator; +import java.util.Set; +import java.util.Vector; + +import javax.swing.DefaultComboBoxModel; +import javax.swing.text.JTextComponent; + +import org.netbeans.modules.xml.util.Util; +import org.openide.nodes.Node; +import org.openide.nodes.NodeOperation; + +import org.xml.sax.*; + +/** + * Gathers data for DTD driven XML document instantionation. + * + * @author Petr Kuzel + * @version it does not work well, no PIDs no roots, ... + */ +public class DTDPanel extends AbstractPanel { + /** Serial Version UID */ + private static final long serialVersionUID = 5310047495162425192L; + + + /** Creates new form DTDPanel */ + public DTDPanel() { + initComponents(); + initAccessibility(); + + // attach focus listener to editor directly + Component editor = pidComboBox.getEditor().getEditorComponent(); + editor.addFocusListener(new FocusAdapter() { + public void focusLost(FocusEvent e) { + if (existsPID()) updatePossibilities(); + } + }); + + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + descTextArea = new javax.swing.JTextArea(); + pidLabel = new javax.swing.JLabel(); + pidComboBox = new javax.swing.JComboBox(); + catalogButton = new javax.swing.JButton(); + sidLabel = new javax.swing.JLabel(); + sidComboBox = new javax.swing.JComboBox(); + rootLabel = new javax.swing.JLabel(); + rootComboBox = new javax.swing.JComboBox(); + fillPanel = new javax.swing.JPanel(); + + setName(Util.THIS.getString(DTDPanel.class, "PROP_dtd_panel_name")); // NOI18N + setLayout(new java.awt.GridBagLayout()); + + descTextArea.setEditable(false); + descTextArea.setLineWrap(true); + descTextArea.setText(Util.THIS.getString(DTDPanel.class, "MSG_dtd_panel_desc")); // NOI18N + descTextArea.setWrapStyleWord(true); + descTextArea.setDisabledTextColor(descTextArea.getForeground()); + descTextArea.setEnabled(false); + descTextArea.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(descTextArea, gridBagConstraints); + + pidLabel.setLabelFor(pidComboBox); + pidLabel.setText(Util.THIS.getString(DTDPanel.class, "PROP_dtd_pid_name")); // NOI18N + pidLabel.setToolTipText("null"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 12); + add(pidLabel, gridBagConstraints); + + pidComboBox.setEditable(true); + pidComboBox.setToolTipText("null"); + pidComboBox.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + pidComboBoxActionPerformed(evt); + } + }); + pidComboBox.addFocusListener(new java.awt.event.FocusAdapter() { + public void focusLost(java.awt.event.FocusEvent evt) { + pidComboBoxFocusLost(evt); + } + }); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(pidComboBox, gridBagConstraints); + + catalogButton.setText(Util.THIS.getString(DTDPanel.class, "PROP_dtd_catalog_name")); // NOI18N + catalogButton.setToolTipText("null"); + catalogButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + catalogButtonActionPerformed(evt); + } + }); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(catalogButton, gridBagConstraints); + + sidLabel.setLabelFor(sidComboBox); + sidLabel.setText(Util.THIS.getString(DTDPanel.class, "PROP_dtd_sid_name")); // NOI18N + sidLabel.setToolTipText("null"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 12); + add(sidLabel, gridBagConstraints); + + sidComboBox.setEditable(true); + sidComboBox.setToolTipText("null"); + sidComboBox.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + sidComboBoxActionPerformed(evt); + } + }); + sidComboBox.addFocusListener(new java.awt.event.FocusAdapter() { + public void focusLost(java.awt.event.FocusEvent evt) { + sidComboBoxFocusLost(evt); + } + }); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(sidComboBox, gridBagConstraints); + + rootLabel.setLabelFor(rootComboBox); + rootLabel.setText(Util.THIS.getString(DTDPanel.class, "PROP_dtd_root_name")); // NOI18N + rootLabel.setToolTipText("null"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 12); + add(rootLabel, gridBagConstraints); + + rootComboBox.setEditable(true); + rootComboBox.setToolTipText("null"); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(rootComboBox, gridBagConstraints); + + fillPanel.setLayout(null); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.weighty = 1.0; + add(fillPanel, gridBagConstraints); + }// //GEN-END:initComponents + + private void catalogButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_catalogButtonActionPerformed + Node catalog = getCatalogNode(); + if (catalog == null) return; + NodeOperation.getDefault().explore(catalog); + }//GEN-LAST:event_catalogButtonActionPerformed + + private void initAccessibility() { + + Util util = Util.THIS; + rootLabel.setDisplayedMnemonic(util.getChar(DTDPanel.class, "PROP_dtd_rootLabel_mne")); + pidLabel.setDisplayedMnemonic(util.getChar(DTDPanel.class, "PROP_dtd_pidLabel_mne")); + sidLabel.setDisplayedMnemonic(util.getChar(DTDPanel.class, "PROP_dtd_sidLabel_mne")); + catalogButton.setMnemonic(util.getChar(DTDPanel.class, "PROP_dtd_catalog_mne")); + getAccessibleContext().setAccessibleDescription(descTextArea.getText()); + } + + private void sidComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sidComboBoxActionPerformed + // ignore listing + if (sidComboBox.isPopupVisible()) return; + if (existsPID() == false) updatePossibilities(); + }//GEN-LAST:event_sidComboBoxActionPerformed + + private void pidComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pidComboBoxActionPerformed + // ignore listing + if (pidComboBox.isPopupVisible()) return; + + if (existsPID()) updatePossibilities(); + }//GEN-LAST:event_pidComboBoxActionPerformed + + private void pidComboBoxFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_pidComboBoxFocusLost + if (existsPID()) updatePossibilities(); + }//GEN-LAST:event_pidComboBoxFocusLost + + private void sidComboBoxFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_sidComboBoxFocusLost + if (existsPID() == false) updatePossibilities(); + }//GEN-LAST:event_sidComboBoxFocusLost + + /** + * Try to access catalog management node or null. + */ + private Node getCatalogNode() { + +// TopManager top = TopManager.getDefault(); +// Node runtime = top.getPlaces().nodes().environment(); +// Children children = runtime.getChildren(); +// Enumeration en = children.nodes(); +// +// while (en.hasMoreElements()) { +// Node next = (Node) en.nextElement(); +// //!!! it is undeclared dependency on catalog module +// if ("XML-CATALOG".equals(next.getName())) { // NOI18N +// return new FilterNode(next); +// } +// } + + return null; + } + + // does user entered a PID + private boolean existsPID() { + Object pid = pidModel.getSelectedItem(); + return (pid != null) && (pid instanceof String) + && (((String)pid).trim().equals("") == false); + } + + private void updatePossibilities() { + //??? we are in AWT parse in separate task + + Util.THIS.debug("Updating possible roots (DTD)..."); + + InputSource in = new InputSource(); + + Object sid = sidModel.getSelectedItem(); + String systemId = null; + try { + if (sid != null) { + systemId = sid.toString(); + URL context = model.getTargetFolderURL(); + if (context != null) { + systemId = new URL(context, systemId).toExternalForm(); + } + } + } catch (MalformedURLException ex) { + // ignore it use one passes by user + } + in.setSystemId(systemId); + + Object pid = pidModel.getSelectedItem(); + in.setPublicId( pid == null ? null : pid.toString() ); + + Util.THIS.debug("PID: " + pid + ", SID:" + sid); + Set roots = new DTDParser().parse(in); + + if (roots.size() > 0) { + rootModel.removeAllElements(); + Iterator it = roots.iterator(); + while (it.hasNext()) { + String next = (String) it.next(); + rootModel.addElement(next); + } + } + + // select suggested text (do not focus it) + Component editor = rootComboBox.getEditor().getEditorComponent(); + if (editor instanceof JTextComponent) { + ((JTextComponent)editor).selectAll(); + } + } + + /** User just entered the panel, init view by model values + */ + protected void initView() { + + // fetch catalogs etc. + String[] pids = Util.getKnownDTDPublicIDs(); + pidModel = new DefaultComboBoxModel(pids); + sidModel = new DefaultComboBoxModel(recentSIDs); + rootModel = new DefaultComboBoxModel(); + + pidComboBox.setModel(pidModel); + pidComboBox.getEditor().selectAll(); + + if (true /* #23966 */ || getCatalogNode() == null) { + catalogButton.setVisible(false); + // !!! gridwith mus be set somehow to remaider! + } + + // set models + rootComboBox.setModel(rootModel); + + sidComboBox.setModel(sidModel); + + } + + /** User just leaved the panel, update model + */ + protected void updateModel() { + Object pid = pidModel.getSelectedItem(); + model.setPublicID( pid == null ? null : pid.toString() ); + + Object sid = sidModel.getSelectedItem(); + model.setSystemID(sid == null ? null : sid.toString()); + + Object root = rootModel.getSelectedItem(); + model.setRoot(root == null ? null : root.toString()); + + Util.THIS.debug("Model updated PID: " + pid + " SID: " + sid + " root: " + root); + + // update recent + + if (recentSIDs.contains(sid) == false) { + recentSIDs.add(sid); + } + } + + /** User just reentered the panel. + */ + protected void updateView() { + } + + private DefaultComboBoxModel rootModel; + private DefaultComboBoxModel pidModel; + private DefaultComboBoxModel sidModel; + + private static Vector recentSIDs = new Vector(); + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton catalogButton; + private javax.swing.JTextArea descTextArea; + private javax.swing.JPanel fillPanel; + private javax.swing.JComboBox pidComboBox; + private javax.swing.JLabel pidLabel; + private javax.swing.JComboBox rootComboBox; + private javax.swing.JLabel rootLabel; + private javax.swing.JComboBox sidComboBox; + private javax.swing.JLabel sidLabel; + // End of variables declaration//GEN-END:variables + +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/DTDParser.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/DTDParser.java Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,148 @@ +/* + * 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.modules.xml.wizard.impl; + +import java.io.*; +import java.util.*; + +import org.xml.sax.*; +import org.xml.sax.ext.*; +import org.xml.sax.helpers.*; + +import org.openide.xml.*; + +import org.netbeans.api.xml.services.UserCatalog; +import org.netbeans.api.xml.parsers.SAXEntityParser; +import org.netbeans.modules.xml.util.Util; + +/** + * Silently produces Set of roots from passed SAX declaration handler events. + * + * @author Petr Kuzel + */ +final class DTDParser extends DefaultHandler implements DeclHandler { + + static final String SAX_PROPERTY = "http://xml.org/sax/properties/"; // NOI18N + static final String DECL_HANDLER = "declaration-handler"; // NOI18N + + private final Set roots = new TreeSet(); + + /** Creates new DTDParser */ + public DTDParser() { + } + + /** + * @param in if filled only SID and PID the entity catalog "normalization" is used + */ + public Set parse(InputSource in) { + + Util.THIS.debug("DTDParser started."); + + try { + // we do not want Crimson, it does not understand relative SYSTEM ids + XMLReader parser = XMLUtil.createXMLReader(true); + parser.setContentHandler(this); + parser.setErrorHandler(this); + parser.setProperty(SAX_PROPERTY + DECL_HANDLER, this); + + // provide fake entity resolver and source + + UserCatalog catalog = UserCatalog.getDefault(); + EntityResolver res = (catalog == null ? null : catalog.getEntityResolver()); + + if (res != null) parser.setEntityResolver(res); + + SAXEntityParser dtdParser = new SAXEntityParser(parser, false); + dtdParser.parse(in); + + throw new IllegalStateException("How we can get here?"); // NOI18N + } catch (Stop stop) { + return roots; // expected + } catch (SAXException ex) { + Util.THIS.debug("Ignoring SAX ex. while parsing DTD:", ex); // NOI18N + if (ex.getException() instanceof RuntimeException) { + Util.THIS.debug("Nested exception:", ex.getException()); // NOI18N + } + return roots; // better partial result than nothing + } catch (IOException ex) { + Util.THIS.debug("Ignoring I/O ex. while parsing DTD:", ex); // NOI18N + return roots; // better partial result than nothing + } finally { + Util.THIS.debug("DTDParser stopped."); // NOI18N + } + } + + public void elementDecl(String name, String model) throws SAXException { + Util.THIS.debug("\telementDecl(" + name + ",...)"); // NOI18N + roots.add(name); + } + + public void externalEntityDecl(String name, String publicId, String systemId) throws SAXException { + } + + public void attributeDecl(String eName, String aName, String type, String valueDefault, String value) throws SAXException { + } + + public void internalEntityDecl(String name, String value) throws SAXException { + } + + public void notationDecl (String name, String publicId, String systemId) throws SAXException { + } + + public void startElement (String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { + Util.THIS.debug("\tstopping parser!"); // NOI18N + throw new Stop(); + } + + private class Stop extends SAXException { + + private static final long serialVersionUID = -64662796017444980L; + + Stop() { + super("STOP"); //NOI18N + } + + public Throwable fillInStackTrace() { + return this; + } + } +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/DTDWizardIterator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/DTDWizardIterator.java Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,311 @@ +/* + * 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-2007 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.modules.xml.wizard.impl; + +//java imports +import java.awt.Component; +import java.io.IOException; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.NoSuchElementException; +import java.util.Set; +import javax.swing.JComponent; +import javax.swing.event.ChangeListener; +import javax.swing.event.ChangeEvent; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +import org.netbeans.api.project.Project; +import org.netbeans.api.project.ProjectUtils; +import org.netbeans.api.project.SourceGroup; +import org.netbeans.api.project.Sources; +import org.netbeans.modules.xml.api.EncodingUtil; +import org.openide.WizardDescriptor; +import org.openide.filesystems.FileObject; +import org.openide.loaders.DataFolder; +import org.openide.loaders.DataObject; +import org.openide.util.Exceptions; +import org.openide.util.NbBundle; +import org.openide.cookies.EditCookie; +import org.openide.loaders.TemplateWizard; +import org.netbeans.spi.project.ui.templates.support.Templates; +import org.openide.cookies.EditorCookie; +import org.openide.cookies.SaveCookie; + +/** + * Sample schema wizard iterator. See layer.xml for template declaration. + * + * @author Samaresh (Samaresh.Panda@Sun.Com) + */ +public class DTDWizardIterator extends Object implements TemplateWizard.Iterator { + + private static final long serialVersionUID = 1L; + private int index; + private final Set changeListeners = new HashSet(); + protected transient WizardDescriptor.Panel[] panels; + protected String encoding; //project's encoding + + /** + * You should define what panels you want to use here: + */ + protected WizardDescriptor.Panel[] createPanels (Project project, + final TemplateWizard wizard) { + DataFolder df = null; + Sources sources = ProjectUtils.getSources(project); + SourceGroup[] folders = sources.getSourceGroups("java"); //NOI18N + if (folders == null || folders.length == 0) { + folders = sources.getSourceGroups(Sources.TYPE_GENERIC); + } + try { + df = wizard.getTargetFolder(); + } catch (IOException ex) { + //just catch + } + if (df != null) { + wizard.setTargetFolder(df); + org.openide.WizardDescriptor.Panel panel = Templates.createSimpleTargetChooser(project, folders); + return new org.openide.WizardDescriptor.Panel[]{panel}; + } + + //make the first one as the default target folder. IZ: 98643 + if (folders != null && folders.length != 0) { + df = DataFolder.findFolder(folders[0].getRootFolder()); + wizard.setTargetFolder(df); + } + WizardDescriptor.Panel panel = Templates.createSimpleTargetChooser(project, folders); + return new WizardDescriptor.Panel[] {panel}; + } + + /** + * Initialization of the wizard iterator. + */ + public void initialize(TemplateWizard wizard) { + index = 0; + Project project = Templates.getProject( wizard ); + panels = createPanels (project, wizard); + + // Creating steps. + Object prop = wizard.getProperty (WizardDescriptor.PROP_CONTENT_DATA); // NOI18N + String[] beforeSteps = null; + if (prop instanceof String[]) { + beforeSteps = (String[])prop; + } + String[] steps = createSteps (beforeSteps, panels); + + for (int i = 0; i < panels.length; i++) { + Component c = panels[i].getComponent (); + if (steps[i] == null) { + // Default step name to component name of panel. + // Mainly useful for getting the name of the target + // chooser to appear in the list of steps. + steps[i] = c.getName (); + } + if (c instanceof JComponent) { // assume Swing components + JComponent jc = (JComponent) c; + // Step #. + jc.putClientProperty (WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, Integer.valueOf(i)); // NOI18N + // Step name (actually the whole list for reference). + jc.putClientProperty (WizardDescriptor.PROP_CONTENT_DATA, steps); // NOI18N + } + } + } + + /** + * Cleanup. + */ + public void uninitialize (TemplateWizard wiz) { + panels = null; + } + + /** + * This is where, the schema gets instantiated from the template. + */ + public Set instantiate (TemplateWizard wizard) throws IOException { + FileObject dir = Templates.getTargetFolder( wizard ); + DataFolder df = DataFolder.findFolder( dir ); + FileObject template = Templates.getTemplate( wizard ); + DataObject dTemplate = DataObject.find( template ); + DataObject dobj = dTemplate.createFromTemplate(df, Templates.getTargetName(wizard)); + if (dobj == null) + return Collections.emptySet(); + + encoding = EncodingUtil.getProjectEncoding(df.getPrimaryFile()); + if(!EncodingUtil.isValidEncoding(encoding)) + encoding = "UTF-8"; //NOI18N + EditCookie edit = dobj.getCookie(EditCookie.class); + if (edit != null) { + EditorCookie editorCookie = dobj.getCookie(EditorCookie.class); + Document doc = (Document)editorCookie.openDocument(); + fixEncoding(doc, encoding); + SaveCookie save = dobj.getCookie(SaveCookie.class); + if (save!=null) save.save(); + } + + return Collections.singleton(dobj.getPrimaryFile()); + } + + /** + * + */ + public void addChangeListener(ChangeListener listener) { + changeListeners.add(listener); + } + + /** + * + * + */ + public void removeChangeListener(ChangeListener listener) { + changeListeners.remove(listener); + } + + /** + * + */ + public void fireStateChanged() { + ChangeEvent event = new ChangeEvent(this); + + Iterator i = changeListeners.iterator(); + while (i.hasNext()) { + try { + i.next().stateChanged(event); + } catch (Exception e) { + //Debug.debugNotify(e); + } + } + } + + /** + * + */ + public String name () { + return NbBundle.getMessage(DTDWizardIterator.class, "TITLE_x_of_y", + Integer.valueOf(index + 1), Integer.valueOf(panels.length)); + } + + /** + * + */ + public boolean hasNext () { + return index < panels.length - 1; + } + + /** + * + */ + public boolean hasPrevious () { + return index > 0; + } + + /** + * + */ + public void nextPanel () { + if (! hasNext ()) throw new NoSuchElementException (); + index++; + } + + /** + * + */ + public void previousPanel () { + if (! hasPrevious ()) throw new NoSuchElementException (); + index--; + } + + /** + * Returns the current panel. + */ + public WizardDescriptor.Panel current () { + return panels[index]; + } + + /** + * Create steps. + */ + private String[] createSteps(String[] before, WizardDescriptor.Panel[] panels) { + //assert panels != null; + // hack to use the steps set before this panel processed + int diff = 0; + if (before == null) { + before = new String[0]; + } else if (before.length > 0) { + diff = ("...".equals (before[before.length - 1])) ? 1 : 0; // NOI18N + } + String[] res = new String[ (before.length - diff) + panels.length]; + for (int i = 0; i < res.length; i++) { + if (i < (before.length - diff)) { + res[i] = before[i]; + } else { + res[i] = panels[i - before.length + diff].getComponent ().getName (); + } + } + return res; + } + + /** + * Utility method to replace text in document. + */ + void replaceInDocument(javax.swing.text.Document document, String replaceFrom, String replaceTo) { + javax.swing.text.AbstractDocument doc = (javax.swing.text.AbstractDocument)document; + int len = replaceFrom.length(); + try { + String content = doc.getText(0,doc.getLength()); + int index = content.lastIndexOf(replaceFrom); + while (index>=0) { + doc.replace(index,len,replaceTo,null); + content=content.substring(0,index); + index = content.lastIndexOf(replaceFrom); + } + } catch (javax.swing.text.BadLocationException ex){} + } + + void fixEncoding(javax.swing.text.Document document, String encoding) { + if(encoding == null) + encoding = "UTF-8"; //NOI18N + try { + document.insertString(19, " encoding=\""+encoding+"\"", null); + } catch (BadLocationException ex) { + Exceptions.printStackTrace(ex); + } + } + +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/DocumentPanel.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/DocumentPanel.form Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,147 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/DocumentPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/DocumentPanel.java Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,245 @@ +/* + * 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.modules.xml.wizard.impl; + +import org.netbeans.modules.xml.wizard.*; +import org.netbeans.modules.xml.util.Util; + +/** + * + * @author Petr Kuzel + */ +public class DocumentPanel extends AbstractPanel { + /** Serial Version UID */ + private static final long serialVersionUID = 3793605846188902177L; + + + /** Creates new form DocumentPanel */ + public DocumentPanel() { + initComponents(); + initAccessibility(); + + // switch off extensibity point - not implemented + otherRadioButton.setVisible(false); + otherComboBox.setVisible(false); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + buttonGroup = new javax.swing.ButtonGroup(); + descTextArea = new javax.swing.JTextArea(); + wellformedRadioButton = new javax.swing.JRadioButton(); + dtdConstrainedRadioButton = new javax.swing.JRadioButton(); + schemaConstrainedRadioButton = new javax.swing.JRadioButton(); + otherRadioButton = new javax.swing.JRadioButton(); + otherComboBox = new javax.swing.JComboBox(); + fillPanel = new javax.swing.JPanel(); + + setName(Util.THIS.getString(DocumentPanel.class, "PROP_doc_panel_name")); // NOI18N + setLayout(new java.awt.GridBagLayout()); + + descTextArea.setEditable(false); + descTextArea.setLineWrap(true); + descTextArea.setText(Util.THIS.getString(DocumentPanel.class, "MSG_document_panel_desc")); // NOI18N + descTextArea.setWrapStyleWord(true); + descTextArea.setDisabledTextColor(descTextArea.getForeground()); + descTextArea.setEnabled(false); + descTextArea.setOpaque(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints.insets = new java.awt.Insets(0, 0, 12, 0); + add(descTextArea, gridBagConstraints); + + buttonGroup.add(wellformedRadioButton); + wellformedRadioButton.setText(Util.THIS.getString(DocumentPanel.class, "PROP_wellformed_name")); // NOI18N + wellformedRadioButton.setToolTipText("null"); + wellformedRadioButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + wellformedRadioButtonActionPerformed(evt); + } + }); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 0); + add(wellformedRadioButton, gridBagConstraints); + + buttonGroup.add(dtdConstrainedRadioButton); + dtdConstrainedRadioButton.setText(Util.THIS.getString(DocumentPanel.class, "PROP_dtd_doc_name")); // NOI18N + dtdConstrainedRadioButton.setToolTipText("null"); + dtdConstrainedRadioButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + dtdConstrainedRadioButtonActionPerformed(evt); + } + }); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 0); + add(dtdConstrainedRadioButton, gridBagConstraints); + + buttonGroup.add(schemaConstrainedRadioButton); + schemaConstrainedRadioButton.setText(Util.THIS.getString(DocumentPanel.class, "PROP_schema_doc_name")); // NOI18N + schemaConstrainedRadioButton.setToolTipText("null"); + schemaConstrainedRadioButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + schemaConstrainedRadioButtonActionPerformed(evt); + } + }); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(0, 12, 12, 0); + add(schemaConstrainedRadioButton, gridBagConstraints); + + buttonGroup.add(otherRadioButton); + otherRadioButton.setText(Util.THIS.getString(DocumentPanel.class, "PROP_other_doc_name")); // NOI18N + otherRadioButton.setEnabled(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 12); + add(otherRadioButton, gridBagConstraints); + + otherComboBox.setEnabled(false); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.weightx = 1.0; + add(otherComboBox, gridBagConstraints); + + fillPanel.setLayout(null); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; + gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.weighty = 1.0; + add(fillPanel, gridBagConstraints); + }// //GEN-END:initComponents + + private void initAccessibility() { + + Util util = Util.THIS; + wellformedRadioButton.setMnemonic(util.getChar( + DocumentPanel.class, "PROP_doc_wellformedRadioButton_mne")); + schemaConstrainedRadioButton.setMnemonic(util.getChar( + DocumentPanel.class, "PROP_doc_schemaConstrainedRadioButton_mne")); + dtdConstrainedRadioButton.setMnemonic(util.getChar( + DocumentPanel.class, "PROP_doc_dtdConstrainedRadioButton_mne")); + getAccessibleContext().setAccessibleDescription(descTextArea.getText()); + } + + private void schemaConstrainedRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_schemaConstrainedRadioButtonActionPerformed + updateModel(); + }//GEN-LAST:event_schemaConstrainedRadioButtonActionPerformed + + private void dtdConstrainedRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dtdConstrainedRadioButtonActionPerformed + updateModel(); + }//GEN-LAST:event_dtdConstrainedRadioButtonActionPerformed + + private void wellformedRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_wellformedRadioButtonActionPerformed + updateModel(); + }//GEN-LAST:event_wellformedRadioButtonActionPerformed + + /** User just entered the panel, init view by model values + */ + protected void initView() { + int type = model.getType(); + switch (type) { + case DocumentModel.NONE: + wellformedRadioButton.setSelected(true); + break; + case DocumentModel.DTD: + dtdConstrainedRadioButton.setSelected(true); + break; + case DocumentModel.SCHEMA: + schemaConstrainedRadioButton.setSelected(true); + break; + case DocumentModel.OTHER: + otherRadioButton.setSelected(true); + break; + default: + throw new IllegalStateException(); + } + } + + /** User just leaved the panel, update model + */ + protected void updateModel() { + if (wellformedRadioButton.isSelected()) { + model.setType(model.NONE); + } else if (dtdConstrainedRadioButton.isSelected()) { + model.setType(model.DTD); + } else if (schemaConstrainedRadioButton.isSelected()) { + model.setType(model.SCHEMA); + } else { + model.setType(model.OTHER); + } + } + + /** User just reentered the panel. + */ + protected void updateView() { + // no dynamic update needed + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.ButtonGroup buttonGroup; + private javax.swing.JTextArea descTextArea; + private javax.swing.JRadioButton dtdConstrainedRadioButton; + private javax.swing.JPanel fillPanel; + private javax.swing.JComboBox otherComboBox; + private javax.swing.JRadioButton otherRadioButton; + private javax.swing.JRadioButton schemaConstrainedRadioButton; + private javax.swing.JRadioButton wellformedRadioButton; + // End of variables declaration//GEN-END:variables + +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/ExternalReferenceDataNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/ExternalReferenceDataNode.java Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,291 @@ +/* + * 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-2007 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.modules.xml.wizard.impl; + +import java.io.File; +import java.net.URI; +import java.net.URISyntaxException; +import org.netbeans.modules.xml.wizard.SchemaParser; +import org.openide.loaders.DataObject; +import org.openide.nodes.FilterNode; +import org.openide.nodes.Node; +import org.openide.ErrorManager; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.nodes.Node.Property; +import org.openide.nodes.PropertySupport.Reflection; +import org.openide.nodes.Sheet; +import org.openide.nodes.Sheet.Set; +import org.openide.util.NbBundle; + +/** + * Represents a collection of external references, or a single file. + * + * @author Ajit Bhate + * @author Nathan Fiedler + */ +public class ExternalReferenceDataNode extends FilterNode { + /** Name of the 'selected' property. */ + public static final String PROP_SELECTED = "selected"; + /** Name of the 'prefix' property. */ + public static final String PROP_PREFIX = "prefix"; + /** Set of PropertySets. */ + private Sheet sheet; + /** True if selected, false otherwise. */ + private boolean selected; + /** The namespace prefix, if specified. */ + private String prefix=null; + private static int counter=0; + private ExternalReferenceDecorator decorator; + + /** + * Creates a new instance of ExternalReferenceDataNode. + * + * @param original the delegate Node. + * @param decorator the external reference decorator. + */ + public ExternalReferenceDataNode(Node original,ExternalReferenceDecorator dec) { + super(original, new Children(original, dec)); + this.decorator=dec; + + } + + public boolean canRename() { + // Disable rename as it serves no purpose here and makes the + // single-click-select-toggle difficult to use. + return false; + } + + /** + * Indicates if this node allows setting it selected. + * + * @return true if this node can be selected, false otherwise. + */ + public boolean canSelect() { + DataObject dobj = (DataObject) getLookup().lookup(DataObject.class); + return dobj != null && !dobj.getPrimaryFile().isFolder() ; + } + + /** + * Creates a node property of the given key (same as the column keys) + * and specific getter/setter methods on the given object. + * + * @param key property name (same as matching column). + * @param type Class of the property (e.g. String.class). + * @param inst object on which to reflect. + * @param getter name of getter method for property value. + * @param setter name of setter method for property value (may be null). + * @return new property. + */ + private Node.Property createProperty(String key, Class type, Object inst, + String getter, String setter) { + Property prop = null; + try { + prop = new Reflection(inst, type, getter, setter); + prop.setName(key); + prop.setDisplayName(NbBundle.getMessage( + ExternalReferenceDataNode.class, + "CTL_SchemaPanel_Column_Name_" + key)); + prop.setShortDescription(NbBundle.getMessage( + ExternalReferenceDataNode.class, + "CTL_SchemaPanel_Column_Desc_" + key)); + } catch (NoSuchMethodException nsme) { + ErrorManager.getDefault().notify(nsme); + } + return prop; + } + + protected Sheet createSheet() { + Sheet sheet = Sheet.createDefault(); + Set set = sheet.get(Sheet.PROPERTIES); + set.put(createProperty(PROP_NAME, String.class, this, + "getHtmlDisplayName", null)); + if (canSelect()) { + set.put(createProperty(PROP_SELECTED, Boolean.TYPE, this, + "isSelected", "setSelected")); + // Node.Property prop = createProperty(PROP_PREFIX, String.class, + // this, "getPrefix", "setPrefix"); + // Suppress the [...] button because it is not needed. + // prop.setValue("suppressCustomEditor", Boolean.TRUE); + // set.put(prop); + } /*else { + // Do not include this property so the checkbox is not shown. + //set.put(createProperty(PROP_SELECTED, Boolean.TYPE, this, + // "isSelected", null)); + Node.Property prop = createProperty(PROP_PREFIX, String.class, + this, "getPrefix", null); + // Suppress the [...] button because it is not needed. + prop.setValue("suppressCustomEditor", Boolean.TRUE); + set.put(prop); + }*/ + return sheet; + } + + protected final synchronized Sheet getSheet() { + if (sheet != null) { + return sheet; + } + sheet = createSheet(); + firePropertySetsChange(null, null); + return sheet; + } + + public PropertySet[] getPropertySets() { + Sheet s = getSheet(); + return s.toArray(); + } + + public String getHtmlDisplayName() { + String name = getOriginal().getHtmlDisplayName(); + return name; + } + + public String getPrefix() { + + if (prefix == null) { + DataObject dobj = (DataObject) getLookup().lookup(DataObject.class); + if( dobj !=null && !(dobj.getPrimaryFile().isFolder()) ) + prefix = decorator.generatePrefix(prefix, dobj); + else + prefix =""; + } + return prefix; + } + + public boolean isSelected() { + return selected; + } + + + public void setDisplayName(String s) { + super.disableDelegation(DELEGATE_GET_DISPLAY_NAME|DELEGATE_SET_DISPLAY_NAME); + super.setDisplayName(s); + } + + /** + * Set the namespace prefix for this node. + * + * @param prefix new namespace prefix. + */ + public void setPrefix(String prefix) { + String old = this.prefix; + this.prefix = prefix; + firePropertyChange(PROP_PREFIX, old, prefix); + } + + /** + * Mark this node as selected. + * + * @param selected true to select, false to unselect. + */ + public void setSelected(boolean selected) { + if (!canSelect()) { + throw new IllegalStateException("node cannot be selected"); + } + boolean old = this.selected; + this.selected = selected; + firePropertyChange(PROP_SELECTED, new Boolean(old), new Boolean(selected)); + } + + public String getNamespace() { + DataObject dobj = (DataObject) getLookup().lookup(DataObject.class); + if (dobj != null) { + FileObject fobj = dobj.getPrimaryFile(); + return SchemaParser.getNamespace(fobj); + } + return null; + } + + public String getSchemaFileName(){ + DataObject dobj = (DataObject) getLookup().lookup(DataObject.class); + if (dobj != null) { + FileObject fobj = dobj.getPrimaryFile(); + File file = FileUtil.toFile(fobj); + String uri = file.getPath(); + if (uri != null) { + try { + // escape the non-ASCII characters + uri = new URI(uri).toASCIIString(); + } catch (URISyntaxException e) { + // the specified uri is not valid, it is too late to fix it now + } + } + return uri; + } + + return null; + + } + + private static class Children extends FilterNode.Children { + /** Controls the appearance of child nodes. */ + ExternalReferenceDecorator decorator; + + public Children(Node original, ExternalReferenceDecorator dec) { + super(original); + this.decorator=dec; + } + + protected Node[] createNodes(Node n) { + DataObject dobj = (DataObject) n.getLookup().lookup(DataObject.class); + if (dobj != null) { + FileObject fobj = dobj.getPrimaryFile(); + if (fobj.isFolder() && fobj.getNameExt().equals("nbproject") && + fobj.getFileObject("project.xml") != null) { + // It is the NetBeans project folder, ignore it. + return new Node[0]; + } + String fname = fobj.getNameExt(); + String ext = decorator.getDocumentType(); + if (fobj.isFolder() || fname.endsWith(ext)) { + return super.createNodes(n); + } + } + return new Node[0]; + } + + protected Node copyNode(Node node) { + return decorator.createExternalReferenceNode(node); + } + + } +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/ExternalReferenceDecorator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/ExternalReferenceDecorator.java Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,112 @@ +/* + * 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-2007 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.modules.xml.wizard.impl; + + +import java.util.HashMap; +import java.util.Map; +import org.openide.loaders.DataObject; +import org.openide.nodes.Node; + +/** + * An ExternalReferenceDecorator is used to control the appearance of the + * nodes in the ExternalReferenceCustomizer. + * + * @author Nathan Fiedler + */ +public class ExternalReferenceDecorator { + + private SchemaImportGUI panel; + private static String SCHEMA = "xsd"; + private static int counter = 0; + /** Prefix for the namespace prefix values (e.g. "ns"). */ + private static final String PREFIX_PREFIX = "ns"; // NOI18N + /** Hashmap to keep track of prefixes */ + private Map prefixMap = new HashMap(); + + public ExternalReferenceDecorator(SchemaImportGUI panel){ + this.panel = panel; + } + /** + * Create an ExternalReferenceNode with the given delegate node. + * Implementors may wish to delegate to the customizer. + * + * @param node delegate Node. + * @return new ExternalReferenceNode. + */ + ExternalReferenceDataNode createExternalReferenceNode(Node original){ + return panel.createExternalReferenceNode(original); + } + + + /** + * Generate a unique prefix value for the document containing the + * customized component. The selected node is provided, which permits + * customizing the prefix based on the model represented by the node. + * + * @param prefix the desired prefix for the namespace prefix; + * if null, a default of "ns" will be used. + * @param dobj DataObject for which to find unique prefix. + * @return unique prefix value (e.g. "ns1"); must not be null. + */ + String generatePrefix(String prefix, DataObject dobj){ + String prefixStr = prefix == null ? PREFIX_PREFIX : prefix; + String existPrefix = (String)prefixMap.get(dobj); + if(existPrefix != null) + return existPrefix; + + String generated = prefixStr + counter++; + prefixMap.put(dobj, generated); + return generated; + } + + /** + * Return the document type that this decorator wants to show in the + * file chooser. + * + * @return the desired document type. + */ + String getDocumentType(){ + return SCHEMA; + } + + } diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/FolderNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/FolderNode.java Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,99 @@ +/* + * 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-2007 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.modules.xml.wizard.impl; + +import java.awt.Image; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.Repository; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataObjectNotFoundException; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.NbBundle; + +/** + * An abstract node that uses a file folder icon. Ideally the icon is + * taken from the Node delegate of DataFolder, if it is available. + * Otherwise a default icon is used. + * + * @author Nathan Fiedler + */ +public class FolderNode extends AbstractNode { + /** The source for our folder icons. */ + private static Node iconSource; + + static { + FileObject fobj = Repository.getDefault().getDefaultFileSystem().getRoot(); + try { + DataObject dobj = DataObject.find(fobj); + iconSource = dobj.getNodeDelegate(); + } catch (DataObjectNotFoundException donfe) { + // In this case, we have our default icons, which are not + // platform-conformant, but they are better than nothing. + } + } + + public FolderNode(Children children) { + super(children); + } + + public Image getIcon(int type) { + if (iconSource != null) { + return iconSource.getIcon(type); + } else { + String url = NbBundle.getMessage(FolderNode.class, + "IMG_FolderNode_Closed"); + return org.openide.util.Utilities.loadImage(url); + } + } + + public Image getOpenedIcon(int type) { + if (iconSource != null) { + return iconSource.getOpenedIcon(type); + } else { + String url = NbBundle.getMessage(FolderNode.class, + "IMG_FolderNode_Opened"); + return org.openide.util.Utilities.loadImage(url); + } + } +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/NamespaceChildren.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/NamespaceChildren.java Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,172 @@ +/* + * 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-2007 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.modules.xml.wizard.impl; + +import java.awt.EventQueue; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import org.netbeans.modules.xml.util.Util; +import org.openide.filesystems.FileObject; +import org.openide.filesystems.FileUtil; +import org.openide.loaders.DataObject; +import org.openide.loaders.DataObjectNotFoundException; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.RequestProcessor; + + +/** + * Represents the collection of files belonging to a common namespace. + * + * @author Ajit Bhate + */ +public class NamespaceChildren extends Children.Keys { + /** Map of namespace to a list of files in that namespace. */ + private HashMap nsFilesMap; + /** Set of folders containing referencable files. */ + private FileObject[] rootFolders; + private ExternalReferenceDecorator decorator; + + /** + * Creates a new instance of NamespaceChildren. + * + * @param roots set of root folders. + * @param decorator used to decorate the nodes. + */ + public NamespaceChildren(FileObject[] roots, ExternalReferenceDecorator decorator) { + super(); + rootFolders = roots; + this.decorator=decorator; + nsFilesMap = new HashMap(); + } + + protected Node[] createNodes(Object key) { + if (key == WaitNode.WAIT_KEY) { + return WaitNode.createNode(); + } else if (key instanceof String) { + List fobjs = (List)nsFilesMap.get(key); + if (fobjs != null && !fobjs.isEmpty()) { + Node[] filterNodes = new Node[fobjs.size()]; + int i = 0; + for (int j=0; j < fobjs.size();j++) { + try { + FileObject fobj = (FileObject)fobjs.get(j); + Node node = DataObject.find(fobj).getNodeDelegate(); + filterNodes[i++] = decorator.createExternalReferenceNode(node); + } catch (DataObjectNotFoundException donfe) { + } + } + Children.Array children = new Children.Array(); + children.add(filterNodes); + Node node = new NamespaceNode(children, (String) key); + return new Node[] { node }; + } + } + return new Node[] { }; + } + + protected void addNotify() { + super.addNotify(); + setKeys(WaitNode.getKeys()); + RequestProcessor.getDefault().post(new Runnable() { + public void run() { + for (int i =0; i < rootFolders.length;i++) { + FileObject root = rootFolders[i]; + java.util.Map map =Util.getFiles2NSMappingInProj(FileUtil.toFile(root), Util.getDocumentType()); + java.util.Set set= map.entrySet(); + Iterator it = set.iterator(); + while(it.hasNext()){ + java.util.Map.Entry entry = (java.util.Map.Entry)it.next(); + String ns = (String)entry.getValue(); + List fobjs = (List)nsFilesMap.get(ns); + if (fobjs == null) { + fobjs = new ArrayList(); + } + fobjs.add((FileObject)entry.getKey()); + nsFilesMap.put(ns, fobjs); + } + } + // Set the keys on the EDT to avoid clobbering the JTree + // and causing an AIOOBE (issue 94498). + EventQueue.invokeLater(new Runnable() { + public void run() { + setKeys(nsFilesMap.keySet()); + } + }); + } + }); + } + + + // @Override + protected void removeNotify() { + setKeys(Collections.emptySet()); + } + + private static class NamespaceNode extends FolderNode { + /** Controls the appearance of this node. */ + public static final String NO_NAME_SPACE = "NO_NAME_SPACE"; + + NamespaceNode(Children children, String myNamespace) { + super(children); + setName(myNamespace); + if (NO_NAME_SPACE.equals(myNamespace)) { + setDisplayName("NoTargetNameSpace"); + } + } + + public String getHtmlDisplayName() { + String name = getDisplayName(); + return name; + } + + public String getNamespace() { + // Our name is our namespace. + return getName(); + } + + } + +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/SchemaImportGUI.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/SchemaImportGUI.form Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,71 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/SchemaImportGUI.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/SchemaImportGUI.java Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,654 @@ +/* + * 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.modules.xml.wizard.impl; + + +import java.awt.BorderLayout; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Iterator; +import javax.swing.DefaultComboBoxModel; +import org.openide.explorer.ExplorerManager; +import org.openide.explorer.view.TreeTableView; +import javax.swing.tree.TreeSelectionModel; +import org.openide.filesystems.FileObject; +import org.openide.loaders.DataObject; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.nodes.PropertySupport; +import java.lang.reflect.InvocationTargetException; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.openide.loaders.TemplateWizard; +import org.openide.loaders.DataFolder; +import org.netbeans.api.project.FileOwnerQuery; +import org.netbeans.api.project.Project; +import org.netbeans.spi.project.SubprojectProvider; +import org.netbeans.spi.project.ui.LogicalViewProvider; +import java.util.Set; +import javax.swing.JPanel; +import javax.swing.tree.TreePath; +import org.netbeans.modules.xml.util.Util; +import org.openide.explorer.view.Visualizer; +import org.openide.util.NbBundle; + + + +/** + * This panel gathers data that are necessary for instantiting of XML + * document conforming to given XML Schema. + *

+ * Data allows to create a document that respect restrictions of current parser + * implementations (they use schemaLocation hint specifically). + * + * @author Petr Kuzel + */ +public class SchemaImportGUI extends JPanel implements ExplorerManager.Provider, PropertyChangeListener{ + /** Serial Version UID */ + private static final long serialVersionUID = -7568909683682244030L; + private transient ExplorerManager explorerManager; + private TemplateWizard templateWizard; + private ExternalReferenceDecorator decorator; + /** Map of registered nodes, keyed by their representative DataObject. */ + private Map registeredNodes; + private FileObject primarySchema=null; + private boolean first= false; + private boolean removeFlag=false; + + /** Creates new form SchemaPanel */ + public SchemaImportGUI(TemplateWizard tw) { + initComponents(); + initAccessibility(); + this.templateWizard = tw; + registeredNodes = new HashMap(); + decorator = new ExternalReferenceDecorator(this); + // View for selecting an external reference. + TreeTableView locationView = new LocationView(); + locationView.setDefaultActionAllowed(false); + locationView.setPopupAllowed(false); + locationView.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); + locationView.setRootVisible(false); + locationView.getAccessibleContext().setAccessibleName(locationLabel.getToolTipText()); + locationView.getAccessibleContext().setAccessibleDescription(locationLabel.getToolTipText()); + Node.Property[] columns = new Node.Property[] { + new Column(ExternalReferenceDataNode.PROP_NAME, String.class, true), + new ImportColumn(referenceTypeName()), + //new Column(ExternalReferenceDataNode.PROP_PREFIX, String.class, false), + }; + locationView.setProperties(columns); + locationView.setTreePreferredWidth(200); + locationView.setTableColumnPreferredWidth(0, 25); +// locationView.setTableColumnPreferredWidth(1, 25); + locationPanel.add(locationView, BorderLayout.CENTER); + explorerManager = new ExplorerManager(); + explorerManager.addPropertyChangeListener(this); + explorerManager.setRootContext(createRootNode()); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + locationPanel = new javax.swing.JPanel(); + locationLabel = new javax.swing.JLabel(); + + setName(Util.THIS.getString(SchemaImportGUI.class, "PROP_schema_panel_name")); // NOI18N + + locationPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); + locationPanel.setLayout(new java.awt.BorderLayout()); + + locationLabel.setLabelFor(locationPanel); + locationLabel.setText(org.openide.util.NbBundle.getMessage(SchemaImportGUI.class, "LBL_SchemaPanel_Location")); // NOI18N + locationLabel.setToolTipText(org.openide.util.NbBundle.getMessage(SchemaImportGUI.class, "TIP_SchemaPanel_Location")); // NOI18N + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) + .add(org.jdesktop.layout.GroupLayout.LEADING, locationLabel) + .add(locationPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 545, Short.MAX_VALUE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(locationLabel) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(locationPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 247, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + +private void primarySchemaCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_primarySchemaCheckBoxActionPerformed + // fireChange(); + +}//GEN-LAST:event_primarySchemaCheckBoxActionPerformed + + private void initAccessibility() { + + // memonics + Util util = Util.THIS; + locationLabel.setDisplayedMnemonic(util.getChar( + SchemaImportGUI.class, "PROP_schema_locationLabel_mne")); + + } + + protected class Column extends PropertySupport.ReadOnly { + /** The keyword for this column. */ + private String key; + + /** + * Constructs a new instance of Column. + * + * @param key keyword for this column. + * @param type type of the property (e.g. String.class). + * @param tree true if this is the 'tree' column. + */ + public Column(String key, Class type, boolean tree) { + super(key, type, NbBundle.getMessage(Column.class, + "CTL_SchemaPanel_Column_Name_" + key), + NbBundle.getMessage(Column.class, + "CTL_SchemaPanel_Column_Desc_" + key)); + this.key = key; + setValue("TreeColumnTTV", Boolean.valueOf(tree)); + } + + public Object getValue() + throws IllegalAccessException, InvocationTargetException { + return key; + } + } + + protected class ImportColumn extends PropertySupport.ReadOnly { + /** The keyword for this column. */ + private String key; + + /** + * Creates a new instance of ImportColumn. + * + * @param name the column's name. + */ + public ImportColumn(String name) { + super("selected", Boolean.TYPE, name,NbBundle.getMessage(Column.class, + "CTL_SchemaPanel_Column_Desc_selected")); + this.key = "selected"; + setValue("TreeColumnTTV", Boolean.FALSE); + } + + public Object getValue() + throws IllegalAccessException, InvocationTargetException { + return key; + } + } + + protected Node createRootNode() { + try { + DataFolder folder = templateWizard.getTargetFolder(); + Project project = FileOwnerQuery.getOwner(folder.getPrimaryFile()); + SubprojectProvider provider = (SubprojectProvider)project.getLookup().lookup(SubprojectProvider.class); + Set refProjects= provider.getSubprojects(); + Iterator it = refProjects.iterator(); + + Node[] rootNodes = new Node[1 + (refProjects == null ? 0 : refProjects.size())]; + LogicalViewProvider viewProvider = (LogicalViewProvider) project.getLookup().lookup(LogicalViewProvider.class); + rootNodes[0] = decorator.createExternalReferenceNode(viewProvider.createLogicalView()); + int rootIndex = 1; + + java.util.List projectRoots = new java.util.ArrayList(); + projectRoots.add(project.getProjectDirectory()); + if (refProjects != null) { + while(it.hasNext()){ + // for (Object o : refProjects) { + Object o = it.next(); + Project refPrj = (Project) o; + viewProvider = (LogicalViewProvider) refPrj.getLookup(). + lookup(LogicalViewProvider.class); + rootNodes[rootIndex++] = decorator.createExternalReferenceNode(viewProvider.createLogicalView()); + projectRoots.add(refPrj.getProjectDirectory()); + } + } + FileObject[] roots = (FileObject[])projectRoots.toArray(new FileObject[projectRoots.size()]); + Children fileChildren = new Children.Array(); + fileChildren.add(rootNodes); + Node byFilesNode = new FolderNode(fileChildren); + byFilesNode.setDisplayName(NbBundle.getMessage( + SchemaImportGUI.class, + "LBL_SchemaPanel_Category_By_File")); + + // Construct the By Namespace node. + Children nsChildren = new NamespaceChildren(roots, decorator); + Node byNsNode = new FolderNode(nsChildren); + byNsNode.setDisplayName(NbBundle.getMessage( + SchemaImportGUI.class, + "LBL_SchemaPanel_Category_By_Namespace")); + Children categories = new Children.Array(); + categories.add(new Node[] { byFilesNode, byNsNode }); + Node rootNode = new AbstractNode(categories); + // Surprisingly, this becomes the name and description of the first column. + rootNode.setDisplayName(NbBundle.getMessage(SchemaImportGUI.class, + "CTL_SchemaPanel_Column_Name_name")); + rootNode.setShortDescription(NbBundle.getMessage(SchemaImportGUI.class, + "CTL_SchemaPanel_Column_Desc_name")); + return rootNode; + } catch(Exception e){ + e.printStackTrace(); + } + return null; + } + + public ExplorerManager getExplorerManager() { + return explorerManager; + } + + + public ExternalReferenceDataNode createExternalReferenceNode(Node original) { + DataObject dobj = (DataObject) original.getLookup().lookup(DataObject.class); + NodeSet set = (NodeSet)registeredNodes.get(dobj); + if (set == null) { + set = new NodeSet(this); + registeredNodes.put(dobj, set); + } + ExternalReferenceDataNode erdn = new ExternalReferenceDataNode(original, decorator); + set.add(erdn); + if (set.isSelected() && erdn.canSelect()) { + erdn.setSelected(true); + } + erdn.addPropertyChangeListener(this); + return erdn; + } + + /** + * Manages the state of a set of nodes. + */ + private static class NodeSet { + /** The property change listener for each node. */ + private PropertyChangeListener listener; + /** Nodes in this set. */ + private List nodes; + /** True if this set is selected, false otherwise. */ + private boolean selected; + + /** + * Creates a new instance of NodeSet. + * + * @param listener listens to the Node. + */ + public NodeSet(PropertyChangeListener listener) { + this.listener = listener; + } + + /** + * Add the given node to this set. + * + * @param node node to be added to set. + */ + public void add(ExternalReferenceDataNode node) { + if (nodes == null) { + nodes = new LinkedList(); + } + nodes.add(node); + } + + /** + * Returns the list of nodes in this set. + * + * @return list of nodes. + */ + public List getNodes() { + return nodes; + } + + /** + * Indicates if this set is selected or not. + * + * @return true if selected, false otherwise. + */ + public boolean isSelected() { + return selected; + } + + /** + * Set the prefix for Nodes in this group. + * + * @param prefix new namespace prefix. + */ + public void setPrefix(String prefix) { + for(int i=0; i 0 && nodes[0] instanceof ExternalReferenceDataNode) { + ExternalReferenceDataNode node = (ExternalReferenceDataNode) nodes[0]; + validateInput(node); + } + } else if (pname.equals(ExternalReferenceDataNode.PROP_PREFIX)) { + ExternalReferenceDataNode erdn = (ExternalReferenceDataNode) event.getSource(); + // Look up the node in the map of sets, and ensure they all + // have the same prefix. + String prefix = (String) event.getNewValue(); + DataObject dobj = (DataObject) erdn.getLookup().lookup(DataObject.class); + NodeSet set = (NodeSet)registeredNodes.get(dobj); + // Ideally the set should already exist, but cope gracefully. + assert set != null : "node not created by customizer"; + if (set == null) { + set = new NodeSet(this); + set.add(erdn); + } + set.setPrefix(prefix); + validateInput(erdn); + } else if (pname.equals(ExternalReferenceDataNode.PROP_SELECTED)) { + ExternalReferenceDataNode erdn = (ExternalReferenceDataNode) event.getSource(); + // Look up the node in the map of sets, and ensure they are all + // selected as a unit. + boolean selected = ((Boolean) event.getNewValue()).booleanValue(); + DataObject dobj = (DataObject) erdn.getLookup().lookup(DataObject.class); + NodeSet set = (NodeSet)registeredNodes.get(dobj); + // Ideally the set should already exist, but cope gracefully. + assert set != null : "node not created by customizer"; + if (set == null) { + set = new NodeSet(this); + set.add(erdn); + } + set.setSelected(selected); + //setPrimarySchema(erdn, selected, false); + // Check if the current selection is valid. + validateInput(erdn); + } + } + + /** + * Determine if the user's input is valid or not. This will enable + * or disable the save/reset controls based on the results, as well + * as issue error messages. + * + * @param node selected node. + */ + private void validateInput(ExternalReferenceDataNode erdn) { + String msg = null; + String ep = erdn.getPrefix(); + // Must be a non-empty prefix, that is not already in use, and + // is unique among the selected nodes (and be selected itself). + if (ep.length() == 0 || (!isValidPrefix(erdn) && erdn.isSelected())) { + msg = NbBundle.getMessage(SchemaImportGUI.class, "LBL_SchemaPanel_InvalidPrefix"); + } + + + int selected = countSelectedNodes(); + if(selected < 0 ) + msg = "ERROR MSG"; + // Must have selected nodes, and no error messages. + //setSaveEnabled((allowEmptySelection() || selected > 0) ); + } + + /** + * Check if prefix is unique on UI. + * + * @return true if Prefix is not unique on UI, false otherwise. + */ + private boolean isValidPrefix(ExternalReferenceDataNode node) { + DataObject dobj = (DataObject) node.getLookup().lookup(DataObject.class); + NodeSet nodeSet = (NodeSet)registeredNodes.get(dobj); + Collection sets = registeredNodes.values(); + Iterator it = sets.iterator(); + while(it.hasNext()) { + // Ignore the set which contains the given node, and those + // sets which are not selected. + NodeSet set = (NodeSet)it.next(); + if (!set.equals(nodeSet) && set.isSelected()) { + // Only need to check the first node, as all of them have + // the same prefix (or at least that is the idea). + ExternalReferenceDataNode other = (ExternalReferenceDataNode)set.getNodes().get(0); + if (node.getPrefix().equals(other.getPrefix())) { + return false; + } + } + } + return true; + } + + + /** + * Determine the number of nodes that the user selected, useful for + * knowing if any nodes are selected or not. + * + * @return number of selected nodes. + */ + public int countSelectedNodes() { + int results = 0; + Collection sets = registeredNodes.values(); + Iterator it = sets.iterator(); + while(it.hasNext()){ + NodeSet set = (NodeSet)it.next(); + List nodes = set.getNodes(); + if (nodes.size() > 0) { + results++; + } + } + + return results; + } + + + /** + * A TreeTableView that toggles the selection of the external reference + * data nodes using a single mouse click. + */ + private class LocationView extends TreeTableView { + /** silence compiler warnings */ + private static final long serialVersionUID = 1L; + + /** + * Creates a new instance of LocationView. + */ + public LocationView() { + super(); + tree.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + // Invert the selection of the data node, if such a + // node was clicked on. + TreePath path = tree.getPathForLocation(e.getX(), e.getY()); + if (path != null) { + Object comp = path.getLastPathComponent(); + Node node = Visualizer.findNode(comp); + if (node instanceof ExternalReferenceDataNode) { + ExternalReferenceDataNode erdn = + (ExternalReferenceDataNode) node; + if (erdn.canSelect()) { + boolean selected = !erdn.isSelected(); + erdn.setSelected(selected); + //setPrimarySchema(erdn, selected, true); + + } + } + } + } + }); + } + } + + + public boolean isPrimarySchemaSelected() { + if(rootModel.getSize() == 0) + return false; + else + return true; + } + + /** + * Retrieve the list of nodes that the user selected. + * + * @return list of selected nodes (empty if none). + */ + protected List getSelectedNodes() { + List results = new LinkedList(); + Collection sets = registeredNodes.values(); + Iterator it = sets.iterator(); + while(it.hasNext()){ + NodeSet set = (NodeSet)it.next(); + if (set.isSelected()) { + List nodes = set.getNodes(); + if (nodes.size() > 0) { + // Use just one of the corresponding nodes, as the + // others are basically duplicates. + results.add(nodes.get(0)); + } + } + } + return results; + } + + /* private void setPrimarySchema(ExternalReferenceDataNode erdn, boolean selected, boolean fromTreeView) { + String ns = null; + DataObject dobj = (DataObject) erdn.getLookup().lookup(DataObject.class); + FileObject fobj = dobj.getPrimaryFile(); + + //if the schema was selected by clicking in the import column, then we dont need to set this + if(fromTreeView) { + erdn.setSelected(selected); + return; + } + + if (selected) { + // Have to collect the namespace value + // when the node is selected. + if(!fobj.isFolder()) { + ns= erdn.getNamespace(); + String key = fobj.getNameExt() + " (" + ns + ")" ; + removeFlag=false; + namespaceModel.addElement(new SchemaComboItem(key, fobj)); + } + } else { + if(!fobj.isFolder()) { + ns=erdn.getNamespace(); + String key=fobj.getNameExt() + " (" + ns + ")"; + for(int i = 0 ; i + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/SchemaPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/SchemaPanel.java Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,776 @@ +/* + * 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.modules.xml.wizard.impl; + +import org.netbeans.modules.xml.wizard.SchemaParser; +import org.netbeans.modules.xml.wizard.*; +import java.awt.Component; + +import java.awt.Color; +import java.awt.Dialog; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.net.*; +import java.io.*; +import java.util.Iterator; +import javax.swing.DefaultComboBoxModel; +import org.openide.filesystems.FileObject; +import org.openide.loaders.DataObject; +import java.util.ArrayList; +import java.util.List; +import org.openide.loaders.TemplateWizard; +import java.util.Vector; +import javax.swing.AbstractCellEditor; +import javax.swing.JComboBox; +import javax.swing.JRadioButton; +import javax.swing.JTable; +import javax.swing.SwingUtilities; +import javax.swing.event.TableModelEvent; +import javax.swing.event.TableModelListener; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableCellRenderer; +import javax.swing.table.TableCellEditor; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; +import org.netbeans.modules.xml.util.Util; +import org.openide.DialogDescriptor; +import org.openide.DialogDisplayer; +import org.openide.WizardDescriptor; +import org.openide.util.NbBundle; + + + +/** + * This panel gathers data that are necessary for instantiting of XML + * document conforming to given XML Schema. + *

+ * Data allows to create a document that respect restrictions of current parser + * implementations (they use schemaLocation hint specifically). + * + * @author Petr Kuzel + */ +public class SchemaPanel extends AbstractPanel implements ActionListener, TableModelListener { + /** Serial Version UID */ + private static final long serialVersionUID = -7568909683682244030L; + private TemplateWizard templateWizard; + private FileObject primarySchema=null; + private Vector rows; + private final static int PRIMARY_COL = 0; + private final static int SCHEMA_COL = 1; + private final static int ROOT_COL = 2; + private final static int PREFIX_COL = 3; + private SchemaTableModel tableModel; + private SchemaImportGUI gui; + private static String startString; + /** Prefix for the namespace prefix values (e.g. "ns"). */ + private static final String PREFIX = "ns"; // NOI18N + /** Hashmap to keep track of prefixes */ + private List prefixMap = new ArrayList(); + + + /** Creates new form SchemaPanel */ + public SchemaPanel(TemplateWizard tw) { + this.templateWizard = tw; + rows = new Vector(); + tableModel = new SchemaTableModel(); + initComponents(); + initAccessibility(); + initComp(); + + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // //GEN-BEGIN:initComponents + private void initComponents() { + + locationPanel = new javax.swing.JPanel(); + jScrollPane1 = new javax.swing.JScrollPane(); + schemaTable = new javax.swing.JTable(); + locationLabel = new javax.swing.JLabel(); + browseButton = new javax.swing.JButton(); + browseButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + browseButtonActionPerformed(evt); + } + }); + removeButton = new javax.swing.JButton(); + + setName(Util.THIS.getString(SchemaPanel.class, "PROP_schema_panel_name")); // NOI18N + + locationPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder()); + locationPanel.setLayout(new java.awt.BorderLayout()); + + schemaTable.setModel(tableModel); + jScrollPane1.setViewportView(schemaTable); + schemaTable.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "LBL_Schema_table")); // NOI18N + schemaTable.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "LBL_Schema_table")); // NOI18N + + locationPanel.add(jScrollPane1, java.awt.BorderLayout.CENTER); + + locationLabel.setLabelFor(locationPanel); + locationLabel.setText(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "LBL_SchemaPanel_Location")); // NOI18N + locationLabel.setToolTipText(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "TIP_SchemaPanel_Location")); // NOI18N + + browseButton.setText(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "LBL_BrowseButton")); // NOI18N + + removeButton.setText(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "LBL_RemoveButton")); // NOI18N + removeButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + removeButtonActionPerformed(evt); + } + }); + + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(locationPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 582, Short.MAX_VALUE) + .add(locationLabel) + .add(layout.createSequentialGroup() + .add(browseButton) + .add(18, 18, 18) + .add(removeButton))) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(layout.createSequentialGroup() + .addContainerGap() + .add(locationLabel) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(locationPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 268, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(browseButton) + .add(removeButton)) + .addContainerGap(82, Short.MAX_VALUE)) + ); + + browseButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "LBL_BrowseButton")); // NOI18N + removeButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "LBL_RemoveButton")); // NOI18N + + getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "PROP_schema_panel_name")); // NOI18N + getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(SchemaPanel.class, "PROP_schema_panel_name")); // NOI18N + }// //GEN-END:initComponents + + private boolean isDuplicate(String schemaFileName) { + if(rows.size() == 1) + return false; + for(int i=0 ; i < rows.size(); i++ ){ + List rowData = (List)rows.get(i); + SchemaObject obj = (SchemaObject)rowData.get(SCHEMA_COL); + if(obj.toString().equals(startString)) + continue; + if(obj.getSchemaFileName().equals(schemaFileName)) + return true; + } + return false; + } + +private void primarySchemaCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_primarySchemaCheckBoxActionPerformed + // fireChange(); + +}//GEN-LAST:event_primarySchemaCheckBoxActionPerformed + +private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed + int row = schemaTable.getSelectedRow(); + //System.out.println("delete row = " + row); + deleteRow(row); +}//GEN-LAST:event_removeButtonActionPerformed + + private void browseButtonActionPerformed(ActionEvent evt){ + gui = new SchemaImportGUI(templateWizard); + final DialogDescriptor descriptor = new DialogDescriptor(gui, + NbBundle.getMessage(SchemaPanel.class,"LBL_Browser"), + true, this); + Dialog dlg = DialogDisplayer.getDefault().createDialog(descriptor); + dlg.getAccessibleContext().setAccessibleDescription("DSC_Browser"); + dlg.setVisible(true); + } + private void initAccessibility() { + + // memonics + Util util = Util.THIS; + locationLabel.setDisplayedMnemonic(util.getChar( + SchemaPanel.class, "PROP_schema_locationLabel_mne")); + browseButton.setMnemonic(util.getChar( + SchemaPanel.class, "LBL_BrowseButton_mme")); + removeButton.setMnemonic(util.getChar( + SchemaPanel.class, "LBL_RemoveButton_mne")); + + } + + /** + * Update namespace and root combo models. + */ + private void updatePossibilities() { + } + + /** User just entered the panel, init view by model values + */ + protected void initView() { + + } + + /** User just leaved the panel, update model + */ + protected void updateModel() { + int numRows = tableModel.getRowCount(); + int numCols = tableModel.getColumnCount(); + String uri = null; + List schemaFiles = new ArrayList(); + for (int i=0; i < numRows; i++) { + List rowData = (List)rows.get(i); + boolean primary= ((Boolean)rowData.get(PRIMARY_COL)).booleanValue(); + String prefix = (String)rowData.get(PREFIX_COL); + SchemaObject obj = (SchemaObject)rowData.get(SCHEMA_COL); + if(obj.toString().equals(startString)) + continue; + //set the prefix since this is the most updated prefix + obj.setPrefix(prefix); + String root = (String)rowData.get(ROOT_COL); + if(primary) { + model.setPrimarySchema(obj.toString()); + model.setNamespace(obj.getNamespace()); + model.setPrefix(prefix); + model.setRoot(root); + File file = new File(obj.toString()); + uri = file.getName(); + if (uri != null) { + // we need to escape spaces, URI does not like them + uri = uri.replaceAll(" ", "%20"); // NOI18N + try { + // escape the non-ASCII characters + uri = new URI(uri).toASCIIString(); + } catch (URISyntaxException e) { + // the specified uri is not valid, it is too late to fix it now + } + } + model.setSystemID(uri == null || uri.length() == 0 ? null : uri); + } + schemaFiles.add(obj); + } + model.setSchemaNodes(schemaFiles); + + } + + /** User just reentered the panel. + */ + protected void updateView() { + } + + private String getStartString() { + return NbBundle.getMessage(SchemaPanel.class, "LBL_TABLE_SCHEMA_PROMPT"); + } + + private void tableKeyPressed(KeyEvent evt) { + if( evt.getKeyCode()==KeyEvent.VK_DELETE ){ + int row = schemaTable.getSelectedRow(); + // System.out.println("delete row = " + row); + deleteRow(row); + } + } + + private void deleteRow(int index) { + if(index!=-1){ + SchemaObject val = (SchemaObject)tableModel.getValueAt(index, SCHEMA_COL); + if(val.toString().equals(startString)) + return; + rows.remove(index); + schemaTable.addNotify(); + fireChange(); + } + + } + + + + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton browseButton; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JLabel locationLabel; + private javax.swing.JPanel locationPanel; + private javax.swing.JButton removeButton; + private javax.swing.JTable schemaTable; + // End of variables declaration//GEN-END:variables + + public void actionPerformed(ActionEvent evt) { + if (evt.getSource().equals(DialogDescriptor.OK_OPTION)) { + List nodes = gui.getSelectedNodes(); + if(nodes != null){ + String noRoot = NbBundle.getMessage(SchemaPanel.class, "LBL_No_Root_Elements"); + for(int i=0;i < nodes.size(); i++ ){ + List row = new ArrayList(); + ExternalReferenceDataNode erdn = (ExternalReferenceDataNode)nodes.get(i); + DataObject dobj = (DataObject) erdn.getLookup().lookup(DataObject.class); + if(isDuplicate(erdn.getSchemaFileName())) + continue; + FileObject fobj = dobj.getPrimaryFile(); + SchemaObject obj = new SchemaObject(erdn.getSchemaFileName()); + obj.setNamespace(erdn.getNamespace()); + obj.setSchemaFileName(erdn.getSchemaFileName()); + + row.add(false); + row.add(obj); + + SchemaParser.SchemaInfo info = SchemaParser.getRootElements(fobj); + if (info != null && info.roots.size() > 0) { + Iterator it = info.roots.iterator(); + String[] rootElements = new String[(info.roots.size())]; + info.roots.toArray(rootElements); + obj.setRootElements(rootElements); + row.add(rootElements[0]); + } else { + //we have to add some dummy element since there are no roots + row.add(noRoot); + } + + String pre = generateUniquePrefix(); + obj.setPrefix(pre); + //keep track of unique prefixes + addPrefix(pre); + row.add(pre); + tableModel.addRow(0,row); + } + schemaTable.addNotify(); + } + } else if(evt.getSource().equals(DialogDescriptor.CANCEL_OPTION)){ + gui.setVisible(false); + } + } + + private List createBlankElement(String val) { + List t = new ArrayList(); + t.add(new Boolean(false)); + t.add(new SchemaObject(val)); + t.add((String) " "); + t.add((String) " "); + return t; + } + + private void addRow(String val) { + List r=createBlankElement(val); + tableModel.addRow(r); + schemaTable.addNotify(); + + } + + private void initComp() { + schemaTable.getModel().addTableModelListener(this); + schemaTable.getTableHeader().setReorderingAllowed( false ); + startString = getStartString(); + + //set key listener to delete rows when user presses del key + schemaTable.addKeyListener(new KeyAdapter() { + public void keyPressed(KeyEvent evt) { + tableKeyPressed(evt); + } + }); + //add the initial row + addRow(startString); + + //set width + TableColumn column = null; + for (int i = 0; i < 4; i++) { + column = schemaTable.getColumnModel().getColumn(i); + if (i == PRIMARY_COL) { + column.setPreferredWidth(40); + } else if(i ==SCHEMA_COL) { + column.setPreferredWidth(250); + } else { + column.setPreferredWidth(80); + } + } + + //set renderer and editor for the first column + schemaTable.getColumnModel().getColumn(PRIMARY_COL).setCellRenderer(new RadioColumnRenderer()); + schemaTable.getColumnModel().getColumn(PRIMARY_COL).setCellEditor(new RadioColumnEditor()); + + //set up rendere/editor for the combo box column + TableColumn rootColumn = schemaTable.getColumnModel().getColumn(ROOT_COL); + rootColumn.setCellEditor(new ComboBoxColumnEditor()); + DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); + renderer.setToolTipText(NbBundle.getMessage(SchemaPanel.class, "TIP_COMBO_COL")); + rootColumn.setCellRenderer(renderer); + + int height = schemaTable.getRowHeight(); + + // Determine highest cell in the row + for (int c=0; c= getRowCount() || col >= getColumnCount()) + return; + if(value == null) + return; + + List rowVector = (List)rows.elementAt(row); + + if (col == PRIMARY_COL && ((Boolean)value).booleanValue() ) { + //only those schemas can be set as primary that have root elements + SchemaObject obj = (SchemaObject)getValueAt(row, SCHEMA_COL); + if(obj.getRootElements() == null || obj.getRootElements().length == 0) { + String errMsg = org.openide.util.NbBundle.getMessage(SchemaPanel.class, "MSG_SchemaPanel_Incorrect_Primary"); + templateWizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, errMsg); + return; + } else + templateWizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, ""); + + for (int i = 0; i < getRowCount(); i++) { + if (i != row) { + setValueAt(new Boolean(false), i, 0); + } + } + rowVector.set(col, value); + + } else if(col == SCHEMA_COL){ + String systemId = (String)value; + + //if the value being set is the same as start string, ignore + //if the value is not a url, ignore + if(systemId.equals(startString)) + return; + try { + File file = new File(systemId); + if( !file.exists() ) { + if( !systemId.startsWith("http") ) + return; + } + URL context = model.getTargetFolderURL(); + if (context != null) { + systemId = new URL(context, systemId).toExternalForm(); + } + } catch (MalformedURLException ex) { + return; + } + + //create a schema object + + SchemaParser parser = new SchemaParser(); + SchemaParser.SchemaInfo info = parser.parse(systemId); + SchemaObject obj = new SchemaObject ((String)value); + if (info.namespace != null) { + obj.setNamespace(info.namespace); + } + if (info != null && info.roots.size() > 0) { + Iterator it = info.roots.iterator(); + String[] rootElements = new String[(info.roots.size())]; + info.roots.toArray(rootElements); + obj.setRootElements(rootElements); + rowVector.set(ROOT_COL, rootElements[0]); + } + obj.setSchemaFileName((String)value); + rowVector.set(col, obj); + + + } else if (col == PREFIX_COL) { + String prefix = (String)value; + if(prefix.trim().length() ==0 ) + return; + if(verifyUniquePrefix( prefix) ) { + addPrefix(prefix); + rowVector.set(col, value); + } + } else { + rowVector.set(col, value); + } + templateWizard.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, ""); + fireChange(); + fireTableCellUpdated(row, col); + } + + private void addRow(List r) { + rows.add(r); + } + + private void addRow(int i, List row) { + rows.add(i, row); + } + + private void printDebugData() { + int numRows = getRowCount(); + int numCols = getColumnCount(); + + for (int i=0; i < numRows; i++) { + System.out.print(" row " + i + ":"); + for (int j=0; j < numCols; j++) { + // System.out.print(" " + data[i][j]); + } + System.out.println(); + } + System.out.println("--------------------------"); + } + + } + + class RadioColumnEditor extends AbstractCellEditor implements TableCellEditor { + // protected EventListenerList listenerList = new EventListenerList(); + // protected ChangeEvent changeEvent = new ChangeEvent(this); + private JRadioButton theRadioButton; + + public RadioColumnEditor() { + super(); + theRadioButton = new JRadioButton(); + theRadioButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + fireEditingStopped(); + } + }); + } + public Component getTableCellEditorComponent(JTable table, Object obj, boolean isSelected, int row, int col) { + theRadioButton.setHorizontalAlignment(SwingUtilities.CENTER); + if(obj != null){ + Boolean lValueAsBoolean = (Boolean)obj; + theRadioButton.setSelected(lValueAsBoolean.booleanValue()); + } + return theRadioButton; + } + + public Object getCellEditorValue() { + return new Boolean(theRadioButton.isSelected()); + } + } + + class RadioColumnRenderer extends JRadioButton implements TableCellRenderer { + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + this.setBackground(Color.WHITE); + if (value == null){ + this.setSelected(false); + } else{ + Boolean ValueAsBoolean = (Boolean)value; + this.setSelected(ValueAsBoolean.booleanValue()); + } + this.setHorizontalAlignment(SwingUtilities.CENTER); + setToolTipText(NbBundle.getMessage(SchemaPanel.class, "TIP_PREFIX_COL")); + return this; + } + } + + class ComboBoxColumnEditor extends AbstractCellEditor implements TableCellEditor { + private JComboBox comboBox; + + public ComboBoxColumnEditor() { + super(); + } + public Component getTableCellEditorComponent(JTable table, Object obj, boolean isSelected, int row, int col) { + comboBox = new JComboBox(); + comboBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent event) { + fireEditingStopped(); + } + }); + DefaultComboBoxModel rootModel = new DefaultComboBoxModel(); + SchemaObject o = (SchemaObject)table.getModel().getValueAt(row, SCHEMA_COL); + + if( !(o.toString().equals(startString))) { + String[] root = o.getRootElements(); + if(root != null && root.length >0) { + for(int i=0; i < root.length; i++) + rootModel.addElement(root[i]); + } + } + comboBox.setModel(rootModel); + return comboBox; + } + + public Object getCellEditorValue() { + return comboBox.getModel().getSelectedItem(); + //return new Boolean(theRadioButton.isSelected()); + } + + + } + + +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/WaitNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/WaitNode.java Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,88 @@ +/* + * 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-2007 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.modules.xml.wizard.impl; + +import java.util.Collection; +import java.util.Collections; +import org.openide.nodes.AbstractNode; +import org.openide.nodes.Children; +import org.openide.nodes.Node; +import org.openide.util.NbBundle; + +/** + * A placeholder node that displays a "please wait" message while the + * task to generate the final node is performed. + * + * @author Nathan Fiedler + */ +public class WaitNode extends AbstractNode { + /** A child key for this node, to be used with Children.Key.setKeys(). */ + public static final Object WAIT_KEY = new Object(); + + /** + * Creates a new instance of WaitNode. + */ + public WaitNode() { + super(Children.LEAF); + setName(NbBundle.getMessage(WaitNode.class, "LBL_WaitNode_Wait")); + setIconBaseWithExtension("org/netbeans/modules/xml/xam/ui/resources/wait.gif"); + } + + /** + * Convenience method that creates an array with a single WaitNode. + * + * @return array with a WaitNode. + */ + public static Node[] createNode() { + return new Node[] { new WaitNode() }; + } + + /** + * Convenience method that creates a collection with a single child key + * entry, that being the WAIT_KEY value. + * + * @return collection with WAIT_KEY. + */ + public static Collection getKeys() { + return Collections.singletonList(WaitNode.WAIT_KEY); + } +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/XMLWizardIterator.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xml/src/org/netbeans/modules/xml/wizard/impl/XMLWizardIterator.java Tue Sep 23 16:17:23 2008 -0500 @@ -0,0 +1,719 @@ +/* + * 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.modules.xml.wizard.impl; + +import org.netbeans.modules.xml.wizard.*; +import java.io.OutputStream; +import java.io.BufferedOutputStream; +import java.io.Writer; +import java.io.OutputStreamWriter; +import java.util.HashSet; +import java.util.Map; +import java.util.HashMap; +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeEvent; +import java.io.File; +import java.util.Set; +import java.io.IOException; +import java.lang.ref.Reference; +import java.lang.ref.WeakReference; +import java.net.URI; +import java.net.URL; +import java.text.DateFormat; +import java.util.Date; +import java.util.List; + +import javax.swing.event.ChangeListener; +import javax.swing.event.ChangeEvent; +import javax.swing.JComponent; +import org.netbeans.api.project.Project; +import org.netbeans.editor.BaseDocument; +import org.netbeans.modules.xml.api.EncodingUtil; + +import org.netbeans.modules.xml.lib.GuiUtil; +import org.netbeans.modules.xml.util.Util; +import org.netbeans.modules.xml.retriever.RetrieveEntry; +import org.netbeans.modules.xml.retriever.RetrieverEngine; +import org.netbeans.modules.xml.retriever.catalog.Utilities; +import org.netbeans.modules.xml.retriever.catalog.Utilities.DocumentTypesEnum; + +import org.netbeans.modules.xml.text.TextEditorSupport; +import org.netbeans.spi.project.CacheDirectoryProvider; +import org.netbeans.spi.project.ui.templates.support.Templates; +import org.openide.loaders.TemplateWizard; +import org.openide.WizardDescriptor; +import org.openide.cookies.EditCookie; +import org.openide.cookies.EditorCookie; +import org.openide.loaders.DataFolder; +import org.openide.filesystems.FileSystem; +import org.openide.filesystems.FileObject; +import org.openide.loaders.DataObject; +import org.openide.filesystems.FileLock; +import org.openide.filesystems.FileUtil; +import org.openide.util.NbBundle; + + + +/** + * Controls new XML Docuemnt wizard. It is kind of dynamic wizard with + * multiple way of diferent length. + * + * @author Petr Kuzel + */ +public class XMLWizardIterator implements TemplateWizard.Iterator { + /** Serial Version UID */ + private static final long serialVersionUID = 5070430920636117204L; + + + private static final String XML_EXT = "xml"; // NOI18N + + // parent wizard + + private transient TemplateWizard templateWizard; + + // model collecting our data + + private transient DocumentModel model; + + // panels + + private transient int current; + + private static final int TARGET_PANEL = 0; + private transient WizardDescriptor.Panel targetPanel; + + private static final int DOCUMENT_PANEL = 1; + private transient DocumentPanel documentPanel; + + private static final int CONSTRAINT_PANEL = 2; + private transient SchemaPanel schemaPanel; + private transient DTDPanel dtdPanel; + + private static final int CONTENT_PANEL = 3; + private transient XMLContentPanel xmlPanel; + + /** Singleton instance of JavaWizardIterator, should it be ever needed. + */ + private static Reference instance; + + private transient Map listenersMap = new HashMap(2); + private transient String[] beforeSteps; + private transient Object targetSteps; + + + /** Returns JavaWizardIterator singleton instance. This method is used + * for constructing the instance from filesystem.attributes. + */ + public static synchronized XMLWizardIterator singleton() { + XMLWizardIterator it = instance == null ? null : instance.get(); + if (it == null) { + it = new XMLWizardIterator(); + instance = new WeakReference(it); + } + return it; + } + + public void initialize(TemplateWizard templateWizard) { + this.templateWizard = templateWizard; + current = TARGET_PANEL; + URL targetFolderURL = null; + try { + DataFolder folder = templateWizard.getTargetFolder(); + targetFolderURL = folder.getPrimaryFile().getURL(); + //#25604 workaround + if (targetFolderURL.toExternalForm().endsWith("/") == false) { + targetFolderURL = new URL(targetFolderURL.toExternalForm() + "/"); + } + } catch (IOException ignore) { + } + model = new DocumentModel(targetFolderURL); + Object prop = templateWizard.getProperty (WizardDescriptor.PROP_CONTENT_DATA); // NOI18N + if (prop != null && prop instanceof String[]) { + beforeSteps = (String[])prop; + } + } + + public void uninitialize(TemplateWizard templateWizard) { + if (targetPanel!=null) { + ((JComponent)targetPanel.getComponent()).putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, targetSteps); + targetPanel = null; + } + current = -1; + model = null; + templateWizard = null; + schemaPanel = null; + dtdPanel = null; + documentPanel = null; + xmlPanel = null; + } + + public Set instantiate(TemplateWizard templateWizard) throws IOException { + final DataFolder folder = templateWizard.getTargetFolder(); + + final File pobj = FileUtil.toFile(folder.getPrimaryFile()); + + final String extension = XML_EXT; + + // #22812 we do not control validity constrains of target panel + // assure uniquess to "" name + + String targetName = templateWizard.getTargetName(); + if (targetName == null || "null".equals(targetName)) { // NOI18N + targetName = "XMLDocument"; // NOI18N + } + final FileObject targetFolder = folder.getPrimaryFile(); + String uniqueTargetName = targetName; + int i = 2; + + while (targetFolder.getFileObject(uniqueTargetName, extension) != null) { + uniqueTargetName = targetName + i; + i++; + } + + final String name = uniqueTargetName; + String encoding = EncodingUtil.getProjectEncoding(folder.getPrimaryFile()); + if (!EncodingUtil.isValidEncoding(encoding)) + encoding = "UTF-8"; //NOI18N + String nameExt = name + "." + extension; + + // in atomic action create data object and return it + + FileSystem filesystem = targetFolder.getFileSystem(); + final FileObject[] fileObject = new FileObject[1]; + FileSystem.AtomicAction fsAction = new FileSystem.AtomicAction() { + public void run() throws IOException { + // XXX use Freemarker instead of this hardcoded template! + //use the project's encoding if there is one + FileObject fo = targetFolder.createData(name, extension); + fileObject[0] = fo; + + } + }; + + + filesystem.runAtomicAction(fsAction); + + StringBuffer sb = new StringBuffer(); + //write the comment + writeXMLComment(sb, nameExt, encoding); + //write the body + writeXMLFile(sb); + + FileLock lock = null; + try { + lock = fileObject[0].lock(); + OutputStream out = fileObject[0].getOutputStream(lock); + out = new BufferedOutputStream(out, 999); + Writer writer = new OutputStreamWriter(out, encoding); + writer.write(sb.toString()); + writer.flush(); + writer.close(); + lock.releaseLock(); + lock = null; + + } finally { + if (lock != null) { + lock.releaseLock(); + } + } + // perform default action and return + Set set = new HashSet(1); + DataObject createdObject = DataObject.find(fileObject[0]); + GuiUtil.performDefaultAction(createdObject); + set.add(createdObject); + + formatXML(fileObject[0]); + return set; + } + + + public WizardDescriptor.Panel current() { + WizardDescriptor.Panel panel = currentComponent(); + if (panel.getComponent() instanceof JComponent) { + ((JComponent)panel.getComponent()).putClientProperty( + WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, // NOI18N + new Integer(current) + ); + } + return panel; + } + + + private WizardDescriptor.Panel currentComponent() { + switch (current) { + case TARGET_PANEL: + return getTargetPanel(); + case DOCUMENT_PANEL: + return getDocumentPanel(); + case CONSTRAINT_PANEL: + switch (model.getType()) { + case DocumentModel.DTD: + return getDTDPanel(); + case DocumentModel.SCHEMA: + return getSchemaPanel(); + default: + throw new IllegalStateException(); + } + case CONTENT_PANEL: + return getXMLContentPanel(); + default: + throw new IllegalStateException(); + } + } + + public boolean hasNext() { + boolean none = model.getType() == model.NONE; + int length = 0; + if(model.getType() == model.SCHEMA) + length = CONTENT_PANEL; + if(model.getType() == model.NONE) + length = DOCUMENT_PANEL; + else if(model.getType() == model.DTD) + length = CONSTRAINT_PANEL; + // int length = none ? DOCUMENT_PANEL : CONSTRAINT_PANEL; + return current < length; + } + + public boolean hasPrevious() { + return current > TARGET_PANEL; + } + + public String name() { + return NbBundle.getMessage(XMLWizardIterator.class, "TITLE_x_of_y", + Integer.valueOf(current + 1), Integer.valueOf(current)); + } + + public void nextPanel() { + current++; + } + + public void previousPanel() { + current--; + } + + // events source ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + // + // To symplify synchronization use bridge listeners delegating to model + // events. We do not need to sample listeners in sync block and then fire + // changes over the sampled listener copies out-of the sync block. + // + + public void removeChangeListener(ChangeListener changeListener) { + if (changeListener == null) return; + synchronized (listenersMap) { + Object bridge = listenersMap.remove(changeListener); + if (bridge == null) return; + if (model == null) return; + model.removePropertyChangeListener((PropertyChangeListener) bridge); + } + } + + public void addChangeListener(final ChangeListener changeListener) { + if (changeListener == null) return; + synchronized (listenersMap) { + PropertyChangeListener listenerBridge = new PropertyChangeListener() { + final ChangeEvent EVENT = new ChangeEvent(XMLWizardIterator.this); + public void propertyChange(PropertyChangeEvent e) { + changeListener.stateChanged(EVENT); + } + }; + + if (listenersMap.put(changeListener, listenerBridge) == null) { + model.addPropertyChangeListener(listenerBridge); + } + } + } + + // implementation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + private WizardDescriptor.Panel getDocumentPanel() { + if (documentPanel == null) { + documentPanel = new DocumentPanel(); + documentPanel.setObject(model); + + String[] steps = new String[3]; + steps[0] = getTargetPanelName(); + steps[1] = getDocumentPanelName(); + steps[2] = Util.THIS.getString(XMLWizardIterator.class, "MSG_unknown"); + String[] newSteps = createSteps(beforeSteps,steps); + documentPanel.putClientProperty( + WizardDescriptor.PROP_CONTENT_DATA, // NOI18N + newSteps + ); + + } + return new AbstractPanel.WizardStep(documentPanel); + } + + private WizardDescriptor.Panel getDTDPanel() { + if (dtdPanel == null) { + dtdPanel = new DTDPanel(); + dtdPanel.setObject(model); + + String[] steps = new String[3]; + steps[0] = getTargetPanelName(); + steps[1] = getDocumentPanelName(); + steps[2] = getDTDPanelName(); + String[] newSteps = createSteps(beforeSteps,steps); + dtdPanel.putClientProperty( + WizardDescriptor.PROP_CONTENT_DATA, // NOI18N + newSteps + ); + + } + return new AbstractPanel.WizardStep(dtdPanel); + } + + private WizardDescriptor.Panel getSchemaPanel() { + if (schemaPanel == null) { + schemaPanel = new SchemaPanel(templateWizard); + schemaPanel.setObject(model); + + String[] steps = new String[4]; + steps[0] = getTargetPanelName(); + steps[1] = getDocumentPanelName(); + steps[2] = getSchemaPanelName(); + steps[3] = getXMLContentPanelName(); + String[] newSteps = createSteps(beforeSteps,steps); + schemaPanel.putClientProperty( + WizardDescriptor.PROP_CONTENT_DATA, // NOI18N + newSteps + ); + } + return new AbstractPanel.WizardStep(schemaPanel); + } + + private WizardDescriptor.Panel getTargetPanel() { + if (targetPanel == null) { + targetPanel = templateWizard.targetChooser(); + // fill component with step hints + if (targetPanel.getComponent() instanceof JComponent) { + JComponent panel = (JComponent) targetPanel.getComponent(); + targetSteps = panel.getClientProperty(WizardDescriptor.PROP_CONTENT_DATA); + String[] steps = new String[3]; + //steps[0] = "Hello"; + steps[0] = getTargetPanelName(); + steps[1] = getDocumentPanelName(); + steps[2] = Util.THIS.getString(XMLWizardIterator.class, "MSG_unknown"); + String[] newSteps = createSteps(beforeSteps,steps); + panel.putClientProperty( + WizardDescriptor.PROP_CONTENT_DATA, // NOI18N + newSteps + ); + } + + } + return targetPanel; + } + + private String getTargetPanelName() { + Object panel = getTargetPanel().getComponent(); + if (panel instanceof JComponent) { + return ((JComponent)panel).getName(); + } else { + return ""; //??? some fallback + } + } + + private String getDocumentPanelName() { + return Util.THIS.getString(XMLWizardIterator.class, "PROP_doc_panel_name"); + } + + private String getDTDPanelName() { + return Util.THIS.getString(XMLWizardIterator.class, "PROP_dtd_panel_name"); + } + + private String getSchemaPanelName() { + return Util.THIS.getString(XMLWizardIterator.class, "PROP_schema_panel_name"); + } + + private static String[] createSteps(String[] before, String[] panelNames) { + //assert panels != null; + // hack to use the steps set before this panel processed + int diff = 0; + if (before == null) { + before = new String[0]; + } else if (before.length > 0) { + diff = ("...".equals (before[before.length - 1])) ? 1 : 0; // NOI18N + } + String[] res = new String[ (before.length - diff) + panelNames.length]; + for (int i = 0; i < res.length; i++) { + if (i < (before.length - diff)) { + res[i] = before[i]; + } else { + res[i] = panelNames[i - before.length + diff]; + } + } + return res; + } + + private WizardDescriptor.Panel getXMLContentPanel() { + if (xmlPanel == null) { + xmlPanel = new XMLContentPanel(); + xmlPanel.setObject(model); + + String[] steps = new String[4]; + steps[0] = getTargetPanelName(); + steps[1] = getDocumentPanelName(); + steps[2] = getSchemaPanelName(); + steps[3] = getXMLContentPanelName(); + String[] newSteps = createSteps(beforeSteps,steps); + xmlPanel.putClientProperty( + WizardDescriptor.PROP_CONTENT_DATA, // NOI18N + newSteps + ); + } + return new AbstractPanel.WizardStep(xmlPanel); + } + + private String getXMLContentPanelName() { + return Util.THIS.getString(XMLWizardIterator.class, "PROP_xml_content_panel_name"); + } + + private void generateXMLBody(DocumentModel model, String root, StringBuffer writer){ + String schemaFileName = model.getPrimarySchema(); + if(model.getPrimarySchema().startsWith("http")) { + schemaFileName = retrieveURLSchema(model.getPrimarySchema()); + } + XMLGeneratorVisitor visitor = new XMLGeneratorVisitor(schemaFileName, model.getXMLContentAttributes(), writer); + visitor.generateXML(root); + } + + private String retrieveURLSchema(String sourceURL) { + try { + Project prj = Templates.getProject(templateWizard); + FileObject prjrtfo = prj.getProjectDirectory(); + // File saveFile = new File(selectedSaveRootFolder.getPath() + File.separator + "nbproject" + File.separator + "private" + File.separator+ schemaFileName); + + File prjrt = FileUtil.toFile(prjrtfo); + URI privateCatalogURI = null; + URI privateCacheURI = null; + //determine the cache dir + CacheDirectoryProvider cdp = (CacheDirectoryProvider) prj.getLookup(). + lookup(CacheDirectoryProvider.class); + String cachestr = Utilities.DEFAULT_PRIVATE_CAHCE_URI_STR; + try{ + if( (cdp != null) && (cdp.getCacheDirectory() != null) ){ + URI prjrturi = prjrt.toURI(); + URI cpduri = FileUtil.toFile(cdp.getCacheDirectory()).toURI(); + String cachedirstr = Utilities.relativize(prjrturi, cpduri); + cachestr = cachedirstr+"/"+Utilities.PRIVATE_CAHCE_URI_STR; + } + privateCacheURI = new URI(cachestr); + }catch(Exception e){ + + } + if(privateCacheURI == null) + return null; + URI cacheURI = prjrt.toURI().resolve(privateCacheURI); + File saveFile = new File(cacheURI ); + if(!saveFile.isDirectory()) + saveFile.mkdirs(); + + RetrieverEngine instance = RetrieverEngine.getRetrieverEngine(saveFile, false); + RetrieveEntry rent =new RetrieveEntry(null, sourceURL, null, null, DocumentTypesEnum.schema, true); + instance.addResourceToRetrieve(rent); + instance.setFileOverwrite(true); + instance.start(); + + //find where the file was downloaded, remove the "http:/" from the url + String returnstr = saveFile.getPath() + sourceURL.substring(6, sourceURL.length()); + return returnstr; + } catch (Exception e) { + //e.printStackTrace(); + return null; + } + } + + private void modifyRootElementAttrs(StringBuffer xmlBuffer) { + Map nsAttrs = model.getXMLContentAttributes().getNamespaceToPrefixMap(); + + if (nsAttrs == null || nsAttrs.size() == 0) { + return; + } + int firstOccur = xmlBuffer.indexOf("xmlns"); + int insertLoc = xmlBuffer.indexOf("xmlns", firstOccur + 1); + + StringBuffer sb = new StringBuffer(); + for (String ns : nsAttrs.keySet()) { + String xmlnsString = "xmlns:" + nsAttrs.get(ns) + "='" + ns + "'"; + if (xmlBuffer.indexOf(xmlnsString) == -1) { + xmlBuffer.insert(insertLoc, xmlnsString + "\n "); + } + + } + xmlBuffer.insert(insertLoc, sb.toString()); + + } + + + private void writeXMLFile(StringBuffer writer) throws IOException { + DataFolder folder = templateWizard.getTargetFolder(); + File pobj = FileUtil.toFile(folder.getPrimaryFile()); + String root = model.getRoot(); + if (root == null) { + root = "root"; + } + String prefix = model.getPrefix(); + + if (model.getType() == model.DTD) { + if (model.getPublicID() == null) { + writer.append("\n"); // NOI18N + + } else { + writer.append("\n"); // NOI18N + + } + writer.append("<" + root + ">\n"); // NOI18N + + } else if (model.getType() == model.SCHEMA) { + String namespace = model.getNamespace(); + List nodes = model.getSchemaNodes(); + + if (prefix == null || "".equals(prefix)) { + writer.append("<" + root + " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"); + } else { + writer.append("<" + prefix + ":" + root + " xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'\n"); + } + + + Map nsToPre = new HashMap(); + if (nodes != null) { + for (int i = 0; i < nodes.size(); i++) { + SchemaObject erdn = (SchemaObject) nodes.get(i); + nsToPre.put(erdn.getNamespace(), erdn.getPrefix()); + + if (erdn.getPrefix() == null || "".equals(erdn.getPrefix())) { + writer.append(" xmlns='" + erdn.getNamespace() + "'\n"); + } else { + writer.append(" xmlns:" + erdn.getPrefix() + "='" + erdn.getNamespace() + "'\n"); + } + } + for (int i = 0; i < nodes.size(); i++) { + SchemaObject erdn = (SchemaObject) nodes.get(i); + String relativePath = null; + if (erdn.toString().startsWith("http")) { + relativePath = erdn.toString(); + } else { + relativePath = Util.getRelativePath((new File(erdn.getSchemaFileName())), pobj); + } + if (i == 0) { + if (nodes.size() == 1) { + writer.append(" xsi:schemaLocation='" + erdn.getNamespace() + " " + relativePath + "'>\n"); + } else { + writer.append(" xsi:schemaLocation='" + erdn.getNamespace() + " " + relativePath + "\n"); + } + } else if (i == nodes.size() - 1) { + writer.append(" " + erdn.getNamespace() + " " + relativePath + "'>\n"); + } else { + writer.append(" " + erdn.getNamespace() + " " + relativePath + "\n"); + } + } + + } + model.getXMLContentAttributes().setNamespaceToPrefixMap(nsToPre); + generateXMLBody(model, root, writer); + modifyRootElementAttrs(writer); + } else { + writer.append("<" + root + ">\n"); // NOI18N + + } + + if (prefix == null || "".equals(prefix)) { + writer.append("\n"); // NOI18N + + writer.append("\n"); // NOI18N + + } else { + writer.append("\n"); // NOI18N + + writer.append("\n"); + } + + // writer.flush(); + // writer.close(); + + } + + private void writeXMLComment(StringBuffer writer, String filename, String encoding) throws IOException { + writer.append("\n"); // NOI18N + writer.append("\n"); // NOI18N + // comment + Date now = new Date(); + String currentDate = DateFormat.getDateInstance(DateFormat.LONG).format(now); + String currentTime = DateFormat.getTimeInstance(DateFormat.SHORT).format(now); + String userName = System.getProperty("user.name"); + writer.append("\n"); // NOI18N + writer.append("\n"); + } + + + + private void formatXML(FileObject fobj){ + try { + DataObject dobj = DataObject.find(fobj); + EditorCookie ec = dobj.getCookie(EditorCookie.class); + if (ec == null) { + return; + } + BaseDocument doc = (BaseDocument) ec.getDocument(); + org.netbeans.modules.xml.text.api.XMLFormatUtil.reformat(doc, 0, doc.getLength()); + EditCookie cookie = dobj.getCookie(EditCookie.class); + if (cookie instanceof TextEditorSupport) { + if (cookie != null) { + ((TextEditorSupport) cookie).saveDocument(); + } + } + + } catch (Exception e) { + //if exception , then the file will be informatted + } + + + } +} diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/folder_closed.png Binary file xml/src/org/netbeans/modules/xml/wizard/impl/folder_closed.png has changed diff -r dc440cc77d77 xml/src/org/netbeans/modules/xml/wizard/impl/folder_opened.png Binary file xml/src/org/netbeans/modules/xml/wizard/impl/folder_opened.png has changed diff -r dc440cc77d77 xml/test/unit/src/org/netbeans/modules/xml/wizard/DTDParserTest.java --- a/xml/test/unit/src/org/netbeans/modules/xml/wizard/DTDParserTest.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/test/unit/src/org/netbeans/modules/xml/wizard/DTDParserTest.java Tue Sep 23 16:17:23 2008 -0500 @@ -47,7 +47,7 @@ package org.netbeans.modules.xml.wizard; -import org.netbeans.modules.xml.wizard.DTDParser; +import org.netbeans.modules.xml.wizard.impl.DTDParser; import java.io.*; import java.net.URL; import java.util.*; diff -r dc440cc77d77 xml/test/unit/src/org/netbeans/modules/xml/wizard/XMLGeneratorTest.java --- a/xml/test/unit/src/org/netbeans/modules/xml/wizard/XMLGeneratorTest.java Mon Sep 22 22:08:43 2008 -0500 +++ b/xml/test/unit/src/org/netbeans/modules/xml/wizard/XMLGeneratorTest.java Tue Sep 23 16:17:23 2008 -0500 @@ -39,6 +39,7 @@ package org.netbeans.modules.xml.wizard; +import org.netbeans.modules.xml.wizard.XMLContentAttributes; import java.io.BufferedReader; import java.io.File; import java.io.InputStream; diff -r dc440cc77d77 xsl/manifest.mf --- a/xsl/manifest.mf Mon Sep 22 22:08:43 2008 -0500 +++ b/xsl/manifest.mf Tue Sep 23 16:17:23 2008 -0500 @@ -4,3 +4,4 @@ OpenIDE-Module-Layer: org/netbeans/modules/xsl/resources/mf-layer.xml OpenIDE-Module-Requires: org.openide.util.HttpServer$Impl AutoUpdate-Show-In-Client: false +OpenIDE-Module-Specification-Version: 1.16 diff -r dc440cc77d77 xsl/nbproject/project.properties --- a/xsl/nbproject/project.properties Mon Sep 22 22:08:43 2008 -0500 +++ b/xsl/nbproject/project.properties Tue Sep 23 16:17:23 2008 -0500 @@ -39,4 +39,3 @@ javac.compilerargs=-Xlint -Xlint:-serial javac.source=1.5 -spec.version.base=1.15.0 diff -r dc440cc77d77 xsl/nbproject/project.xml --- a/xsl/nbproject/project.xml Mon Sep 22 22:08:43 2008 -0500 +++ b/xsl/nbproject/project.xml Tue Sep 23 16:17:23 2008 -0500 @@ -93,7 +93,7 @@ - + 1.2 diff -r dc440cc77d77 xslt.core/manifest.mf --- a/xslt.core/manifest.mf Mon Sep 22 22:08:43 2008 -0500 +++ b/xslt.core/manifest.mf Tue Sep 23 16:17:23 2008 -0500 @@ -1,6 +1,6 @@ Manifest-Version: 1.0 AutoUpdate-Show-In-Client: false -OpenIDE-Module-Specification-Version: 1.1 +OpenIDE-Module-Specification-Version: 1.2 OpenIDE-Module: org.netbeans.modules.xslt.core/1 OpenIDE-Module-Layer: org/netbeans/modules/xslt/core/resources/layer.xml OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/xslt/core/resources/Bundle.properties diff -r dc440cc77d77 xslt.core/nbproject/project.xml --- a/xslt.core/nbproject/project.xml Mon Sep 22 22:08:43 2008 -0500 +++ b/xslt.core/nbproject/project.xml Tue Sep 23 16:17:23 2008 -0500 @@ -146,7 +146,7 @@ - + 1.2