1 package org.opensync.tools;
2
3 import java.io.File;
4 import java.net.MalformedURLException;
5 import java.net.URL;
6
7 import org.xml.sax.InputSource;
8
9 public class EntityResolver implements org.xml.sax.EntityResolver {
10
11 private String uri;
12 private String ref;
13
14 public void setURI(String uri){
15 // this.uri = uri.substring(0,uri.lastIndexOf("/")+1);
16 this.uri = uri;
17 try{
18 URL url = new URL(uri);
19 ref = url.getRef();
20 }catch(MalformedURLException e){
21
22 }
23 }
24
25 public InputSource resolveEntity(String publicId, String systemId) {
26 String systemUrl = null;
27 //System.out.println("EntityResolver :: systemId : " + systemId ); //JT
28 //System.out.println("EntityResolver :: uri : " + uri ); //JT
29 //System.out.println("EntityResolver :: ref : " + ref ); //JT
30 if (systemId != null){
31 if(ref!=null){
32 //This means that AssetPlus.war file is running in Windows //JT
33 /* This loop is introduced because Weblogic 6.0 and 7.x has a bug in windows,
34 when using the application in a war file.
35 For systemID, instead of Passing :
36 "zip:D:/bea/wlserver6.1/config/mydomain/applications/.wlnotdelete/wl_compXXXXX.war#WEB_INF/config/XXX.xml"
37 It passes :
38 "zip:D:/bea//wlserver6.1/config/mydomain/applications/.wlnotdelete/XXX.xml"
39 Hence to correct in windows, this loop.
40 In Unix, when using a war file with WebLogic, systemID is passed correctly :
41 "zip:/opt/wlserver6.1/config/mydomain/applications/.wlnotdelete/wl_compXXXXX.war!WEB_INF/config/XXX.xml"
42 */
43 String file = systemId.substring(systemId.lastIndexOf("/.wlnotdelete/") + "/.wlnotdelete/".length());
44 try{
45 systemUrl = new URL(uri+file).toExternalForm();
46 }catch(Exception ex){
47 ex.printStackTrace(System.out);
48 return null;
49 }
50
51 }else{
52 try{
53 systemUrl = new URL(systemId).toExternalForm();
54 //System.out.println("unix or exploded or tomcat"); //JT
55 }catch (Exception e){
56 try{
57 systemUrl = new URL(new URL(uri),systemId).toExternalForm();
58 //System.out.println("exception"); //JT
59 }catch(Exception ex){
60 // This is the old contents of EntityResolver.java
61 File aFile;
62 try {
63 aFile = new File(new URL(systemId).getFile());
64 if (aFile.exists()) {
65 return new InputSource(systemId);
66 } else
67 return null;
68 } catch (Exception ex1) {
69 try {
70 aFile = new File(new URL(uri+systemId).getFile());
71 } catch (Exception ex2) {
72 return null;
73 }
74 if (aFile.exists()) {
75 return new InputSource(uri+systemId);
76 } else
77 return null;
78 }
79 }
80 }
81 }
82 }
83 //System.out.println("EntityResolver :: systemUrl : " + systemUrl ); //JT
84 return new InputSource(systemUrl);
85
86
87 }
88 }