diff --git a/platform/lang-impl/src/com/intellij/xml/index/XsdNamespaceBuilder.java b/platform/lang-impl/src/com/intellij/xml/index/XsdNamespaceBuilder.java index 61d69ba241ad..b98a605ea2e3 100644 --- a/platform/lang-impl/src/com/intellij/xml/index/XsdNamespaceBuilder.java +++ b/platform/lang-impl/src/com/intellij/xml/index/XsdNamespaceBuilder.java @@ -16,31 +16,31 @@ package com.intellij.xml.index; +import com.intellij.openapi.util.Comparing; import com.intellij.util.xml.NanoXmlUtil; import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.util.ArrayList; +import java.util.List; /** * @author Dmitry Avdeev */ -public class XsdNamespaceBuilder extends NanoXmlUtil.IXMLBuilderAdapter { +public class XsdNamespaceBuilder extends NanoXmlUtil.IXMLBuilderAdapter implements Comparable { - @Nullable public static String computeNamespace(final InputStream is) { - return computeNamespace(new InputStreamReader(is)); + return computeNamespace(new InputStreamReader(is)).getNamespace(); } - @Nullable - public static String computeNamespace(final Reader reader) { + public static XsdNamespaceBuilder computeNamespace(final Reader reader) { try { final XsdNamespaceBuilder builder = new XsdNamespaceBuilder(); NanoXmlUtil.parse(reader, builder); - return builder.myNamespace; + return builder; } finally { try { @@ -54,25 +54,82 @@ public class XsdNamespaceBuilder extends NanoXmlUtil.IXMLBuilderAdapter { } } + private String myCurrentTag; + + private int myCurrentDepth; private String myNamespace; + private String myVersion; + private List myTags = new ArrayList(); + private List myAttributes = new ArrayList(); public void startElement(@NonNls final String name, @NonNls final String nsPrefix, @NonNls final String nsURI, final String systemID, final int lineNr) throws Exception { - if ( !"http://www.w3.org/2001/XMLSchema".equals(nsURI) || !name.equals("schema")) { - stop(); + if (myCurrentDepth < 2 && "http://www.w3.org/2001/XMLSchema".equals(nsURI)) { + myCurrentTag = name; } + myCurrentDepth++; + } + + @Override + public void endElement(String name, String nsPrefix, String nsURI) throws Exception { + myCurrentDepth--; + myCurrentTag = null; } public void addAttribute(@NonNls final String key, final String nsPrefix, final String nsURI, final String value, final String type) throws Exception { - if (key.equals("targetNamespace")) { - myNamespace = value; - stop(); + if ("schema".equals(myCurrentTag)) { + if ("targetNamespace".equals(key)) { + myNamespace = value; + } + else if ("version".equals(key)) { + myVersion = value; + } + } + else if ("element".equals(myCurrentTag) && "name".equals(key)) { + myTags.add(value); } } - public void endElement(final String name, final String nsPrefix, final String nsURI) throws Exception { - stop(); + @Override + public int compareTo(XsdNamespaceBuilder o) { + return Comparing.compare(myNamespace, o.myNamespace); + } + + public int getRating(String tagName, String version) { + int rate = 0; + if (tagName != null && myTags.contains(tagName)) { + rate |= 0x02; + } + if (Comparing.equal(version, myVersion)) { + rate |= 0x01; + } + return rate; + } + + private XsdNamespaceBuilder() { + } + + public XsdNamespaceBuilder(String namespace, String version, List tags) { + myNamespace = namespace; + myVersion = version; + myTags = tags; + } + + public String getNamespace() { + return myNamespace; + } + + public String getVersion() { + return myVersion; + } + + public List getTags() { + return myTags; + } + + public List getAttributes() { + return myAttributes; } } diff --git a/platform/platform-resources/src/META-INF/XmlPlugin.xml b/platform/platform-resources/src/META-INF/XmlPlugin.xml index 0050b4c3f41a..f0ce976e2508 100644 --- a/platform/platform-resources/src/META-INF/XmlPlugin.xml +++ b/platform/platform-resources/src/META-INF/XmlPlugin.xml @@ -372,6 +372,10 @@ XML com.intellij.codeInsight.daemon.impl.analysis.AddSchemaPrefixIntention + + XML + com.intellij.codeInsight.daemon.impl.quickfix.AddXsiSchemaLocationForExtResourceAction + XML com.intellij.codeInsight.daemon.impl.analysis.ConvertSchemaPrefixToDefaultIntention diff --git a/xml/impl/resources/intentionDescriptions/AddXsiSchemaLocationForExtResourceAction/after.xml.template b/xml/impl/resources/intentionDescriptions/AddXsiSchemaLocationForExtResourceAction/after.xml.template new file mode 100644 index 000000000000..e46b6149d826 --- /dev/null +++ b/xml/impl/resources/intentionDescriptions/AddXsiSchemaLocationForExtResourceAction/after.xml.template @@ -0,0 +1,12 @@ + +<xs:schema targetNamespace="http://mySchema" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns:my="http://mySchema"> + + <xs:element name="myElement" type="my:TYPE"/> + <xs:simpleType name="TYPE" id="TYPE"> + <xs:restriction base="xs:integer"> + <xs:minInclusive value="0" id="nonNegativeInteger.minInclusive"/> + xs:restriction> + xs:simpleType> +xs:schema> diff --git a/xml/impl/resources/intentionDescriptions/AddXsiSchemaLocationForExtResourceAction/before.xml.template b/xml/impl/resources/intentionDescriptions/AddXsiSchemaLocationForExtResourceAction/before.xml.template new file mode 100644 index 000000000000..2e2b85a8344e --- /dev/null +++ b/xml/impl/resources/intentionDescriptions/AddXsiSchemaLocationForExtResourceAction/before.xml.template @@ -0,0 +1,12 @@ + +xmlns="http://www.w3.org/2001/XMLSchema" + xmlns:my="http://mySchema"> + + + + + + + + diff --git a/xml/impl/resources/intentionDescriptions/AddXsiSchemaLocationForExtResourceAction/description.html b/xml/impl/resources/intentionDescriptions/AddXsiSchemaLocationForExtResourceAction/description.html new file mode 100644 index 000000000000..5742887b0798 --- /dev/null +++ b/xml/impl/resources/intentionDescriptions/AddXsiSchemaLocationForExtResourceAction/description.html @@ -0,0 +1,5 @@ + + +Adds xsi:schemaLocation attribute. + + \ No newline at end of file diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddXsiSchemaLocationForExtResourceAction.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddXsiSchemaLocationForExtResourceAction.java index 179cd42b5389..3da301a23b8a 100644 --- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddXsiSchemaLocationForExtResourceAction.java +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/AddXsiSchemaLocationForExtResourceAction.java @@ -19,15 +19,20 @@ import com.intellij.codeInsight.CodeInsightUtilBase; import com.intellij.codeInsight.daemon.XmlErrorMessages; import com.intellij.codeInsight.daemon.impl.analysis.CreateNSDeclarationIntentionFix; import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; +import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.XmlElementFactory; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.psi.xml.XmlAttribute; +import com.intellij.psi.xml.XmlAttributeValue; +import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; import com.intellij.util.ArrayUtil; import com.intellij.util.IncorrectOperationException; +import com.intellij.xml.XmlBundle; import com.intellij.xml.util.XmlUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -91,4 +96,17 @@ public class AddXsiSchemaLocationForExtResourceAction extends BaseExtResourceAct final TextRange textRange = new TextRange(range.getEndOffset() - offset - 1, range.getEndOffset() - 1); editor.getCaretModel().moveToOffset(textRange.getStartOffset()); } + + @Override + public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + if (!(file instanceof XmlFile)) return false; + + PsiElement element = file.findElementAt(editor.getCaretModel().getOffset()); + XmlAttributeValue value = PsiTreeUtil.getParentOfType(element, XmlAttributeValue.class); + if (value == null) return false; + XmlAttribute attribute = PsiTreeUtil.getParentOfType(value, XmlAttribute.class); + if (attribute == null || !"xmlns".equals(attribute.getLocalName())) return false; + setText(XmlBundle.message(getQuickFixKeyId())); + return true; + } } \ No newline at end of file diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/BaseExtResourceAction.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/BaseExtResourceAction.java index 18215cba6ba1..f41a9f6a5158 100644 --- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/BaseExtResourceAction.java +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/BaseExtResourceAction.java @@ -79,11 +79,8 @@ abstract class BaseExtResourceAction extends BaseIntentionAction { public static String findUri(PsiFile file, int offset) { PsiReference currentRef = file.getViewProvider().findReferenceAt(offset, file.getLanguage()); if (currentRef == null) currentRef = file.getViewProvider().findReferenceAt(offset); - if (( currentRef instanceof URLReference || - currentRef instanceof URIReferenceProvider.DependentNSReference - ) && - currentRef.resolve() == null - ) { + if (currentRef instanceof URLReference || + currentRef instanceof URIReferenceProvider.DependentNSReference) { return currentRef.getCanonicalText(); } return null; diff --git a/xml/impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java b/xml/impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java index 67c0a85a6aea..f3261dbe01fa 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java +++ b/xml/impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java @@ -23,6 +23,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; +import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.util.*; @@ -58,6 +59,9 @@ import com.intellij.xml.XmlExtension; import com.intellij.xml.XmlNSDescriptor; import com.intellij.xml.impl.dtd.XmlNSDescriptorImpl; import com.intellij.xml.impl.schema.AnyXmlElementDescriptor; +import com.intellij.xml.index.IndexedRelevantResource; +import com.intellij.xml.index.XmlNamespaceIndex; +import com.intellij.xml.index.XsdNamespaceBuilder; import com.intellij.xml.util.XmlTagUtil; import com.intellij.xml.util.XmlUtil; import gnu.trove.THashMap; @@ -335,7 +339,7 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag { return new Result(descriptor, ArrayUtil.append(descriptor.getDependences(), XmlTagImpl.this)); } - XmlFile currentFile = retrieveFile(fileLocation, version); + XmlFile currentFile = retrieveFile(fileLocation, version, namespace); if (currentFile == null) { final XmlDocument document = XmlUtil.getContainingFile(XmlTagImpl.this).getDocument(); if (document != null) { @@ -392,16 +396,21 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag { } @Nullable - private XmlFile retrieveFile(final String fileLocation, String version) { + private XmlFile retrieveFile(final String fileLocation, final String version, String namespace) { final String targetNs = XmlUtil.getTargetSchemaNsFromTag(this); if (fileLocation.equals(targetNs)) { return null; } - else { - final XmlFile file = XmlUtil.getContainingFile(this); - final PsiFile psiFile = ExternalResourceManager.getInstance().getResourceLocation(fileLocation, file, version); - return psiFile instanceof XmlFile ? (XmlFile)psiFile : null; + + final XmlFile file = XmlUtil.getContainingFile(this); + final PsiFile psiFile = ExternalResourceManager.getInstance().getResourceLocation(fileLocation, file, version); + if (psiFile instanceof XmlFile) { + return (XmlFile)psiFile; } + + IndexedRelevantResource resource = + XmlNamespaceIndex.guessSchema(namespace, myLocalName, version, ModuleUtilCore.findModuleForPsiElement(file)); + return resource == null ? null : (XmlFile)file.getManager().findFile(resource.getFile()); } @Nullable diff --git a/xml/impl/src/com/intellij/xml/index/XmlNamespaceIndex.java b/xml/impl/src/com/intellij/xml/index/XmlNamespaceIndex.java index 77400f1557c9..1127a1101883 100644 --- a/xml/impl/src/com/intellij/xml/index/XmlNamespaceIndex.java +++ b/xml/impl/src/com/intellij/xml/index/XmlNamespaceIndex.java @@ -28,64 +28,120 @@ import com.intellij.util.text.CharArrayUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.util.*; /** * @author Dmitry Avdeev */ -public class XmlNamespaceIndex extends XmlIndex { +public class XmlNamespaceIndex extends XmlIndex { @Nullable public static String getNamespace(@NotNull VirtualFile file, final Project project) { - final List list = FileBasedIndex.getInstance().getValues(NAME, file.getUrl(), createFilter(project)); - return list.size() == 0 ? null : list.get(0); + final List list = FileBasedIndex.getInstance().getValues(NAME, file.getUrl(), createFilter(project)); + return list.size() == 0 ? null : list.get(0).getNamespace(); } - public static List> getResourcesByNamespace(String namespace, final Project project, Module module) { - List> resources = IndexedRelevantResource.getResources(NAME, namespace, module, project, + public static List> getResourcesByNamespace(String namespace, final Project project, Module module) { + List> resources = IndexedRelevantResource.getResources(NAME, namespace, module, project, null); Collections.sort(resources); return resources; } - public static List> getAllResources(@NotNull final Module module) { + public static List> getAllResources(@NotNull final Module module) { return getAllResources(module, null); } - public static List> getAllResources(@NotNull final Module module, @Nullable NullableFunction>, IndexedRelevantResource> chooser) { + + public static List> getAllResources(@NotNull final Module module, + @Nullable NullableFunction>, IndexedRelevantResource> chooser) { return IndexedRelevantResource.getAllResources(NAME, module, chooser); } - private static final ID NAME = ID.create("XmlNamespaces"); + private static final ID NAME = ID.create("XmlNamespaces"); @Override @NotNull - public ID getName() { + public ID getName() { return NAME; } @Override @NotNull - public DataIndexer getIndexer() { - return new DataIndexer() { + public DataIndexer getIndexer() { + return new DataIndexer() { @Override @NotNull - public Map map(final FileContent inputData) { - final String ns = XsdNamespaceBuilder.computeNamespace(CharArrayUtil.readerFromCharSequence(inputData.getContentAsText())); - final HashMap map = new HashMap(2); - if (ns != null) { - map.put(ns, ""); + public Map map(final FileContent inputData) { + final XsdNamespaceBuilder + builder = XsdNamespaceBuilder.computeNamespace(CharArrayUtil.readerFromCharSequence(inputData.getContentAsText())); + final HashMap map = new HashMap(2); + String namespace = builder.getNamespace(); + if (namespace != null) { + map.put(namespace, builder); } - map.put(inputData.getFile().getUrl(), ns == null ? "" : ns); + map.put(inputData.getFile().getUrl(), builder); return map; } }; } @Override - public DataExternalizer getValueExternalizer() { - return KEY_DESCRIPTOR; + public DataExternalizer getValueExternalizer() { + return new DataExternalizer() { + @Override + public void save(DataOutput out, XsdNamespaceBuilder value) throws IOException { + out.writeUTF(value.getNamespace() == null ? "" : value.getNamespace()); + out.writeUTF(value.getVersion() == null ? "" : value.getVersion()); + out.writeInt(value.getTags().size()); + for (String s : value.getTags()) { + out.writeUTF(s); + } + } + + @Override + public XsdNamespaceBuilder read(DataInput in) throws IOException { + + int count; + XsdNamespaceBuilder builder = new XsdNamespaceBuilder(in.readUTF(), in.readUTF(), new ArrayList(count = in.readInt())); + for (int i = 0; i < count; i++) { + builder.getTags().add(in.readUTF()); + } + return builder; + } + }; + } + + @Override + public int getVersion() { + return 2; + } + + @Nullable + public static IndexedRelevantResource guessSchema(String namespace, + @Nullable final String tagName, + @Nullable final String version, + Module module) { + + if (module == null) return null; + + Project project = module.getProject(); + final List> + resources = getResourcesByNamespace(namespace, project, module); + + if (resources.isEmpty()) return null; + + return Collections + .max(resources, new Comparator>() { + @Override + public int compare(IndexedRelevantResource o1, + IndexedRelevantResource o2) { + + int i = o1.getValue().getRating(tagName, version) - o2.getValue().getRating(tagName, version); + return i == 0 ? o1.compareTo(o2) : i; + } + }); } } diff --git a/xml/impl/src/com/intellij/xml/util/XmlUtil.java b/xml/impl/src/com/intellij/xml/util/XmlUtil.java index 61feeb764660..a4f710f21066 100644 --- a/xml/impl/src/com/intellij/xml/util/XmlUtil.java +++ b/xml/impl/src/com/intellij/xml/util/XmlUtil.java @@ -67,6 +67,7 @@ import com.intellij.xml.impl.schema.XmlElementDescriptorImpl; import com.intellij.xml.impl.schema.XmlNSDescriptorImpl; import com.intellij.xml.index.IndexedRelevantResource; import com.intellij.xml.index.XmlNamespaceIndex; +import com.intellij.xml.index.XsdNamespaceBuilder; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -251,11 +252,12 @@ public class XmlUtil { } public static Collection findNSFilesByURI(String namespace, final Project project, Module module) { - final List> resources = XmlNamespaceIndex.getResourcesByNamespace(namespace, project, module); + final List> + resources = XmlNamespaceIndex.getResourcesByNamespace(namespace, project, module); final PsiManager psiManager = PsiManager.getInstance(project); - return ContainerUtil.mapNotNull(resources, new NullableFunction, XmlFile>() { - public XmlFile fun(IndexedRelevantResource stringStringIndexedRelevantResource) { - PsiFile file = psiManager.findFile(stringStringIndexedRelevantResource.getFile()); + return ContainerUtil.mapNotNull(resources, new NullableFunction, XmlFile>() { + public XmlFile fun(IndexedRelevantResource resource) { + PsiFile file = psiManager.findFile(resource.getFile()); return file instanceof XmlFile ? (XmlFile)file : null; } }); diff --git a/xml/tests/src/com/intellij/xml/index/XmlSchemaIndexTest.java b/xml/tests/src/com/intellij/xml/index/XmlSchemaIndexTest.java index abb7f4bdfd57..eb18d4812cc8 100644 --- a/xml/tests/src/com/intellij/xml/index/XmlSchemaIndexTest.java +++ b/xml/tests/src/com/intellij/xml/index/XmlSchemaIndexTest.java @@ -8,6 +8,7 @@ import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import java.io.IOException; +import java.io.InputStreamReader; import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -44,6 +45,14 @@ public class XmlSchemaIndexTest extends CodeInsightFixtureTestCase { assertTrue(xstags.contains("schema")); } + public void testXsdNamespaceBuilder() throws Exception { + VirtualFile file = myFixture.copyFileToProject("web-app_2_5.xsd"); + final XsdNamespaceBuilder builder = XsdNamespaceBuilder.computeNamespace(new InputStreamReader(file.getInputStream())); + assertEquals("http://java.sun.com/xml/ns/javaee", builder.getNamespace()); + assertEquals("2.5", builder.getVersion()); + assertEquals(Arrays.asList("web-app"), builder.getTags()); + } + public void testTagNameIndex() { myFixture.copyDirectoryToProject("", ""); @@ -72,11 +81,26 @@ public class XmlSchemaIndexTest extends CodeInsightFixtureTestCase { myFixture.copyDirectoryToProject("", ""); - final List> files = - XmlNamespaceIndex.getResourcesByNamespace("http://www.springframework.org/schema/beans", + final List> files = + XmlNamespaceIndex.getResourcesByNamespace("http://java.sun.com/xml/ns/javaee", getProject(), myModule); - assertEquals(1, files.size()); + assertEquals(2, files.size()); + + IndexedRelevantResource + resource = XmlNamespaceIndex.guessSchema("http://java.sun.com/xml/ns/javaee", "web-app", "3.0", myModule); + assertNotNull(resource); + XsdNamespaceBuilder builder = resource.getValue(); + assertEquals("http://java.sun.com/xml/ns/javaee", builder.getNamespace()); + assertEquals("3.0", builder.getVersion()); + assertEquals(Arrays.asList("web-app"), builder.getTags()); + + resource = XmlNamespaceIndex.guessSchema("http://java.sun.com/xml/ns/javaee", "web-app", "2.5", myModule); + assertNotNull(resource); + builder = resource.getValue(); + assertEquals("http://java.sun.com/xml/ns/javaee", builder.getNamespace()); + assertEquals("2.5", builder.getVersion()); + assertEquals(Arrays.asList("web-app"), builder.getTags()); } @Override diff --git a/xml/tests/testData/index/web-app_2_5.xsd b/xml/tests/testData/index/web-app_2_5.xsd new file mode 100644 index 000000000000..28e956fd8ccf --- /dev/null +++ b/xml/tests/testData/index/web-app_2_5.xsd @@ -0,0 +1,1290 @@ + + + + + + + + @(#)web-app_2_5.xsds 1.62 05/08/06 + + + + + + + Copyright 2003-2005 Sun Microsystems, Inc. + 4150 Network Circle + Santa Clara, California 95054 + U.S.A + All rights reserved. + + Sun Microsystems, Inc. has intellectual property rights + relating to technology described in this document. In + particular, and without limitation, these intellectual + property rights may include one or more of the U.S. patents + listed at http://www.sun.com/patents and one or more + additional patents or pending patent applications in the + U.S. and other countries. + + This document and the technology which it describes are + distributed under licenses restricting their use, copying, + distribution, and decompilation. No part of this document + may be reproduced in any form by any means without prior + written authorization of Sun and its licensors, if any. + + Third-party software, including font technology, is + copyrighted and licensed from Sun suppliers. + + Sun, Sun Microsystems, the Sun logo, Solaris, Java, J2EE, + JavaServer Pages, Enterprise JavaBeans and the Java Coffee + Cup logo are trademarks or registered trademarks of Sun + Microsystems, Inc. in the U.S. and other countries. + + Federal Acquisitions: Commercial Software - Government Users + Subject to Standard License Terms and Conditions. + + + + + + + + ... + + + The instance documents may indicate the published version of + the schema using the xsi:schemaLocation attribute for Java EE + namespace with the following location: + + http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd + + ]]> + + + + + + + The following conventions apply to all Java EE + deployment descriptor elements unless indicated otherwise. + + - In elements that specify a pathname to a file within the + same JAR file, relative filenames (i.e., those not + starting with "/") are considered relative to the root of + the JAR file's namespace. Absolute filenames (i.e., those + starting with "/") also specify names in the root of the + JAR file's namespace. In general, relative names are + preferred. The exception is .war files where absolute + names are preferred for consistency with the Servlet API. + + + + + + + + + + + + + + + The web-app element is the root of the deployment + descriptor for a web application. Note that the sub-elements + of this element can be in the arbitrary order. Because of + that, the multiplicity of the elements of distributable, + session-config, welcome-file-list, jsp-config, login-config, + and locale-encoding-mapping-list was changed from "?" to "*" + in this schema. However, the deployment descriptor instance + file must not contain multiple elements of session-config, + jsp-config, and login-config. When there are multiple elements of + welcome-file-list or locale-encoding-mapping-list, the container + must concatenate the element contents. The multiple occurence + of the element distributable is redundant and the container + treats that case exactly in the same way when there is only + one distributable. + + + + + + + + + The servlet element contains the name of a servlet. + The name must be unique within the web application. + + + + + + + + + + + + The filter element contains the name of a filter. + The name must be unique within the web application. + + + + + + + + + + + + The ejb-local-ref-name element contains the name of an EJB + reference. The EJB reference is an entry in the web + application's environment and is relative to the + java:comp/env context. The name must be unique within + the web application. + + It is recommended that name is prefixed with "ejb/". + + + + + + + + + + + + The ejb-ref-name element contains the name of an EJB + reference. The EJB reference is an entry in the web + application's environment and is relative to the + java:comp/env context. The name must be unique within + the web application. + + It is recommended that name is prefixed with "ejb/". + + + + + + + + + + + + The resource-env-ref-name element specifies the name of + a resource environment reference; its value is the + environment entry name used in the web application code. + The name is a JNDI name relative to the java:comp/env + context and must be unique within a web application. + + + + + + + + + + + + The message-destination-ref-name element specifies the name of + a message destination reference; its value is the + environment entry name used in the web application code. + The name is a JNDI name relative to the java:comp/env + context and must be unique within a web application. + + + + + + + + + + + + The res-ref-name element specifies the name of a + resource manager connection factory reference. The name + is a JNDI name relative to the java:comp/env context. + The name must be unique within a web application. + + + + + + + + + + + + The env-entry-name element contains the name of a web + application's environment entry. The name is a JNDI + name relative to the java:comp/env context. The name + must be unique within a web application. + + + + + + + + + + + + + A role-name-key is specified to allow the references + from the security-role-refs. + + + + + + + + + + + + The keyref indicates the references from + security-role-ref to a specified role-name. + + + + + + + + + + + + + + + + The auth-constraintType indicates the user roles that + should be permitted access to this resource + collection. The role-name used here must either correspond + to the role-name of one of the security-role elements + defined for this web application, or be the specially + reserved role-name "*" that is a compact syntax for + indicating all roles in the web application. If both "*" + and rolenames appear, the container interprets this as all + roles. If no roles are defined, no user is allowed access + to the portion of the web application described by the + containing security-constraint. The container matches + role names case sensitively when determining access. + + + + + + + + + + + + + + + + + + The auth-methodType is used to configure the authentication + mechanism for the web application. As a prerequisite to + gaining access to any web resources which are protected by + an authorization constraint, a user must have authenticated + using the configured mechanism. Legal values are "BASIC", + "DIGEST", "FORM", "CLIENT-CERT", or a vendor-specific + authentication scheme. + + Used in: login-config + + + + + + + + + + + + + + + + The dispatcher has four legal values: FORWARD, REQUEST, INCLUDE, + and ERROR. A value of FORWARD means the Filter will be applied + under RequestDispatcher.forward() calls. A value of REQUEST + means the Filter will be applied under ordinary client calls to + the path or servlet. A value of INCLUDE means the Filter will be + applied under RequestDispatcher.include() calls. A value of + ERROR means the Filter will be applied under the error page + mechanism. The absence of any dispatcher elements in a + filter-mapping indicates a default of applying filters only under + ordinary client calls to the path or servlet. + + + + + + + + + + + + + + + + + + + + + The encodingType defines IANA character sets. + + + + + + + + + + + + + + + + The error-code contains an HTTP error code, ex: 404 + + Used in: error-page + + + + + + + + + + + + + + + + + + + The error-pageType contains a mapping between an error code + or exception type to the path of a resource in the web + application. + + Used in: web-app + + + + + + + + + + + + + The exception-type contains a fully qualified class + name of a Java exception type. + + + + + + + + + + + The location element contains the location of the + resource in the web application relative to the root of + the web application. The value of the location must have + a leading `/'. + + + + + + + + + + + + + + + Declaration of the filter mappings in this web + application is done by using filter-mappingType. + The container uses the filter-mapping + declarations to decide which filters to apply to a request, + and in what order. The container matches the request URI to + a Servlet in the normal way. To determine which filters to + apply it matches filter-mapping declarations either on + servlet-name, or on url-pattern for each filter-mapping + element, depending on which style is used. The order in + which filters are invoked is the order in which + filter-mapping declarations that match a request URI for a + servlet appear in the list of filter-mapping elements.The + filter-name value must be the value of the filter-name + sub-elements of one of the filter declarations in the + deployment descriptor. + + + + + + + + + + + + + + + + + + + + + + The logical name of the filter is declare + by using filter-nameType. This name is used to map the + filter. Each filter name is unique within the web + application. + + Used in: filter, filter-mapping + + + + + + + + + + + + + + + + The filterType is used to declare a filter in the web + application. The filter is mapped to either a servlet or a + URL pattern in the filter-mapping element, using the + filter-name value to reference. Filters can access the + initialization parameters declared in the deployment + descriptor at runtime via the FilterConfig interface. + + Used in: web-app + + + + + + + + + + + + The fully qualified classname of the filter. + + + + + + + + + + The init-param element contains a name/value pair as + an initialization param of a servlet filter + + + + + + + + + + + + + + + The form-login-configType specifies the login and error + pages that should be used in form based login. If form based + authentication is not used, these elements are ignored. + + Used in: login-config + + + + + + + + + + + The form-login-page element defines the location in the web + app where the page that can be used for login can be + found. The path begins with a leading / and is interpreted + relative to the root of the WAR. + + + + + + + + + + The form-error-page element defines the location in + the web app where the error page that is displayed + when login is not successful can be found. + The path begins with a leading / and is interpreted + relative to the root of the WAR. + + + + + + + + + + + + + + + + + A HTTP method type as defined in HTTP 1.1 section 2.2. + + + + + + + + + + + + + + + + + + + + + + + The locale-encoding-mapping-list contains one or more + locale-encoding-mapping(s). + + + + + + + + + + + + + + + + + The locale-encoding-mapping contains locale name and + encoding name. The locale name must be either "Language-code", + such as "ja", defined by ISO-639 or "Language-code_Country-code", + such as "ja_JP". "Country code" is defined by ISO-3166. + + + + + + + + + + + + + + + + + + The localeType defines valid locale defined by ISO-639-1 + and ISO-3166. + + + + + + + + + + + + + + + + The login-configType is used to configure the authentication + method that should be used, the realm name that should be + used for this application, and the attributes that are + needed by the form login mechanism. + + Used in: web-app + + + + + + + + + + + The realm name element specifies the realm name to + use in HTTP Basic authorization. + + + + + + + + + + + + + + + + The mime-mappingType defines a mapping between an extension + and a mime type. + + Used in: web-app + + + + + + + + + The extension element contains a string describing an + extension. example: "txt" + + + + + + + + + + + + + + + + + The mime-typeType is used to indicate a defined mime type. + + Example: + "text/plain" + + Used in: mime-mapping + + + + + + + + + + + + + + + + + This type defines a string which contains at least one + character. + + + + + + + + + + + + + + + + + + + + + + + + The security-constraintType is used to associate + security constraints with one or more web resource + collections + + Used in: web-app + + + + + + + + + + + + + + + + + + + + The servlet-mappingType defines a mapping between a + servlet and a url pattern. + + Used in: web-app + + + + + + + + + + + + + + + + + + The servlet-name element contains the canonical name of the + servlet. Each servlet name is unique within the web + application. + + + + + + + + + + + + + + + + The servletType is used to declare a servlet. + It contains the declarative data of a + servlet. If a jsp-file is specified and the load-on-startup + element is present, then the JSP should be precompiled and + loaded. + + Used in: web-app + + + + + + + + + + + + + The servlet-class element contains the fully + qualified class name of the servlet. + + + + + + + + + + + + + + + The load-on-startup element indicates that this + servlet should be loaded (instantiated and have + its init() called) on the startup of the web + application. The optional contents of these + element must be an integer indicating the order in + which the servlet should be loaded. If the value + is a negative integer, or the element is not + present, the container is free to load the servlet + whenever it chooses. If the value is a positive + integer or 0, the container must load and + initialize the servlet as the application is + deployed. The container must guarantee that + servlets marked with lower integers are loaded + before servlets marked with higher integers. The + container may choose the order of loading of + servlets with the same load-on-start-up value. + + + + + + + + + + + + + + + + + The session-configType defines the session parameters + for this web application. + + Used in: web-app + + + + + + + + + + The session-timeout element defines the default + session timeout interval for all sessions created + in this web application. The specified timeout + must be expressed in a whole number of minutes. + If the timeout is 0 or less, the container ensures + the default behaviour of sessions is never to time + out. If this element is not specified, the container + must set its default timeout period. + + + + + + + + + + + + + + + The transport-guaranteeType specifies that the communication + between client and server should be NONE, INTEGRAL, or + CONFIDENTIAL. NONE means that the application does not + require any transport guarantees. A value of INTEGRAL means + that the application requires that the data sent between the + client and server be sent in such a way that it can't be + changed in transit. CONFIDENTIAL means that the application + requires that the data be transmitted in a fashion that + prevents other entities from observing the contents of the + transmission. In most cases, the presence of the INTEGRAL or + CONFIDENTIAL flag will indicate that the use of SSL is + required. + + Used in: user-data-constraint + + + + + + + + + + + + + + + + + + + + The user-data-constraintType is used to indicate how + data communicated between the client and container should be + protected. + + Used in: security-constraint + + + + + + + + + + + + + + + + + + The elements that use this type designate a path starting + with a "/" and interpreted relative to the root of a WAR + file. + + + + + + + + + + + + + + + + + This type contains the recognized versions of + web-application supported. It is used to designate the + version of the web application. + + + + + + + + + + + + + + + + + + + + + The context-param element contains the declaration + of a web application's servlet context + initialization parameters. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The metadata-complete attribute defines whether this + deployment descriptor and other related deployment + descriptors for this module (e.g., web service + descriptors) are complete, or whether the class + files available to this module and packaged with + this application should be examined for annotations + that specify deployment information. + + If metadata-complete is set to "true", the deployment + tool must ignore any annotations that specify deployment + information, which might be present in the class files + of the application. + + If metadata-complete is not specified or is set to + "false", the deployment tool must examine the class + files of the application for annotations, as + specified by the specifications. + + + + + + + + + + + + + + The web-resource-collectionType is used to identify a subset + of the resources and HTTP methods on those resources within + a web application to which a security constraint applies. If + no HTTP methods are specified, then the security constraint + applies to all HTTP methods. + + Used in: security-constraint + + + + + + + + + + The web-resource-name contains the name of this web + resource collection. + + + + + + + + + + + + + + + + + + The welcome-file-list contains an ordered list of welcome + files elements. + + Used in: web-app + + + + + + + + + + The welcome-file element contains file name to use + as a default welcome file, such as index.html + + + + + + + + + + diff --git a/xml/tests/testData/index/web-app_3_0.xsd b/xml/tests/testData/index/web-app_3_0.xsd new file mode 100644 index 000000000000..bbcdf43cd3ab --- /dev/null +++ b/xml/tests/testData/index/web-app_3_0.xsd @@ -0,0 +1,272 @@ + + + + + + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + + Copyright 2003-2009 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 + https://glassfish.dev.java.net/public/CDDL+GPL.html or + glassfish/bootstrap/legal/LICENSE.txt. 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 + glassfish/bootstrap/legal/LICENSE.txt. 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): + + 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 + don't 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. + + + + + + + + ... + + + The instance documents may indicate the published version of + the schema using the xsi:schemaLocation attribute for Java EE + namespace with the following location: + + http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd + + ]]> + + + + + + + The following conventions apply to all Java EE + deployment descriptor elements unless indicated otherwise. + + - In elements that specify a pathname to a file within the + same JAR file, relative filenames (i.e., those not + starting with "/") are considered relative to the root of + the JAR file's namespace. Absolute filenames (i.e., those + starting with "/") also specify names in the root of the + JAR file's namespace. In general, relative names are + preferred. The exception is .war files where absolute + names are preferred for consistency with the Servlet API. + + + + + + + + + + + + + + The web-app element is the root of the deployment + descriptor for a web application. Note that the sub-elements + of this element can be in the arbitrary order. Because of + that, the multiplicity of the elements of distributable, + session-config, welcome-file-list, jsp-config, login-config, + and locale-encoding-mapping-list was changed from "?" to "*" + in this schema. However, the deployment descriptor instance + file must not contain multiple elements of session-config, + jsp-config, and login-config. When there are multiple elements of + welcome-file-list or locale-encoding-mapping-list, the container + must concatenate the element contents. The multiple occurence + of the element distributable is redundant and the container + treats that case exactly in the same way when there is only + one distributable. + + + + + + + + The servlet element contains the name of a servlet. + The name must be unique within the web application. + + + + + + + + + + + The filter element contains the name of a filter. + The name must be unique within the web application. + + + + + + + + + + + The ejb-local-ref-name element contains the name of an EJB + reference. The EJB reference is an entry in the web + application's environment and is relative to the + java:comp/env context. The name must be unique within + the web application. + + It is recommended that name is prefixed with "ejb/". + + + + + + + + + + + The ejb-ref-name element contains the name of an EJB + reference. The EJB reference is an entry in the web + application's environment and is relative to the + java:comp/env context. The name must be unique within + the web application. + + It is recommended that name is prefixed with "ejb/". + + + + + + + + + + + The resource-env-ref-name element specifies the name of + a resource environment reference; its value is the + environment entry name used in the web application code. + The name is a JNDI name relative to the java:comp/env + context and must be unique within a web application. + + + + + + + + + + + The message-destination-ref-name element specifies the name of + a message destination reference; its value is the + environment entry name used in the web application code. + The name is a JNDI name relative to the java:comp/env + context and must be unique within a web application. + + + + + + + + + + + The res-ref-name element specifies the name of a + resource manager connection factory reference. The name + is a JNDI name relative to the java:comp/env context. + The name must be unique within a web application. + + + + + + + + + + + The env-entry-name element contains the name of a web + application's environment entry. The name is a JNDI + name relative to the java:comp/env context. The name + must be unique within a web application. + + + + + + + + + + + A role-name-key is specified to allow the references + from the security-role-refs. + + + + + + + + + + + The keyref indicates the references from + security-role-ref to a specified role-name. + + + + + + + + + diff --git a/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix.xml b/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix.xml index 914c11d91f62..35ad230ec04f 100644 --- a/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix.xml +++ b/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix2.xml b/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix2.xml index 4d315d4ed5b3..2d04020a05a4 100644 --- a/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix2.xml +++ b/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix2.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix2_after.xml b/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix2_after.xml index d148dabdd660..5c90f8ae5a80 100644 --- a/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix2_after.xml +++ b/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix2_after.xml @@ -1,4 +1,4 @@ \ No newline at end of file + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"/> \ No newline at end of file diff --git a/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix_after.xml b/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix_after.xml index 66c517712815..ac13da938f3f 100644 --- a/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix_after.xml +++ b/xml/tests/testData/xml/SpecifyXsiSchemaLocationQuickFix_after.xml @@ -1,3 +1,3 @@ - \ No newline at end of file