Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 78c7802e821dee40c4f37281de4fa6c3d7c2365d (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*******************************************************************************
 * Copyright (c) 2007 Oracle Corporation.
 * 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:
 *    Oracle - initial API and implementation
 *    
 ********************************************************************************/
package org.eclipse.jst.pagedesigner.jsp.core.internal.metadata;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.jst.jsf.common.metadata.internal.AbstractMetaDataLocator;
import org.eclipse.jst.jsf.common.metadata.internal.IMetaDataLocator;
import org.eclipse.jst.jsf.common.metadata.internal.IMetaDataSourceModelProvider;
import org.eclipse.jst.jsf.common.metadata.internal.IPathSensitiveMetaDataLocator;
import org.eclipse.jst.jsp.core.internal.contentmodel.tld.CMDocumentFactoryTLD;
import org.eclipse.jst.jsp.core.taglib.ITaglibRecord;
import org.eclipse.jst.jsp.core.taglib.TaglibIndex;
import org.eclipse.wst.html.core.internal.contentmodel.HTMLCMDocumentFactory;
import org.eclipse.wst.xml.core.internal.contentmodel.CMDocument;
import org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMDocType;

/**
 * Locator of tag library meta data
 *
 */
public class TaglibMetaDataLocator extends AbstractMetaDataLocator implements IPathSensitiveMetaDataLocator{
	//project must be set to the current project context during locate only...  should not be used when noifying observers
	private IProject project;
	private TaglibMetaDataSource source;
	
	/**
	 * Constructor
	 */
	public TaglibMetaDataLocator(){
		super();
	}
	
	public List/*<IMetaDataModelProvider>*/ locateMetaDataModelProviders(String uri) {
		List ret = new ArrayList();
		CMDocument doc = null;

		if (uri == null){
			return ret;
		}
		else if (uri.equalsIgnoreCase(CMDocType.HTML_DOC_TYPE)){
			doc = HTMLCMDocumentFactory.getCMDocument(CMDocType.HTML_DOC_TYPE);
		}
		else if (uri.equalsIgnoreCase(CMDocType.JSP11_DOC_TYPE)){
			doc = HTMLCMDocumentFactory.getCMDocument(CMDocType.JSP11_DOC_TYPE);
		}
		else if (uri.equalsIgnoreCase(CMDocType.JSP12_DOC_TYPE)){
			doc = HTMLCMDocumentFactory.getCMDocument(CMDocType.JSP12_DOC_TYPE);
		}
		else if (uri.equalsIgnoreCase(CMDocType.JSP20_DOC_TYPE)){
			doc = HTMLCMDocumentFactory.getCMDocument(CMDocType.JSP20_DOC_TYPE);
		}
		else if (project != null ){//TLD
			CMDocumentFactoryTLD factory = new CMDocumentFactoryTLD();
			ITaglibRecord[] tldRecs = TaglibIndex.getAvailableTaglibRecords(project.getFullPath());
			ITaglibRecord tldRec = findTLD(tldRecs, uri);
			if (tldRec != null)
				doc = factory.createCMDocument(tldRec);
		}
		
		if (doc != null){
			source = new TaglibMetaDataSource(doc);
			ret.add(source);
		}
				
		return ret;
	}

	private ITaglibRecord findTLD(ITaglibRecord[] tldRecs, String uri) {
		for (int i=0;i<tldRecs.length;i++){
			ITaglibRecord tld = tldRecs[i];
			if (uri.equals(tld.getDescriptor().getURI()))
				return tld;
		}
		return null;
	}

	public void startLocating() {
//		TaglibIndex.addTaglibIndexListener(this);
	}
	public void stopLocating() {		
//		TaglibIndex.removeTaglibIndexListener(this);//non-api call.... danger
	}
	
	//not currently listening, so will not be called
//	public void indexChanged(ITaglibDescriptor event) {
//		if (event.getURI() != null && event.getURI().equals(uri)){
//			if (!_notificationEventOccuring){
//				_notificationEventOccuring = true;
//				int type = adaptTagLibEvent(event);
//				IMetaDataChangeNotificationEvent mdEvent = new MetaDataChangeNotificationEvent(this, uri, type);
//				fireEvent(mdEvent);						
//				_notificationEventOccuring = false;
//			}
//		}
//	}

//	private int adaptTagLibEvent(ITaglibRecordEvent event) {
//		switch (event.getType()){
//		case ITaglibRecordEvent.ADDED:
//			return IMetaDataChangeNotificationEvent.ADDED;
//		case ITaglibRecordEvent.REMOVED:
//			return IMetaDataChangeNotificationEvent.REMOVED;
//		default:
//			return IMetaDataChangeNotificationEvent.CHANGED;
//		}		
//	}

//	private void fireEvent(final IMetaDataChangeNotificationEvent event) {
//		SafeRunnable.run(new ISafeRunnable(){
//
//			public void handleException(Throwable exception) {
//				// TODO Auto-generated method stub				
//			}
//
//			public void run() throws Exception {
//				Iterator it = getObservers().iterator();
//				while (it.hasNext()){
//					IMetaDataObserver observer = (IMetaDataObserver)it.next();
//					observer.notifyMetadataChanged(event);
//				}
//			}
//
//		});
//		
//	}

	public void setProjectContext(IProject project) {
		this.project = project;		
	}
	
	private class TaglibMetaDataSource implements IMetaDataSourceModelProvider{

		private CMDocument doc;
		private IMetaDataLocator locator;

		TaglibMetaDataSource(CMDocument doc){
			super();
			this.doc = doc;
		}
		
		public Object getSourceModel() {
			return doc;
		}

		public IMetaDataLocator getLocator() {
			return locator;
		}

		public void setLocator(IMetaDataLocator locator) {
			this.locator = locator;			
		}

		public Object getAdapter(Class klass) {
			return null;
		}
	}

}

Back to the top