Skip to content

Commit

Permalink
Initialize xsl plugin (see #91)
Browse files Browse the repository at this point in the history
  • Loading branch information
angelozerr committed Sep 4, 2018
1 parent 2ccd125 commit b0389c6
Show file tree
Hide file tree
Showing 11 changed files with 5,949 additions and 0 deletions.
36 changes: 36 additions & 0 deletions extensions/org.eclipse.lsp4xml.xsl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
build/
.out/
bin/
.bin/
target/

/gradle.properties
/archive/
/META-INF

.classpath
.project
.settings

.idea/
*.iml
*.iws
*.ipr
.idea_modules/
**/out/

*.tmp
*.bak
*.swp
*~

.gradle

.DS_Store*
.AppleDouble
.LSOverride

.directory
.Trash*

**/adhoctest/
57 changes: 57 additions & 0 deletions extensions/org.eclipse.lsp4xml.xsl/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse</groupId>
<artifactId>lsp4xml-extensions</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.lsp4xml.xsl</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.eclipse.lsp4j</groupId>
<artifactId>org.eclipse.lsp4j</artifactId>
<version>${lsp4j.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.lsp4j</groupId>
<artifactId>org.eclipse.lsp4j.jsonrpc</artifactId>
<version>${lsp4j.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext.xbase.lib</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse</groupId>
<artifactId>org.eclipse.lsp4xml</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.eclipse.lsp4xml.xsl.XSLPlugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.eclipse.lsp4xml.xsl;

import org.eclipse.lsp4xml.services.extensions.IXMLExtension;
import org.eclipse.lsp4xml.services.extensions.XMLExtensionsRegistry;
import org.eclipse.lsp4xml.uriresolver.URIResolverExtensionManager;

public class XSLPlugin implements IXMLExtension {

private final XSLURIResolverExtension uiResolver;

public XSLPlugin() {
uiResolver = new XSLURIResolverExtension();
}

@Override
public void updateSettings(Object settings) {

}

@Override
public void start(XMLExtensionsRegistry registry) {
URIResolverExtensionManager.getInstance().registerResolver(uiResolver);
}

@Override
public void stop(XMLExtensionsRegistry registry) {
URIResolverExtensionManager.getInstance().unregisterResolver(uiResolver);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.eclipse.lsp4xml.xsl;

import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.eclipse.lsp4xml.uriresolver.URIResolverExtension;

public class XSLURIResolverExtension implements URIResolverExtension {

/**
* The XSL namespace URI (= http://www.w3.org/1999/XSL/Transform)
*/
private static final String XSL_NAMESPACE_URI = "http://www.w3.org/1999/XSL/Transform"; //$NON-NLS-1$

@Override
public String resolve(String baseLocation, String publicId, String systemId) {
if (!XSL_NAMESPACE_URI.equals(publicId)) {
return null;
}
else {

}
// TODO: extract version from XML Document
String version = "1.0";
String schemaFileName = "xslt-" + version + ".xsd";
String schemaPath = "/xslt-schemas/" + schemaFileName;

try {
Path baseDir = Paths.get("C://lsp4xml");

This comment has been minimized.

Copy link
@fbricon

fbricon Sep 4, 2018

Contributor

nononono

This comment has been minimized.

Copy link
@angelozerr

angelozerr Sep 5, 2018

Author Contributor

Indeed @fbricon it was just a POC that I have done to validate my concept with URIResolverExtension.
Don't worry, it's a plugin extension so it will not in the *all JAR). We must define an utility class which deploy files. Have you an idea in which directory we can do that?

Files.createDirectories(baseDir);
Path outFile = baseDir.resolve(schemaFileName);
if (!outFile.toFile().exists()) {
InputStream in = XSLURIResolverExtension.class.getResourceAsStream(schemaPath);
String xml = convertStreamToString(in);
saveToFile(xml, outFile);
}
return outFile.toFile().toURI().toString();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}

private static void saveToFile(String xml, Path outFile) throws IOException {
try (Writer writer = Files.newBufferedWriter(outFile, StandardCharsets.UTF_8)) {
writer.write(xml);
}
}

static String convertStreamToString(java.io.InputStream is) {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}

}
Loading

0 comments on commit b0389c6

Please sign in to comment.