KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > j2ee > blueprints > stringposervice > POEntityResolver


1 /* Copyright 2005 Sun Microsystems, Inc. All rights reserved. You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at:
2  http://developer.sun.com/berkeley_license.html
3  $Id: POEntityResolver.java,v 1.2 2005/08/12 20:46:39 smitha Exp $ */

4
5 package com.sun.j2ee.blueprints.stringposervice;
6
7 import java.io.*;
8
9 import org.xml.sax.*;
10
11 public class POEntityResolver implements EntityResolver {
12     
13     private static String JavaDoc RESOURCE_LOCATION = "/resources/";
14     private static String JavaDoc BLUEPRINTS_NS = "http://java.sun.com/blueprints/schemas/";
15     
16     public InputSource resolveEntity(String JavaDoc publicId, String JavaDoc systemId) {
17         if (systemId.equals(BLUEPRINTS_NS + "PurchaseOrder.xsd")) {
18             return getClassPathSource("PurchaseOrder.xsd");
19         } else{
20             return null;
21         }
22     }
23     
24     private InputSource getClassPathSource(String JavaDoc name) {
25         InputStream is = null;
26         try {
27             is = getClass().getResourceAsStream(RESOURCE_LOCATION + name);
28             return new InputSource(is);
29         } catch (Exception JavaDoc exe) {
30             System.err.println("POEntityResolver error resolving: " + name);
31             exe.printStackTrace();
32         }
33         return null;
34     }
35 }
36
37
Popular Tags