/* * Copyright IBM Corp. 2012 * * 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.ibm.xsp.sbtsdk.servlets; import java.io.IOException; import java.util.Iterator; import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.ibm.commons.runtime.Application; import com.ibm.commons.runtime.RuntimeConstants; import com.ibm.commons.runtime.util.UrlUtil; import com.ibm.sbt.jslibrary.servlet.DojoLibrary; import com.ibm.sbt.jslibrary.servlet.JQueryLibrary; import com.ibm.sbt.jslibrary.servlet.LibraryException; import com.ibm.sbt.jslibrary.servlet.LibraryRequest; import com.ibm.sbt.jslibrary.servlet.LibraryRequestParams; import com.ibm.sbt.jslibrary.servlet.LibraryServlet; import com.ibm.xsp.sbtsdk.resources.SbtResourceProvider; public class ToolkitServlet extends LibraryServlet { private static final long serialVersionUID = 1L; public static class DominoLibraryRequest extends LibraryRequest { public DominoLibraryRequest(HttpServletRequest req, HttpServletResponse resp) { super(req, resp); } public void init(LibraryRequestParams params) throws LibraryException { //public void init(SBTEnvironment defaultEnvironment, String toolkitUrl, String toolkitJsUrl, String proxyUrl, String iframeUrl) throws ServletException, IOException { // Calculate the toolkit URL //http://priand2/xsp/.ibmxspres/.sbtsdk/sbt/Cache.js String toolkitUrl = UrlUtil.getServerUrl(getHttpRequest())+"/xsp"+SbtResourceProvider.RESOURCE_PATH+"/js/sdk/"; String toolkitJsUrl = toolkitUrl; params.setToolkitUrl(toolkitUrl); params.setToolkitJsUrl(toolkitJsUrl); String jsLibraryUrl = UrlUtil.getServerUrl(getHttpRequest())+"/xsp"+SbtResourceProvider.RESOURCE_PATH+"/js/libs/"; params.setJsLibraryUrl(jsLibraryUrl); // Should be contributed by the other library... // Hard coded for now boolean sbtx = true; if(sbtx) { String toolkitExtUrl = UrlUtil.getServerUrl(getHttpRequest())+"/xsp"+SbtResourceProvider.RESOURCE_PATH+"x/js/sdk/"; String toolkitExtJsUrl = toolkitExtUrl; params.setToolkitExtUrl(toolkitExtUrl); params.setToolkitExtJsUrl(toolkitExtJsUrl); } // Calculate the proxy URL String serviceUrl = RuntimeConstants.get().getBaseProxyUrl(getHttpRequest()); params.setServiceUrl(serviceUrl); // Calculate the library servlet URL String libraryUrl = UrlUtil.getRequestUrl(getHttpRequest()); params.setLibraryUrl(libraryUrl); super.init(params); } protected String getDefaultJsLib() { return JavaScriptLibraries.LIBRARIES[0].getLibType().toString(); } protected String getDefaultJsVersion() { return JavaScriptLibraries.LIBRARIES[0].getLibVersion(); } } protected List<Object> readLibraries(Application application) { List<Object> libraries = super.readLibraries(application); // Filter out the conflicting libraries for(Iterator<Object> it=libraries.iterator(); it.hasNext(); ) { Object o = it.next(); if(o instanceof DojoLibrary) { if(!(o instanceof DominoDojoLibrary)) { it.remove(); } } else if(o instanceof JQueryLibrary) { if(!(o instanceof JQueryLibrary)) { it.remove(); } } } return libraries; } protected LibraryRequest createLibraryRequest(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { return new DominoLibraryRequest(req, resp); } }