Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 6c8b1936043c4172ef9720f4dde7955bb2d34bf0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************************
 * Copyright (c) 2002, 2006 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     Jens Lukowski/Innoopract - initial renaming/restructuring
 *     
 *******************************************************************************/
package org.eclipse.wst.xml.core.internal.contentmodel.factory;

import com.ibm.icu.util.StringTokenizer;

import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.wst.xml.core.internal.Logger;




public class CMDocumentFactoryRegistryReader
{
  protected static final String EXTENSION_POINT_ID = "documentFactories"; //$NON-NLS-1$
  protected static final String TAG_NAME = "factory"; //$NON-NLS-1$
  protected static final String ATT_CLASS = "class"; //$NON-NLS-1$
  protected static final String ATT_TYPE = "type";   //$NON-NLS-1$
  protected String pluginId, extensionPointId;
  
  protected CMDocumentFactoryRegistry registry;
  
  public CMDocumentFactoryRegistryReader(CMDocumentFactoryRegistry registry)
  {
  	this.registry = registry;
  }

  public void readRegistry()
  {
    String bundleid = "org.eclipse.wst.xml.core"; //$NON-NLS-1$
    IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(bundleid, EXTENSION_POINT_ID);
    if (point != null)
    {
      IConfigurationElement[] elements = point.getConfigurationElements();
      for (int i = 0; i < elements.length; i++)
      {
        readElement(elements[i]);
      }
    }
  }

  protected void readElement(IConfigurationElement element)
  {
    if (element.getName().equals(TAG_NAME))
    {
      String factoryClass = element.getAttribute(ATT_CLASS);
      String filenameExtensions = element.getAttribute(ATT_TYPE);
      if (factoryClass != null && filenameExtensions != null)
      {
        try
        {
          CMDocumentFactoryDescriptor descriptor = new CMDocumentFactoryDescriptor(element);
          for (StringTokenizer st = new StringTokenizer(filenameExtensions, ","); st.hasMoreTokens(); ) //$NON-NLS-1$
          {
          	String token = st.nextToken().trim();
			registry.putFactory(token, descriptor);	
          }         
        }
        catch (Exception e)
        {
			Logger.logException(e);
        }
      }
    }
  }
}

Back to the top