Project

General

Profile

« Previous | Next » 

Revision 906

Added by berkley almost 23 years ago

updated metacat so that the xmlparserv2.jar file is no longer needed. replaced all of teh oracle xml processing with xalan and xerces.

View differences:

build.oracle.xml
98 98
                value="/oracle01/app/oracle/product/8.1.6" />
99 99
      <property name="toolsdir" 
100 100
                value="/usr/local/devtools" />
101
      <property name="xmlp" 
102
                value="${toolsdir}/OracleXSU111/lib/xmlparserv2.jar" />
103 101
      <property name="xmlp2" 
104 102
                value="${toolsdir}/xerces-1_1_3/xerces.jar" />
105 103
      <property name="jdbc" 
......
112 110
                value="lib/srbrmi" />
113 111
      <property name="cos" 
114 112
                value="lib/cos.jar" />
113
      <property name="xalan"
114
                value="lib/xalan/xalan.jar" />
115
      <property name="xalanxml-apis"
116
                value="lib/xalan/xml-apis.jar" />
115 117
      <property name="cpath" 
116
                value="${xmlp2}:${xmlp}:${jdbc}:${jserv}:${jsdk}:${srb}:${cos}"/>
118
                value="${xmlp2}:${xalan}:${xalanxml-apis}:${jdbc}:${jserv}:${jsdk}:${srb}:${cos}"/>
117 119
      <property name="package.home" value="edu/ucsb/nceas/metacat" />
118 120

  
119 121
   </target>
build.postgres.xml
98 98
                value="/oracle01/app/oracle/product/8.1.6" />
99 99
      <property name="toolsdir" 
100 100
                value="/usr/local/devtools" />
101
      <property name="xmlp" 
102
                value="./lib/xmlparserv2.jar" />
103 101
      <property name="xmlp2" 
104 102
                value="./lib/xerces.jar" />
105 103
      <property name="jdbc" 
106
                value="/home/berkley/xmltodb/lib/jdbc7.1-1.2.jar" />
104
                value="lib/jdbc7.1-1.2.jar" />
107 105
      <property name="jserv" 
108 106
                value="/usr/lib/apache/ApacheJServ.jar" />
109 107
      <property name="jsdk" 
......
112 110
                value="lib/srbrmi" />
113 111
      <property name="cos" 
114 112
                value="lib/cos.jar" />
113
      <property name="xalan"
114
                value="lib/xalan/xalan.jar" />
115
      <property name="xalanxml-apis"
116
                value="lib/xalan/xml-apis.jar" />
115 117
      <property name="cpath" 
116
                value="${xmlp2}:${xmlp}:${jdbc}:${jserv}:${jsdk}:${srb}:${cos}"/>
118
                value="${xalan}:${xalanxml-apis}:${xmlp2}:${jdbc}:${jserv}:${jsdk}:${srb}:${cos}"/>
117 119
      <property name="package.home" value="edu/ucsb/nceas/metacat" />
118

  
119 120
   </target>
120 121
   
121 122
   <target name="prepare" depends="init">
......
199 200
             tofile="${installdir}/WEB-INF/lib/oracle-jdbc111.jar" />
200 201
       <copy file="${cos}" 
201 202
             tofile="${installdir}/WEB-INF/lib/cos.jar" />
203
       <copy file="${xalan}" 
204
             tofile="${installdir}/WEB-INF/lib/xalan.jar" />
205
       <copy file="${xalanxml-apis}" 
206
             tofile="${installdir}/WEB-INF/lib/xml-apis.jar" />
202 207
       <copy file="lib/web.xml" 
203 208
             tofile="${installdir}/WEB-INF/web.xml" />
204 209
       <copy todir="${build.img}" filtering="no">
