Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 61e6631bb3a5315cd011ae565266de65eb1f950d (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
package org.eclipse.wst.xml.core.internal.catalog;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalog;
import org.eclipse.wst.xml.core.internal.catalog.provisional.ICatalogElement;


public class CatalogElement implements ICatalogElement
{
	int type;

	String id;

	Map attributes = new HashMap();

	ICatalog ownerCatalog;

	public CatalogElement(int aType)
	{
		super();
		type = aType;
	}

	public int getType()
	{
		return type;
	}

	public String getAttributeValue(String name)
	{
		return (String) attributes.get(name);
	}

	public void setAttributeValue(String name, String value)
	{
		attributes.put(name, value);
	}

	public String[] getAttributes()
	{
		Collection c = attributes.values();
		String[] result = new String[c.size()];
		attributes.keySet().toArray(result);
		return result;
	}

	public String getId()
	{
		return id;
	}

	public void setId(String id)
	{
		this.id = id;
	}

	public ICatalog getOwnerCatalog()
	{
		return ownerCatalog;
	}

	public void setOwnerCatalog(ICatalog catalog)
	{
		this.ownerCatalog = catalog;
	}

	protected static String makeAbsolute(String baseLocation, String location)
	{
		URL local = null;
		location = location.replace('\\', '/');
		try
		{
			URL baseURL = new URL(baseLocation);
			local = new URL(baseURL, location);
		} catch (MalformedURLException e)
		{
		}

		if (local != null)
		{
			return local.toString();
		} else
		{
			return location;
		}
	}

	public String getAbsolutePath(String path)
	{
		try
		{
			URI uri = new URI(path);
			if (uri.isAbsolute())
			{
				return path;
			}
		} catch (URISyntaxException e)
		{
		}

		String result = path;
		Catalog catalog = (Catalog) getOwnerCatalog();
		if (catalog != null)
		{
			String base = catalog.getBase();
			if (base == null || base.equals("")) //$NON-NLS-1$
			{
				base = catalog.getLocation();
			}
			result = makeAbsolute(base, path);
		}
		return result;
	}
	
	  /*
	   * Since we don't have events notifications for entry properties, clone()
	   * could allow to copy and edit entry and then replace it in catalog. Entry
	   * replacement will signal ICatalogEvent @return
	   */
	  public Object clone()
	  {
		ICatalogElement element = ownerCatalog.createCatalogElement(type);
	    String[] attributes = getAttributes();   
	    for (int i = 0; i < attributes.length; i++)
	    {
	      String attrName = attributes[i];
	      String attrValue = getAttributeValue(attrName);
	      element.setAttributeValue(attrName, attrValue);
	    }
		element.setOwnerCatalog(ownerCatalog);
		element.setId(id);
	    return element;
	  }

	
}

Back to the top