コード例 #1
0
 /**
  * Returns the namespace prefix for the given URI.
  *
  * @param doc document object model of the XML source file
  * @param namespaceUri namespace URI to examine
  * @return namespace prefix for the given URI
  */
 public static String getPrefixForNamespaceUri(IDOMDocument doc, String namespaceUri) {
   if (doc != null && namespaceUri != null) {
     NamespaceTable table = new NamespaceTable(doc);
     Element elem = doc.getDocumentElement();
     table.addElementLineage(elem);
     return table.getPrefixForURI(namespaceUri);
   }
   return null;
 }
コード例 #2
0
 protected CMElementDeclaration getDerivedCMElementDeclaration(
     Element element, CMElementDeclaration ed, NamespaceTable namespaceTable) {
   CMElementDeclaration result = null;
   String xsiPrefix =
       namespaceTable.getPrefixForURI("http://www.w3.org/2001/XMLSchema-instance"); // $NON-NLS-1$
   if (xsiPrefix != null) {
     String xsiTypeValue = element.getAttribute(xsiPrefix + ":type"); // $NON-NLS-1$
     if (xsiTypeValue != null && xsiTypeValue.length() > 0) {
       String typePrefix = DOMNamespaceHelper.getPrefix(xsiTypeValue);
       String typeName = DOMNamespaceHelper.getUnprefixedName(xsiTypeValue);
       String typeURI = namespaceTable.getURIForPrefix(typePrefix);
       String uriQualifiedTypeName = typeName;
       if (typeURI != null && typeURI.length() > 0) {
         uriQualifiedTypeName = "[" + typeURI + "]" + typeName; // $NON-NLS-1$ //$NON-NLS-2$
       }
       result =
           (CMElementDeclaration)
               ed.getProperty("DerivedElementDeclaration=" + uriQualifiedTypeName); // $NON-NLS-1$
       if (result == null) {
         String reference = null;
         NamespaceInfo namespaceInfo = namespaceTable.getNamespaceInfoForPrefix(typePrefix);
         if (namespaceInfo != null) {
           String locationHint =
               resolveGrammarURI(
                   element.getOwnerDocument(), namespaceInfo.uri, namespaceInfo.locationHint);
           if (locationHint != null) {
             reference = "[" + locationHint + "]" + typeName; // $NON-NLS-1$ //$NON-NLS-2$
           }
         }
         if (reference != null) {
           result =
               (CMElementDeclaration)
                   ed.getProperty(
                       "ExternallyDerivedElementDeclaration=" + reference); // $NON-NLS-1$
         }
       }
     }
   }
   return result;
 }