src/edu/ucsb/nceas/metacat/DBTransform.java
34 34
import java.sql.*;
35 35
import java.util.Stack;
36 36

  
37
import javax.xml.transform.TransformerFactory;
38
import javax.xml.transform.Transformer;
39
import javax.xml.transform.stream.StreamSource;
40
import javax.xml.transform.stream.StreamResult;
41
import javax.xml.transform.TransformerException;
42
import javax.xml.transform.TransformerConfigurationException;
43

  
44
import org.apache.xerces.parsers.DOMParser;
45
import org.w3c.dom.Attr;
46
import org.w3c.dom.NamedNodeMap;
47
import org.w3c.dom.NodeList;
48
import org.w3c.dom.Document;
49
import org.w3c.dom.Node;
50
import org.w3c.dom.NodeList;
51
import org.w3c.dom.DocumentType;
52
import org.xml.sax.SAXException;
53
import org.xml.sax.InputSource;
54
import org.apache.xerces.dom.DocumentTypeImpl;
55
import org.apache.xpath.XPathAPI;
56
import org.w3c.dom.NamedNodeMap;
57

  
58
/*
37 59
import oracle.xml.parser.v2.XSLStylesheet;
38 60
import oracle.xml.parser.v2.XSLException;
39 61
import oracle.xml.parser.v2.XMLParseException;
40 62
import oracle.xml.parser.v2.XSLProcessor;
41 63
import oracle.xml.parser.v2.XMLDocument;
42 64
import oracle.xml.parser.v2.DOMParser;
65
*/
43 66
import org.w3c.dom.Document;
44 67
import org.w3c.dom.Node;
45 68
import org.w3c.dom.Element;
......
91 114
    if (xsl_system_id != null) {
92 115
      // Create a stylesheet from the system id that was found
93 116
      try {
94
        XSLStylesheet style = new XSLStylesheet(new URL(xsl_system_id), null);
95
        DOMParser dp = new DOMParser();
96
        dp.setValidationMode(false);
97
        dp.parse((Reader)(new StringReader(doc)));
98
        new XSLProcessor().processXSL(style, dp.getDocument(), pw);
117
        TransformerFactory tFactory = TransformerFactory.newInstance();
118
        Transformer transformer = tFactory.newTransformer(
119
                                  new StreamSource(xsl_system_id));
120
        transformer.transform(new StreamSource(new StringReader(doc)), 
121
                              new StreamResult(pw));
122
	
99 123
      } catch (Exception e) {
100 124
        pw.println(xsl_system_id + "Error transforming document in " +
101 125
                   "DBTransform.transformXMLDocument: " +
102 126
                   e.getMessage());
127
        //e.printStackTrace();
103 128
      }
104 129
    } else {
105 130
      // No stylesheet registered form this document type, so just return the 
......
107 132
      pw.print(doc);
108 133
    }
109 134
  }
135
  
136
  
137
  /**
138
   * gets the content of a tag in a given xml file with the given path
139
   * @param f the file to parse
140
   * @param path the path to get the content from
141
   */
142
  public static NodeList getPathContent(File f, String path) 
143
  {
144
    if(f == null)
145
    {
146
      return null;
147
    }
148
   
149
    DOMParser parser = new DOMParser();
150
    InputSource in;
151
    FileInputStream fs;
152
    
153
    try
154
    { 
155
      fs = new FileInputStream(f);
156
      in = new InputSource(fs);
157
    }
158
    catch(FileNotFoundException fnf)
159
    {
160
      fnf.printStackTrace();
161
      return null;
162
    }
163
    
164
    try
165
    {
166
      parser.parse(in);
167
      fs.close();
168
    }
169
    catch(Exception e1)
170
    {
171
      System.err.println("File: " + f.getPath() + " : parse threw: " + 
172
                         e1.toString());
173
      return null;
174
    }
175
    
176
    Document doc = parser.getDocument();
177
    
178
    try
179
    {
180
      NodeList docNodeList = XPathAPI.selectNodeList(doc, path);
181
      return docNodeList;
182
    }
183
    catch(Exception se)
184
    {
185
      System.err.println("file: " + f.getPath() + " : parse threw: " + 
186
                         se.toString());
187
      return null;
188
    }
189
  }
