private static boolean checkSchemaNamespace(String name, XmlTag context) {
   final String namespace = context.getNamespaceByPrefix(XmlUtil.findPrefixByQualifiedName(name));
   if (namespace.length() > 0) {
     return checkSchemaNamespace(namespace);
   }
   return XSD_PREFIX.equals(XmlUtil.findPrefixByQualifiedName(name));
 }
  public XmlAttributeDescriptor getAttributeDescriptor(String attributeName, final XmlTag context) {
    String caseSensitiveAttributeName =
        !myCaseSensitive ? attributeName.toLowerCase() : attributeName;
    XmlAttributeDescriptor descriptor =
        super.getAttributeDescriptor(caseSensitiveAttributeName, context);
    if (descriptor == null)
      descriptor =
          RelaxedHtmlFromSchemaElementDescriptor.getAttributeDescriptorFromFacelets(
              attributeName, context);

    if (descriptor == null) {
      String prefix = XmlUtil.findPrefixByQualifiedName(attributeName);

      if ("xml"
          .equals(
              prefix)) { // todo this is not technically correct dtd document references namespaces
                         // but we should handle it at least for xml stuff
        XmlNSDescriptor nsdescriptor = context.getNSDescriptor(XmlUtil.XML_NAMESPACE_URI, true);
        if (nsdescriptor instanceof XmlNSDescriptorImpl) {
          descriptor =
              ((XmlNSDescriptorImpl) nsdescriptor)
                  .getAttribute(
                      XmlUtil.findLocalNameByQualifiedName(caseSensitiveAttributeName),
                      XmlUtil.XML_NAMESPACE_URI,
                      context);
        }
      }
    }
    if (descriptor == null && HtmlUtil.isHtml5Context(context)) {
      descriptor = myDelegate.getAttributeDescriptor(attributeName, context);
    }
    return descriptor;
  }
