use of org.apache.xml.resolver.CatalogManager in project midpoint by Evolveum.
the class SchemaRegistryImpl method initResolver.
private void initResolver() throws IOException {
CatalogManager catalogManager = new CatalogManager();
catalogManager.setUseStaticCatalog(true);
catalogManager.setIgnoreMissingProperties(true);
catalogManager.setVerbosity(1);
catalogManager.setPreferPublic(true);
CatalogResolver catalogResolver = new CatalogResolver(catalogManager);
Catalog catalog = catalogResolver.getCatalog();
if (catalogFiles != null && catalogFiles.length > 0) {
for (File catalogFile : catalogFiles) {
LOGGER.trace("Using catalog file {}", catalogFile);
catalog.parseCatalog(catalogFile.getPath());
}
} else if (catalogResourceName != null) {
LOGGER.trace("Using catalog from resource: {}", catalogResourceName);
Enumeration<URL> catalogs = Thread.currentThread().getContextClassLoader().getResources(catalogResourceName);
while (catalogs.hasMoreElements()) {
URL catalogResourceUrl = catalogs.nextElement();
LOGGER.trace("Parsing catalog from URL: {}", catalogResourceUrl);
catalog.parseCatalog(catalogResourceUrl);
}
} else {
throw new IllegalStateException("Catalog is not defined");
}
builtinSchemaResolver = catalogResolver;
}
use of org.apache.xml.resolver.CatalogManager in project cxf by apache.
the class OASISCatalogManager method getResolver.
private static EntityResolver getResolver() {
try {
CatalogManager catalogManager = new CatalogManager();
if (DEBUG_LEVEL != null) {
catalogManager.debug.setDebug(Integer.parseInt(DEBUG_LEVEL));
}
catalogManager.setUseStaticCatalog(false);
catalogManager.setIgnoreMissingProperties(true);
return new CatalogResolver(catalogManager) {
public String getResolvedEntity(String publicId, String systemId) {
String s = super.getResolvedEntity(publicId, systemId);
if (s != null && s.startsWith("classpath:")) {
try (URIResolver r = new URIResolver(s)) {
if (r.isResolved()) {
return r.getURL().toExternalForm();
}
} catch (IOException e) {
// ignore
}
}
return s;
}
};
} catch (Throwable t) {
// ignore
}
return null;
}
use of org.apache.xml.resolver.CatalogManager in project midpoint by Evolveum.
the class SchemaDistMojo method execute.
public void execute() throws MojoExecutionException, MojoFailureException {
getLog().info("SchemaDist plugin started");
try {
processArtifactItems();
} catch (InvalidVersionSpecificationException e) {
handleFailure(e);
}
final File outDir = initializeOutDir(outputDirectory);
CatalogManager catalogManager = new CatalogManager();
catalogManager.setVerbosity(999);
for (ArtifactItem artifactItem : artifactItems) {
Artifact artifact = artifactItem.getArtifact();
getLog().info("SchemaDist unpacking artifact " + artifact);
File workDir = new File(workDirectory, artifact.getArtifactId());
initializeOutDir(workDir);
artifactItem.setWorkDir(workDir);
unpack(artifactItem, workDir);
if (translateSchemaLocation) {
String catalogPath = artifactItem.getCatalog();
if (catalogPath != null) {
File catalogFile = new File(workDir, catalogPath);
if (!catalogFile.exists()) {
throw new MojoExecutionException("No catalog file " + catalogPath + " in artifact " + artifact);
}
Catalog catalog = new Catalog(catalogManager);
catalog.setupReaders();
try {
// UGLY HACK. On Windows, file names like d:\abc\def\catalog.xml eventually get treated very strangely
// (resulting in names like "file:<current-working-dir>d:\abc\def\catalog.xml" that are obviously wrong)
// Prefixing such names with "file:/" helps.
String prefix;
if (catalogFile.isAbsolute() && !catalogFile.getPath().startsWith("/")) {
prefix = "/";
} else {
prefix = "";
}
String fileName = "file:" + prefix + catalogFile.getPath();
getLog().debug("Calling parseCatalog with: " + fileName);
catalog.parseCatalog(fileName);
} catch (MalformedURLException e) {
throw new MojoExecutionException("Error parsing catalog file " + catalogPath + " in artifact " + artifact, e);
} catch (IOException e) {
throw new MojoExecutionException("Error parsing catalog file " + catalogPath + " in artifact " + artifact, e);
}
artifactItem.setResolveCatalog(catalog);
}
} else {
getLog().debug("Catalog search disabled for " + artifact);
}
}
for (ArtifactItem artifactItem : artifactItems) {
Artifact artifact = artifactItem.getArtifact();
getLog().info("SchemaDist processing artifact " + artifact);
final File workDir = artifactItem.getWorkDir();
FileVisitor<Path> fileVisitor = new FileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
// nothing to do
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path filePath, BasicFileAttributes attrs) throws IOException {
String fileName = filePath.getFileName().toString();
if (fileName.endsWith(".xsd")) {
getLog().debug("=======================> Processing file " + filePath);
try {
processXsd(filePath, workDir, outDir);
} catch (MojoExecutionException | MojoFailureException e) {
throw new RuntimeException(e.getMessage(), e);
}
} else if (fileName.endsWith(".wsdl")) {
getLog().debug("=======================> Processing file " + filePath);
try {
processWsdl(filePath, workDir, outDir);
} catch (MojoExecutionException | MojoFailureException e) {
throw new RuntimeException(e.getMessage(), e);
}
} else {
getLog().debug("=======================> Skipping file " + filePath);
}
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
return FileVisitResult.TERMINATE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
// nothing to do
return FileVisitResult.CONTINUE;
}
};
try {
Files.walkFileTree(workDir.toPath(), fileVisitor);
} catch (IOException e) {
throw new MojoExecutionException("Error processing files of artifact " + artifact, e);
}
}
getLog().info("SchemaDist plugin finished");
}
use of org.apache.xml.resolver.CatalogManager in project intellij-community by JetBrains.
the class XMLCatalogManagerTest method testCatalogManager.
public void testCatalogManager() throws Exception {
XMLCatalogManager manager = getManager();
CatalogManager catalogManager = manager.getManager();
Vector files = catalogManager.getCatalogFiles();
assertEquals(1, files.size());
String filePath = (String) files.get(0);
assertTrue(filePath, filePath.endsWith("catalog.xml"));
assertTrue(filePath, new File(new URI(filePath)).exists());
}
Aggregations