forked from eclipse-vorto/vorto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: shiv12095 <[email protected]>
- Loading branch information
Showing
61 changed files
with
1,827 additions
and
1,357 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,5 @@ bin/ | |
.project | ||
generated-sources | ||
*.orig | ||
|
||
devtool-project-repository/ |
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
81 changes: 81 additions & 0 deletions
81
...ipse.vorto.editor.web/src/org/eclipse/vorto/editor/web/resource/FileResourceHandler.xtend
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,81 @@ | ||
/** | ||
* Copyright (c) 2017 Bosch Software Innovations GmbH and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* and Eclipse Distribution License v1.0 which accompany this distribution. | ||
* | ||
* The Eclipse Public License is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* The Eclipse Distribution License is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* Contributors: | ||
* Bosch Software Innovations GmbH - Please refer to git log | ||
*/ | ||
package org.eclipse.vorto.editor.web.resource | ||
|
||
import com.google.inject.Inject | ||
import java.io.File | ||
import java.io.IOException | ||
import java.io.OutputStreamWriter | ||
import org.eclipse.emf.common.util.URI | ||
import org.eclipse.emf.common.util.WrappedException | ||
import org.eclipse.vorto.devtool.projectrepository.IProjectRepositoryService | ||
import org.eclipse.vorto.devtool.projectrepository.file.ProjectRepositoryFileConstants | ||
import org.eclipse.vorto.devtool.projectrepository.file.ProjectRepositoryServiceFS | ||
import org.eclipse.xtext.parser.IEncodingProvider | ||
import org.eclipse.xtext.resource.XtextResource | ||
import org.eclipse.xtext.web.server.IServiceContext | ||
import org.eclipse.xtext.web.server.model.IWebDocumentProvider | ||
import org.eclipse.xtext.web.server.model.IWebResourceSetProvider | ||
import org.eclipse.xtext.web.server.model.IXtextWebDocument | ||
import org.eclipse.xtext.web.server.persistence.IServerResourceHandler | ||
|
||
class FileResourceHandler implements IServerResourceHandler { | ||
|
||
@Inject | ||
private IWebResourceSetProvider resourceSetProvider | ||
|
||
@Inject | ||
private IWebDocumentProvider documentProvider | ||
|
||
@Inject | ||
private IEncodingProvider encodingProvider | ||
|
||
private String projectRepositoryPath = "../devtool-project-repository"; | ||
|
||
private IProjectRepositoryService projectRepositoryService = new ProjectRepositoryServiceFS(projectRepositoryPath); | ||
|
||
def getFileURI(String resourceId) { | ||
val resource = projectRepositoryService.createQuery().property(ProjectRepositoryFileConstants.META_PROPERTY_RESOURCE_ID, resourceId).singleResult(); | ||
return URI.createFileURI(projectRepositoryPath + File.separator + resource.path); | ||
} | ||
|
||
override get(String resourceId, IServiceContext serviceContext) throws IOException { | ||
try { | ||
val uri = getFileURI(resourceId) | ||
if (uri === null) | ||
throw new IOException('The requested resource does not exist.') | ||
val resourceSet = resourceSetProvider.get(resourceId, serviceContext) | ||
val resource = resourceSet.getResource(uri, true) as XtextResource | ||
println(resourceSet) | ||
return documentProvider.get(resourceId, serviceContext) => [ | ||
setInput(resource) | ||
] | ||
} catch (WrappedException exception) { | ||
throw exception.cause | ||
} | ||
} | ||
|
||
override put(IXtextWebDocument document, IServiceContext serviceContext) throws IOException { | ||
try { | ||
val uri = getFileURI(document.resourceId) | ||
val outputStream = document.resource.resourceSet.URIConverter.createOutputStream(uri) | ||
val writer = new OutputStreamWriter(outputStream, encodingProvider.getEncoding(uri)) | ||
writer.write(document.text) | ||
writer.close | ||
} catch (WrappedException exception) { | ||
throw exception.cause | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -663,4 +663,4 @@ | |
</build> | ||
</profile> | ||
</profiles> | ||
</project> | ||
</project> |
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
21 changes: 21 additions & 0 deletions
21
...java/org/eclipse/vorto/devtool/projectrepository/file/ProjectRepositoryFileConstants.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,21 @@ | ||
package org.eclipse.vorto.devtool.projectrepository.file; | ||
|
||
import org.eclipse.vorto.devtool.projectrepository.model.Resource; | ||
|
||
public class ProjectRepositoryFileConstants { | ||
|
||
public static final String META_PROPERTY_AUTHOR = Resource.META_PROPERTY_AUTHOR; | ||
|
||
public static final String META_PROPERTY_RESOURCE_ID = "resourceId"; | ||
|
||
public static final String META_PROPERTY_NAME = "name"; | ||
|
||
public static final String META_PROPERTY_NAMESPACE = "namespace"; | ||
|
||
public static final String META_PROPERTY_VERSION = "version"; | ||
|
||
public static final String META_PROPERTY_MODEL_TYPE = "modelType"; | ||
|
||
public static final String META_PROPERTY_MODEL_SUB_TYPE = "modelSubType"; | ||
|
||
} |
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.