Code Search for Developers
 
 
  

ThinkcapCommand.java from ThinkCap Collaborative Knowledge Portal at Krugle


Show ThinkcapCommand.java syntax highlighted

package org.integratedmodelling.thinkcap;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URL;
import java.util.HashMap;

import javax.servlet.ServletContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.velocity.VelocityContext;
import org.integratedmodelling.thinkcap.widget.ThinkcapWidgetManager;
import org.integratedmodelling.thinklab.command.Command;
import org.integratedmodelling.thinklab.exception.ThinklabException;
import org.integratedmodelling.thinklab.exception.ThinklabIOException;
import org.integratedmodelling.thinklab.interfaces.IPlugin;
import org.integratedmodelling.thinklab.interfaces.ISession;

/**
 * Wraps a standard IMA command to provide facilitated access to servlet context and session parameters.
 * @author Ferdinando Villa, Ecoinformatics Collaboratory, UVM
 *
 */
public class ThinkcapCommand extends Command {

	public HttpServletRequest request;
	public HttpServletResponse response;
	public VelocityContext context;
	public ThinkcapSession session;
	public PrintWriter writer = null;
	public ServletOutputStream outputStream = null;
	public ServletContext servletContext;

	public ThinkcapCommand(HashMap<String, String> args, HttpServletRequest req, HttpServletResponse resp,
			VelocityContext ctx) throws ThinklabException {
		super(null, args);
		request = req;
		response = resp;
		session = (ThinkcapSession)request.getSession().getAttribute("thinkcap.session.IMTSession");	
		context = ctx;
	}
	
	public ThinkcapCommand(String mode, HashMap<String, String> args, HttpServletRequest req,
			HttpServletResponse resp) throws ThinklabException {

		super(mode, args);
		request = req;
		response = resp;
		session = (ThinkcapSession)request.getSession().getAttribute("thinkcap.session.IMTSession");
	}

	public PrintWriter getPrintWriter() throws ThinklabIOException {
		if (writer == null) {
			try {
				writer = response.getWriter();
			} catch (IOException e) {
				throw new ThinklabIOException("internal: " + e.getMessage());
			}
		}
		return writer;
	}

	public ServletOutputStream getOutputStream() throws ThinklabIOException {
		if (outputStream == null) {
			try {
				outputStream = response.getOutputStream();
			} catch (IOException e) {
				throw new ThinklabIOException("internal: " + e.getMessage());
			}
		}
		return outputStream;
	}
	
	/**
	 * Get the full URL for the passed command, with any additional parameters (pass parameter name
	 * and value in sequence). 
	 * @param command
	 * @param parameters
	 * @return
	 */
	public URL getURLForCommand(String command, String ... parameters) {
		return session.getURLForCommand(command, parameters);
	}
	
	/**
	 * Return the widget manager for this session and page context, creating it if necessary.
	 * @return
	 */
	public ThinkcapWidgetManager getWidgetManager() {
		
		return session.getWidgetManager();
	}
	
	/**
	 * Get the current HTTP session. 
	 * @return the current HTTP session, dummy.
	 */
	public HttpSession getHttpSession() {
		return request.getSession();
	}
	
	/**
	 * Return the IMT session associated with the command.
	 * @return the current IMT session. Can't be null, or at least should never be null.
	 * @see org.integratedmodelling.ima.core.ISession
	 */
	public ISession getSession() {
		return session;
	}
	
	public PageSpecs getPageSpecs() {
		return (PageSpecs)context.get("pageSpecs");
	}
	
	/**
	 * Log a string wherever logging is done
	 * @param txt text to be logged on the container's log.
	 */
	public void log(String txt) {
		servletContext.log(txt);
	}

	public ThinkcapManager getKnowledgeManager() {
		return ThinkcapManager.getThinkcapManager();
	}
	
	public ThinkCap getThinkcap() {
		return ThinkcapManager.getThinkcapManager().getThinkcap();
	}

	public IPlugin getPlugin(String string) {
		return getKnowledgeManager().getPluginRegistry().retrievePlugin(string);
	}
}




See more files for this project here

ThinkCap Collaborative Knowledge Portal

A portal to explore and edit the knowledge contained in a set of ontologies in intuitive ways. Presents a Dictionary view (a Google-like interface), a Thesaurus view (a graphical display with simplified relationships) and a full graphical Concept view.

Project homepage: http://sourceforge.net/projects/thinkcap
Programming language(s): Java,JavaScript,XML
License: other

  basecommands/
    StreamResource.java
    StreamTemplate.java
    ThinkcapMain.java
  exceptions/
    ThinkcapException.java
    ThinkcapWidgetException.java
  portfolio/
    ThinkcapPortfolio.java
  widget/
    HtmlLink.java
    IItemDecorator.java
    IThinkcapWidget.java
    IWidgetPublisher.java
    ImageDecorator.java
    PopupMenu.java
    ThinkcapInputWidget.java
    ThinkcapWidgetManager.java
  PageSpecs.java
  ResultContainer.java
  TemplateProcessor.java
  ThinkCap.java
  ThinkcapAction.java
  ThinkcapAnswer.java
  ThinkcapCommand.java
  ThinkcapManager.java
  ThinkcapPlugin.java
  ThinkcapSession.java
  ThinkcapSessionListener.java