001: /*---------------- FILE HEADER ------------------------------------------
002: This file is part of adv ebrim project.
003: Copyright (C) 2007 by:
004:
005: Andreas Poth
006: lat/lon GmbH
007: Aennchenstr. 19
008: 53177 Bonn
009: Germany
010: E-Mail: poth@lat-lon.de
011:
012: ---------------------------------------------------------------------------*/
013: package de.latlon.adv;
014:
015: import java.io.File;
016: import java.io.FileWriter;
017: import java.io.IOException;
018: import java.net.MalformedURLException;
019: import java.net.URISyntaxException;
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import javax.xml.transform.TransformerException;
024:
025: import org.deegree.framework.log.ILogger;
026: import org.deegree.framework.log.LoggerFactory;
027: import org.deegree.framework.xml.XMLFragment;
028: import org.deegree.framework.xml.XMLTools;
029: import org.deegree.framework.xml.XSLTDocument;
030: import org.w3c.dom.Element;
031: import org.xml.sax.SAXException;
032:
033: /**
034: * The <code>EBRIMTransformer</code> class
035: *
036: * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
037: *
038: * @author last edited by: $Author: bezema $
039: *
040: * @version $Revision: 1.6 $, $Date: 2007-06-11 16:40:49 $
041: *
042: */
043:
044: public class EBRIMTransformer {
045: private static ILogger LOG = LoggerFactory
046: .getLogger(EBRIMTransformer.class);
047:
048: /**
049: * simple main method to test the xslt transforming of ebrim to wfs
050: *
051: * @param args
052: * the commandline arguments
053: */
054: public static void main(String[] args) {
055: try {
056:
057: // String xsltScript= "scripts/xslt/outEBRIM.xsl";
058: // String inputXML= "resources/output/GetFeatureResponse_all_registry_objects.xml";
059:
060: //String inputXML= "resources/output/GetFeatureResponse_classification_node.xml";
061: String xsltScript = "scripts/xslt/ebrim/inEBRIM.xsl";
062: String inputXML = "resources/requests/csw/Transaction/xml/very_small_registry_package.xml";
063: XMLFragment transactionInsertDocument = new XMLFragment(
064: new File(inputXML));
065: LOG.logInfo("Input GetRecords request:\n"
066: + transactionInsertDocument.getAsPrettyString());
067: Element n = transactionInsertDocument.getRootElement();
068: try {
069: LOG.logInfo("the rim prefix is bound to: "
070: + XMLTools.getNamespaceForPrefix("rim", n));
071: } catch (URISyntaxException e) {
072: // TODO Auto-generated catch block
073: e.printStackTrace();
074: }
075: // incoming GetRecord request must be transformed to a GetFeature
076: // request because the underlying 'data engine' of the CSW is a WFS
077: XSLTDocument xslSheet = new XSLTDocument(new File(
078: xsltScript).toURI().toURL());
079: Map<String, String> params = new HashMap<String, String>();
080: params.put("REQUEST_NAME", "GetRecords");
081: params.put("VERSION", "2.0.0");
082: params.put("SEARCH_STATUS", "bla");
083: params.put("ELEMENT_SET", "full");
084: params.put("RECORD_SCHEMA", "bla");
085: params.put("RECORDS_MATCHED", "10");
086: params.put("RECORDS_RETURNED", "10");
087: params.put("NEXT_RECORD", "0");
088:
089: LOG.logInfo("Transforming: " + inputXML + " with script: "
090: + xsltScript);
091: XMLFragment getFeatureDocument = xslSheet.transform(
092: transactionInsertDocument, "http://deegree.org",
093: null, params);
094: LOG.logInfo("Writing generated output to /dev/shm/out.xml");
095: getFeatureDocument.prettyPrint(new FileWriter(new File(
096: "/dev/shm/out.xml")));
097: LOG.logInfo("Generated WFS GetFeature request:\n"
098: + getFeatureDocument.getAsPrettyString());
099: } catch (TransformerException e) {
100: e.printStackTrace();
101: String msg = "Can't transform GetRecord request to WFS GetFeature request: "
102: + e.getMessage();
103: LOG.logError(msg, e);
104: } catch (MalformedURLException e) {
105: e.printStackTrace();
106: String msg = "Can't transform GetRecord request to WFS GetFeature request: "
107: + e.getMessage();
108: LOG.logError(msg, e);
109: } catch (IOException e) {
110: e.printStackTrace();
111: String msg = "Can't transform GetRecord request to WFS GetFeature request: "
112: + e.getMessage();
113: LOG.logError(msg, e);
114: } catch (SAXException e) {
115: e.printStackTrace();
116: String msg = "Can't transform GetRecord request to WFS GetFeature request: "
117: + e.getMessage();
118: LOG.logError(msg, e);
119: }
120: }
121: }
|