Commits

Anonymous committed 32f99ca

Initial import from CVS HEAD on 2010-04-06.

  • Participants
  • Tags 1.4.0

Comments (0)

Files changed (514)

+syntax: glob
+*.class
+classes/*
+.classpath
+.project

File lib/PlexiViewer-1.3.jar

Binary file added.

File lib/activation-1.0.2.jar

Binary file added.

File lib/ant-1.6.1.jar

Binary file added.

File lib/avalon-framework-4.1.4.jar

Binary file added.

File lib/axis-1_3.jar

Binary file added.

File lib/commons-beanutils-1.6.1.jar

Binary file added.

File lib/commons-codec-1.1.jar

Binary file added.

File lib/commons-collections-3.0.jar

Binary file added.

File lib/commons-configuration-1.0-dev.jar

Binary file added.

File lib/commons-configuration-1.0.jar

Binary file added.

File lib/commons-dbcp-1.2.1.jar

Binary file added.

File lib/commons-digester-1.5.jar

Binary file added.

File lib/commons-discovery-0.2.jar

Binary file added.

File lib/commons-email-1.2.jar

Binary file added.

File lib/commons-fileupload-1.2.1.jar

Binary file added.

File lib/commons-lang-2.0.jar

Binary file added.

File lib/commons-logging-1.0.4.jar

Binary file added.

File lib/commons-pool-1.0.jar

Binary file added.

File lib/commons-pool-1.2.jar

Binary file added.

File lib/cryptix-3.2.0.jar

Binary file added.

File lib/dom4j-1.4.jar

Binary file added.

File lib/ecs-1.4.2.jar

Binary file added.

File lib/excalibur-component-1.1.jar

Binary file added.

File lib/excalibur-instrument-1.0.jar

Binary file added.

File lib/excalibur-logger-1.0.1.jar

Binary file added.

File lib/excalibur-pool-1.2.jar

Binary file added.

File lib/fop.jar

Binary file added.

File lib/iText.jar

Binary file added.

File lib/iTextXML.jar

Binary file added.

File lib/ij-1.39b.jar

Binary file added.

File lib/jakarta-regexp-1.2.jar

Binary file added.

File lib/jargon-1.4.25.jar

Binary file added.

File lib/javamail-1.3.2.jar

Binary file added.

File lib/jaxrpc-1.jar

Binary file added.

File lib/jcs-20030822.182132.jar

Binary file added.

File lib/jdbc-2.0.jar

Binary file added.

File lib/jndi-1.2.1.jar

Binary file added.

File lib/jul-to-slf4j-1.5.8.jar

Binary file added.

File lib/junit-3.8.1.jar

Binary file added.

File lib/jython-2.1.jar

Binary file added.

File lib/log4j-1.2.15.jar

Binary file added.

File lib/logkit-1.0.1.jar

Binary file added.

File lib/mysql-connector-java-2.0.14-bin.jar

Binary file added.

File lib/oro-2.0.7.jar

Binary file added.

File lib/parser.jar

Binary file added.

File lib/pg74.214.jdbc2.jar

Binary file added.

File lib/postgresql-7.4.214.jdbc2.jar

Binary file added.

File lib/saaj-1.jar

Binary file added.

File lib/servlet-api.jar

Binary file added.

File lib/slf4j-api-1.5.8.jar

Binary file added.

File lib/slf4j-log4j12-1.5.8.jar

Binary file added.

File lib/stratum-1.0-b5.jar

Binary file added.

File lib/torque-3.1.1.jar

Binary file added.

File lib/turbine-2.3.1.jar

Binary file added.

File lib/velocity-1.3.1.jar

Binary file added.

File lib/village-2.0-dev-20030825.jar

Binary file added.

File lib/xalan-2.5.1.jar

Binary file added.

File lib/xerces-J_1.4.0.jar

Binary file added.

File lib/xercesImpl-2.4.0.jar

Binary file added.

File lib/xml-apis-1.0.b2.jar

Binary file added.

File lib/xmlrpc-1.2-b1.jar

Binary file added.

File lib/xnatsrb-1.jar

Binary file added.

File org/nrg/xdat/XDAT.java

+//Copyright 2005 Harvard University / Howard Hughes Medical Institute (HHMI) All Rights Reserved
+/* 
+ * XDAT � Extensible Data Archive Toolkit
+ * Copyright (C) 2005 Washington University
+ */
+/*
+ * Created on Jan 3, 2005
+ *
+ */
+package org.nrg.xdat;
+
+import java.io.File;
+import java.util.Iterator;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+import org.apache.stratum.lifecycle.Configurable;
+import org.apache.stratum.lifecycle.Initializable;
+import org.apache.torque.TorqueException;
+import org.nrg.xdat.display.DisplayManager;
+import org.nrg.xdat.security.ElementSecurity;
+import org.nrg.xft.XFT;
+import org.nrg.xft.db.ViewManager;
+import org.nrg.xft.exception.ElementNotFoundException;
+import org.nrg.xft.exception.XFTInitException;
+import org.nrg.xft.generators.SQLCreateGenerator;
+import org.nrg.xft.generators.SQLUpdateGenerator;
+import org.nrg.xft.schema.Wrappers.GenericWrapper.GenericWrapperElement;
+import org.nrg.xft.utils.FileUtils;
+/**
+ * @author Tim
+ *
+ */
+public class XDAT implements Initializable,Configurable{
+	static org.apache.log4j.Logger logger = Logger.getLogger(XDAT.class);
+	private String instanceSettingsLocation = null;
+	/**
+	 * configure torque
+	 *
+	 * @param conf Configuration
+	 * @see org.apache.stratum.lifecycle.Configurable
+	 * @throws TorqueException Any exceptions caught during processing will be
+	 *         rethrown wrapped into a TorqueException.
+	 */
+	public void configure(Configuration conf)
+	{
+		instanceSettingsLocation = conf.getString("instance_settings_directory");
+	}
+
+	/**
+	 * initialize Torque
+	 *
+	 * @see org.apache.stratum.lifecycle.Initializable
+	 * @throws TorqueException Any exceptions caught during processing will be
+	 *         rethrown wrapped into a TorqueException.
+	 */
+	public void initialize()
+	{
+		try {
+			logger.info("Starting Service XDAT");
+			init(instanceSettingsLocation);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	public static void init(String location) throws Exception
+	{
+		XDAT.init(location,true,true);
+	}
+	
+	public static void RefreshDisplay()
+	{
+		DisplayManager.clean();
+		DisplayManager.GetInstance();
+	}
+	
+	public static void init(String location,boolean allowDBAccess) throws Exception
+	{
+		init(location,allowDBAccess,true);
+	}
+	
+	public static void init(String location,boolean allowDBAccess, boolean initLog4j) throws Exception
+	{
+		DisplayManager.clean();
+		if (initLog4j)
+		{
+			location = FileUtils.AppendSlash(location);
+			PropertyConfigurator.configure(location + "log4j.properties");
+			initLog4j= false;
+		}
+		XFT.init(location,allowDBAccess,initLog4j);
+		//XFT.LogCurrentTime("XDAT INIT: 1","ERROR");
+		if (allowDBAccess)
+		{
+			try {
+	            Iterator quarantineElements = ElementSecurity.GetQuarantinedElements().iterator();
+	            while (quarantineElements.hasNext())
+	            {
+	                ElementSecurity es = (ElementSecurity)quarantineElements.next();
+	                GenericWrapperElement.GetElement(es.getElementName()).setQuarantineSetting(es.getBooleanProperty("quarantine",false));
+	            }
+	            
+	            Iterator preloadElements = ElementSecurity.GetPreLoadElements().iterator();
+	            while (preloadElements.hasNext())
+	            {
+	                ElementSecurity es = (ElementSecurity)preloadElements.next();
+	                GenericWrapperElement.GetElement(es.getElementName()).setPreLoad(es.getBooleanProperty("pre_load",false));
+	            }
+	        } catch (Exception e) {
+	            logger.error("",e);
+	        }
+		}
+
+		//XFT.LogCurrentTime("XDAT INIT: 2","ERROR");
+		logger.info("Initializing Display Manager");
+		DisplayManager.GetInstance();
+		//XFT.LogCurrentTime("XDAT INIT: 3","ERROR");
+	}
+	
+	public static void GenerateUpdateSQL(String file) throws XFTInitException,ElementNotFoundException, Exception
+	{
+	    StringBuffer sb =new StringBuffer();
+	    sb.append("-- Generated SQL File for updating an existing XNAT database.\n");
+	    sb.append("-- This script is created by the update XNAT feature, which reviews an existing database and only specifies create statements for missing TABLES and COLUMNS.  It will also drop and recreate any necessary functions or views.\n");
+	    
+	    sb.append("-- If you are running from pgAdmin, remove the following line to stop on errors (pgAdmin does not recognize the statement)");
+	    sb.append("\n\\set ON_ERROR_STOP 1;");
+	    
+	    Iterator iter = SQLUpdateGenerator.GetSQLCreate().iterator();
+	    while (iter.hasNext())
+	    {
+	        sb.append(iter.next() +"\n--BR\n");
+	    }
+		sb.append("\n\n-- REMOVE OLD VIEWS FOR DISPLAY DOCS\n\n");
+		sb.append("\n\nSELECT removeViews();\n--BR\n");
+		sb.append("\n\n-- ADDED VIEWS FOR DISPLAY DOCS\n\n");
+		iter = DisplayManager.GetCreateViewsSQL(true).iterator();
+	    while (iter.hasNext())
+	    {
+	        sb.append(iter.next() +"\n--BR\n");
+	    }
+		FileUtils.OutputToFile(sb.toString(),file);
+		
+		logger.info("File Created: " + file);
+	}
+	
+	public static void GenerateCreateSQL(String file) throws XFTInitException,ElementNotFoundException, Exception
+	{
+	    StringBuffer sb =new StringBuffer();
+	    sb.append("-- Generated SQL File for creating an XNAT database from scratch.\n");
+	    
+	    sb.append("-- If you are running from pgAdmin, remove the following line to stop on errors (pgAdmin does not recognize the statement)");
+	    sb.append("\n\\set ON_ERROR_STOP 1;");
+	    
+	    Iterator iter = SQLCreateGenerator.GetSQLCreate().iterator();
+	    while (iter.hasNext())
+	    {
+	        sb.append(iter.next() +"\n--BR\n");
+	    }
+		sb.append("\n\n-- ADDED VIEWS FOR DISPLAY DOCS\n\n");
+		iter = DisplayManager.GetCreateViewsSQL(false).iterator();
+	    while (iter.hasNext())
+	    {
+	        sb.append(iter.next() +"\n--BR\n");
+	    }
+		FileUtils.OutputToFile(sb.toString(),file);
+		
+		ViewManager.OutputFieldNames();
+		logger.info("File Created: " + file);
+	}
+}

File org/nrg/xdat/XDATItem.java

+//Copyright 2005 Harvard University / Howard Hughes Medical Institute (HHMI) All Rights Reserved
+/* 
+ * XDAT � Extensible Data Archive Toolkit
+ * Copyright (C) 2005 Washington University
+ */
+/*
+ * Created on Jan 13, 2005
+ *
+ */
+package org.nrg.xdat;
+
+
+/**
+ * @author Tim
+ *
+ */
+public class XDATItem {
+	
+}
+

File org/nrg/xdat/XDATTool.java

+//Copyright 2005 Harvard University / Howard Hughes Medical Institute (HHMI) All Rights Reserved
+/*
+ * Created on Jun 23, 2005
+ *
+ */
+package org.nrg.xdat;
+
+import java.io.File;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import org.apache.log4j.Logger;
+import org.nrg.xdat.base.BaseElement;
+import org.nrg.xdat.presentation.CSVPresenter;
+import org.nrg.xdat.presentation.HTMLPresenter;
+import org.nrg.xdat.schema.SchemaElement;
+import org.nrg.xdat.schema.SchemaField;
+import org.nrg.xdat.search.DisplaySearch;
+import org.nrg.xdat.security.Authenticator;
+import org.nrg.xdat.security.XDATUser;
+import org.nrg.xdat.security.XDATUser.FailedLoginException;
+import org.nrg.xft.ItemI;
+import org.nrg.xft.XFT;
+import org.nrg.xft.XFTItem;
+import org.nrg.xft.XFTTable;
+import org.nrg.xft.XFTTableI;
+import org.nrg.xft.collections.ItemCollection;
+import org.nrg.xft.exception.DBPoolException;
+import org.nrg.xft.exception.ElementNotFoundException;
+import org.nrg.xft.exception.FieldNotFoundException;
+import org.nrg.xft.exception.ValidationException;
+import org.nrg.xft.exception.XFTInitException;
+import org.nrg.xft.generators.SQLCreateGenerator;
+import org.nrg.xft.references.XFTReferenceManager;
+import org.nrg.xft.schema.XFTManager; 
+import org.nrg.xft.schema.Wrappers.XMLWrapper.SAXReader;
+import org.nrg.xft.schema.Wrappers.XMLWrapper.XMLWriter;
+import org.nrg.xft.search.ItemSearch;
+import org.nrg.xft.search.TableSearch;
+import org.nrg.xft.utils.FileUtils;
+import org.nrg.xft.utils.SaveItemHelper;
+import org.nrg.xft.utils.StringUtils;
+import org.nrg.xft.utils.XMLValidator;
+import org.nrg.xft.utils.ValidationUtils.ValidationResults;
+import org.nrg.xft.utils.ValidationUtils.XFTValidator;
+
+/**
+ * @author Tim
+ *
+ */
+public class XDATTool {
+	static org.apache.log4j.Logger logger = Logger.getLogger(XDATTool.class);
+    private String location = null;
+    private XDATUser user = null;
+    private boolean ignoreSecurity = false;
+    public XDATTool() throws XFTInitException
+    {
+        location = XFTManager.GetInstance().getSourceDir();
+    }
+    /**
+     *
+     */
+    public XDATTool(String instanceLocation) throws Exception {
+    	instanceLocation = FileUtils.AppendSlash(instanceLocation);
+        location= instanceLocation;
+        XDAT.init(location,false);
+    }
+    /**
+     *
+     */
+    public XDATTool(String instanceLocation,XDATUser u) throws Exception {
+    	instanceLocation = FileUtils.AppendSlash(instanceLocation);
+        user=u;
+        location= instanceLocation;
+        XDAT.init(location,false);
+    }
+
+    public XDATTool(String instanceLocation,String username, String password) throws DBPoolException,SQLException,FailedLoginException,Exception
+    {
+    	instanceLocation = FileUtils.AppendSlash(instanceLocation);
+        location= instanceLocation;
+        XDAT.init(location,true);
+        login(username,password);
+    }
+
+    private void login(String username, String password) throws DBPoolException,SQLException,FailedLoginException,Exception
+    {
+        try {
+            user = Authenticator.Authenticate(new Authenticator.Credentials(username,password));
+        } catch (XFTInitException e) {
+            logger.error("",e);
+        } catch (ElementNotFoundException e) {
+            logger.error("",e);
+        } catch (FieldNotFoundException e) {
+            logger.error("",e);
+        }
+    }
+
+    /**
+	 * Generate CREATE, ALTER, VIEW, and INSERT statements for each element in the
+	 * defined schemas.
+	 * @param outputFile (location to save generated sql)
+	 */
+	public void generateSQL() throws Exception
+	{
+		SQLCreateGenerator.generateDoc(getWorkDirectory() + "xdat.sql");
+	}
+
+    /**
+	 * Generate CREATE, ALTER, VIEW, and INSERT statements for each element in the
+	 * defined schemas.
+	 * @param outputFile (location to save generated sql)
+	 */
+	public void generateSQL(String s) throws Exception
+	{
+	    XDAT.GenerateCreateSQL(s);
+	}
+
+	public void storeXML(String fileLocation,Boolean quarantine, boolean allowItemRemoval) throws Exception
+	{
+	    storeXML(new File(fileLocation),quarantine,allowItemRemoval);
+	}
+
+
+    /**
+     * @return Returns the ignoreSecurity.
+     */
+    public boolean isIgnoreSecurity() {
+        return ignoreSecurity;
+    }
+    /**
+     * @param ignoreSecurity The ignoreSecurity to set.
+     */
+    public void setIgnoreSecurity(boolean ignoreSecurity) {
+        this.ignoreSecurity = ignoreSecurity;
+    }
+
+	public void storeXML(File fileLocation,Boolean quarantine, boolean allowItemRemoval) throws Exception
+	{
+	    boolean overrideSecurity = false;
+	    if (user == null && (!ignoreSecurity))
+	    {
+	        if(!fileLocation.getAbsolutePath().endsWith("security.xml"))
+	        {
+	            throw new Exception("Error: No username and password.");
+	        }else{
+	            overrideSecurity=true;
+	        }
+	    }
+	    if (! fileLocation.exists())
+	    {
+	        throw new Exception("File Not Found: " + fileLocation.getPath());
+	    }
+
+	    //Document doc = XMLUtils.GetDOM(fileLocation);
+	    if (XFT.VERBOSE)
+	        System.out.println("Found Document:" + fileLocation);
+	    logger.info("Found Document:" + fileLocation);
+
+	    XMLValidator validator = new XMLValidator();
+	    validator.validateSchema(fileLocation.getAbsolutePath());
+
+		//XFTItem item = XMLReader.TranslateDomToItem(doc,this.user);
+	   SAXReader reader = new SAXReader(user);
+	   XFTItem item = reader.parse(fileLocation);
+		if (XFT.VERBOSE)
+	        System.out.println("Loaded XML Item:" + item.getProperName());
+	    logger.info("Loaded XML Item:" + item.getProperName());
+
+		ValidationResults vr = XFTValidator.Validate(item);
+		if (vr.isValid())
+		{
+		    if (XFT.VERBOSE)
+		        System.out.println("Validation: PASSED");
+		    logger.info("Validation: PASSED");
+
+			boolean q;
+			boolean override;
+			if (quarantine!=null)
+			{
+			    q = quarantine.booleanValue();
+			    override = true;
+			}else{
+			    q = item.getGenericSchemaElement().isQuarantine();
+			    override = false;
+			}
+        	SaveItemHelper.Save(item,user,overrideSecurity,q,override,allowItemRemoval);
+			if(XFT.VERBOSE)System.out.println("Item Successfully Stored.");
+		    logger.info("Item Successfully Stored.");
+		}else
+		{
+			throw new ValidationException(vr);
+		}
+	}
+
+	public void XMLSearch(String elementName, boolean isBackup, String dir,boolean limited,boolean pp) throws Exception
+	{
+	    if (user == null && (!ignoreSecurity))
+	    {
+	        throw new Exception("Error: No username and password.");
+	    }
+
+	    SchemaElement se = SchemaElement.GetElement(elementName);
+
+	    String query = "SELECT ";
+	    ArrayList pks = se.getAllPrimaryKeys();
+
+        String proper =  XFTReferenceManager.GetProperName(se.getFullXMLName());
+		if (proper == null || proper.equalsIgnoreCase(""))
+		{
+			proper = se.getSQLName();
+		}
+
+	    int counter = 0;
+	    Iterator iter = pks.iterator();
+	    while (iter.hasNext())
+	    {
+	        SchemaField sf = (SchemaField)iter.next();
+	        if (counter==0)
+	            query += sf.getSQLName();
+	        else
+	            query += ", " + sf.getSQLName();
+	    }
+
+	    query += " FROM " + se.getSQLName() + ";";
+
+	    String login="";
+	    if(user != null)
+	    {
+	        login = user.getLogin();
+	    }
+
+	    XFTTable table = TableSearch.Execute(query,se.getDbName(),login);
+
+	    table.resetRowCursor();
+	    while (table.hasMoreRows())
+	    {
+	        Hashtable row = table.nextRowHash();
+
+	        ItemSearch search = ItemSearch.GetItemSearch(elementName,user);
+
+	        String fileName = proper;
+
+			    iter = pks.iterator();
+			    while (iter.hasNext())
+			    {
+			        SchemaField sf = (SchemaField)iter.next();
+			        Object pk = row.get(sf.getSQLName().toLowerCase());
+			        search.addCriteria(sf.getGenericXFTField().getXMLPathString(se.getFullXMLName()),pk);
+
+			        fileName += "_" + pk;
+			    }
+
+			    fileName += ".xml";
+
+
+		    File f = new File(dir + fileName);
+		    if ((!f.exists()) || (!isBackup))
+		    {
+			    ItemCollection items= search.exec();
+			    XMLWriter.StoreXFTItemListToXMLFile(items.items(),dir,limited,pp);
+		    }else{
+		        if (XFT.VERBOSE)
+			        System.out.println(f.getAbsolutePath() + " already exists.");
+		    }
+	    }
+	}
+
+	public void XMLSearch(String elementName,String xmlPath, Object value, String dir, boolean limited,boolean pp) throws Exception
+	{
+	    if (user == null && (!ignoreSecurity))
+	    {
+	        throw new Exception("Error: No username and password.");
+	    }
+	    ItemCollection items= ItemSearch.GetItems(xmlPath,value,user,false);
+	    XMLWriter.StoreXFTItemListToXMLFile(items.items(),dir,limited,pp);
+	}
+
+	public int XMLSearch(String elementName,String xmlPath, String comparisonType, Object value, String dir,boolean limited,boolean pp) throws Exception
+	{
+	    if (user == null && (!ignoreSecurity))
+	    {
+	        throw new Exception("Error: No username and password.");
+	    }
+
+	    xmlPath = StringUtils.StandardizeXMLPath(xmlPath);
+	    ItemSearch search = ItemSearch.GetItemSearch(elementName,user);
+	    search.setAllowMultiples(false);
+	    search.addCriteria(xmlPath,value,comparisonType);
+
+	    ItemCollection items= search.exec(false);
+
+	    if (items.size()>0)
+	    {
+		    return XMLWriter.StoreXFTItemListToXMLFile(items.items(),dir,limited,pp);
+	    }else{
+	    	if(XFT.VERBOSE) System.out.println("No Matches Found.");
+	        return 1;
+	    }
+	}
+
+	public void HTMLSearch(String xmlPath, String comparisonType, Object value) throws Exception
+	{
+	    if (user == null && (!ignoreSecurity))
+	    {
+	        throw new Exception("Error: No username and password.");
+	    }
+	    String rootElement = StringUtils.GetRootElementName(xmlPath);
+	    DisplaySearch ds = user.getSearch(rootElement,"listing");
+	    ds.addCriteria(xmlPath,comparisonType,value);
+	    XFTTableI table =ds.execute(new HTMLPresenter(""),user.getLogin());
+	    FileUtils.OutputToFile(table.toHTML(true,"FFFFFF","FFFFCC",new java.util.Hashtable(),0),getSearchFileName("html"));
+	}
+
+	public int VelocitySearch(String elementName,String xmlPath, String comparisonType, Object value) throws Exception
+	{
+	    if (user == null && (!ignoreSecurity))
+	    {
+	        throw new Exception("Error: No username and password.");
+	    }
+
+	    xmlPath = StringUtils.StandardizeXMLPath(xmlPath);
+	    ItemSearch search = ItemSearch.GetItemSearch(elementName,user);
+	    search.setAllowMultiples(false);
+	    search.addCriteria(xmlPath,value,comparisonType);
+
+	    ItemCollection items= search.exec(false);
+
+	    if (items.size()>0)
+	    {
+		    Iterator iter = items.getItemIterator();
+		    if(XFT.VERBOSE)System.out.println(items.size()+ " Matching Items Found.\n\n");
+		    while (iter.hasNext())
+		    {
+		        XFTItem item =(XFTItem)iter.next();
+		        ItemI bo = BaseElement.GetGeneratedItem(item);
+		        System.out.println(bo.output());
+
+		        System.out.println("\n");
+		    }
+		    return 0;
+	    }else{
+	    	if(XFT.VERBOSE)System.out.println("No Matches Found.");
+	        return 1;
+	    }
+	}
+
+	public void CSVSearch(String xmlPath, String comparisonType, Object value) throws Exception
+	{
+	    if (user == null && (!ignoreSecurity))
+	    {
+	        throw new Exception("Error: No username and password.");
+	    }
+	    String rootElement = StringUtils.GetRootElementName(xmlPath);
+	    DisplaySearch ds = user.getSearch(rootElement,"listing");
+	    ds.addCriteria(xmlPath,comparisonType,value);
+	    XFTTableI table =ds.execute(new CSVPresenter(),user.getLogin());
+	    FileUtils.OutputToFile(table.toString(","),getSearchFileName("csv"));
+	}
+
+	public void HTMLSearch(String elementName) throws Exception
+	{
+	    if (user == null && (!ignoreSecurity))
+	    {
+	        throw new Exception("Error: No username and password.");
+	    }
+	    DisplaySearch ds = user.getSearch(elementName,"listing");
+	    XFTTableI table =ds.execute(new HTMLPresenter(""),user.getLogin());
+	    FileUtils.OutputToFile(table.toHTML(true,"FFFFFF","FFFFCC",new java.util.Hashtable(),0),getSearchFileName("html"));
+	}
+
+	public void CSVSearch(String elementName) throws Exception
+	{
+	    if (user == null && (!ignoreSecurity))
+	    {
+	        throw new Exception("Error: No username and password.");
+	    }
+	    DisplaySearch ds = user.getSearch(elementName,"listing");
+	    XFTTableI table =ds.execute(new CSVPresenter(),user.getLogin());
+	    FileUtils.OutputToFile(table.toString(","),getSearchFileName("csv"));
+	}
+
+	public String getWorkDirectory()
+	{
+	    File f = new File(location + "work");
+	    if (!f.exists())
+	    {
+	        f.mkdir();
+	    }
+	    return location +"work" + File.separator;
+	}
+
+	public String getSearchFileName(String extension)
+	{
+	    int counter =0;
+
+	    File f = new File(getWorkDirectory() + "search" +counter +"." + extension);
+
+	    while (f.exists())
+	    {
+	        f = new File(getWorkDirectory() + "search" + (++counter) +"." + extension);
+	    }
+	    return f.getAbsolutePath();
+	}
+
+	public String getSettingsDirectory()
+	{
+	    return location;
+	}
+
+	public static String GetSettingsDirectory()
+	{
+	    try {
+            String s=  XFTManager.GetInstance().getSourceDir();
+        	s = FileUtils.AppendSlash(s);
+            return s;
+        } catch (XFTInitException e) {
+            logger.error("",e);
+            return "XDAT NOT INITIALIZED";
+        }
+	}
+    /**
+     * @return Returns the user.
+     */
+    public XDATUser getUser() {
+        return user;
+    }
+    /**
+     * @param user The user to set.
+     */
+    public void setUser(XDATUser user) {
+        this.user = user;
+    }
+
+    public void close() throws SQLException
+    {
+        XFT.closeConnections();
+    }
+
+    public void info(String message)
+    {
+        logger.info(message);
+    }
+
+    public void debug(String message)
+    {
+        logger.debug(message);
+    }
+
+    public void error(String message)
+    {
+        logger.error(message);
+    }
+
+    public void info(Exception e)
+    {
+        logger.info(e);
+    }
+
+    public void debug(Exception e)
+    {
+        logger.debug(e);
+    }
+
+    public void error(Exception e)
+    {
+        logger.error(e);
+    }
+}

File org/nrg/xdat/ajax/EmailCustomSearch.java

+//Copyright 2007 Washington University School of Medicine All Rights Reserved
+/*
+ * Created on Sep 19, 2007
+ *
+ */
+package org.nrg.xdat.ajax;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Iterator;
+import java.util.List;
+import javax.mail.MessagingException;
+import javax.mail.internet.InternetAddress;
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import org.apache.log4j.Logger;
+import org.nrg.xdat.security.XDATUser;
+import org.nrg.xdat.turbine.utils.AdminUtils;
+import org.nrg.xdat.turbine.utils.TurbineUtils;
+import org.nrg.xft.db.PoolDBUtils;
+import org.nrg.xft.email.EmailUtils;
+import org.nrg.xft.exception.DBPoolException;
+import org.nrg.xft.utils.StringUtils;
+
+public class EmailCustomSearch {
+    static org.apache.log4j.Logger logger = Logger.getLogger(EmailCustomSearch.class);
+    public void send(HttpServletRequest req, HttpServletResponse response,ServletConfig sc) throws IOException{
+        String xmlString = req.getParameter("search_xml");
+        
+        HttpSession session = req.getSession();
+        XDATUser user = ((XDATUser)session.getAttribute("user"));        
+
+        String _return ="<DIV class=\"error\">Unknown Exception</DIV>";
+        if (user!=null){
+            String toAddress = req.getParameter("toAddress");
+            String ccAddress = req.getParameter("ccAddress");
+            String bccAddress = req.getParameter("bccAddress");
+            String subject = req.getParameter("subject");
+            String message = req.getParameter("message");
+            
+            if (toAddress!=null || ccAddress!=null || bccAddress!=null) {  
+                try {
+                  List<InternetAddress> tos=new ArrayList<InternetAddress>();
+                  List<InternetAddress> ccs=new ArrayList<InternetAddress>();
+                  List<InternetAddress> bccs=new ArrayList<InternetAddress>();
+                    if (toAddress!=null && !toAddress.equals("")){ 
+                        ArrayList al = StringUtils.CommaDelimitedStringToArrayList(toAddress);
+                        Iterator iter = al.iterator();
+                        while (iter.hasNext())
+                        {
+                            tos.add(new InternetAddress((String)iter.next()));
+                        }
+                    }
+                    if (ccAddress!=null && !ccAddress.equals("")){
+                        ArrayList al = StringUtils.CommaDelimitedStringToArrayList(ccAddress);
+                        Iterator iter = al.iterator();
+                        while (iter.hasNext())
+                        {
+                            ccs.add(new InternetAddress((String)iter.next()));
+                        }
+                    }
+                    if (bccAddress!=null && !bccAddress.equals("")){
+                        ArrayList al = StringUtils.CommaDelimitedStringToArrayList(bccAddress);
+                        Iterator iter = al.iterator();
+                        while (iter.hasNext())
+                        {
+                            bccs.add(new InternetAddress((String)iter.next()));
+                        }
+                    }
+                    
+                    if(AdminUtils.GetPageEmail()){
+                    	bccs.add(new InternetAddress(AdminUtils.getAdminEmailId()));
+                    }
+                    Object search_id=PoolDBUtils.LogCustomSearch(user.getUsername(), xmlString, user.getDBName());
+                    try {
+                    	EmailUtils.sendEmail(tos, ccs, bccs, user.getEmail(), subject, getHtmlMessage(req,user,message,search_id));
+                        
+                        _return=("<DIV class=\"warning\">Message sent.</DIV>");
+                    } catch (Exception e) {
+                        logger.error("",e);
+                        _return=("<DIV class=\"error\">Unable to send mail.</DIV>");
+                    }
+                } catch (MessagingException e) {
+                    logger.error("",e);
+                } catch (SQLException e) {
+                    logger.error("",e);
+                } catch (DBPoolException e) {
+                    logger.error("",e);
+                } catch (Exception e) {
+                    logger.error("",e);
+                }
+                
+
+            }
+        }else{
+            _return= "<DIV class=\"error\">Missing User Account</DIV>";
+        }
+        response.setContentType("text/html");
+        response.setHeader("Cache-Control", "no-cache");
+        response.getWriter().write(_return);
+    }
+
+    
+    public String getTxtMessage(HttpServletRequest req, XDATUser user,String msg, Object search_id)
+    {
+        if (req.getParameter("txtmessage")==null)
+        {
+            try {                
+                StringBuffer sb = new StringBuffer();
+                sb.append(user.getFirstname()).append(" ").append(user.getLastname());
+                sb.append(" thought you might be interested in a data set contained in the ").append(TurbineUtils.GetSystemName()).append(".");
+                sb.append(" Please follow <" +TurbineUtils.GetFullServerPath() + "/app/action/DisplaySearchAction");
+                sb.append("/search_id/").append(search_id);
+
+                sb.append(">this link to view the data.\n\n");
+                
+                sb.append("Message from sender:\n");
+                sb.append(msg);
+                sb.append("\n\nThis email was sent by the <" +TurbineUtils.GetFullServerPath() + ">XNAT data management system on ").append(Calendar.getInstance().getTime()).append(".");
+                sb.append("  If you have questions or concerns, please contact the <" + org.nrg.xft.XFT.GetAdminEmail() + ">CNDA administrator.");
+                return sb.toString();
+            } catch (Exception e) {
+                logger.error("",e);
+                return "error";
+            }
+        }else{
+            return req.getParameter("txtmessage");
+        }
+
+    }
+    
+    public String getHtmlMessage(HttpServletRequest req, XDATUser user,String msg, Object search_id)
+    {
+        if (req.getParameter("htmlmessage")==null)
+        {
+            try {
+                StringBuffer sb = new StringBuffer();
+                sb.append("<html>");
+                sb.append("<body>");
+                sb.append(user.getFirstname()).append(" ").append(user.getLastname());
+                sb.append(" thought you might be interested in a data set contained in the ").append(TurbineUtils.GetSystemName()).append(".");
+                sb.append(" Please follow <A HREF=\"" +TurbineUtils.GetFullServerPath() + "/app/action/DisplaySearchAction");
+                sb.append("/search_id/").append(search_id);
+                                
+                sb.append("\">this link</A> to view the data.<BR><BR>");
+                
+                sb.append("Message from sender:<BR>");
+                sb.append(msg);
+                sb.append("<BR><BR>This email was sent by the <A HREF=\"" +TurbineUtils.GetFullServerPath() + "\">XNAT</A> data management system on ").append(Calendar.getInstance().getTime()).append(".");
+                sb.append("  If you have questions or concerns, please contact the <A HREF=\"mailto:" + org.nrg.xft.XFT.GetAdminEmail() + "\">").append(TurbineUtils.GetSystemName()).append(" administrator</A>.");
+                
+                sb.append("</body>");
+                sb.append("</html>");
+                
+                return sb.toString();
+            } catch (Exception e) {
+                logger.error("",e);
+                return "error";
+            }
+        }else{
+            return req.getParameter("htmlmessage");
+        }
+
+    }
+}

File org/nrg/xdat/ajax/StoreXML.java

+//Copyright 2007 Washington University School of Medicine All Rights Reserved
+/*
+ * Created on Nov 27, 2007
+ *
+ */
+package org.nrg.xdat.ajax;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Iterator;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+
+import org.apache.log4j.Logger;
+import org.nrg.xdat.security.XDATUser;
+import org.nrg.xdat.security.XdatStoredSearch;
+import org.nrg.xft.XFTItem;
+import org.nrg.xft.collections.ItemCollection;
+import org.nrg.xft.exception.ElementNotFoundException;
+import org.nrg.xft.exception.FieldNotFoundException;
+import org.nrg.xft.exception.XFTInitException;
+import org.nrg.xft.schema.Wrappers.XMLWrapper.SAXReader;
+import org.nrg.xft.schema.Wrappers.XMLWrapper.SAXWriter;
+import org.nrg.xft.search.ItemSearch;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class StoreXML {
+    static org.apache.log4j.Logger logger = Logger.getLogger(StoreXML.class);
+    public void execute(HttpServletRequest req, HttpServletResponse response,ServletConfig sc) throws IOException{
+        String xmlString = req.getParameter("xml");
+        String allowDString = req.getParameter("allowDataDeletion");
+        boolean allowDataDeletion = true;
+        if (allowDString!=null){
+            allowDataDeletion=Boolean.valueOf(allowDString).booleanValue();
+        }
+        response.setContentType("text/plain");
+        response.setHeader("Cache-Control", "no-cache");
+        XDATUser user = (XDATUser)req.getSession().getAttribute("user");
+        if (user!=null){
+            StringReader sr = new StringReader(xmlString);
+            InputSource is = new InputSource(sr);
+            
+            boolean successful=false;
+            SAXReader reader = new SAXReader(user);
+            try {
+
+                XFTItem item = reader.parse(is);
+                
+                item.save(user, false, allowDataDeletion);
+
+                
+                SAXWriter writer = new SAXWriter(response.getOutputStream(),false);
+                writer.setWriteHiddenFields(true);
+                writer.write(item);
+                return;
+            } catch (SAXException e) {
+                logger.error("",e);
+                response.getWriter().write("<error msg=\"" + e.getMessage() + "\"/>");
+            } catch (XFTInitException e) {
+                logger.error("",e);
+                response.getWriter().write("<error msg=\"" + e.getMessage() + "\"/>");
+            } catch (ElementNotFoundException e) {
+                logger.error("",e);
+                response.getWriter().write("<error msg=\"" + e.getMessage() + "\"/>");
+            } catch (FieldNotFoundException e) {
+                logger.error("",e);
+                response.getWriter().write("<error msg=\"" + e.getMessage() + "\"/>");
+            } catch (Exception e) {
+                logger.error("",e);
+                response.getWriter().write("<error msg=\"" + e.getMessage() + "\"/>");
+            }
+
+        }else{
+
+            response.getWriter().write("<error msg=\"Invalid User\"/>");
+        }
+    }
+}

File org/nrg/xdat/ajax/XMLSearch.java

+//Copyright 2007 Washington University School of Medicine All Rights Reserved
+/*
+ * Created on Nov 26, 2007
+ *
+ */
+package org.nrg.xdat.ajax;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Iterator;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+
+import org.apache.log4j.Logger;
+import org.nrg.xdat.security.XDATUser;
+import org.nrg.xdat.security.XdatStoredSearch;
+import org.nrg.xft.XFTItem;
+import org.nrg.xft.collections.ItemCollection;
+import org.nrg.xft.exception.ElementNotFoundException;
+import org.nrg.xft.exception.FieldNotFoundException;
+import org.nrg.xft.exception.XFTInitException;
+import org.nrg.xft.schema.Wrappers.XMLWrapper.SAXReader;
+import org.nrg.xft.schema.Wrappers.XMLWrapper.SAXWriter;
+import org.nrg.xft.search.ItemSearch;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class XMLSearch {
+    static org.apache.log4j.Logger logger = Logger.getLogger(XMLSearch.class);
+    public void execute(HttpServletRequest req, HttpServletResponse response,ServletConfig sc) throws IOException{
+        String xmlString = req.getParameter("search");
+        String allowMultiples = req.getParameter("allowMultiples");
+        boolean allowChildren = true;
+        if (allowMultiples!=null){
+            allowChildren=Boolean.valueOf(allowMultiples).booleanValue();
+        }
+        XDATUser user = (XDATUser)req.getSession().getAttribute("user");
+        if (user!=null){
+            StringReader sr = new StringReader(xmlString);
+            InputSource is = new InputSource(sr);
+            
+            response.setContentType("text/plain");
+            response.setHeader("Cache-Control", "no-cache");
+            boolean successful=false;
+            SAXReader reader = new SAXReader(user);
+            try {
+
+                XFTItem item = reader.parse(is);
+                
+                XdatStoredSearch xss = new XdatStoredSearch(item);
+                ItemSearch search= xss.getItemSearch(user);
+                ItemCollection items =search.exec(allowChildren);
+                if (items.size()>1 || items.size()==0){
+                    response.getWriter().write("<matchingResults xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
+                    Iterator iter = items.iterator();
+                    while(iter.hasNext())
+                    {
+                        XFTItem next = (XFTItem)iter.next();
+                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                        response.getWriter().write("<matchingResult>");
+                        
+                        try {
+                            SAXWriter writer = new SAXWriter(baos,false);
+                            writer.setWriteHiddenFields(true);
+                            writer.write(next);
+                        } catch (TransformerConfigurationException e) {
+                            logger.error("",e);
+                        } catch (TransformerFactoryConfigurationError e) {
+                            logger.error("",e);
+                        } catch (FieldNotFoundException e) {
+                            logger.error("",e);
+                        }
+                        response.getWriter().write(baos.toString());
+                        response.getWriter().flush();
+                        
+                        response.getWriter().write("</matchingResult>");
+                    }
+                    response.getWriter().write("</matchingResults>");
+                }else{
+                    XFTItem next = (XFTItem)items.first();
+                        
+                        try {
+                            SAXWriter writer = new SAXWriter(response.getOutputStream(),false);
+                            writer.setWriteHiddenFields(true);
+                            
+                            writer.write(next);
+                        } catch (TransformerConfigurationException e) {
+                            logger.error("",e);
+                        } catch (TransformerFactoryConfigurationError e) {
+                            logger.error("",e);
+                        } catch (FieldNotFoundException e) {
+                            logger.error("",e);
+                        }
+                        
+                }
+
+            } catch (SAXException e) {
+                logger.error("",e);
+            } catch (XFTInitException e) {
+                logger.error("",e);
+            } catch (ElementNotFoundException e) {
+                logger.error("",e);
+            } catch (FieldNotFoundException e) {
+                logger.error("",e);
+            } catch (Exception e) {
+                logger.error("",e);
+            }
+        }
+    }
+
+}

File org/nrg/xdat/base/BaseElement.java

+//Copyright 2005 Harvard University / Howard Hughes Medical Institute (HHMI) All Rights Reserved
+/*
+ * XDAT � Extensible Data Archive Toolkit
+ * Copyright (C) 2005 Washington University
+ */
+/*
+ * Created on Mar 10, 2005
+ * 
+ */
+package org.nrg.xdat.base;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.StringWriter;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.apache.velocity.Template;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+import org.nrg.xdat.display.DisplayField;
+import org.nrg.xdat.om.XdatUserI;
+import org.nrg.xdat.schema.SchemaElement;
+import org.nrg.xdat.schema.SchemaField;
+import org.nrg.xft.ItemI;
+import org.nrg.xft.ItemWrapper;
+import org.nrg.xft.XFTItem;
+import org.nrg.xft.XFTTableI;
+import org.nrg.xft.db.DBAction;
+import org.nrg.xft.exception.ElementNotFoundException;
+import org.nrg.xft.exception.FieldNotFoundException;
+import org.nrg.xft.exception.InvalidValueException;
+import org.nrg.xft.exception.XFTInitException;
+import org.nrg.xft.generators.JavaFileGenerator;
+import org.nrg.xft.schema.XFTManager;
+import org.nrg.xft.schema.Wrappers.GenericWrapper.GenericWrapperElement;
+import org.nrg.xft.search.TableSearch;
+import org.nrg.xft.security.UserI;
+import org.nrg.xft.utils.FileUtils;
+import org.nrg.xft.utils.ResourceFile;
+import org.nrg.xft.utils.VelocityUtils;
+import org.w3c.dom.Document;
+
+/**
+ * @author Tim
+ *
+ */
+public abstract class BaseElement extends ItemWrapper implements ItemI {
+	static org.apache.log4j.Logger logger = Logger.getLogger(BaseElement.class);
+	private SchemaElement schemaElement=null;
+	private Hashtable displayFields = null;
+    public BaseElement(ItemI i)
+	{
+        if (i instanceof XFTItem)
+        {
+            setItem(i);
+        }else{
+            if (i instanceof ItemWrapper)
+            {
+                setItem(((ItemWrapper)i).getItem());
+            }
+        }
+	}