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: 35c131dbd365f166689af18dce4a3208d49f0620 (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
/***********************************************************************
 * Copyright (c) 2008 by SAP AG, Walldorf. 
 * 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:
 *     SAP AG - initial API and implementation
 ***********************************************************************/
package org.eclipse.jst.jee.ui.internal.navigator.web;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin;
import org.eclipse.jst.javaee.core.UrlPatternType;
import org.eclipse.jst.javaee.web.FilterMapping;
import org.eclipse.jst.javaee.web.WebApp;
import org.eclipse.jst.jee.ui.internal.Messages;
import org.eclipse.jst.jee.ui.plugin.JEEUIPluginIcons;
import org.eclipse.swt.graphics.Image;

/**
 * Filter mappings group in Deployment Descriptor node. 
 * 
 * @author Dimitar Giormov
 *
 */
public class GroupFilterMappingItemProvider extends AbstractWebGroupProvider {

	private static Image FILTER_MAPPING;

	public GroupFilterMappingItemProvider(WebApp webApp) {
		super(webApp);
		text = Messages.FILTER_MAPPING_ITEM_PROVIDER;
	}

	@Override
	public List<?> getChildren() {
		if (javaee != null){
			return flattenMapping(((WebApp) javaee).getFilterMappings());
		}
		return null;
	}

	private List<?> flattenMapping(List<FilterMapping> filterMappings) {
		List<FilterMappingUIWrapper> result = new ArrayList<FilterMappingUIWrapper>();
		if (filterMappings != null && filterMappings.size() > 0){
			for (FilterMapping filterMapping : filterMappings) {
				result.addAll(getFilterMappingDisplay(filterMapping));
			}
		}
		return result;
	}

	@Override
	public Image getImage() {
		return getFilterMappingImage();
	}

	@Override
	public boolean hasChildren() {
		return !getChildren().isEmpty();
	}

	public static Image getFilterMappingImage() {
		if (FILTER_MAPPING == null) {
			URL url = (URL) J2EEPlugin.getPlugin().getImage(JEEUIPluginIcons.GROUP_FILTER_MAPPING);
			ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(url); 
			FILTER_MAPPING = imageDescriptor.createImage();
		}
		return FILTER_MAPPING;
	}
	
	private List<FilterMappingUIWrapper> getFilterMappingDisplay(FilterMapping element) {
		List<FilterMappingUIWrapper> result = new ArrayList<FilterMappingUIWrapper>();
		String value = null;
		if (element.getUrlPatterns().size() > 0){
			for (UrlPatternType pattern : element.getUrlPatterns()) {
				value = pattern.getValue();
				result.add(new FilterMappingUIWrapper(value + " -> " + element.getFilterName())); //$NON-NLS-1$
			}
			
		}
		return result;
	}
	
	public class FilterMappingUIWrapper {
		private String value;

		public String getValue() {
			return value;
		}

		public FilterMappingUIWrapper(String value) {
			super();
			this.value = value;
		}
	}


}

Back to the top