Project

General

Profile

Revision 1441

Added by Jing Tao over 18 years ago

Fixed bug the no matter the xml is base on schema or dtd, the output will add a line for doctype. This will cause eml document invalidate.

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
70 70
public class DocumentImpl {
71 71

  
72 72
   /* Constants */
73
   public static final String SCHEMA                 = "schema";
74
   public static final String DTD                    = "dtd";
73
   public static final String SCHEMA                 = "Schema";
74
   public static final String DTD                    = "DTD";
75 75
   public static final String EML2                   = "eml2";
76 76
   public static final String EXTERNALSCHEMALOCATIONPROPERTY = 
77 77
              "http://apache.org/xml/properties/schema/external-schemaLocation";
......
102 102
  private String updatedVersion=null;
103 103
  private String docname = null;
104 104
  private String doctype = null;
105
  private String validateType = null; //base on dtd or schema
105 106
// DOCTITLE attr cleared from the db
106 107
//  private String doctitle = null;
107 108
  private String createdate = null;
......
168 169
    this(docid, true);
169 170
  }
170 171

  
171
  /** 
172
   * Construct a new document instance, writing the contents to the database.
173
   * This method is called from DBSAXHandler because we need to know the
174
   * root element name for documents without a DOCTYPE before creating it.
175
   *
176
   * @param conn the JDBC Connection to which all information is written
177
   * @param rootnodeid - sequence id of the root node in the document
178
   * @param docname - the name of DTD, i.e. the name immediately following 
179
   *        the DOCTYPE keyword ( should be the root element name ) or
180
   *        the root element name if no DOCTYPE declaration provided
181
   *        (Oracle's and IBM parsers are not aware if it is not the 
182
   *        root element name)
183
   * @param doctype - Public ID of the DTD, i.e. the name immediately 
184
   *                  following the PUBLIC keyword in DOCTYPE declaration or
185
   *                  the docname if no Public ID provided or
186
   *                  null if no DOCTYPE declaration provided
187
   * @param docid the docid to use for the INSERT OR UPDATE
188
   * @param action the action to be performed (INSERT OR UPDATE)
189
   * @param user the user that owns the document
190
   * @param pub flag for public "read" access on document
191
   * @param serverCode the serverid from xml_replication on which this document
192
   *        resides.
193
   *
194
   */
195
  /*public DocumentImpl(Connection conn, long rootnodeid, String docname, 
196
                      String doctype, String docid, String action, String user,
197
                      String pub, String catalogid, int serverCode)
198
                      throws SQLException, Exception
199
  {
200
    this.conn = conn;
201
    this.rootnodeid = rootnodeid;
202
    this.docname = docname;
203
    this.doctype = doctype;
204
    this.docid = docid;
205
    writeDocumentToDB(action, user, pub, catalogid, serverCode);
206
  }*/
172
 
207 173
  
208 174
  /** 
209 175
   * Construct a new document instance, writing the contents to the database.
......
751 717
    return rev;
752 718
  }
753 719
  
720
  public String getValidateType()
721
  {
722
    return validateType;
723
  }
724
  
754 725
  /**
755 726
   * Print a string representation of the XML document
756 727
   */
......
916 887
      // Handle the DOCUMENT node
917 888
      if (currentNode.nodetype.equals("DOCUMENT")) {
918 889
        out.println("<?xml version=\"1.0\"?>");
919
      
920
        if (docname != null) {
921
          if ((doctype != null) && (system_id != null)) {
890
        if (docname != null && validateType != null && validateType.equals(DTD)) 
891
        {
892
          if ((doctype != null) && (system_id != null)) 
893
          {
894
            
922 895
            out.println("<!DOCTYPE " + docname + " PUBLIC \"" + doctype + 
923 896
                       "\" \"" + system_id + "\">");
924
          } else {
897
          } 
898
          else 
899
          {
900
            
925 901
            out.println("<!DOCTYPE " + docname + ">");
926 902
          }
927 903
        }
......
1173 1149
      pstmt.close();
1174 1150
      if (this.doctype != null) {
1175 1151
        pstmt =
1176
          dbconn.prepareStatement("SELECT system_id " +
1152
          dbconn.prepareStatement("SELECT system_id, entry_type " +
1177 1153
                                  "FROM xml_catalog " +
1178 1154
                                 "WHERE public_id = ?");
1179 1155
        //should increase usage count again
......
1186 1162
        tableHasRows = rs.next();
1187 1163
        if (tableHasRows) {
1188 1164
          this.system_id  = rs.getString(1);
1165
          this.validateType = rs.getString(2);
1166
          
1189 1167
        } 
1190 1168
        pstmt.close();
1191 1169
      }

Also available in: Unified diff