Exemplo n.º 3
0
  @NotNull
  public PsiReference[] getReferences() {
    ProgressManager.checkCanceled();
    final ASTNode startTagName = XmlChildRole.START_TAG_NAME_FINDER.findChild(this);
    if (startTagName == null) return PsiReference.EMPTY_ARRAY;
    final ASTNode endTagName = XmlChildRole.CLOSING_TAG_NAME_FINDER.findChild(this);
    List<PsiReference> refs = new ArrayList<PsiReference>();
    String prefix = getNamespacePrefix();

    TagNameReference startTagRef =
        TagNameReference.createTagNameReference(this, startTagName, true);
    refs.add(startTagRef);
    if (prefix.length() > 0) {
      refs.add(createPrefixReference(startTagName, prefix, startTagRef));
    }
    if (endTagName != null) {
      TagNameReference endTagRef = TagNameReference.createTagNameReference(this, endTagName, false);
      refs.add(endTagRef);
      prefix = XmlUtil.findPrefixByQualifiedName(endTagName.getText());
      if (StringUtil.isNotEmpty(prefix)) {
        refs.add(createPrefixReference(endTagName, prefix, endTagRef));
      }
    }

    // ArrayList.addAll() makes a clone of the collection
    //noinspection ManualArrayToCollectionCopy
    for (PsiReference ref :
        ReferenceProvidersRegistry.getReferencesFromProviders(this, XmlTag.class)) {
      refs.add(ref);
    }

    return ContainerUtil.toArray(refs, new PsiReference[refs.size()]);
  }
 private boolean isCertainTypeElement(
     XmlTagImpl xml, final String typeName, final String nsPrefix) {
   if (!isTypeElement(xml)) return false;
   final XmlAttribute name = getNameAttr(xml);
   if (name == null) return false;
   final String value = name.getValue();
   if (value == null) return false;
   final String localName = XmlUtil.findLocalNameByQualifiedName(value);
   return typeName.equals(localName) && nsPrefix.equals(XmlUtil.findPrefixByQualifiedName(value));
 }
  static @NotNull XmlNSDescriptorImpl getNSDescriptorToSearchIn(
      XmlTag rootTag, final String name, XmlNSDescriptorImpl defaultNSDescriptor) {
    if (name == null) return defaultNSDescriptor;
    final String namespacePrefix = XmlUtil.findPrefixByQualifiedName(name);

    if (namespacePrefix != null && namespacePrefix.length() > 0) {
      final String namespace = rootTag.getNamespaceByPrefix(namespacePrefix);
      final XmlNSDescriptor nsDescriptor = rootTag.getNSDescriptor(namespace, true);

      if (nsDescriptor instanceof XmlNSDescriptorImpl) {
        return (XmlNSDescriptorImpl) nsDescriptor;
      }
    }

    return defaultNSDescriptor;
  }
  private boolean checkElementNameEquivalence(
      String localName, String namespace, String fqn, XmlTag context) {
    final String localAttrName = XmlUtil.findLocalNameByQualifiedName(fqn);
    if (!localAttrName.equals(localName)) return false;
    final String attrNamespace =
        context.getNamespaceByPrefix(XmlUtil.findPrefixByQualifiedName(fqn));
    if (attrNamespace.equals(namespace)) return true;

    if (myTargetNamespace == null) {
      if (XmlUtil.EMPTY_URI.equals(attrNamespace)) return true;
    } else {
      final boolean b = myTargetNamespace.equals(namespace);
      if (b) return b;
      return context.getNSDescriptor(namespace, true)
          == this; // schema's targetNamespace could be different from file systemId
    }
    return false;
  }
 public static boolean isElementWithEmbeddedType(
     XmlTagImpl xml, final String typeName, final String typeNsPrefix) {
   final String localName = xml.getLocalName();
   if (!(XmlUtil.XML_SCHEMA_URI.equals(xml.getNamespace()) && "element".equals(localName))) {
     return false;
   }
   final XmlAttribute nameAttr = getNameAttr(xml);
   if (nameAttr == null || nameAttr.getValue() == null) return false;
   final String localTypeName = XmlUtil.findLocalNameByQualifiedName(nameAttr.getValue());
   final String prefix = XmlUtil.findPrefixByQualifiedName(nameAttr.getValue());
   if (!typeName.equals(localTypeName) || !typeNsPrefix.equals(prefix)) {
     return false;
   }
   final XmlTag[] tags = xml.getSubTags();
   for (XmlTag tag : tags) {
     if (isTypeElement((XmlTagImpl) tag)) {
       return true;
     }
   }
   return false;
 }
  private static XmlTag findSpecialTagIn(
      final XmlTag[] tags,
      final String specialName,
      final String name,
      final XmlTag rootTag,
      final XmlNSDescriptorImpl descriptor,
      final HashSet<XmlTag> visited) {
    for (XmlTag tag : tags) {
      if (equalsToSchemaName(tag, specialName)) {
        String attribute = tag.getAttributeValue("name");

        if (name.equals(attribute)
            || name.indexOf(":") >= 0 && name.substring(name.indexOf(":") + 1).equals(attribute)) {
          return tag;
        }
      } else if (equalsToSchemaName(tag, INCLUDE_TAG_NAME)
          || (equalsToSchemaName(tag, IMPORT_TAG_NAME)
              && rootTag
                  .getNamespaceByPrefix(XmlUtil.findPrefixByQualifiedName(name))
                  .equals(tag.getAttributeValue("namespace")))) {
        final String schemaLocation = tag.getAttributeValue("schemaLocation");

        if (schemaLocation != null) {
          final XmlFile xmlFile =
              XmlUtil.findNamespaceByLocation(rootTag.getContainingFile(), schemaLocation);

          if (xmlFile != null) {
            final XmlDocument document = xmlFile.getDocument();
            if (document != null) {
              final XmlTag rTag =
                  findSpecialTag(name, specialName, document.getRootTag(), descriptor, visited);

              if (rTag != null) return rTag;
            }
          }
        }
      } else if (equalsToSchemaName(tag, REDEFINE_TAG_NAME)) {
        XmlTag rTag =
            findSpecialTagIn(tag.getSubTags(), specialName, name, rootTag, descriptor, visited);
        if (rTag != null) return rTag;

        final XmlNSDescriptorImpl nsDescriptor = getRedefinedElementDescriptor(tag);
        if (nsDescriptor != null) {
          final XmlTag redefinedRootTag =
              ((XmlDocument) nsDescriptor.getDeclaration()).getRootTag();

          rTag =
              findSpecialTagIn(
                  redefinedRootTag.getSubTags(),
                  specialName,
                  name,
                  redefinedRootTag,
                  nsDescriptor,
                  visited);
          if (rTag != null) return rTag;
        }
      }
    }

    return null;
  }
 @Nullable
 protected TypeDescriptor findTypeDescriptor(final String qname, XmlTag context) {
   String namespace = context.getNamespaceByPrefix(XmlUtil.findPrefixByQualifiedName(qname));
   return findTypeDescriptor(XmlUtil.findLocalNameByQualifiedName(qname), namespace);
 }
Exemplo n.º 10
0
 @NotNull
 public String getNamespacePrefix() {
   return XmlUtil.findPrefixByQualifiedName(getName());
 }