View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2012-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.xml;
6   
7   import org.w3c.dom.ls.LSInput;
8   import org.w3c.dom.ls.LSResourceResolver;
9   
10  /**
11   * {@link LSResourceResolver} implementation
12   * supporting classpath lookups.
13   *
14   * @since 0.1
15   */
16  public final class ClasspathResolver implements LSResourceResolver {
17  
18      @Override
19      @SuppressWarnings("PMD.UseObjectForClearerAPI")
20      // @checkstyle ParameterNumber (10 lines)
21      public LSInput resolveResource(
22          final String type,
23          final String nspace,
24          final String pid,
25          final String sid,
26          final String base
27      ) {
28          LSInput input = null;
29          final ClassLoader loader = Thread.currentThread().getContextClassLoader();
30          if (sid != null && loader.getResource(sid) != null) {
31              input = new ClasspathInput(pid, sid);
32          }
33          return input;
34      }
35  }