1 5 6 package org.exoplatform.services.xml.resolving.impl.xmlcommons; 7 8 import java.util.Vector ; 9 import java.io.IOException ; 10 import java.io.File ; 11 12 import org.xml.sax.EntityResolver ; 13 14 import org.apache.xml.resolver.Catalog; 15 import org.apache.xml.resolver.CatalogManager; 16 import org.apache.xml.resolver.tools.CatalogResolver; 17 import org.exoplatform.services.xml.resolving.XMLCatalogResolvingService; 18 19 20 30 31 public class XMLCommonsResolvingServiceImpl implements XMLCatalogResolvingService 32 { 33 private CatalogResolver resolver; 34 35 public XMLCommonsResolvingServiceImpl() 36 { 37 resolver = new CatalogResolver(); 38 String catalogs = System.getProperty("xml.catalog.files"); 39 if(catalogs == null) { 40 Vector catalogFiles = new CatalogManager().getCatalogFiles(); 41 String files = ""; 42 for (int count = 0; count < catalogFiles.size(); count++) { 43 String file = (String ) catalogFiles.elementAt(count); 44 if(files != "") 45 files+=";"; 46 files+=file; 47 } 48 System.setProperty("xml.catalog.files", files); 49 } 50 } 51 52 56 public EntityResolver getEntityResolver() 57 { 58 return resolver; 59 } 60 61 65 public boolean isLocallyResolvable(String publicId) 66 { 67 Catalog catalog = resolver.getCatalog(); 68 String result = null; 69 try { 70 result = catalog.resolveDoctype(null, publicId, null); 71 } catch (Exception e) { 72 } 73 74 if(result == null) 75 return false; 76 else 77 return true; 78 } 79 80 84 public void addCatalog(String path) throws IOException 85 { 86 if( ! new File (path).exists() ) 87 throw new IOException ("XmlCommonsResolvingServiceImpl.addCatalog( "+path+") failed! Reason: file not found."); 88 String catalogs = System.getProperty("xml.catalog.files"); 89 if(catalogs == null) 90 catalogs = path; 91 else 92 catalogs+=";"+path; 93 System.setProperty("xml.catalog.files", path); 94 } 95 96 } 97 | Popular Tags |