Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update schema handling and prepare migration #1129

Merged
merged 3 commits into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 49 additions & 9 deletions uncoupled/deegree-jaxb-resolver/pom.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.deegree</groupId>
<artifactId>deegree-jaxb-resolver</artifactId>
<version>1.0</version>
<version>1.1-SNAPSHOT</version>
<name>deegree-jaxb-resolver</name>
<packaging>jar</packaging>
<description>JAXB resolver to search for deegree schema files on classpath</description>

<parent>
<groupId>org.deegree</groupId>
<artifactId>deegree</artifactId>
<version>3.4-RC1</version>
</parent>

<repositories>
<repository>
<id>deegree-repo</id>
Expand All @@ -26,7 +22,15 @@
</repository>
</repositories>

<!-- TRICKY require to start compiler forked, to allow build against reference in rt.jar -->
<scm>
<connection>scm:git:git@github.com:deegree/deegree3.git</connection>
<developerConnection>scm:git:git@github.com:deegree/deegree3.git</developerConnection>
<url>https://github.com/deegree/deegree3</url>
<tag>HEAD</tag>
</scm>

<!-- TRICKY require to start compiler forked, to allow build against reference
in rt.jar -->
<build>
<plugins>
<plugin>
Expand All @@ -39,9 +43,40 @@
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<tagNameFormat>jaxb-resolver-@{project.version}</tagNameFormat>
</configuration>
</plugin>
</plugins>
</build>

<licenses>
<license>
<name>GNU Lesser General Public License (LGPL), version 2.1</name>
<url>http://www.gnu.org/licenses/lgpl-2.1.html</url>
<distribution>repo</distribution>
</license>
</licenses>

<issueManagement>
<system>github</system>
<url>https://github.com/deegree/deegree3/issues</url>
</issueManagement>

<developers>
<developer>
<id>TMC</id>
<name>Technical Management Committee</name>
<organization>OSGeo deegree project</organization>
<organizationUrl>https://www.deegree.org</organizationUrl>
<email>tmc@deegree.org</email>
</developer>
</developers>

<dependencies>
<dependency>
<groupId>java</groupId>
Expand All @@ -51,4 +86,9 @@
<systemPath>${java.home}/lib/rt.jar</systemPath>
</dependency>
</dependencies>

<ciManagement>
<system>Jenkins CI</system>
<url>http://buildserver.deegree.org/</url>
</ciManagement>
</project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/*----------------------------------------------------------------------------
This file is part of deegree
Copyright (C) 2001-2014 by:
This file is part of deegree, http://deegree.org/
Copyright (C) 2001-2022 by:
- Department of Geography, University of Bonn -
and
- lat/lon GmbH -
and
- grit GmbH -
and others
- grit graphische Informationstechnik Beratungsgesellschaft mbH -

This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Expand All @@ -22,21 +21,39 @@

Contact information:

grit graphische Informationstechnik Beratungsgesellschaft mbH
Landwehrstr. 143, 59368 Werne
Germany
http://www.grit.de/

lat/lon GmbH
Aennchenstr. 19, 53177 Bonn
Germany
http://lat-lon.de/

Department of Geography, University of Bonn
Prof. Dr. Klaus Greve
Postfach 1147, 53001 Bonn
Germany
http://www.geographie.uni-bonn.de/deegree/

e-mail: info@deegree.org
website: http://www.deegree.org/
----------------------------------------------------------------------------*/
----------------------------------------------------------------------------*/
package org.deegree.uncoupled.jaxb;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

