All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.effektif.workflow.impl.bpmn.ClasspathResourceResolver Maven / Gradle / Ivy

package com.effektif.workflow.impl.bpmn;

import java.io.InputStream;
import java.io.InputStreamReader;

import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSResourceResolver;

/**
 * Loads files from the classpath, used instead of loading files from the filesystem directly when reading XML Schema
 * files that use xsd:include and xsd:import directives to load other schema files.
 */
public class ClasspathResourceResolver implements LSResourceResolver {

  private String basePath;

  /**
   * @param basePath Specifies the resource path within the classpath; does not start with slash; ends with a slash.
   */
  public ClasspathResourceResolver(String basePath) {
    this.basePath = basePath;
  }

  @Override
  public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
    LoadInput input = new LoadInput();
    String resourcePath = basePath + systemId;
    InputStream stream = getClass().getClassLoader().getResourceAsStream(resourcePath);
    if (stream == null) {
      throw new IllegalArgumentException("Could not read resource as stream from path " + resourcePath);
    }
    input.setPublicId(publicId);
    input.setSystemId(systemId);
    input.setBaseURI(baseURI);
    input.setCharacterStream(new InputStreamReader(stream));
    return input;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy