software/ncitbrowser/src/java/gov/nih/nci/evs/browser/bean/CartActionBean.java
/**
     * Export cart in XML format
     * @return
     * @throws Exception
     */
Export cart in XML format
@return
@throws Exception
Export cart in XML format @return @throws Exception
public String exportCartXML(HttpServletRequest request, HttpServletResponse response) throws Exception {
        updateSelection(request);
        ResolvedConceptReference ref = null;
        HashMap<String, SchemeVersion> versionList = null;
    	if (getCount() < 1) {
        	_messageflag = true;
        	_message = NO_CONCEPTS;
        	request.getSession().setAttribute("message", _message);
        	return null;
    	}
    	if (!hasSelected()) {
        	_messageflag = true;
        	_message = NOTHING_SELECTED;
        	request.getSession().setAttribute("message", _message);
        	return null;
    	}
    	LexEVSValueSetDefinitionServices vsd_service = null;
        if (_cart != null && _cart.size() > 0) {
        	versionList = getSchemeVersionList();
    		vsd_service = RemoteServerUtil.getLexEVSValueSetDefinitionServices();
            Mappings maps = new Mappings();
    		ValueSetDefinition vsd = new ValueSetDefinition();
    		vsd.setMappings(maps);
			vsd.setValueSetDefinitionURI("EXPORT:VSDREF_CART");
			vsd.setValueSetDefinitionName("VSDREF_CART");
			vsd.setConceptDomain("Concepts");
			DuplicateCheck dc = new DuplicateCheck();
			for (Iterator<Entry<String, SchemeVersion>> i = versionList
					.entrySet().iterator(); i.hasNext();) {
				Entry<String, SchemeVersion> x = i.next();
				SchemeVersion sv = x.getValue();
				SupportedCodingScheme scs = new SupportedCodingScheme();
				scs.setLocalId(sv.codingScheme);
				scs.setUri(sv.uri);
				if (dc.test(sv.codingScheme)) {
					maps.addSupportedCodingScheme(scs);
					_logger.debug("Adding CS: "
							+ sv.codingScheme + " ("
							+ sv.uri + ")");
				}
			}
			dc.reset();
			for (Iterator<Entry<String, SchemeVersion>> i = versionList
					.entrySet().iterator(); i.hasNext();) {
				Entry<String, SchemeVersion> x = i.next();
				SchemeVersion sv = x.getValue();
            	SupportedNamespace sns = new SupportedNamespace();
            	sns.setLocalId(sv.namespace);
            	sns.setEquivalentCodingScheme(sv.codingScheme);
            	if (dc.test(sv.namespace)) {
            		maps.addSupportedNamespace(sns);
            		_logger.debug("Adding NS: " + sv.namespace);
            	}
            }
			DefinitionEntry de = new DefinitionEntry();
			de.setRuleOrder(1L);
			de.setOperator(DefinitionOperator.OR);
			ValueSetDefinitionReference vsdRef = new ValueSetDefinitionReference();
			vsdRef.setValueSetDefinitionURI("EXPORT:CART_NODES");
			de.setValueSetDefinitionReference(vsdRef);
			vsd.addDefinitionEntry(de);
			DefinitionEntry deSub = null;
			long ruleOrder = 2;
            for (Iterator<Concept> i = getConcepts().iterator(); i.hasNext();) {
                Concept item = (Concept) i.next();
                ref = getConceptByCode(item.codingScheme, item.version, item.code);
                if (item.getSelected() && ref != null) {
					_logger.debug("Exporting: " + ref.getCode() + "("
							+ item.codingScheme + ":" + item.version + ")");
					deSub = new DefinitionEntry();
					deSub.setRuleOrder(ruleOrder); ruleOrder++;
					deSub.setOperator(DefinitionOperator.OR);
            		EntityReference entityRef = new EntityReference();
                    String entityCode = ref.getEntity().getEntityCode();
                    String entityNameSpace = ref.getCodeNamespace();
            		entityRef.setEntityCode(entityCode);
            		entityRef.setEntityCodeNamespace(entityNameSpace);
            		entityRef.setLeafOnly(false);
            		entityRef.setTransitiveClosure(false);
            		deSub.setEntityReference(entityRef);
            		vsd.addDefinitionEntry(deSub);
                }
            }
/*
			// Add list of coding schemes version reference
			AbsoluteCodingSchemeVersionReferenceList csvList = new AbsoluteCodingSchemeVersionReferenceList();
			HashSet uri_hset = new HashSet();
            Vector cart_coding_scheme_ref_vec = (Vector) request.getSession().getAttribute("cart_coding_scheme_ref_vec");
            if (cart_coding_scheme_ref_vec == null) return null;
            for (int i=0; i<cart_coding_scheme_ref_vec.size(); i++) {
				String cart_coding_scheme_ref = (String) cart_coding_scheme_ref_vec.elementAt(i);
				Vector u = DataUtils.parseData(cart_coding_scheme_ref);
				String cs_uri = (String) u.elementAt(0);
				if (!uri_hset.contains(cs_uri)) {
					uri_hset.add(cs_uri);
					String version = HTTPUtils.cleanXSS((String) request.getParameter(cs_uri));
					if (version != null) {
						csvList.addAbsoluteCodingSchemeVersionReference(Constructors.createAbsoluteCodingSchemeVersionReference(cs_uri, version));
				    }
				}
			}
*/
            StringBuffer buf = null;
            InputStream reader = null;
            HashMap<String, ValueSetDefinition> referencedVSDs = null;
            String csVersionTag = null;
            boolean failOnAllErrors = false;
/*
            try {
	    		//reader = vsd_service.exportValueSetResolution(vsd, null, csvList, null, false);
                reader = vsd_service.exportValueSetResolution(vsd, referencedVSDs, csvList, csVersionTag, failOnAllErrors);
				if (reader != null) {
					buf = new StringBuffer();
					for (int c = reader.read(); c != -1; c = reader.read()) {
						buf.append((char) c);
					}
				} else {
					buf = new StringBuffer("<error>exportValueSetResolution returned null.</error>");
				}
            } catch (Exception e) {
				e.printStackTrace();
				buf = new StringBuffer("<error>The VSD export service is not supported by your current LexEVS setup.</error>");
				buf.append("<!-- " + e.getMessage() + " -->");
			} finally {
				try {
					reader.close();
				} catch (Exception e) {
					new StringBuffer("<error>" + e.getMessage() + "</error>");
				}
			}
*/
            try {
				buf = vsd_service.exportValueSetDefinition(vsd);
            } catch (Exception e) {
				buf = new StringBuffer("<error>The VSD export service is not supported by your current LexEVS setup.</error>");
				buf.append("<!-- " + e.getMessage() + " -->");
			} finally {
				try {
				} catch (Exception e) {
					new StringBuffer("<error>" + e.getMessage() + "</error>");
				}
			}
            /*
            HttpServletResponse response = (HttpServletResponse) FacesContext
                    .getCurrentInstance().getExternalContext().getResponse();
            */
            response.setContentType(XML_CONTENT_TYPE);
            response.setHeader("Content-Disposition", "attachment; filename="
                    + XML_FILE_NAME);
            response.setContentLength(buf.length());
            ServletOutputStream ouputStream = response.getOutputStream();
            ouputStream.write(buf.toString().getBytes("UTF8"), 0, buf.length());
            ouputStream.flush();
            ouputStream.close();
        }
        return null;
    }
