Coverage Report - org.kuali.core.db.torque.ImpexDTDResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
ImpexDTDResolver
0%
0/7
0%
0/2
2
 
 1  
 package org.kuali.core.db.torque;
 2  
 
 3  
 import java.io.IOException;
 4  
 
 5  
 import org.apache.torque.engine.database.transform.DTDResolver;
 6  
 import org.springframework.core.io.DefaultResourceLoader;
 7  
 import org.springframework.core.io.Resource;
 8  
 import org.springframework.core.io.ResourceLoader;
 9  
 import org.xml.sax.InputSource;
 10  
 import org.xml.sax.SAXException;
 11  
 
 12  
 /**
 13  
  * Kuali customized Torque's database.dtd by adding sequence and view. Thus we need to use our custom dtd instead of the
 14  
  * latest one from Torque. At the moment the Kuali database.dtd is stored in many different spots inside Subversion.
 15  
  * This is because the impex was not set up such that XML parsing/generation was able to read Kuali's customized
 16  
  * database.dtd off of the classpath. Thus, database.dtd has to be present on the file system in the same directory as
 17  
  * any schema.xml files that are being parsed.
 18  
  * 
 19  
  * This class allows a single copy of database.dtd to be bundled into a .jar and shared by everyone at Kuali.
 20  
  */
 21  
 public class ImpexDTDResolver extends DTDResolver {
 22  
         public static final String DTD_NAME = "database.dtd";
 23  
         public static final String DTD_LOCATION = "http://www.kuali.org/dtd/" + DTD_NAME;
 24  
 
 25  
         public ImpexDTDResolver() throws SAXException {
 26  0
                 super();
 27  0
         }
 28  
 
 29  
         @Override
 30  
         public InputSource resolveEntity(String publicId, String systemId) throws IOException, SAXException {
 31  0
                 if (DTD_LOCATION.equals(systemId)) {
 32  0
                         ResourceLoader loader = new DefaultResourceLoader();
 33  0
                         Resource resource = loader.getResource("classpath:" + DTD_NAME);
 34  0
                         return new InputSource(resource.getInputStream());
 35  
                 } else {
 36  0
                         return super.resolveEntity(publicId, systemId);
 37  
                 }
 38  
         }
 39  
 
 40  
 }