001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * This file creating date: 11.10.2004
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.context;
044:
045: import net.jforum.util.preferences.ConfigKeys;
046:
047: /**
048: * @author Marc Wick
049: * @version $Id: JForumContext.java,v 1.4 2006/09/09 21:32:37 rafaelsteil Exp $
050: */
051: public class JForumContext implements ForumContext {
052: private String contextPath;
053: private String servletExtension;
054: private RequestContext request;
055: private ResponseContext response;
056: private boolean isEncodingDisabled;
057: private boolean isBot;
058:
059: public JForumContext(String contextPath, String servletExtension,
060: RequestContext request, ResponseContext response) {
061: this .contextPath = contextPath;
062: this .servletExtension = servletExtension;
063: this .request = request;
064: this .response = response;
065:
066: Boolean isBotObject = (Boolean) request
067: .getAttribute(ConfigKeys.IS_BOT);
068: this .isBot = (isBotObject != null && isBotObject.booleanValue());
069:
070: this .isEncodingDisabled = isBot;
071: }
072:
073: public JForumContext(String contextPath, String servletExtension,
074: RequestContext request, ResponseContext response,
075: boolean isEncodingDisabled) {
076: this .contextPath = contextPath;
077: this .servletExtension = servletExtension;
078: this .request = request;
079: this .response = response;
080: this .isEncodingDisabled = isEncodingDisabled;
081:
082: Boolean isBotObject = (Boolean) request
083: .getAttribute(ConfigKeys.IS_BOT);
084: this .isBot = (isBotObject != null && isBotObject.booleanValue());
085: }
086:
087: public boolean isBot() {
088: return isBot;
089: }
090:
091: public String encodeURL(String url) {
092: return this .encodeURL(url, servletExtension);
093: }
094:
095: public String encodeURL(String url, String extension) {
096: String ucomplete = contextPath + url + extension;
097:
098: if (isEncodingDisabled()) {
099: return ucomplete;
100: }
101:
102: return response.encodeURL(ucomplete);
103: }
104:
105: public boolean isEncodingDisabled() {
106: return this .isEncodingDisabled;
107: }
108:
109: public RequestContext getRequest() {
110: return request;
111: }
112:
113: public ResponseContext getResponse() {
114: return response;
115: }
116: }
|