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: cf5a62c5c7e55421924fa5b43d2d57658875e45f (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
package org.eclipse.wst.xml.ui.internal.catalog;

import org.eclipse.wst.common.uriresolver.internal.util.URIHelper;

public class URIUtils {
	
	  private static final String PROTOCOL_PATTERN = ":"; 
	  private static final String FILE_PROTOCOL = "file:";
	  private static final String PLATFORM_RESOURCE_PROTOCOL = "platform:/resource/";
	  private static final String LOCAL_FILE_PROTOCOL_FORWARD_SLASH = "\\\\\\";
	  private static final String LOCAL_FILE_PROTOCOL_BACK_SLASH = "///";
	  private static final char   PATH_SEPARATOR_FORWARD_SLASH = '/';
	  private static final char   PATH_SEPARATOR_BACK_SLASH = '\\';
	  
	  public static String convertURIToLocation(String uri) {
			String location = uri;
			if (uri != null) {
				if (uri.startsWith(FILE_PROTOCOL)) {
					location = org.eclipse.wst.common.uriresolver.internal.URI.createURI(uri).toFileString();
					if (location != null && (location.startsWith(LOCAL_FILE_PROTOCOL_BACK_SLASH)
							|| location.startsWith(LOCAL_FILE_PROTOCOL_FORWARD_SLASH))) {
						location = location.substring(LOCAL_FILE_PROTOCOL_BACK_SLASH.length());
					}
				} else if (uri.startsWith(PLATFORM_RESOURCE_PROTOCOL)) {
					location = uri.substring(PLATFORM_RESOURCE_PROTOCOL.length());
				}
			}
		return location;
	  }
	  
	  public static String convertLocationToURI(String location) {
		  String uri = location;
			if (!URIHelper.hasProtocol(location)) {
				uri = URIHelper.isAbsolute(location)? org.eclipse.wst.common.uriresolver.internal.URI.createFileURI(location).toString()
						: URIHelper.prependPlatformResourceProtocol(location);
			}
			if (uri.startsWith(FILE_PROTOCOL) && uri.indexOf(PROTOCOL_PATTERN, FILE_PROTOCOL.length()) != -1) {
				uri = URIHelper.ensureFileURIProtocolFormat(uri);
			}
			uri = uri.replace(PATH_SEPARATOR_BACK_SLASH, PATH_SEPARATOR_FORWARD_SLASH);
			return uri;
	  }

}

Back to the top