-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use file temp to download XML Schema, DTD + add warning message when
validation is done and XML Schema is downloading (see #159)
- Loading branch information
1 parent
2bbe54b
commit 6f50788
Showing
11 changed files
with
214 additions
and
73 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
/** | ||
* Copyright (c) 2018 Angelo ZERR | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Angelo Zerr <[email protected]> - initial API and implementation | ||
*/ | ||
package org.eclipse.lsp4xml.extensions.contentmodel.uriresolver; | ||
|
||
import java.io.IOException; | ||
|
@@ -10,19 +20,32 @@ | |
import org.eclipse.lsp4xml.uriresolver.CacheResourcesManager; | ||
import org.eclipse.lsp4xml.uriresolver.URIResolverExtension; | ||
|
||
/** | ||
* URI resolver which download the first time the XML Schema, DTD from "http" or | ||
* "ftp" in the file system. The second time, teh downloaded file is used | ||
* instead of accessing from "http" or "ftp". This cache improves drastically | ||
* the performance of some XML Schema (ex: xml.xsd) | ||
* | ||
*/ | ||
public class XMLCacheResolverExtension implements URIResolverExtension { | ||
|
||
@Override | ||
public String resolve(String baseLocation, String publicId, String systemId) { | ||
// Don't resolve the URI | ||
return null; | ||
} | ||
|
||
@Override | ||
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException { | ||
String url = resourceIdentifier.getExpandedSystemId(); | ||
// Cache is used only for resource coming from "http" or "ftp". | ||
if (CacheResourcesManager.getInstance().canUseCache(url)) { | ||
Path file = CacheResourcesManager.getInstance().getResources(url); | ||
// Try to get the downloaded resource. In the case of the resource is | ||
// downloading and takes so many time, | ||
// the exception CacheResourceDownloadingException is thrown. | ||
Path file = CacheResourcesManager.getInstance().getResource(url); | ||
if (file != null) { | ||
// The resource is downloaded in the file system, use it. | ||
XMLInputSource source = new XMLInputSource(resourceIdentifier); | ||
source.setByteStream(Files.newInputStream(file)); | ||
return source; | ||
|
@@ -31,6 +54,11 @@ public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) th | |
return null; | ||
} | ||
|
||
/** | ||
* Set true if cache must be used and false otherwise. | ||
* | ||
* @param useCache true if cache must be used and false otherwise. | ||
*/ | ||
public void setUseCache(boolean useCache) { | ||
CacheResourcesManager.getInstance().setUseCache(useCache); | ||
} | ||
|
58 changes: 58 additions & 0 deletions
58
...4xml/src/main/java/org/eclipse/lsp4xml/uriresolver/CacheResourceDownloadingException.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,58 @@ | ||
/** | ||
* Copyright (c) 2018 Angelo ZERR | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Angelo Zerr <[email protected]> - initial API and implementation | ||
*/ | ||
package org.eclipse.lsp4xml.uriresolver; | ||
|
||
import java.nio.file.Path; | ||
import java.text.MessageFormat; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
* Exception thrown when a resource (XML Schema, DTD) is downloading. | ||
* | ||
*/ | ||
public class CacheResourceDownloadingException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
private static final String RESOURCE_LOADING_MSG = "The resource ''{0}'' is downloading."; | ||
|
||
private final String resourceURI; | ||
|
||
private final CompletableFuture<Path> future; | ||
|
||
public CacheResourceDownloadingException(String resourceURI, CompletableFuture<Path> future) { | ||
super(MessageFormat.format(RESOURCE_LOADING_MSG, resourceURI)); | ||
this.resourceURI = resourceURI; | ||
this.future = future; | ||
} | ||
|
||
/** | ||
* Returns the resource URI which is downloading. | ||
* | ||
* @return the resource URI which is downloading. | ||
*/ | ||
public String getResourceURI() { | ||
return resourceURI; | ||
} | ||
|
||
/** | ||
* Returns true if it's a DTD which id downloading and false otherwise. | ||
* | ||
* @return true if it's a DTD which id downloading and false otherwise. | ||
*/ | ||
public boolean isDTD() { | ||
return resourceURI != null && resourceURI.endsWith(".dtd"); | ||
} | ||
|
||
public CompletableFuture<Path> getFuture() { | ||
return future; | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
....lsp4xml/src/main/java/org/eclipse/lsp4xml/uriresolver/CacheResourceLoadingException.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.