コード例 #1
0
 protected CMElementDeclaration checkExternalSchema(Element element) {
   final Document document = element.getOwnerDocument();
   if (document instanceof IDOMDocument) {
     final String baseLocation = ((IDOMDocument) document).getModel().getBaseLocation();
     if (baseLocation != null) {
       final IPath basePath = new Path(baseLocation);
       IFile file = null;
       if (basePath.segmentCount() > 1) {
         file = ResourcesPlugin.getWorkspace().getRoot().getFile(basePath);
       }
       final URI uri =
           (file == null || !file.isAccessible())
               ? new File(baseLocation).toURI()
               : file.getLocationURI();
       if (uri != null) {
         IExternalSchemaLocationProvider[] providers =
             ExternalSchemaLocationProviderRegistry.getInstance().getProviders();
         for (int i = 0; i < providers.length; i++) {
           long time = _trace ? System.currentTimeMillis() : 0;
           final Map locations = providers[i].getExternalSchemaLocation(uri);
           if (_trace) {
             long diff = System.currentTimeMillis() - time;
             if (diff > 250)
               Logger.log(
                   Logger.INFO,
                   "Schema location provider took ["
                       + diff
                       + "ms] for URI ["
                       + uri
                       + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
           }
           if (locations != null && !locations.isEmpty()) {
             Object location =
                 locations.get(IExternalSchemaLocationProvider.NO_NAMESPACE_SCHEMA_LOCATION);
             if (location != null)
               return getCMElementDeclaration(
                   element,
                   NamespaceTable.getElementLineage(element),
                   uri.toString(),
                   location.toString());
           }
         }
       }
     }
   }
   return null;
 }
 public String[] getPrefix() {
   if (fPrefix == null) {
     if (fElement != null) {
       if (isCustom()) { // custom
         IConfigurationElement[] prefixes = fElement.getChildren("startwith"); // $NON-NLS-1$
         if (prefixes != null) {
           List prefixValues = new ArrayList(prefixes.length);
           for (int i = 0; i < prefixes.length; i++) {
             String prefix = prefixes[i].getAttribute("prefix"); // $NON-NLS-1$
             if (prefix != null) {
               prefixValues.add(prefix);
             } else {
               try {
                 Logger.log(
                     Logger.WARNING,
                     "misconfigured comment element in" + fElement.getContributor().getName(),
                     new IllegalArgumentException("startwith")); // $NON-NLS-1$ //$NON-NLS-2$
               } catch (InvalidRegistryObjectException e) {
                 // stale bundle?
               }
             }
           }
           if (!prefixValues.isEmpty()) {
             fPrefix = (String[]) prefixValues.toArray(new String[prefixValues.size()]);
           }
         }
       } else { // basic
         String name = getProperty("elementname"); // $NON-NLS-1$
         if (name != null) {
           if (isEmpty()) {
             fPrefix = new String[1];
             fPrefix[0] = name;
           } else {
             fPrefix = new String[2];
             fPrefix[0] = name;
             fPrefix[1] = '/' + name;
           }
         }
       }
     }
   }
   if (fPrefix == null) {
     fPrefix = new String[0];
   }
   return fPrefix;
 }