writing files in exported eclipse rcp product - eclipse-plugin

I am a newbie and I am working on eclipse-rcp and trying to build a address book with data saved in xml files.when I am running the project it is able to read and write into the xml file but when I am exporting it into a rcp product it is only reading the file but not able to write.
I tried searching Google but couldn't find the relevant answers so I turned to SO.
Any suggestions??
Edit This is my method where I am trying to read the file and writing it into xml file
public void writedata() {
try {
DocumentBuilderFactory builderFactory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = builderFactory.newDocumentBuilder();
Bundle bundle = Platform.getBundle(Activator.PLUGIN_ID);
URL fileURL = bundle.getEntry("/xmlfiles/person.xml");
InputStream inputStream=fileURL.openStream();
Document xmlDocument = builder.parse(inputStream);
..................................................
..................................................
..................................................
TransformerFactory transformerFactory = TransformerFactory
.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(xmlDocument);
Bundle bundle1 = Platform.getBundle(Activator.PLUGIN_ID);
URL fileURL1 = bundle1.getEntry("/xmlfiles/person.xml");
StreamResult result = new StreamResult(new File(FileLocator.resolve(fileURL1).getPath()));
transformer.transform(source, result);

When you run your application from Eclipse it uses the expanded project folder for your plugin. Your XML file is writeable in this location.
When you export as an RCP application your plugin gets packaged up as a plugin jar file with the XML file inside it. You won't be able to write to this file.
For the file to be writeable it needs to be outside your plugin project, either in the RCP application workspace or in an external folder.

Related

have a problem accessing the files in wwwroot

In the wwwroot folder I can access all files(images, java script, css, zip). But when I upload an apk file, it is not accessible.
When I compress this apk file to zip I can download it
AspNetCore uses this list of media types and according to this list, it does not know what an APK file is, so AspNetCore will return a 404 error.
To allow this, you can map your own. REF: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-6.0#fileextensioncontenttypeprovider
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".apk"] = "application/vnd.android.package-archive";
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = provider
});

How to load external config from s3 bucket in grails 2.5.1?

In Grails 3.1.4, there is a method to load external yml file as inputstream as
S3Service s3Service = new RestS3Service(awsCredentials)
S3Object downloadedObject= S3Service.getObject("bucketName","application.yml")
Resource resourceConfig = new InputStreamResource(downloadedObject.getDataInputStream())
YamlPropertiesFactoryBean ypfb = new YamlPropertiesFactoryBean()
ypfb.setResources(resourceConfig)
ypfb.afterPropertiesSet()
I want to do the same in grails 2.5.1 but could not figure out. I don't want to download the file to local and set path to grails.config.location.

use beanshell to execute a scripts from a specific folder (error no such file or directory)

I added the library bsh to my android project (jar file), the I create a file executor.bsh under scripts(a folder that I have created under the project)
I used the code below
private final Interpreter i= new Interpreter();
i.source("scripts/executor.bsh");
I got an error:
No such file or directory
Help !!
Interpreter.source(..) looks for a File, where you have a jar entry. However, you can still use it with:
try (Reader script = new InputStreamReader(getClass().getClassLoader().getResourceAsStream("scripts/executor.bsh")) {
Interpreter in = new Interpreter(script, System.in, System.out, System.err, false);
// your script was already loaded
// do something with Interpreter here.
}

Can't access properties file

I've made a plugin from external jar. In this jar there is access to properties file:
final Properties properties = new Properties();
final String fileName = "/" + thisClass.getName() + ".properties";
InputStream inputStream;
try
{
inputStream = thisClass.getResourceAsStream(fileName);
properties.load(inputStream);
}
In my RCP-Application the inputStream is null. I've also exported the default package in the plugin. What's wrong.
I've solved my problem. The solution is to make an Eclipse-BuddyPolicy Entry to the Manifest.mf of the plugin with the external jar.
Eclipse-BuddyPolicy: global
This is described in the Eclipse Help: Platform Plugin Developer Guide-->Reference-->Other reference information-->Third party libraries and classloading

Get/Read files from SharePoint document library and ZIP them using DotNetZip?

I have files uploaded to sharepoint document library. Trying to use DotNetZip to get those files from document library, zip them and render the zip file.
Response.Clear();
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "filename=" + "MyFiles.zip");
using (ZipFile zip = new ZipFile())
{
//Query the sharepoint document library and get SPFolder (folder in this case)
foreach (SPFolder folder in userFolder.SubFolders)
{
foreach (SPFile file in folder.Files)
{
zip.AddFile(file.URL);// Is this possible?
}
}
zip.Save(Response.OutputStream);
Can we pass file URL to AddFile method? If not, is there any another way to do this?
The dotnetzip addfile method does not accept urls. It needs to be a relative or full qualified path. See the documentation
Try the vZIP add-on, it is working great on our SharePoint 2010.