XsdEntityResolver.java
2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.resourceresolverhelper.ResourceResolverHelper
* javax.jcr.Binary
* javax.jcr.Node
* javax.jcr.Property
* javax.jcr.RepositoryException
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.aemds.guide.xsd;
import com.adobe.granite.resourceresolverhelper.ResourceResolverHelper;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.jcr.Binary;
import javax.jcr.Node;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class XsdEntityResolver
implements EntityResolver {
private ResourceResolverHelper resourceResolverHelper;
private List<String> pathOfChildXSD;
private Logger logger = LoggerFactory.getLogger(XsdEntityResolver.class);
public XsdEntityResolver(ResourceResolverHelper resourceResolverHelper) {
this.resourceResolverHelper = resourceResolverHelper;
}
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
InputSource isrc = null;
ResourceResolver resolver = this.resourceResolverHelper.getResourceResolver();
String path = systemId.substring(5) + "/jcr:content";
Resource slingResource = resolver.resolve(path);
Node jcrNode = (Node)slingResource.adaptTo(Node.class);
InputStream is = null;
try {
if (!jcrNode.hasProperty("jcr:data")) {
jcrNode = jcrNode.getNode("renditions/original/jcr:content");
}
is = jcrNode.getProperty("jcr:data").getBinary().getStream();
isrc = new InputSource(is);
this.pathOfChildXSD = new ArrayList<String>();
this.addXSDPathToList(path);
isrc.setSystemId(systemId);
}
catch (RepositoryException e) {
this.logger.error("Unable to access the jcr repository", (Throwable)e);
}
return isrc;
}
private void addXSDPathToList(String path) {
this.pathOfChildXSD.add(path);
}
public List<String> getListOfAllXSD() {
return this.pathOfChildXSD;
}
}