001/* 002 * Copyright 2018 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.core.ui.resources.css; 017 018import java.net.URISyntaxException; 019import java.util.regex.Matcher; 020import java.util.regex.Pattern; 021 022/** 023 * JSASS Resource URI for workspaces URI 024 */ 025public class WorkspacesJSASSResourceURI implements JSASSResourceURI 026{ 027 private static final Pattern URI_SUPPORTED_PATTERN = Pattern.compile("^workspace:([^:]+)://(.*)$"); 028 private static final Pattern PATH_SUPPORTED_PATTERN = Pattern.compile("^/_([^/]+)/(.*)$"); 029 030 @Override 031 public String resolve(String uri) throws URISyntaxException 032 { 033 Matcher matcher = URI_SUPPORTED_PATTERN.matcher(uri); 034 if (matcher.matches()) 035 { 036 String target = matcher.group(1); 037 String path = matcher.group(2); 038 039 StringBuilder relativeSb = new StringBuilder(); 040 relativeSb.append("/_"); 041 relativeSb.append(target); 042 relativeSb.append("/"); 043 relativeSb.append(path); 044 045 return relativeSb.toString(); 046 } 047 return null; 048 } 049 050 @Override 051 public String resolvePath(String path) 052 { 053 Matcher matcher = PATH_SUPPORTED_PATTERN.matcher(path); 054 if (matcher.matches()) 055 { 056 StringBuilder uri = new StringBuilder(); 057 uri.append("workspace:"); 058 uri.append(matcher.group(1)); 059 uri.append("://"); 060 uri.append(matcher.group(2)); 061 return uri.toString(); 062 } 063 return null; 064 } 065 066}