/**
 * <!-- LICENSE_TEXT_START -->
 * <!-- LICENSE_TEXT_END -->
 */
package gov.nih.nci.caadapter.hl7.mif.v1;

import java.util.Hashtable;

import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

import gov.nih.nci.caadapter.hl7.mif.MIFClass;
import gov.nih.nci.caadapter.hl7.mif.MIFReferenceResolver;

/**
 * The class provides Utilities to access the MIF info.
 *
 * @author OWNER: Ye Wu
 * @author LAST UPDATE $Author: wangeug $
 * @version Since caAdapter v4.0
 *          revision    $Revision: 1.4 $
 *          date        $Date: 2007-08-27 17:34:22 $
 */
public class MIFParserUtil {

	public static MIFClass getMIFClass(String mifFileName) {
		MIFParser mifParser = new MIFParser();
		MIFClass mifClass = null;
		try {
			mifClass = mifParser.loadMIF(mifFileName);
		//resolve the internal reference
			MIFReferenceResolver refResolver=new MIFReferenceResolver();
			refResolver.getReferenceResolved(mifClass);
		}catch(Exception e) {
			e.printStackTrace();
		}
		return mifClass;
	}
	/**
	 * 
	 * @return
	 */
	public static Hashtable<String, String> getDocumentElementAttributes( Node docNode )
	{
		Hashtable<String, String> rtnHash=new Hashtable<String, String>();
		if (docNode==null)
			return rtnHash;
			
		NamedNodeMap attrMap=docNode.getAttributes();
		if (attrMap != null) 
		{
			for (int i=0;i<attrMap.getLength();i++)
			{
				Node attrNode=attrMap.item(i);
				rtnHash.put(attrNode.getNodeName(), attrNode.getNodeValue());
			}
		}
		return rtnHash;
	}
}
@@ -120,24 +120,256 @@
 ava.
-util.Hashtable;%0A
+io.IOException;%0Aimport java.io.InputStream;%0Aimport java.util.Hashtable;%0A%0Aimport javax.xml.parsers.DocumentBuilder;%0Aimport javax.xml.parsers.DocumentBuilderFactory;%0Aimport javax.xml.parsers.ParserConfigurationException;%0A%0Aimport org.w3c.dom.Document;
 %0Aimp
@@ -422,16 +422,49 @@
 om.Node;
+%0Aimport org.xml.sax.SAXException;
 %0A%0Aimport
@@ -763,17 +763,17 @@
 sion: 1.
-4
+5
  $%0A *   
@@ -808,21 +808,21 @@
 07-0
-8-27 17:34:22
+9-18 15:16:27
  $%0A 
@@ -909,17 +909,18 @@
 ileName)
- 
+%0A%09
 %7B%0A%09%09MIFP
@@ -1253,18 +1253,1211 @@
 fClass;%0A
-%09%7D
+//%09%09DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();%0A//  %09%09DocumentBuilder db;%0A//  %09%09MIFParser mifParser = new MIFParser();%0A//%09%09try %7B%0A//%09%09%09db = dbf.newDocumentBuilder();%0A//%09%09%09System.out.println(%22MIFParserUtil.getMIFClass()...build document:%22+mifFileName);%0A//%09%09%09InputStream is =mifParser.getClass().getResourceAsStream(%22/%22+mifFileName);%0A//%09%09%09Document mifDoc = db.parse(is);%0A//%09%09    mifParser.parse(mifDoc);%0A//%09%09%7D catch (ParserConfigurationException e) %7B%0A//%09%09%09// TODO Auto-generated catch block%0A//%09%09%09e.printStackTrace();%0A//%09%09%7D catch (SAXException e) %7B%0A//%09%09%09// TODO Auto-generated catch block%0A//%09%09%09e.printStackTrace();%0A//%09%09%7D catch (IOException e) %7B%0A//%09%09%09// TODO Auto-generated catch block%0A//%09%09%09e.printStackTrace();%0A//%09%09%7D%0A//%0A// %09%09String msgType=mifFileName;%0A//%09%09if (msgType.indexOf(%22UV%22)%3E-1)%0A//%09%09%09msgType=msgType.substring(0, msgType.indexOf(%22UV%22));%0A//%09%09else if (msgType.indexOf(%22.mif%22)%3E-1)%0A//%09%09%09msgType=msgType.substring(0, msgType.indexOf(%22.mif%22));%0A//%09%09%09%09%09%0A//%09%09MIFClass rtnClass=mifParser.getMIFClass();%0A//%09%09rtnClass.setMessageType(msgType);%0A//%09%09MIFReferenceResolver refResolver=new MIFReferenceResolver();%0A//%09%09refResolver.getReferenceResolved(rtnClass);%0A//%09%09return rtnClass;%0A%09%7D%0A
 %0A%09/**%0A%09 

implement method to load MIF from mif.zip file