public Document execute(String pMethod, Hashtable pParams) throws ExternalException { Document doc = null; if( pMethod.equalsIgnoreCase("readDCR") { String dcrPath = (String)pParams.get("dcrPath"); if( dcrPath != null && !"".equals(dcrPath.trim()) { // creates document. doc = getEmptyExternalDoc(); Element rootnode = doc.getDocumentElement(); // read the dcr Document dcrDoc = readXMLFile(dcrPath); // import the dcr nodes into the external doc // the 2nd parameter is a "deep" import which we want. doc.importNode(dcrDoc.getDocumentElement(),true); // append the DCR's DOM as a child of the // node. rootnode.appendChild(dcrDoc.getDocumentElement()); } else { // error check. } } else { throw new ExternalException("Invalid method [" + pMethod + "]!"); } return doc; }
/** * Reads an XML file from the file-system and returns a valid org.w3c.Document. * @param pRelativePath The relative-path to the XML file. * @return A valid Document, or null if there's an error/file is missing/etc. */ public Document readXMLFile(String pRelativePath) { DOMWrapper dom = null; EndUserSite site = getSite(); FileDALIfc fileDAL = getUser().getFileDAL(); String dcrPath = fileDAL.getWebRoot(site) + pRelativePath; try { String dcrXML = fileDAL.read(dcrPath); if( dcrXML != null && !"".equals(dcrXML.trim()) ) { dom = new DOMWrapper(dcrXML); } } catch(SAXException se) { if( mLogger.isErrorEnabled() ) { mLogger.error("fetchDCRXML: could not parse FormEntry XML!",se); } } catch(RuntimeException re) { if( mLogger.isErrorEnabled() ) { mLogger.error("fetchDCRXML: could not read FormEntry: " + dcrPath,re); } } return dom == null ? null : dom.getDocument(); }