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

org.apache.myfaces.custom.stylesheet.TextResourceFilterProvider Maven / Gradle / Ivy

Go to download

JSF components and utilities that can be used with any JSF implementation. This library is based on the JSF1.1 version of Tomahawk, but with minor source code and build changes to take advantage of JSF2.1 features. A JSF2.1 implementation is required to use this version of the Tomahawk library.

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.apache.myfaces.custom.stylesheet;

import org.apache.myfaces.renderkit.html.util.ResourceProvider;

import javax.servlet.ServletContext;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Allow URLs to return data that is cached by the TextResourceFilter class.
 * 

* This implements the Tomahawk ResourceProvider interface which works together * with the Tomahawk AddResourceFactory, ExtensionsFilter and AddResource classes. * The AddResourceFactory can generate a URL which can be embedded in an HTML page. * When invoked, that URL triggers the ExtensionsFilter which invokes AddResource * which then calls back into this class. And this class then retrieves the * requested data from the TextResourceFilter. */ public class TextResourceFilterProvider implements ResourceProvider { // Hack note: a slash has to be prefixed to the resource value here because // we are abusing the AddResource API in StylesheetRenderer; see comments // in StylesheetRenderer.encodeEnd for details. public boolean exists(ServletContext context, String resource) { resource = "/" + resource; // hack return TextResourceFilter.getInstance(context).getFilteredResource(resource) != null; } public int getContentLength(ServletContext context, String resource) throws IOException { resource = "/" + resource; // hack return TextResourceFilter.getInstance(context).getFilteredResource(resource).getSize(); } public long getLastModified(ServletContext context, String resource) throws IOException { resource = "/" + resource; // hack return TextResourceFilter.getInstance(context).getFilteredResource(resource).getLastModified(); } public InputStream getInputStream(ServletContext context, String resource) throws IOException { resource = "/" + resource; // hack return new ByteArrayInputStream( TextResourceFilter.getInstance(context).getFilteredResource(resource).getText().getBytes( getEncoding(context, resource) )); } public String getEncoding(ServletContext context, String resource) throws IOException { return "UTF-8"; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy