Project

General

Profile

« Previous | Next » 

Revision 941

Added by Jing Tao over 22 years ago

A method named transformXmlDocument were overload. It transform an XML document to StringWriter using the stylesheet reference from the db.

View differences:

src/edu/ucsb/nceas/metacat/DBTransform.java
105 105
   * @param qformat the name of the style set to use
106 106
   * @param pw the PrintWriter to which output is printed
107 107
   */
108
  public void transformXMLDocument(String doc, String sourcetype, 
109
                String targettype, String qformat, PrintWriter pw) {
108
  public void transformXMLDocument(String doc, String sourceType, 
109
                String targetType, String qformat, PrintWriter pw) {
110 110
    
111 111
    // Look up the stylesheet for this type combination
112
    String xsl_system_id = getStyleSystemId(qformat, sourcetype, targettype);
112
    String xslSystemId = getStyleSystemId(qformat, sourceType, targetType);
113 113

  
114
    if (xsl_system_id != null) {
114
    if (xslSystemId != null) {
115 115
      // Create a stylesheet from the system id that was found
116 116
      try {
117 117
        TransformerFactory tFactory = TransformerFactory.newInstance();
118 118
        Transformer transformer = tFactory.newTransformer(
119
                                  new StreamSource(xsl_system_id));
120
	transformer.setParameter("qformat", qformat);
119
                                  new StreamSource(xslSystemId));
120
        transformer.setParameter("qformat", qformat);
121 121
        transformer.transform(new StreamSource(new StringReader(doc)), 
122 122
                              new StreamResult(pw));
123
	
124 123
      } catch (Exception e) {
125
        pw.println(xsl_system_id + "Error transforming document in " +
124
        pw.println(xslSystemId + "Error transforming document in " +
126 125
                   "DBTransform.transformXMLDocument: " +
127 126
                   e.getMessage());
128
        //e.printStackTrace();
127
       
129 128
      }
130 129
    } else {
131 130
      // No stylesheet registered form this document type, so just return the 
......
134 133
    }
135 134
  }
136 135
  
136
  /**
137
   * Transform an XML document to StringWriter using the stylesheet reference 
138
   * from the db
139
   * @param doc the document to be transformed
140
   * @param sourceType the document type of the source
141
   * @param targetType the target document type
142
   * @param qFormat the name of the style set to use
143
   * @param pw the StringWriter to which output will be stored
144
   */
145
  public void transformXMLDocument(String doc, String sourceType,
146
                String targetType, String qFormat, StringWriter pw) {
147

  
148
    // Look up the stylesheet for this type combination
149
    String xslSystemId = getStyleSystemId(qFormat, sourceType, targetType);
150

  
151
    if (xslSystemId != null) {
152
      // Create a stylesheet from the system id that was found
153
      try {
154
        TransformerFactory tFactory = TransformerFactory.newInstance();
155
        Transformer transformer = tFactory.newTransformer(
156
                                  new StreamSource(xslSystemId));
157
        transformer.setParameter("qFormat", qFormat);
158
        transformer.transform(new StreamSource(new StringReader(doc)),
159
                              new StreamResult(pw));
160
      } catch (Exception e) {
161
        util.debugMessage(xslSystemId + "Error transforming document in " +
162
                   "DBTransform.transformXMLDocument: " +
163
                   e.getMessage());
164
       
165
      }
166
    } else {
167
      // No stylesheet registered form this document type, so just return the 
168
      // XML stream we were passed
169
      util.debugMessage(doc);
170
    }
171
  }
137 172
  
138 173
  /**
139 174
   * gets the content of a tag in a given xml file with the given path
......
242 277
                  if(nChildText.getNodeType() == Node.TEXT_NODE)
243 278
                  { //get the text from the target node
244 279
                    systemId = nChildText.getNodeValue();
245
                    System.out.println("systemId: " + systemId);
246 280
                    breakflag = true;
247 281
                    break;
248 282
                  }

Also available in: Unified diff