/**
* JAXB Catalog Resolver
*
* The Resolver is build to allow JAXB to find deegree bundled schemas inside the build classpath instead of resolving
* schema files online.
* The Resolver is build to allow JAXB to find deegree bundled schemas inside
* the build classpath instead of resolving schema files online.
*
* <blockquote> <b>Note:</b> Eclipse only builds this class if the following setting is changed, because of internal
* API:
* <blockquote> <b>Note:</b> Eclipse only builds this class if the following
* setting is changed, because of internal API:
*
* <pre>
* Window > Preferences > Java > Compiler > Errors/Warnings
Expand All @@ -48,49 +65,110 @@
*
* @author <a href="mailto:reichhelm@grit.de">Stephan Reichhelm</a>
*/
@SuppressWarnings("restriction")
public class CatalogResolver extends com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver {

private static final String REWRITE_FROM = "http://schemas.deegree.org/";

private static final String REWRITE_TO = "META-INF/schemas/";

private boolean debug = false;

public CatalogResolver() {
String dbg = System.getProperty( "deeegree.jaxb.debug" );
if ( dbg != null && !dbg.isEmpty() ) {
debug = true;
}
}

@Override
public String getResolvedEntity( String publicId, String systemId ) {

if ( systemId != null && systemId.toLowerCase().startsWith( REWRITE_FROM ) ) {
if ( debug ) {
System.err.println( "*** deegree JAXB CatalogResolver: publicId: " + publicId + " systemId: "
+ systemId );
}

String newid = REWRITE_TO + systemId.substring( REWRITE_FROM.length() );

try {
URL resource = Thread.currentThread().getContextClassLoader().getResource( newid );
if ( resource == null ) {
resource = getClass().getResource( "/" + newid );
}
if ( resource != null ) {
if ( debug ) {
System.err.println( "Resolved localy to: " + resource );
}
return resource.toString();
}
} catch ( Exception ex ) {
System.err.println( "Error: " + ex.getMessage() );
}
}

// Use default lookup
return super.getResolvedEntity( publicId, systemId );
}
private Map<String, String> cacheRelatives = new HashMap<String, String>();

private static final String PUBLIC_FROM_HTTP = "http://www.deegree.org/";

private static final String REWRITE_FROM_HTTP = "http://schemas.deegree.org/";

private static final String REWRITE_FROM_HTTPS = "https://schemas.deegree.org/";

private static final Pattern PAT_VERSION = Pattern.compile("^[0-9]+\\.[0-9]+");

private static final String REWRITE_TO = "META-INF/schemas/";

private boolean debug = true;

public CatalogResolver() {
String dbg = System.getProperty("deeegree.jaxb.debug");
if (dbg != null && !dbg.isEmpty()) {
debug = true;
}
}

@Override
public String getResolvedEntity(String publicId, String systemId) {

if (systemId == null) {
} else if (systemId.toLowerCase().startsWith(REWRITE_FROM_HTTP)) {
// TODO seems to be not required anymore
debug("*** deegree JAXB CatalogResolver: publicId: " + publicId + " systemId: " + systemId);

String path = systemId.substring(REWRITE_FROM_HTTP.length());
String res = lookup(path);
if (res != null) {
return res;
}
} else if (systemId.toLowerCase().startsWith(REWRITE_FROM_HTTPS)) {
// TODO seems to be not required anymore
debug("*** deegree JAXB CatalogResolver: publicId: " + publicId + " systemId: " + systemId);

String path = systemId.substring(REWRITE_FROM_HTTPS.length());
String res = lookup(path);
if (res != null) {
return res;
}
} else if (systemId.startsWith("../") && publicId.toLowerCase().startsWith(PUBLIC_FROM_HTTP)) {
debug("*** deegree JAXB CatalogResolver: publicId: " + publicId + " systemId: " + systemId);

String path = systemId;
while (path.startsWith("../")) {
path = path.substring(3);
}
String res = lookup(path);
if (res != null) {
debug("--> " + res);
cacheRelatives.put(publicId, res);
return res;
}
} else {
debug("*** deegree JAXB CatalogResolver: publicId: " + publicId + " systemId: " + systemId);
if (publicId != null) {
String res = cacheRelatives.get(publicId);
if ( res != null ) {
debug("==>: " + res + " [cache]");
return res;
}
}
}

// Use default lookup
return super.getResolvedEntity(publicId, systemId);
}

private void debug(String msg) {
if (!debug) {
return;
}
System.err.println(msg);
}

private String lookup(String path) {

try {
int posSlash = path.indexOf('/');
if (posSlash > 0 && PAT_VERSION.matcher(path).find()) {
// Ignore version for internal lookup
path = path.substring(posSlash + 1);
}
String newid = REWRITE_TO + path;

URL resource = Thread.currentThread().getContextClassLoader().getResource(newid);
if (resource == null) {
resource = getClass().getResource("/" + newid);
}
if (resource != null) {
if (debug) {
System.err.println("Resolved localy to: " + resource);
}
return resource.toString();
}
} catch (Exception ex) {
System.err.println("Error: " + ex.getMessage());
}
return null;
}
}
Loading