
com.stormpath.sdk.servlet.io.ServletContextResource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stormpath-sdk-servlet Show documentation
Show all versions of stormpath-sdk-servlet Show documentation
Servlet-specific additions allowing one to more easily deploy the Stormpath SDK in a servlet-container-based
web application.
The newest version!
/*
* Copyright 2015 Stormpath, Inc.
*
* 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.stormpath.sdk.servlet.io;
import com.stormpath.sdk.impl.io.AbstractResource;
import com.stormpath.sdk.lang.Assert;
import javax.servlet.ServletContext;
import java.io.IOException;
import java.io.InputStream;
/**
* @since 1.0.RC3
*/
public class ServletContextResource extends AbstractResource {
public static final String SCHEME = "servletContext";
private final ServletContext servletContext;
public ServletContextResource(String location, ServletContext servletContext) {
super(qualify(location));
Assert.notNull(servletContext, "servletContext argument cannot be null.");
this.servletContext = servletContext;
}
@Override
protected String canonicalize(String input) {
return qualify(super.canonicalize(input));
}
private static String qualify(String location) {
if (location != null && !location.startsWith("/")) {
return "/" + location;
}
return location;
}
@Override
protected String getScheme() {
return SCHEME;
}
@Override
public InputStream getInputStream() throws IOException {
return servletContext.getResourceAsStream(getLocation());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy