Project

General

Profile

« Previous | Next » 

Revision 1688

Added by Jing Tao about 21 years ago

Revise code and make it more generic to pass parameters to style sheet.

View differences:

src/edu/ucsb/nceas/metacat/DBTransform.java
32 32
import java.net.URL;
33 33
import java.net.MalformedURLException;
34 34
import java.sql.*;
35
import java.util.Enumeration;
35 36
import java.util.Hashtable;
36 37
import java.util.Stack;
37 38

  
......
121 122
        TransformerFactory tFactory = TransformerFactory.newInstance();
122 123
        Transformer transformer = tFactory.newTransformer(
123 124
                                  new StreamSource(xslSystemId));
124
        transformer.setParameter("qformat", qformat);
125
        MetaCatUtil.debugMessage("qformat: "+qformat, 30);
126
        // Set up parameter for eml2 transformation
125
        //transformer.setParameter("qformat", qformat);
126
        //MetaCatUtil.debugMessage("qformat: "+qformat, 30);
127
        
128
        // Set up parameter for transformation
127 129
        if ( param != null)
128 130
        {
129
           // pass docid
130
           String docid=((String[])param.get("docid"))[0];
131
           if (docid != null && !docid.trim().equals(""))
132
           {
133
             transformer.setParameter("docid", docid);
134
           }
135
           System.out.print("docid: "+docid);
136
           // pass displaymodule
137
           if (param.get("displaymodule") != null)
138
           {
139
             String displayModule=((String[])param.get("displaymodule"))[0];
140
             System.out.print("displayModule1: "+displayModule);
141
             if (displayModule != null && !displayModule.trim().equals(""))
142
             {
143
               System.out.print("displayModule2: "+displayModule);
144
               transformer.setParameter("displaymodule", displayModule);
145
             }
146
             System.out.print("displayModule3: "+displayModule);
147
           }
148
           // pass entitytype
149
           if (param.get("entitytype") != null)
150
           {
151
             String entityType=((String[])param.get("entitytype"))[0];
152
             if (entityType != null && !entityType.trim().equals(""))
153
             {
154
               transformer.setParameter("entitytype", entityType);
155
             }
156
             System.out.print("entityType: "+entityType);
157
           }
158
           // pass entityindex
159
           if (param.get("entityindex") != null)
160
           {
161
             String entityIndex=((String[])param.get("entityindex"))[0];
162
             if (entityIndex != null && !entityIndex.trim().equals(""))
163
             {
164
               transformer.setParameter("entityindex", entityIndex);
165
             }
166
           }
167
            // pass physicalindex
168
           if (param.get("physicalindex") != null)
169
           {
170
             String physicalIndex=((String[])param.get("physicalindex"))[0];
171
             if (physicalIndex != null && !physicalIndex.trim().equals(""))
172
             {
173
               transformer.setParameter("physicalindex", physicalIndex);
174
             }
175
           }
176
            // pass distributionindex
177
           if (param.get("distributionindex") != null)
178
           {
179
             String distributionIndex=((String[])param.get("distributionindex"))[0];
180
             if (distributionIndex != null && !distributionIndex.trim().equals(""))
181
             {
182
               transformer.setParameter("distributionindex", distributionIndex);
183
             }
184
           }
185
            // pass attributeindex
186
           if (param.get("attributeindex") != null)
187
           {
188
             String attributeIndex=((String[])param.get("attributeindex"))[0];
189
             if (attributeIndex != null && !attributeIndex.trim().equals(""))
190
             {
191
               transformer.setParameter("attributeindex", attributeIndex);
192
             }
193
           }
131
          Enumeration en = param.keys();
132
          while (en.hasMoreElements())
133
          {
134
            String key =(String)en.nextElement();
135
            String value = ((String[])(param.get(key)))[0];
136
            MetaCatUtil.debugMessage(key+" : "+value, 30);
137
            transformer.setParameter(key, value);
138
          }
194 139
        }
140
      
195 141
        transformer.transform(new StreamSource(new StringReader(doc)), 
196 142
                              new StreamResult(pw));
197 143
      } catch (Exception e) {

Also available in: Unified diff