Skip to content
This repository was archived by the owner on Jul 8, 2020. It is now read-only.

Commit

Permalink
Adding XML export functionality.
Browse files Browse the repository at this point in the history
SVN-Revision: 1777
  • Loading branch information
Will Garcia committed Nov 30, 2010
1 parent b58bb5d commit 771c91d
Show file tree
Hide file tree
Showing 7 changed files with 587 additions and 16 deletions.
1 change: 1 addition & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,6 @@
<classpathentry kind="lib" path="software/ncitbrowser/lib/lexevs-tree-2.0.1.jar"/>
<classpathentry kind="lib" path="software/ncitbrowser/lib/lexevsapi60-beans.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="lib" path="software/ncitbrowser/extlib/xercesImpl.jar"/>
<classpathentry kind="output" path="software/ncitbrowser/build/web/WEB-INF/classes"/>
</classpath>
2 changes: 1 addition & 1 deletion .project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ncit</name>
<name>ncitbrowser</name>
<comment></comment>
<projects>
</projects>
Expand Down
Binary file added software/ncitbrowser/extlib/xercesImpl.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import gov.nih.nci.evs.browser.utils.SearchCart;
import gov.nih.nci.evs.browser.utils.SearchUtils;
import gov.nih.nci.evs.browser.utils.ExportCartXML;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;

import org.LexGrid.LexBIG.DataModel.Core.ResolvedConceptReference;

Expand All @@ -15,6 +17,8 @@
import javax.servlet.ServletOutputStream;

import org.LexGrid.concepts.Entity;
import org.LexGrid.commonTypes.Property;

import org.apache.log4j.Logger;

/**
Expand Down Expand Up @@ -73,8 +77,8 @@ public class CartActionBean {
private String _codingScheme = null;
private HashMap<String, Concept> _cart = null;
private String _backurl = null;
static public final String EXPORT_FILE = "cart.txt";
static public final String CONTENT_TYPE = "text/txt";
static public final String XML_FILE_NAME = "cart.xml";
static public final String XML_CONTENT_TYPE = "text/xml";

// Getters & Setters

Expand Down Expand Up @@ -140,7 +144,8 @@ private void _init() {
*/
public void addToCart() throws Exception {
String code = null;
String codingScheme = null;
String codingScheme = null;
String nameSpace = null;
String name = null;

// Get concept information from the Entity item passed in
Expand All @@ -157,14 +162,18 @@ public void addToCart() throws Exception {
// Get coding scheme
codingScheme = (String)request.getSession().getAttribute(_codingScheme);

// Get concept name space
nameSpace = curr_concept.getEntityCodeNamespace();

// Get concept name
name = curr_concept.getEntityDescription().getContent();
name = curr_concept.getEntityDescription().getContent();

// Add concept to cart
if (_cart == null) _init();
Concept item = new Concept();
item.setCode(code);
item.setCodingScheme(codingScheme);
item.setNameSpace(nameSpace);
item.setName(name);

if (!_cart.containsKey(code))
Expand All @@ -189,11 +198,72 @@ public void removeFromCart() throws Exception {
}

/**
* Export cart
* Export cart in XML format
* @return
* @throws Exception
*/
public void exportCart() throws Exception {
public void exportCartXML() throws Exception {

SearchCart search = new SearchCart();
ExportCartXML xml = new ExportCartXML();
ResolvedConceptReference ref = null;
String sb = null;

// Get Entities to be exported and build export xml string
// in memory

if (_cart != null && _cart.size() > 0) {

xml.addCartTag();

// Add all terms from the cart
for (Iterator<Concept> i = getConcepts().iterator(); i.hasNext();) {
Concept item = (Concept) i.next();
ref = search.getConceptByCode(item.codingScheme, item.code);
if (ref != null) {
_logger.info("Exporting: " + ref.getCode());

// Add parent concepts
Vector<Entity> parents = search.getParentConcepts(ref);

// Add child concepts
Vector<Entity> children = search.getChildConcepts(ref);

// Add terms and properties
Property[] pres = search.getPresentationValues(ref);
Property[] def = search.getDefinitionValues(ref);
Property[] prop = search.getPropertyValues(ref);
Property[] comm = search.getCommentValues(ref);
xml.addTermTag(item.name, item.code, item.codingScheme,
pres, def, prop, comm, parents, children);
}
}

// Send export XML string to browser

sb = xml.generateXMLString();
HttpServletResponse response = (HttpServletResponse) FacesContext
.getCurrentInstance().getExternalContext().getResponse();
response.setContentType(XML_CONTENT_TYPE);
response.setHeader("Content-Disposition", "attachment; filename="
+ XML_FILE_NAME);
response.setContentLength(sb.length());
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(sb.toString().getBytes(), 0, sb.length());
ouputStream.flush();
ouputStream.close();

// Don't allow JSF to forward to cart.jsf
FacesContext.getCurrentInstance().responseComplete();
}
}

/**
* Export cart in Excel format
* @return
* @throws Exception
*/
public void exportCartEXCEL() throws Exception {

SearchCart search = new SearchCart();
ResolvedConceptReference ref = null;
Expand Down Expand Up @@ -226,9 +296,9 @@ public void exportCart() throws Exception {

HttpServletResponse response = (HttpServletResponse) FacesContext
.getCurrentInstance().getExternalContext().getResponse();
response.setContentType(CONTENT_TYPE);
response.setContentType(XML_CONTENT_TYPE);
response.setHeader("Content-Disposition", "attachment; filename="
+ EXPORT_FILE);
+ XML_FILE_NAME);
response.setContentLength(sb.length());
ServletOutputStream ouputStream = response.getOutputStream();
ouputStream.write(sb.toString().getBytes(), 0, sb.length());
Expand All @@ -238,7 +308,7 @@ public void exportCart() throws Exception {
// Don't allow JSF to forward to cart.jsf
FacesContext.getCurrentInstance().responseComplete();
}
}
}

/**
* Subclass to hold contents of the cart
Expand All @@ -247,6 +317,7 @@ public void exportCart() throws Exception {
public class Concept {
private String code = null;
private String codingScheme = null;
private String nameSpace = null;
private String name = null;
private boolean selected = false;

Expand All @@ -267,6 +338,14 @@ public String getCodingScheme() {
public void setCodingScheme(String codingScheme) {
this.codingScheme = codingScheme;
}

public String getNameSpace() {
return this.nameSpace;
}

public void setNameSpace(String namespace) {
this.nameSpace = namespace;
}

public String getName() {
return this.name;
Expand Down Expand Up @@ -305,6 +384,7 @@ public String toString() {
Concept item = (Concept)i.next();
sb.append("\t Code = " + item.code + "\n");
sb.append("\tCoding scheme = " + item.codingScheme + "\n");
sb.append("\t Name space = " + item.nameSpace + "\n");
sb.append("\t Name = " + item.name + "\n");
sb.append("\t Selected = " + item.selected + "\n");
}
Expand Down
Loading

0 comments on commit 771c91d

Please sign in to comment.