KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > xml > resolving > impl > xmlcommons > XMLCommonsResolvingServiceImpl


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5
6 package org.exoplatform.services.xml.resolving.impl.xmlcommons;
7
8 import java.util.Vector JavaDoc;
9 import java.io.IOException JavaDoc;
10 import java.io.File JavaDoc;
11
12 import org.xml.sax.EntityResolver JavaDoc;
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 /**
21  * Created by The eXo Platform SARL .
22  *
23  * XML Catalog resolving service - based on Apache XML commons Resolver.
24  * is implementation of OASIS Entity Resolution Technical Committee definitions
25  * and supports OASIS XML Catalogs, OASIS TR9401 Catalogs, XCatalogs (supported by Apache)
26  * catalog formats.
27  * @author <a HREF="mailto:geaz@users.sourceforge.net">Gennady Azarenkov</a>
28  * @version $Id: XMLCommonsResolvingServiceImpl.java 566 2005-01-25 12:50:49Z kravchuk $
29  */

30
31 public class XMLCommonsResolvingServiceImpl implements XMLCatalogResolvingService
32 {
33    private CatalogResolver resolver;
34
35    public XMLCommonsResolvingServiceImpl()
36    {
37       resolver = new CatalogResolver();
38       String JavaDoc catalogs = System.getProperty("xml.catalog.files");
39       if(catalogs == null) {
40          Vector JavaDoc catalogFiles = new CatalogManager().getCatalogFiles();
41          String JavaDoc files = "";
42          for (int count = 0; count < catalogFiles.size(); count++) {
43             String JavaDoc file = (String JavaDoc) catalogFiles.elementAt(count);
44             if(files != "")
45                files+=";";
46             files+=file;
47          }
48          System.setProperty("xml.catalog.files", files);
49       }
50    }
51
52   /**
53    * XmlResolvingService method
54    * @return EntityResolver object
55    */

56    public EntityResolver JavaDoc getEntityResolver()
57    {
58        return resolver;
59    }
60
61   /**
62    * @return is this PublicID resolvable locally?
63    * @param publicId
64    */

65    public boolean isLocallyResolvable(String JavaDoc publicId)
66    {
67       Catalog catalog = resolver.getCatalog();
68       String JavaDoc result = null;
69       try {
70           result = catalog.resolveDoctype(null, publicId, null);
71       } catch (Exception JavaDoc e) {
72       }
73
74       if(result == null)
75          return false;
76       else
77          return true;
78    }
79
80   /**
81    * Adds new local-file based catalog
82    * @param path - path+name to a local catalog
83    */

84    public void addCatalog(String JavaDoc path) throws IOException JavaDoc
85    {
86       if( ! new File JavaDoc(path).exists() )
87          throw new IOException JavaDoc("XmlCommonsResolvingServiceImpl.addCatalog( "+path+") failed! Reason: file not found.");
88       String JavaDoc 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