Changeset 24247


Ignore:
Timestamp:
2011-07-08T16:38:27+12:00 (10 years ago)
Author:
sjb48
Message:

Oran code for supporting format changes to document.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/action/FormatAction.java

    r24203 r24247  
    5555   
    5656        String coll = (String)params.get(GSParams.COLLECTION); //SYSTEM_CLUSTER);
    57         //String subaction = (String)params.get(GSParams.SUBACTION);
    5857        String service = (String)params.get(GSParams.SERVICE);
    5958        String classifier = (String)params.get("cl");
    60 
    61 
    62         logger.error("Collection="+coll);
    63         logger.error("Subaction="+subaction);
    64         logger.error("Service="+service);
    65         logger.error("Classifier="+classifier);
    66 
    6759
    6860        String to = "";
     
    8173        mr_request_message.appendChild(mr_request);
    8274   
    83         //Element format = this.doc.createElement(GSXML.FORMAT_STRING_ELEM);
    84         //mr_request.appendChild(format);
    85 
    8675        String format_string = (String)params.get("data");
    87         //logger.error("Original format string");
    88         //logger.error(format_string);
    8976   
    9077        Element page_response = this.doc.createElement(GSXML.RESPONSE_ELEM);
    9178
    9279        Iterator it = params.keySet().iterator();
    93         //while(it.hasNext())
    94         //{
    95         //    logger.error("Param: "+it.next());
    96         //}     
    9780
    98         try {
    99             //DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    100             //DocumentBuilder builder = factory.newDocumentBuilder();
    101             //String input = "<html><head><title></title></head><body>" + format_string + "</body></html>";
    102             //String input = format_string;
    103             //InputSource is = new InputSource( new StringReader( input ) );
    104             //Document d = (Document) builder.parse( is );
    105             Document d = this.converter.getDOM(format_string); //(Document) builder.parse( is );
    106             //Node n1 = d.getFirstChild();           
    107             //Document d2 = (Document) this.doc.importNode(e, true);
     81        if(subaction.equals("saveDocument"))
     82        {
     83            Element format = this.doc.createElement(GSXML.FORMAT_STRING_ELEM);
     84            try{
     85                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
     86                DocumentBuilder builder = factory.newDocumentBuilder();
     87                InputSource is = new InputSource( new StringReader( format_string ) );
     88                Document d = (Document) builder.parse( is );
     89                Node n1 = d.getFirstChild();
    10890
    109             //Element format_statement = this.doc.importNode(d, true);
     91                Element format_statement = (Element) this.doc.importNode(n1, true);
     92                format.appendChild(format_statement);
     93                mr_request.appendChild(format);
     94            } catch( Exception ex ) {
     95                logger.error("There was an exception "+ex);
    11096
    111             // Call XSLT to transform document to xml format string
    112             XMLTransformer transformer = new XMLTransformer();
    113             // HOW DO I DO THIS PROPERLY?
    114             //String style = stylesheetFile(String gsdl3_home, String site_name, String collection, String interface_name, ArrayList base_interfaces, String filename);
    115             //Document style_doc = this.converter.getDOM(new File(style), "UTF-8"); //"/home/sam/greenstone3/web/interfaces/oran/transform/formatString.xsl"), "UTF-8");  /*************************/
    116             Document style_doc = this.converter.getDOM(new File("/research/sjb48/greenstone3/web/interfaces/oran/transform/formatString.xsl"), "UTF-8");  /*************************/
     97                StringWriter sw = new StringWriter();
     98                PrintWriter pw = new PrintWriter(sw, true);
     99                ex.printStackTrace(pw);
     100                pw.flush();
     101                sw.flush();
     102                logger.error(sw.toString());
     103            }
    117104
    118             if(style_doc == null)
    119                 logger.error("style_doc is null");
    120 
    121             // not sure what to do here - some code from Transforming Receptionist
    122             //String transformed = transformer.transformToString(style_doc, d);
    123             logger.error("About to transform");
    124             Node transformed = (Node) transformer.transform(style_doc, d); 
    125             // Failing org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted. ; SystemID: file:///home/sam/greenstone3/packages/tomcat/bin/dummy.xsl
    126 
    127             logger.error("Transform successful?");
    128          
    129             if(transformed==null)  // not null
    130                 logger.error("TRANSFORMED IS NULL");
    131 
    132             if(transformed.getNodeType() == Node.DOCUMENT_NODE)
    133                 transformed = ((Document)transformed).getDocumentElement();
    134             logger.error("Node type: "+transformed.getNodeType());
    135 
    136             //logger.error("begin import");
    137             //Node imported = this.doc.importNode(transformed, true); // There was an exception org.w3c.dom.DOMException: NOT_SUPPORTED_ERR: The implementation does not support the requested type of object or operation.
    138             //logger.error("finished import");
    139 
    140             //String format_string2 = GSXML.xmlNodeToString(imported); // null pointer exception occuring here
    141             //logger.error("format string="+format_string2);
    142  
    143             Element format = this.doc.createElement(GSXML.FORMAT_STRING_ELEM);
    144             //GSXML.setNodeText(format, transformed);
    145             format.appendChild(this.doc.importNode(transformed,true));
    146             //format.setNodeValue(transformed);
    147             mr_request.appendChild(format);
    148             logger.error("Transformed: "+transformed);
    149 
    150 
    151             //page_response.appendChild(this.doc.importNode(e, true));
    152         } catch( Exception ex ) {
    153             logger.error("There was an exception "+ex);
    154            
    155             StringWriter sw = new StringWriter();
    156             PrintWriter pw = new PrintWriter(sw, true);
    157             ex.printStackTrace(pw);
    158             pw.flush();
    159             sw.flush();
    160             logger.error(sw.toString());
    161105        }
    162106
     107        else
     108        {
    163109
    164         // Call XSLT to transform document to xml format string
    165         //XMLTransformer transformer = new XMLTransformer();
     110            try {
     111                Document d = this.converter.getDOM(format_string);
    166112
    167         // not sure what to do here - some code from Transforming Receptionist
    168         //transformer.transformToString(Document stylesheet, Document source);
     113                // Call XSLT to transform document to xml format string
     114                XMLTransformer transformer = new XMLTransformer();
     115                String style = GSFile.interfaceStylesheetFile(GlobalProperties.getGSDL3Home(),(String)this.config_params.get(GSConstants.INTERFACE_NAME), "formatString.xsl");
     116                //logger.error("Style doc is "+style+", compared to /research/sjb48/greenstone3/web/interfaces/oran/transform/formatString.xsl");
     117                Document style_doc = this.converter.getDOM(new File(style), "UTF-8");
     118                //Document style_doc = this.converter.getDOM(new File("/research/sjb48/greenstone3/web/interfaces/oran/transform/formatString.xsl"), "UTF-8");  /*************************/
    169119
    170         // create a mesage to send to the collection object via the message router
     120                if(style_doc == null)
     121                    logger.error("style_doc is null");
     122
     123                logger.error("About to transform");
     124                Node transformed = (Node) transformer.transform(style_doc, d); 
     125               
     126                if(transformed.getNodeType() == Node.DOCUMENT_NODE)
     127                    transformed = ((Document)transformed).getDocumentElement();
     128
     129                Element format = this.doc.createElement(GSXML.FORMAT_STRING_ELEM);
     130                format.appendChild(this.doc.importNode(transformed,true));
     131                mr_request.appendChild(format);
     132                logger.error("Transformed: "+transformed);
     133
     134            } catch( Exception ex ) {
     135                logger.error("There was an exception "+ex);
     136
     137                StringWriter sw = new StringWriter();
     138                PrintWriter pw = new PrintWriter(sw, true);
     139                ex.printStackTrace(pw);
     140                pw.flush();
     141                sw.flush();
     142                logger.error(sw.toString());
     143            }
     144        }
    171145
    172146        Node response_message = this.mr.process(mr_request_message);
Note: See TracChangeset for help on using the changeset viewer.