preconfiguredresource.java
来自「ajax patterns 这是关于ajax设计模式方面的原代码」· Java 代码 · 共 74 行
JAVA
74 行
/*
Copyright 2006 Christian Gross http://www.devspace.com
From the book Ajax Patterns and Best Practices
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 devspace.ajax.permutations.implementations;
import devspace.ajax.permutations.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.util.*;
import devspace.testDrivenDevelopment.tracer.*;
public class PreConfiguredResource extends ResourceRewriterBase< HttpServletRequest, HttpServletResponse, FilterChain> {
private HashSet< String> _handlerIdentifiers = new HashSet< String>();
public PreConfiguredResource() {
_handlerIdentifiers.add( "/persistentcommunications/globalstatus");
_handlerIdentifiers.add( "/persistentcommunications/globalpresence");
_handlerIdentifiers.add( "/persistentcommunications/globalserverpush");
_handlerIdentifiers.add( "/restmvc/dotranslation");
_handlerIdentifiers.add( "/cachecontroller/etagexample1");
_handlerIdentifiers.add( "/cachecontroller/etagexample2");
_handlerIdentifiers.add( "/decouplednavigation/convertcase");
_handlerIdentifiers.add( "/infinitedata/primenumbercalculator");
_handlerIdentifiers.add( "/logging/message");
}
public boolean isResource(HttpServletRequest request) {
String uri = request.getRequestURI();
if( _handlerIdentifiers.contains( uri)) {
GenerateOutput.Write( "PreConfiguredResource.IsResource", "Found a handler (" + uri + ")");
return true;
}
else if( uri.compareTo( "/") == 0) {
GenerateOutput.Write( "PreConfiguredResource.IsResource", "Found the root handler (" + uri + ")");
return true;
}
else {
for( String handlerURI: _handlerIdentifiers) {
if( uri.indexOf( handlerURI) != -1) {
GenerateOutput.Write( "PreConfiguredResource.IsResource", "Found a handler (" + uri + ") for (" + handlerURI + ")");
return true;
}
}
}
GenerateOutput.Write( "PreConfiguredResource.IsResource", "Delegating path (" + uri + ")");
return false;
}
public void writeRepresentation(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
if( request.getRequestURI().compareTo( "/") == 0) {
GenerateOutput.Write( "PreConfiguredResource.writeRepresentation", "Handling root request");
RequestDispatcher dispatcher = request.getRequestDispatcher( "/index.jsp");
dispatcher.forward( request, response);
}
else {
GenerateOutput.Write( "PreConfiguredResource.writeRepresentation", "Handling request");
chain.doFilter( request, response);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?