MCPcopy Create free account
hub / github.com/eXist-db/exist / AbstractSource

Class AbstractSource

exist-core/src/main/java/org/exist/source/AbstractSource.java:47–160  ·  view source on GitHub ↗

@author wolf @author Adam Retter

Source from the content-addressed store, hash-verified

45 * @author <a href="mailto:adam@evolvedbinary.com">Adam Retter</a>
46 */
47public abstract class AbstractSource implements Source {
48
49 private final long key;
50
51 protected AbstractSource(final long key) {
52 this.key = key;
53 }
54
55 @Override
56 public long getKey() {
57 return key;
58 }
59
60 @Override
61 public Charset getEncoding() throws IOException {
62 return null;
63 }
64
65 @Deprecated
66 public void validate(final Subject subject, final int perm) throws PermissionDeniedException {
67 // no-op
68 }
69
70 @Override
71 public boolean equals(final Object obj) {
72 if (obj != null && obj instanceof Source) {
73 return key == (((Source)obj).getKey());
74 }
75 return false;
76 }
77
78 public abstract int hashCode();
79
80 @Override
81 public QName isModule() throws IOException {
82 return null;
83 }
84
85 /**
86 * Check if the XQuery file declares a content encoding in the
87 * XQuery declaration.
88 *
89 * @param is the input stream
90 * @return The guessed encoding.
91 */
92 protected static String guessXQueryEncoding(final InputStream is) {
93 final XQueryLexer lexer = new XQueryLexer(null, new InputStreamReader(is));
94 final DeclScanner scanner = new DeclScanner(lexer);
95 try {
96 scanner.versionDecl();
97 } catch (final RecognitionException | XPathException | TokenStreamException e) {
98 //Nothing to do
99 }
100 return scanner.getEncoding();
101 }
102
103 /**
104 * Check if the source is an XQuery module. If yes, return a QName containing

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected