Code Search for Developers
 
 
  

MaseSystem.java from MASE: Agile Software Engineering at Krugle


Show MaseSystem.java syntax highlighted

package ca.ucalgary.cpsc.ebe.fitClipse.connector;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.Socket;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.sql.Timestamp;
import java.util.Hashtable;
import java.util.List;

import javax.naming.Context;
import javax.naming.InitialContext;

import mase.fit.FitPages;
import ca.ucalgary.cpsc.ebe.fitClipse.runner.FitTest;
import ca.ucalgary.cpsc.ebe.fitClipse.ui.testHierarchy.model.WikiPageModel;

public class MaseSystem implements IServerConnector{
	private ServerConfiguration config = ServerConfiguration.getInstance();	
	private static final String jndiFitLookUp = "ebe/FitPagesBean/remote";
	private FitPages pages = null;
	public static Hashtable<String, String> environment = new Hashtable<String, String>();
	private Context context;
		
	public MaseSystem(ServerConfiguration config)throws Exception{
		String url = config.getHost() + ":" + config.getBeanPort();
		environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
		environment.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
		environment.put(Context.PROVIDER_URL, url);
		context = new InitialContext(environment);
		pages = (FitPages) context.lookup(MaseSystem.jndiFitLookUp);
	}
	
	public String getFitPageText(String name){
			return pages.getWikiPageText(name);
	}

	
	public String getWikiPageTree(){
		try{
			String pageName = config.getProjectNameSpace();
		return pages.getWikiPageTreeXML(pageName);
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}
	}
	

	public boolean doesPageExist(String pName){
		try {
			return pages.doesPageExist(pName);
		}catch (Exception e){
			return false;
		}
	}
	
	public long persistTestSuite(String testRoot,  boolean isSuite, Timestamp executionDate, long executionTime, List<FitTest> tests){
		
		return pages.persistFitTestSuite(testRoot, isSuite, executionDate, executionTime, tests);
	
	}




	public String getConnectorName() {
		return "MASE";
	}



	public void deleteWikiPage(String name) {
		try{
			pages.deleteWikiPage(name);
		}catch(Exception e){
		}
		
	}




	public boolean tagPageAsFitTest(String name, boolean value) {
		try{
			pages.tagWikiPageAsFitTest(name, value);
			return true;
		}catch(Exception e){
			return false;
		}
		
	}




	public FitTest getFitTestFromDatabase(long id, String qName) {
		
		return pages.getFitTestFromDatabase(id,qName);
	}




	public List<FitTest> getFitTestHistory(String qName) {
		return pages.getFitTestHistoryFromDatabase(qName);
	}



//TODO: needs refactoring
	public boolean saveGenericWikiPage(WikiPageModel model, String content) {
		int type = 0;
		if(model.getParent() == null){
			type= FitPages.TYPE_PROJECT;
		}else if(model.getParent().isProject()){
			type = FitPages.TYPE_RELEASE;
		}else if(model.getParent().isRelease()){
			type = FitPages.TYPE_ITERATION;
		}else if(model.getParent().isIteration()){
			type = FitPages.TYPE_STORY_CARD;
		}
//		else if (model.getParent().isStoryCard()){
//			type = FitPages.TYPE_TASK;
//		}
	
		try{
			return pages.saveWikiPageText(model.getQName(), content, model.isFitTest(), type);
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}




	public String getHTMLForPage(String qName) {
		InputStream in = null;
		OutputStream out = null;
		
		try {
			qName = URLEncoder.encode(qName, "UTF-8");
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
			return null;
		}
		String url = "/ebe/Raw.jsp?page=" + qName;
		StringBuffer messageBody = new StringBuffer();
		try {
			//get rid of unproper chatericters
			System.out.println("encoded url is: " + url);
			Socket socket = new Socket(config.getHost(), Integer.parseInt(config.getWebPort()));
			in = socket.getInputStream();
			out = socket.getOutputStream();
			PrintWriter writer = new PrintWriter(out);
			writer.println("GET " + url + " HTTP/1.0\n\n");
			writer.flush();
			BufferedReader reader = new BufferedReader(
					new InputStreamReader(in));
			String line = null;
			while ((line = reader.readLine()) != null && !"".equals(line)) {
				System.out.println("header: " + line);
			}
			while ((line = reader.readLine()) != null) {
				messageBody.append(line).append("\n");
			}
//			System.out.println("the message is: " + messageBody.toString());
			return messageBody.toString();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public String getResultDetailsUrl(String qName) {
		String host="http://"+config.getHost()+":"+config.getWebPort();	
		String Url=host+"/"+config.getWebPath();
		if(qName!=null)
		{
			char lastChar=Url.charAt(Url.length()-1);
			String url=Url+(lastChar=='/'?"":"/").concat("FitReport.jsp?page=")+qName;
			return url;
		}
		return null;
	}

	public String getWikiEditorUrl(String qName) {
		String host="http://"+config.getHost()+":"+config.getWebPort();	
		String Url=host+"/"+config.getWebPath();
		if(qName!=null)
		{
			char lastChar=Url.charAt(Url.length()-1);
			String url=Url+(lastChar=='/'?"":"/").concat("Wiki.jsp?page=")+qName;
			return url;
		}
		return null;
	}

	public String getSuiteDetailsUrl(String qName) {
		// TODO Auto-generated method stub
		return null;
	}
	

}




See more files for this project here

MASE: Agile Software Engineering

The MASE project investigates methods to support the coordination and executable acceptance testing of software projects. Keywords: Agile methods, distributed teams, Extreme Programming. See http://ebe.cpsc.ucalgary.ca/ebe for more information.

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

  FitNesse.java
  IServerConnector.java
  MaseSystem.java
  ServerConfiguration.java
  ServerConnectorFactory.java