1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.helger.schematron.resolve;
18
19 import java.io.IOException;
20 import java.net.URL;
21
22 import javax.annotation.Nonnull;
23 import javax.annotation.Nullable;
24
25 import com.helger.commons.annotation.Nonempty;
26 import com.helger.commons.io.resource.IReadableResource;
27 import com.helger.commons.string.ToStringGenerator;
28 import com.helger.xml.ls.SimpleLSResourceResolver;
29
30
31
32
33
34
35
36
37 public class DefaultSchematronIncludeResolver implements ISchematronIncludeResolver
38 {
39 private final String m_sBaseHref;
40
41 @Nullable
42 private static String _getBaseHref (@Nonnull final IReadableResource aResource)
43 {
44 final URL aURL = aResource.getAsURL ();
45 return aURL == null ? null : aURL.toExternalForm ();
46 }
47
48 public DefaultSchematronIncludeResolver (@Nonnull final IReadableResource aResource)
49 {
50 this (_getBaseHref (aResource));
51 }
52
53 public DefaultSchematronIncludeResolver (@Nullable final String sBaseHref)
54 {
55 m_sBaseHref = sBaseHref;
56 }
57
58 @Nullable
59 public String getBaseHref ()
60 {
61 return m_sBaseHref;
62 }
63
64 @Nonnull
65 public IReadableResource getResolvedSchematronResource (@Nonnull @Nonempty final String sHref) throws IOException
66 {
67 return SimpleLSResourceResolver.doStandardResourceResolving (sHref, getBaseHref ());
68 }
69
70 @Override
71 public String toString ()
72 {
73 return new ToStringGenerator (this).append ("baseHref", m_sBaseHref).toString ();
74 }
75 }