public String exportCartXML ( HttpServletRequest request , HttpServletResponse response ) throws Exception { updateSelection ( request ) ; ResolvedConceptReference ref = null ; HashMap < String , SchemeVersion > versionList = null ; if ( getCount ( ) < 1 ) { _messageflag = true ; _message = NO_CONCEPTS ; request . getSession ( ) . setAttribute ( "message" , _message ) ; return null ; } if ( ! hasSelected ( ) ) { _messageflag = true ; _message = NOTHING_SELECTED ; request . getSession ( ) . setAttribute ( "message" , _message ) ; return null ; } LexEVSValueSetDefinitionServices vsd_service = null ; if ( _cart != null && _cart . size ( ) > 0 ) { versionList = getSchemeVersionList ( ) ; vsd_service = RemoteServerUtil . getLexEVSValueSetDefinitionServices ( ) ; Mappings maps = new Mappings ( ) ; ValueSetDefinition vsd = new ValueSetDefinition ( ) ; vsd . setMappings ( maps ) ; vsd . setValueSetDefinitionURI ( "EXPORT:VSDREF_CART" ) ; vsd . setValueSetDefinitionName ( "VSDREF_CART" ) ; vsd . setConceptDomain ( "Concepts" ) ; DuplicateCheck dc = new DuplicateCheck ( ) ; for ( Iterator < Entry < String , SchemeVersion > > i = versionList . entrySet ( ) . iterator ( ) ; i . hasNext ( ) ; ) { Entry < String , SchemeVersion > x = i . next ( ) ; SchemeVersion sv = x . getValue ( ) ; SupportedCodingScheme scs = new SupportedCodingScheme ( ) ; scs . setLocalId ( sv . codingScheme ) ; scs . setUri ( sv . uri ) ; if ( dc . test ( sv . codingScheme ) ) { maps . addSupportedCodingScheme ( scs ) ; _logger . debug ( "Adding CS: " + sv . codingScheme + " (" + sv . uri + ")" ) ; } } dc . reset ( ) ; for ( Iterator < Entry < String , SchemeVersion > > i = versionList . entrySet ( ) . iterator ( ) ; i . hasNext ( ) ; ) { Entry < String , SchemeVersion > x = i . next ( ) ; SchemeVersion sv = x . getValue ( ) ; SupportedNamespace sns = new SupportedNamespace ( ) ; sns . setLocalId ( sv . namespace ) ; sns . setEquivalentCodingScheme ( sv . codingScheme ) ; if ( dc . test ( sv . namespace ) ) { maps . addSupportedNamespace ( sns ) ; _logger . debug ( "Adding NS: " + sv . namespace ) ; } } DefinitionEntry de = new DefinitionEntry ( ) ; de . setRuleOrder ( 1L ) ; de . setOperator ( DefinitionOperator . OR ) ; ValueSetDefinitionReference vsdRef = new ValueSetDefinitionReference ( ) ; vsdRef . setValueSetDefinitionURI ( "EXPORT:CART_NODES" ) ; de . setValueSetDefinitionReference ( vsdRef ) ; vsd . addDefinitionEntry ( de ) ; DefinitionEntry deSub = null ; long ruleOrder = 2 ; for ( Iterator < Concept > i = getConcepts ( ) . iterator ( ) ; i . hasNext ( ) ; ) { Concept item = ( Concept ) i . next ( ) ; ref = getConceptByCode ( item . codingScheme , item . version , item . code ) ; if ( item . getSelected ( ) && ref != null ) { _logger . debug ( "Exporting: " + ref . getCode ( ) + "(" + item . codingScheme + ":" + item . version + ")" ) ; deSub = new DefinitionEntry ( ) ; deSub . setRuleOrder ( ruleOrder ) ; ruleOrder ++ ; deSub . setOperator ( DefinitionOperator . OR ) ; EntityReference entityRef = new EntityReference ( ) ; String entityCode = ref . getEntity ( ) . getEntityCode ( ) ; String entityNameSpace = ref . getCodeNamespace ( ) ; entityRef . setEntityCode ( entityCode ) ; entityRef . setEntityCodeNamespace ( entityNameSpace ) ; entityRef . setLeafOnly ( false ) ; entityRef . setTransitiveClosure ( false ) ; deSub . setEntityReference ( entityRef ) ; vsd . addDefinitionEntry ( deSub ) ; } } /*
			// Add list of coding schemes version reference
			AbsoluteCodingSchemeVersionReferenceList csvList = new AbsoluteCodingSchemeVersionReferenceList();
			HashSet uri_hset = new HashSet();
            Vector cart_coding_scheme_ref_vec = (Vector) request.getSession().getAttribute("cart_coding_scheme_ref_vec");
            if (cart_coding_scheme_ref_vec == null) return null;
            for (int i=0; i<cart_coding_scheme_ref_vec.size(); i++) {
				String cart_coding_scheme_ref = (String) cart_coding_scheme_ref_vec.elementAt(i);
				Vector u = DataUtils.parseData(cart_coding_scheme_ref);
				String cs_uri = (String) u.elementAt(0);
				if (!uri_hset.contains(cs_uri)) {
					uri_hset.add(cs_uri);
					String version = HTTPUtils.cleanXSS((String) request.getParameter(cs_uri));
					if (version != null) {
						csvList.addAbsoluteCodingSchemeVersionReference(Constructors.createAbsoluteCodingSchemeVersionReference(cs_uri, version));
				    }
				}
			}
*/ StringBuffer buf = null ; InputStream reader = null ; HashMap < String , ValueSetDefinition > referencedVSDs = null ; String csVersionTag = null ; boolean failOnAllErrors = false ; /*
            try {
	    		//reader = vsd_service.exportValueSetResolution(vsd, null, csvList, null, false);
                reader = vsd_service.exportValueSetResolution(vsd, referencedVSDs, csvList, csVersionTag, failOnAllErrors);
				if (reader != null) {
					buf = new StringBuffer();
					for (int c = reader.read(); c != -1; c = reader.read()) {
						buf.append((char) c);
					}
				} else {
					buf = new StringBuffer("<error>exportValueSetResolution returned null.</error>");
				}
            } catch (Exception e) {
				e.printStackTrace();
				buf = new StringBuffer("<error>The VSD export service is not supported by your current LexEVS setup.</error>");
				buf.append("<!-- " + e.getMessage() + " -->");
			} finally {
				try {
					reader.close();
				} catch (Exception e) {
					new StringBuffer("<error>" + e.getMessage() + "</error>");
				}
			}
*/ try { buf = vsd_service . exportValueSetDefinition ( vsd ) ; } catch ( Exception e ) { buf = new StringBuffer ( "<error>The VSD export service is not supported by your current LexEVS setup.</error>" ) ; buf . append ( "<!-- " + e . getMessage ( ) + " -->" ) ; } finally { try { } catch ( Exception e ) { new StringBuffer ( "<error>" + e . getMessage ( ) + "</error>" ) ; } } /*
            HttpServletResponse response = (HttpServletResponse) FacesContext
                    .getCurrentInstance().getExternalContext().getResponse();
            */ response . setContentType ( XML_CONTENT_TYPE ) ; response . setHeader ( "Content-Disposition" , "attachment; filename=" + XML_FILE_NAME ) ; response . setContentLength ( buf . length ( ) ) ; ServletOutputStream ouputStream = response . getOutputStream ( ) ; ouputStream . write ( buf . toString ( ) . getBytes ( "UTF8" ) , 0 , buf . length ( ) ) ; ouputStream . flush ( ) ; ouputStream . close ( ) ; } return null ; }
Export cart in XML format
 @return
 @throws Exception
Export cart in XML format @return @throws Exception
//SearchCart search = new SearchCart();
 // Get Entities to be exported and build export XML string
 // in memory
 // Generate unique list of scheme / versions for the cart
 //versionList = getSchemeVersionList(search);
 // Setup lexbig service
 //instantiate the mappings
 // Instantiate VSD
 // Add supported coding schemes
 // Add supported name spaces
 // Instantiate DefinitionEntry(Rule Set)
 // Instantiate ValueSetDefinitionReference
 // Add terms from the cart - DefinitionEntry(Rule Set)
 //ref = search.getConceptByCode(item.codingScheme, item.version, item.code);
 // Instantiate EntityReference
 // set appropriate values for entityReference
 // Build a buffer holding the XML data
 //public InputStream exportValueSetResolution(ValueSetDefinition valueSetDefinition, HashMap<String, ValueSetDefinition> referencedVSDs, AbsoluteCodingSchemeVersionReferenceList csVersionList, String csVersionTag, boolean failOnAllErrors)
 // [GF#32966] Unable to Export XML from CART
 //reader.close();
 // Send export XML string to browser
 // Don't allow JSF to forward to cart.jsf
 //FacesContext.getCurrentInstance().responseComplete();
