Project

General

Profile

« Previous | Next » 

Revision 9913

Added by Jing Tao over 8 years ago

use the new rules to validate an xml object base on dtds.

View differences:

src/edu/ucsb/nceas/metacat/DBEntityResolver.java
97 97
  public InputSource resolveEntity (String publicId, String systemId)
98 98
                     throws SAXException
99 99
  {
100
    logMetacat.debug("DBEntityResolver.resolveEntity - in resolveEntity");
100
    InputSource dtdSource= null;
101
    logMetacat.debug("DBEntityResolver.resolveEntity - in resolveEntity "+" the public id is "+publicId+" and systemId is "+systemId);
101 102
    String dbSystemID;
102 103
    String doctype = null;
103 104

  
......
114 115
            logMetacat.debug("DBEntityResolver.resolveEntity - in get type from publicId and doctype is: "
115 116
                                     + doctype);
116 117
          // assume public ID (doctype) is docname
117
          } else if (systemId != null) {
118
          } else {
118 119
            doctype = dhandler.getDocname();
120
            logMetacat.debug("DBEntityResolver.resolveEntity - there is not public id and in get type from the doc name and doctype is: "
121
                    + doctype);
119 122
          }
120 123
        }
121 124
      } else if ( handler instanceof AccessControlList ) {
122 125
        AccessControlList ahandler = null;
123 126
        ahandler = (AccessControlList)handler;
124
        //if ( ahandler.processingDTD() ) {
127
        if ( ahandler.processingDTD() ) {
125 128
          // public ID is doctype
126 129
          if (publicId != null) {
127 130
            doctype = publicId;
128 131
          // assume public ID (doctype) is docname
129
          } else if (systemId != null) {
132
          } else {
130 133
            doctype = ahandler.getDocname();
131 134
          }
132
        //}
135
        }
133 136
      }
137
    } else {
138
        logMetacat.debug("DBEntityResolver.resolveEntity - the handler is null");
134 139
    }
135 140

  
136 141
    // get System ID for doctype
......
139 144
      logMetacat.info("DBEntityResolver.resolveEntity - get systemId from doctype: " + doctype);
140 145
      dbSystemID = getDTDSystemID(doctype);
141 146
      logMetacat.info("DBEntityResolver.resolveEntity - The Systemid is: " + dbSystemID);
147
      if(dbSystemID == null) {
148
          throw new SAXException("The doctype "+doctype+" ,which was defined by a DTD document, isn't registered in Metacat. Please contact the operator of the Metacat");
149
      }
142 150
      // check that it is accessible on our system before getting too far
143 151
      try {
144 152
    	  InputStream in = checkURLConnection(dbSystemID);
153
    	  dtdSource = new InputSource(in);
145 154
	  } catch (SAXException se) {
155
	      se.printStackTrace();
156
	      throw se;
146 157
		  // after an upgrade, the dtd will not exist on disk, but it is in xml catalog.  The db system id may be pointing 
147 158
		  // back at this system  Try and download it from the original system id and see if we still have a problem
148 159
		  // checking the URL connection.
149
		  logMetacat.warn("DBEntityResolver.resolveEntity - Problem when checking URL Connection: " + se.getMessage());
160
		  /*logMetacat.warn("DBEntityResolver.resolveEntity - Problem when checking URL Connection: " + se.getMessage());
150 161
		  logMetacat.warn("DBEntityResolver.resolveEntity - Probably, dtd for doc type " + doctype + " existed in xml catalog, but not on disk.  Uploading from: " + systemId);
151 162
		  InputStream istream = checkURLConnection(systemId);
152 163
		  uploadDTDFromURL(istream, systemId);
......
157 168
			  logMetacat.error("DBEntityResolver.resolveEntity - still could not find dtd for doc type " + doctype + " at " 
158 169
					  + dbSystemID + " : " + e2.getMessage());
159 170
			  dbSystemID = null;
160
		  }
171
		  }*/
161 172
	  } 
162
      boolean doctypeIsInDB = true;
173
      /*boolean doctypeIsInDB = true;
163 174
      // no System ID found in db XML Catalog
164 175
      if (dbSystemID == null) {
165 176
        doctypeIsInDB = false;
......
198 209
      }
199 210
      istream = checkURLConnection(dbSystemID);
200 211
      is.setByteStream(istream);
201
      return is;
212
      return is;*/
202 213
    } else {
203
      // use provided systemId for the other cases
204
      logMetacat.info("DBEntityResolver.resolveEntity - doctype is null and using system id from file");
205
      InputStream istream = checkURLConnection(systemId);
206
      return null;
207

  
214
      //we can't determine the public id or the name of the root element in for this dtd defined xml document
215
      String message = "Metacat can't determine the public id or the name of the root element of the document, so the validation can't be imposed and the document is rejected";
216
      logMetacat.error("DBEntityResolver.resolveEntity - "+message);
217
      throw new SAXException(message);
218
      //InputStream istream = checkURLConnection(systemId);
219
      //return null;
208 220
    }
221
    return dtdSource;
209 222

  
210 223
  }
211 224

  

Also available in: Unified diff