
org.nbnResolving.views.BaseView Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resolver-core Show documentation
Show all versions of resolver-core Show documentation
Java classes providing resolving functionality for Persistent Identifiers.
Main focus is on National Bibliography Numbers, but some other known systems are also supported.
See the official URN:NBN Resolver http://nbn-resolving.org or http://persid.org
The newest version!
/* *********************************************************************
* Abstract Class BaseView
*
* Copyright (c) 2011-2012, German National Library/Deutsche Nationalbibliothek
* Adickesallee 1, D-60322 Frankfurt am Main, Federal Republic of Germany
*
* This program is free 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.
*
* Thomas Haidlas -- German National Library
* Kadir Karaca Kocer -- German National Library
**********************************************************************/
/* ********************************************************************
* CHANGELOG:
*
* 2012-04-03 Port to Maven by Timo Heck & Karaca Kocer
* Created on 2011-12-12 by Karaca Kocer
********************************************************************/
package org.nbnResolving.views;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.view.AbstractView;
/**
* Abstract Class to unify the HTTP-Header/Cache Setting-Code for all used
* different views.
* See HTTP 1.1 specification for details.
*
* @see org.springframework.web.servlet.view.AbstractView
* @see javax.servlet.http.HttpServletResponse
* {@link "http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html"}
* @author Kadir Karaca Kocer, German National Library
*/
public abstract class BaseView extends AbstractView {
protected String ENCODING = "UTF-8" ; //default encoding UTF-8 should be used if not overwritten
protected int cacheIntervall = 15; //Max Age of cache in minutes. Default 15 minutes
//protected String server = "";
@Override
protected void prepareResponse(HttpServletRequest request, HttpServletResponse response) {
response.setContentType(getContentType());
response.setCharacterEncoding(getENCODING());
long now = System.currentTimeMillis();
response.addDateHeader("Date", now);
response.addDateHeader("Last-Modified", now);
if (this.cacheIntervall < 1) {
response.addHeader("Pragma", "no-cache");
response.addHeader("Cache-Control", "no-cache, no-store, max-age=0");
response.addDateHeader("Expires", 1L);
} else {
//write Cache
response.addHeader("Cache-Control", "public, max-age=" + getCacheIntervall() * 60); //seconds
response.addDateHeader("Expires", now + (getCacheIntervall() * 60000)); //milliseconds
}
}
/**
* @return the ENCODING
*/
protected String getENCODING() {
return this.ENCODING;
}
/**
* @param encoding the ENCODING to set
*/
protected void setENCODING(String encoding) {
this.ENCODING = encoding;
}
/**
* @return the cacheIntervall
*/
protected int getCacheIntervall() {
return this.cacheIntervall;
}
/**
* @param intervall the cacheIntervall to set
*/
protected void setCacheIntervall(int intervall) {
this.cacheIntervall = intervall;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy