-
-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Core, common and domain migrated to PATH
- Loading branch information
Jesse Eichar
committed
Nov 5, 2014
1 parent
3974b09
commit 05c2d89
Showing
314 changed files
with
2,893 additions
and
2,359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
common/src/main/java/org/fao/geonet/utils/NioPathAwareCatalogResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.fao.geonet.utils; | ||
|
||
import org.apache.xml.resolver.CatalogManager; | ||
import org.apache.xml.resolver.tools.CatalogResolver; | ||
import org.xml.sax.InputSource; | ||
import org.xml.sax.SAXException; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import javax.xml.transform.Source; | ||
import javax.xml.transform.TransformerException; | ||
import javax.xml.transform.stream.StreamSource; | ||
|
||
/** | ||
* @author Jesse on 11/4/2014. | ||
*/ | ||
class NioPathAwareCatalogResolver extends CatalogResolver { | ||
public NioPathAwareCatalogResolver(CatalogManager catMan) { | ||
super(catMan); | ||
} | ||
|
||
@Override | ||
public String getResolvedEntity(String publicId, String systemId) { | ||
return super.getResolvedEntity(publicId, systemId); | ||
} | ||
|
||
@Override | ||
public InputSource resolveEntity(String publicId, String systemId) { | ||
try { | ||
final InputSource inputSource = Xml.PATH_RESOLVER.resolveEntity(publicId, systemId); | ||
if (inputSource != null) { | ||
return inputSource; | ||
} | ||
} catch (SAXException | IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
return super.resolveEntity(publicId, systemId); | ||
} | ||
|
||
@Override | ||
public Source resolve(String href, String base) throws TransformerException { | ||
try { | ||
final Path basePath = Paths.get(new URI(base)); | ||
final Path resolvedResource = basePath.getParent().resolve(href); | ||
if (Files.isRegularFile(resolvedResource)) { | ||
return new StreamSource(Files.newInputStream(resolvedResource), resolvedResource.toUri().toASCIIString()); | ||
} | ||
} catch (Exception e) { | ||
// ignore | ||
} | ||
return super.resolve(href, base); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
common/src/main/java/org/fao/geonet/utils/NioPathAwareEntityResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.fao.geonet.utils; | ||
|
||
import org.xml.sax.EntityResolver; | ||
import org.xml.sax.InputSource; | ||
import org.xml.sax.SAXException; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* An Xml Entity Resolver that resolves xml files relative to a java.nio.file.Path object. This means that | ||
* the xml can be loaded from any Java NIO filesystem not just the default filesystem. | ||
* | ||
* @author Jesse on 11/4/2014. | ||
*/ | ||
public class NioPathAwareEntityResolver implements EntityResolver { | ||
|
||
|
||
@Override | ||
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { | ||
return NioPathHolder.resolveEntity(publicId, systemId); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
common/src/main/java/org/fao/geonet/utils/NioPathHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.fao.geonet.utils; | ||
|
||
import org.xml.sax.InputSource; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* Holder the information required by {@link org.fao.geonet.utils.NioPathAwareCatalogResolver} | ||
* and {@link org.fao.geonet.utils.NioPathAwareEntityResolver} for resolving paths. | ||
* | ||
* @author Jesse on 11/4/2014. | ||
*/ | ||
public class NioPathHolder { | ||
private static final ThreadLocal<Path> ACTUAL_RELATIVE_TO = new InheritableThreadLocal<>(); | ||
private static final ThreadLocal<Path> SYS_ID_RELATIVE_TO = new InheritableThreadLocal<>(); | ||
|
||
static void setBase(Path base) { | ||
if (base != null) { | ||
ACTUAL_RELATIVE_TO.set(base.getParent()); | ||
SYS_ID_RELATIVE_TO.set(new File(".").getAbsoluteFile().toPath().getParent()); | ||
} else { | ||
ACTUAL_RELATIVE_TO.set(null); | ||
SYS_ID_RELATIVE_TO.set(null); | ||
} | ||
} | ||
|
||
static InputSource resolveEntity(String publicId, String systemId) throws IOException { | ||
if (ACTUAL_RELATIVE_TO.get() != null && systemId.startsWith("file:/")) { | ||
try { | ||
final Path srcPath = Paths.get(new URI(systemId)); | ||
|
||
final Path relativePath = SYS_ID_RELATIVE_TO.get().relativize(srcPath); | ||
Path finalPath = ACTUAL_RELATIVE_TO.get().resolve(relativePath.toString()); | ||
if (Files.isRegularFile(finalPath)) { | ||
return new InputSource(Files.newInputStream(finalPath)); | ||
} | ||
} catch (URISyntaxException e) { | ||
// ignore | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.