public void generateEngineOutputManager( File servicePath, Document describeDocument, String processingName) throws Exception { File stylesheet = new File(servicePath, SHELL_OUTPUT_MANAGER_XLST_PATH); Document xslDocument; File shellScriptFolder = new File(servicePath, SHELL_SCRIPT_PATH); shellScriptFolder.mkdirs(); if (stylesheet.exists()) { xslDocument = domUtil.fileToDocument(stylesheet); transformer = TransformerFactory.newInstance() .newTemplates(new DOMSource(xslDocument)) .newTransformer(); transformer.setParameter("processingName", processingName); transformer.setParameter( "complexDataFolderPath", new File(servicePath, COMPLEX_DATA_PATH).getAbsolutePath()); transformer.transform( new StreamSource(DOMUtil.getDocumentAsInputStream(describeDocument)), new StreamResult( new FileOutputStream( new File( shellScriptFolder, SHELL_SCRIPT_FILE_PREFIX + processingName + "_outputManager.tmp")))); } }
private Document extractMetadataFromItem(String itemId, StoreItem storeItem, File webappDir) throws Exception { Document extractedDoc = null; Properties props; props = new Properties(); props.load( new FileInputStream( new File(webappDir, "WEB-INF/classes/metadataExtractionProcessings.properties"))); // trying shell script String command = props.getProperty("shell." + storeItem.type); if (command != null && command.equals("") == false) { File commandFile; commandFile = new File(webappDir, "WEB-INF/metadataExtractors/" + command); commandFile.setExecutable(true, false); Properties prefs = Prefs.load(webappDir); File dataFile; dataFile = new File(prefs.getProperty("download.dir"), itemId); File outFile; outFile = new File(prefs.getProperty("download.dir"), itemId + "_metadata.xml"); ProcessBuilder pb; Process p; pb = new ProcessBuilder("./" + command, dataFile.getAbsolutePath(), outFile.getAbsolutePath()); pb.directory(commandFile.getParentFile()); p = pb.start(); p.waitFor(); DOMUtil util; util = new DOMUtil(); extractedDoc = util.fileToDocument(outFile); } return extractedDoc; }
public String generateEngineTemplate( File newServicePath, Document describeDocument, String processingName) throws Exception { Document xslDocument; String shellTemplate = null; File stylesheet = new File(newServicePath, SHELL_TEMPLATE_XSLT_PATH); File shellScriptFolder = new File(newServicePath, SHELL_SCRIPT_PATH); shellScriptFolder.mkdirs(); if (stylesheet.exists()) { xslDocument = domUtil.fileToDocument(stylesheet); transformer = TransformerFactory.newInstance().newTransformer(new DOMSource(xslDocument)); transformer.transform( new StreamSource(DOMUtil.getDocumentAsInputStream(describeDocument)), new StreamResult( new FileOutputStream( new File( shellScriptFolder, SHELL_SCRIPT_FILE_PREFIX + processingName + "_template.sh")))); shellTemplate = IOUtil.loadString( new File( shellScriptFolder, SHELL_SCRIPT_FILE_PREFIX + processingName + "_template.sh")); } return shellTemplate; }
@Override public Object executeTag(org.w3c.dom.Element connEl) throws Exception { CswClient client; Object opType = null; try { String operationType = this.engine.evaluateString( connEl.getAttribute("type"), IEngine.EngineStringType.ATTRIBUTE); LinkedList<Element> children = DOMUtil.getChildren(connEl); client = (CswClient) this.executeChildTag(children.get(0)); Document xmlSnippet; xmlSnippet = (Document) this.executeChildTag(children.get(1)); TransactionType t = new TransactionType(); if (operationType.equals("DELETE")) { DeleteType delete = new DeleteType(); delete.setTypeName(evaluateAttribute(connEl, "typeName")); QueryConstraintType con = new QueryConstraintType(); con.setVersion(""); delete.setConstraint(con); JAXBElement<FilterType> filter = (JAXBElement<FilterType>) JAXBUtil.getInstance().unmarshall(DOMUtil.getDocumentAsInputStream(xmlSnippet)); con.setFilter(filter.getValue()); opType = delete; } else if (operationType.equals("INSERT")) { InsertType insert = new InsertType(); insert .getAny() .add(JAXBUtil.getInstance().unmarshall(DOMUtil.getDocumentAsInputStream(xmlSnippet))); opType = insert; } /*else { UpdateType update=new UpdateType(); update.getAny().add(JAXBUtil.getInstance().unmarshall(DOMUtil.getDocumentAsInputStream(xmlSnippet))); opType=update; }*/ t.getInsertOrUpdateOrDelete().add(opType); TransactionResponseType response = client.transact(t); File tempFile = IOUtil.getTemporaryFile(); JAXBUtil.getInstance() .marshall( OFactory.csw.createTransactionResponse(response), new FileOutputStream(tempFile)); DOMUtil util; util = new DOMUtil(); Document xmlDoc = util.fileToDocument(tempFile); tempFile.delete(); return xmlDoc; } catch (Exception e) { e.printStackTrace(); throw e; } // JAXBUtil.getInstance().marshall(response, new // FileOutputStream("/home/massi/TEMP/GetRecordsResponse.xml")); }