KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > xml > resolving > impl > simple > SimpleResolver


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.simple;
7
8 import java.io.IOException JavaDoc;
9 import java.io.InputStream JavaDoc;
10
11 import org.xml.sax.EntityResolver JavaDoc;
12 import org.xml.sax.InputSource JavaDoc;
13
14 import org.apache.commons.logging.Log;
15 import org.exoplatform.services.log.LogService;
16 import org.exoplatform.container.PortalContainer;
17 import org.exoplatform.container.RootContainer;
18
19
20 /**
21  * Created by The eXo Platform SARL .
22  *
23  * Entity Resolver for SimpleDir resolving service
24  * @author <a HREF="mailto:geaz@users.sourceforge.net">Gennady Azarenkov</a>
25  * @version $Id: SimpleResolver.java 566 2005-01-25 12:50:49Z kravchuk $
26  */

27
28 public class SimpleResolver implements EntityResolver JavaDoc{
29    private String JavaDoc localPath;
30    private Log log;
31
32    public SimpleResolver(String JavaDoc localPath)
33    {
34       this.localPath = localPath;
35
36       LogService logService = (LogService) RootContainer.getInstance().
37                               getComponentInstanceOfType(LogService.class);
38       log = logService.getLog(this.getClass());
39    }
40
41    public InputSource JavaDoc resolveEntity (String JavaDoc publicId, String JavaDoc systemId) throws IOException JavaDoc
42    {
43       log.debug("query for resolve entity publicId["+publicId+" systemId["+systemId+"]");
44       int fileIndex = systemId.lastIndexOf('/');
45       if(fileIndex == -1)
46           return null;
47
48       String JavaDoc dtdPath = localPath+systemId.substring(fileIndex);
49       log.debug("local path is ["+dtdPath+"]");
50
51       if(this.getClass().getResource(dtdPath) == null) {
52           log.warn("Local entity definitions of '"+dtdPath+" not found in catalog. Trying to load from "+systemId+"..");
53           return null;
54       }
55       InputSource JavaDoc source = new InputSource JavaDoc(this.getClass().getResourceAsStream(dtdPath));
56       log.debug("Local entity definitions found in '" + dtdPath + "'");
57
58       source.setSystemId(systemId);
59       return source;
60    }
61 }
62
63
Popular Tags