110 190

  
111 191
  /**
112 192
   * Lookup a stylesheet reference from the db catalog
......
125 205

  
126 206
    // Load the style-set map for this qformat into a DOM
127 207
    try {
208
      boolean breakflag = false;
128 209
      String filename = configDir + "/" + qformat + ".xml";       
129 210
      util.debugMessage("Trying style-set file: " + filename);
130

  
131
      DOMParser dp = new DOMParser();
132
      dp.setValidationMode(false);
133
      dp.parse((Reader)(new FileReader(filename)));
134
      Document doc = dp.getDocument();
135
      Element root = doc.getDocumentElement();
136
      String styleName = root.getAttribute("name");
137
      util.debugMessage("Root style-set element is: " + styleName);
211
      File f = new File(filename);
212
      NodeList nlDoctype = getPathContent(f, "/style-set/doctype");
213
      NodeList nlDefault = getPathContent(f, "/style-set/default-style");
214
      Node nDefault = nlDefault.item(0);
215
      systemId = nDefault.getFirstChild().getNodeValue(); //set the default
138 216
      
139
      Element currentElement = (Element)root.getFirstChild();
140
      systemId = ((Node)currentElement.getFirstChild()).getNodeValue();
141
      util.debugMessage("Default is: " + systemId);
142

  
143
      while ((currentElement = 
144
              (Element)currentElement.getNextSibling()) != null) {
145
        String tagName = currentElement.getTagName();
146
        util.debugMessage("Processing element: " + tagName);
147
        if (tagName.equals("doctype")) {
148
          String doctype = currentElement.getAttribute("publicid");
149
          util.debugMessage("Processing publicid: " + doctype);
150
          util.debugMessage("Comparing to source: " + sourcetype);
151
          if (doctype.equals(sourcetype)) {
152
            Element currentChild = (Element)currentElement.getFirstChild();
153
            while (currentChild != null) {
154
              String target = currentChild.getAttribute("publicid");
155
              util.debugMessage("Processing target publicid: " + target);
156
              util.debugMessage("Comparing to target: " + targettype);
157
              if (target.equals(targettype)) {
158
                Node styleText = currentChild.getFirstChild();
159
                systemId = styleText.getNodeValue();
160
                break; 
217
      for(int i=0; i<nlDoctype.getLength(); i++)
218
      { //look for the right sourcetype
219
        Node nDoctype = nlDoctype.item(i);
220
        NamedNodeMap atts = nDoctype.getAttributes();
221
        Node nAtt = atts.getNamedItem("publicid");
222
        String doctype = nAtt.getFirstChild().getNodeValue();
223
        if(doctype.equals(sourcetype))
224
        { //found the right sourcetype now we need to get the target type
225
          NodeList nlChildren = nDoctype.getChildNodes();
226
          for(int j=0; j<nlChildren.getLength(); j++)
227
          {
228
            Node nChild = nlChildren.item(j);
229
            String childName = nChild.getNodeName();
230
            if(childName.equals("target"))
231
            {
232
              NamedNodeMap childAtts = nChild.getAttributes();
233
              Node nTargetPublicId = childAtts.getNamedItem("publicid");
234
              String target = nTargetPublicId.getFirstChild().getNodeValue();
235
              if(target.equals(targettype))
236
              { //we found the right target type
237
                NodeList nlTarget = nChild.getChildNodes();
238
                for(int k=0; k<nlTarget.getLength(); k++)
239
                {
240
                  Node nChildText = nlTarget.item(k);
241
                  if(nChildText.getNodeType() == Node.TEXT_NODE)
242
                  { //get the text from the target node
243
                    systemId = nChildText.getNodeValue();
244
                    System.out.println("systemId: " + systemId);
245
                    breakflag = true;
246
                    break;
247
                  }
248
                }
161 249
              }
162
              currentChild = (Element)currentChild.getNextSibling();
163 250
            }
251
            
252
            if(breakflag)
253
            {
254
              break;
255
            }
164 256
          }
165 257
        }
258
        
259
        if(breakflag)
260
        {
261
          break;
262
        }
166 263
      }
167
    } catch (IOException ioe) {
168
      util.debugMessage("Caught IOException while opening style-set config.");
169
    } catch (XMLParseException xpe) {
170
      util.debugMessage("Error parsing style-set file");
171
    } catch (SAXException se) {
172
      util.debugMessage("SAX error parsing style-set file");
173 264
    }
265
    catch(Exception e)
266
    {
267
      System.out.println("Error parsing style-set file: " + e.getMessage());
268
      e.printStackTrace();
269
    }
174 270

  
175 271
    // Return the system ID for this particular source document type
176 272
    return systemId;
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
64 64
import javax.servlet.http.HttpUtils;
65 65
import javax.servlet.ServletOutputStream;
66 66

  
67
import oracle.xml.parser.v2.XSLStylesheet;
68
import oracle.xml.parser.v2.XSLException;
69
import oracle.xml.parser.v2.XMLDocumentFragment;
70
import oracle.xml.parser.v2.XSLProcessor;
71

  
72 67
import org.xml.sax.SAXException;
73 68

  
74 69
/**
build.xml
32 32
<project name="metacat" default="jar" basedir=".">
33 33
   <target name="init">
34 34
      <property name="jdbc-connect" 
35
                value="jdbc:oracle:thin:@dev.nceas.ucsb.edu:1521:exp"/>
36
      <property name="installdir" value="/opt/tomcat/webapps/metacat" />
37
      <property name="dbDriver" value="oracle.jdbc.driver.OracleDriver"/>
35
                value="jdbc:postgresql://localhost/berkley"/>
36
      <property name="installdir" value="/home/berkley/tomcat/webapps/metacat" />
37
      <property name="dbDriver" value="org.postgresql.Driver"/>
38 38
      <property name="name" value="metacat"/>
39 39
      <property name="Name" value="MetaCat"/>
40 40
      <property name="release" value="1.0.3"/>
41 41
      <property name="web-base-url" 
42
                value="http://knb.ecoinformatics.org"/>
42
                value="http://alpha.nceas.ucsb.edu:8080/"/>
43 43

  
44 44
      <property name="replication-path" value="/servlet/replication"/>
45 45
      <property name="servlet-path" value="/metacat/servlet/metacat"/>
46 46
      <property name="html-path" value="/metacat"/>
47 47
      <property name="image-path" value="/img/metacat" />
48 48
      <property name="style-path" value="/metacat/style"/>
49
      <property name="server" value="dev.nceas.ucsb.edu"/>
50
      <property name="replication-log" value="/tmp/metacatreplication.log"/>
51
      <property name="user" value="metacat_username"/>
52
      <property name="password" value="your_pw_here"/>
49
      <property name="server" value="alpha.nceas.ucsb.edu:8080"/>
50
      <property name="replication-log" value="/home/berkley/tomcat/webapps/metacat/metacatreplication.log"/>
51
      <property name="user" value="berkley"/>
52
      <property name="password" value=""/>
53 53
      <property name="config-dir" value="${installdir}" />
54 54
      <property name="default-style" value="knb" />
55 55
      <property name="eml-module" value="mdstandards/eml" />
......
98 98
                value="/oracle01/app/oracle/product/8.1.6" />
99 99
      <property name="toolsdir" 
100 100
                value="/usr/local/devtools" />
101
      <property name="xmlp" 
102
                value="${toolsdir}/OracleXSU111/lib/xmlparserv2.jar" />
103 101
      <property name="xmlp2" 
104
                value="${toolsdir}/xerces-1_1_3/xerces.jar" />
102
                value="./lib/xerces.jar" />
105 103
      <property name="jdbc" 
106
                value="${oracle_home}/jdbc/lib/classes111.zip" />
104
                value="lib/jdbc7.1-1.2.jar" />
107 105
      <property name="jserv" 
108 106
                value="/usr/lib/apache/ApacheJServ.jar" />
109 107
      <property name="jsdk" 
110
                value="${toolsdir}/jakarta-tomcat/lib/servlet.jar" />
108
                value="/home/berkley/tomcat/lib/common/servlet.jar" />
111 109
      <property name="srb" 
112 110
                value="lib/srbrmi" />
113 111
      <property name="cos" 
114 112
                value="lib/cos.jar" />
113
      <property name="xalan"
114
                value="lib/xalan/xalan.jar" />
115
      <property name="xalanxml-apis"
116
                value="lib/xalan/xml-apis.jar" />
115 117
      <property name="cpath" 
116
                value="${xmlp2}:${xmlp}:${jdbc}:${jserv}:${jsdk}:${srb}:${cos}"/>
118
                value="${xalan}:${xalanxml-apis}:${xmlp2}:${jdbc}:${jserv}:${jsdk}:${srb}:${cos}"/>
117 119
      <property name="package.home" value="edu/ucsb/nceas/metacat" />
118

  
119 120
   </target>
120 121
   
121 122
   <target name="prepare" depends="init">
......
199 200
             tofile="${installdir}/WEB-INF/lib/oracle-jdbc111.jar" />
200 201
       <copy file="${cos}" 
201 202
             tofile="${installdir}/WEB-INF/lib/cos.jar" />
203
       <copy file="${xalan}" 
204
             tofile="${installdir}/WEB-INF/lib/xalan.jar" />
205
       <copy file="${xalanxml-apis}" 
206
             tofile="${installdir}/WEB-INF/lib/xml-apis.jar" />
202 207
       <copy file="lib/web.xml" 
203 208
             tofile="${installdir}/WEB-INF/web.xml" />
204 209
       <copy todir="${build.img}" filtering="no">

Also available in: Unified diff