All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.wesleyhome.johksoftware.resource.JarResourceEvaluator Maven / Gradle / Ivy

/*
 * Copyright 2011 JOHK Software
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.wesleyhome.johksoftware.resource;

import java.net.MalformedURLException;
import java.net.URL;

import com.wesleyhome.johksoftware.resource.api.ClassResourceLoader;
import com.wesleyhome.johksoftware.resource.api.ResourceEvaluator;

/**
 * @author Justin Wesley
 * @since 1.0.0
 *
 */
public class JarResourceEvaluator implements ResourceEvaluator {

	/* (non-Javadoc)
	 * @see com.wesleyhome.johksoftware.resource.ResourceEvaluator#canLoad(java.net.URL)
	 */
	@Override
	public boolean canLoad(final URL systemResource) {
		return JarResourceLoader.JAR_PROTOCOL.equalsIgnoreCase(systemResource.getProtocol());
	}

	/* (non-Javadoc)
	 * @see com.wesleyhome.johksoftware.resource.ResourceEvaluator#getLoader(java.net.URL, java.lang.String)
	 */
	@Override
	public ClassResourceLoader getLoader(final URL systemResource, final String resourceName) {
		try {
			String resourceFileName = systemResource.getFile();
			String[] splits = resourceFileName.split("!");
			return new JarResourceLoader(new URL(splits[0]));
		} catch (MalformedURLException e) {
			throw new RuntimeException(e);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy