Eclipse Plugin Open a PDF file from inside a plugin package - eclipse

I am trying to open a PDF file that represents the documentation of my plugin from inside a package, since I have opened a properties file the same way using getClass().getResource(URI).
I am trying the same with the PDF file, and I'm trying to get the URL of the file, then passing it to Desktop.browse() converted to URI, but it gives me a Malformed URI exception. Is there a way to do this easier and also to work?
This is my code so far:
try{
URL url = new URL(getClass().getResource("Documentation.pdf"), null);
Desktop.getDesktop().browse(url.toURI());
}catch(Exception exception){
Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, exception.getLocalizedMessage(), exception);
ErrorDialog.openError(null, "Error", "Error occured!", status);
}

The URL/URI you get back from getResource uses the bundleresource scheme which is not understood by many things.
For an Eclipse plugin you should use the FileLocator class.
Bundle bundle = FrameworkUtil.getBundle(getClass());
IPath path = new Path("path relative to root of the plugin");
URL url = FileLocator.find(bundle, path, null);
URL fileURL = FileLocator.toFileURL(url);
Desktop.getDesktop().browse(fileURL.toURI());
Again the URL returned by FileLocator.find uses a special scheme and is not understood by many things. FileLocator.toFileURL converts this URL to a normal file scheme - to do this it may be necessary to unpack the file from the plugin jar to a temporary location.
Note: Path is org.eclipse.core.runtime.Path

Related

How to download a pdf file using Flutter?

void getHttp() async
{
print("Got called");
var response = await Dio().download('https://www.google.com/', 'assets/xx.html');
print("DDDDD:");
print(response);
}
The directory assets is present with read and write permissions.
I am calling this on the press of a button. "Got called" DOES get printed.
There are no errors present, still "DDDDD" doesn't get printed.
The xx.html doesn't get saved.
Where am I going wrong?
Based on documentation the syntax for Dio to download a file is
var response = await Dio().download('https://www.google.com/', <<Destination directory from which your app is running. Like internal storage or external storage.>>);
I guess you are providing the file path which is associated with the projects assets directory where the file cannot be downloaded since it is bundled with the app.
Use the following package to access the device file system and provide that path to download your file.
var response = await Dio().download('https://www.google.com/', <<Path from internal storage.>>);

Flutter web download a pdf from API and save in directory

I build a flutter web app and My requirement is to get a file(PDF) and write it in file or download it,
i get my file from an API and it gave me a file not a link,
Can anyone help me with this. An example would be more helpful.
Thank you
Use this utility method:
import 'dart:html' as html;
void openDownloadLink(String href, String filename) {
html.document.createElement('a') as html.AnchorElement
..href = href
..download = filename
..dispatchEvent(html.Event.eventType('MouseEvent', 'click'));
}
Uri getHref() => Uri.parse(html.window.location.href);
The first parameter is the URL of the file to be downloaded, the second is the 'suggested' filename that the browser will show. Note that you can't put in a full path to the local file - the file name is just a suggestion.
The getHref function may be useful. It returns a Uri representing where the Flutter web app was launched from. If you want a path relative to that for your PDF, modify it, keeping the https://server... part the same. Equally, you could probably use a relative path as the href parameter, like ../pdfs/somefile

Play Swagger UI url alias

I have Swagger UI for API documentation, I use the same approach like in official specification for accessing it I use next URL:
http://localhost:9000/docs/swagger-ui/index.html?url=/assets/swagger.json
But I want to use http://localhost:9000/docs/ instead. I won't want to use WS for delegating, I would like to use single line in routes, like this:
GET /docs controllers.Assets.at(path:String="/public/lib/swagger-ui", file:String="index.html?url=/assets/swagger.json")
Or
GET /docs controllers.Assets.at(path:String="/public/lib/swagger-ui", file:String="index.html")
and http://localhost:9000/docs?url=/assets/swagger.json
What shold I change so it work?
You can't make shortness in route file for the URL /docs/swagger-ui/index.html?url=/assets/swagger.json because index.html is generated by swagger-ui plugin to public directory and requires access to files nearby (like js and css files). Play swagger-ui uses javascript for fetching json based description of your routes via URL parameter for further parsing this document to swagger-ui, in your case it's /assets/swagger.json endpoint.
I tried to make the mapping swagger's index.html file, so pass json location like URL parameter directly:
GET /swagger-ui controllers.Assets.at(path = "/public/lib/swagger-ui", file = "index.html")
Play couldn't render this page, and CSS wasn't found. I appended dummy mapping to every file in swagger's default directory /public/lib/swagger-ui:
GET /*file controllers.Assets.at(path = "/public/lib/swagger-ui", file)
Even after that Play couldn't properly render index.html.
How it can be solved without Play-Swagger:
Create directory public\swagger in your project;
Download all files from https://github.com/swagger-api/swagger-ui/tree/master/dist and copy them to public\swagger;
Copy your swagger.json (it's specification, right?) to public\specification;
Add to your routes file next line:
GET /docs
controllers.Assets.versioned(path="/public/specification", file: Asset
= "swagger.json")

How to mkdirs on gwt when fileupload on client

i mode development in eclipse. the fileupload works just fine. but i will make directory to /var/wms/year/month/file.jpg on linux. this my source code from client:
add component to form
fileUpload = new SingleUploader(FileInputType.LABEL);
fileUpload.setFileInputPrefix("PJ");
fileUpload.addOnFinishUploadHandler(onFinishUploaderHandler);
layoutContainerItemRight.add(fileUpload, formData);
method is addOnFinishUploadHandler
private IUploader.OnFinishUploaderHandler onFinishUploaderHandler = new IUploader.OnFinishUploaderHandler() {
public void onFinish(IUploader uploader) {
if (uploader.getStatus() == gwtupload.client.IUploadStatus.Status.SUBMITING) {
String month = VisionProperties.getBulan();
String year = DateTimeFormat.getFormat( "d-M-yyyy" ).format( new Date() ).split( "-")[2];
String strDirectoy = "/var/wms/" + year + "/" + month + "/";
File file = new File(strDirectoy);
if (!file.exists()) {
file.mkdirs();
}
}
if (uploader.getStatus() == gwtupload.client.IUploadStatus.Status.SUCCESS) {
String msg = uploader.getServerInfo().message;
fileName = msg.toString();
if(selectWindow != 2){
img.setUrl("servlet.gupld?show=&fieldname=" + fileName);
itemPanel.render(img.getElement());
}else{
tb.setVisible(true);
tb.setText("Download File "+uploader.getFileName());
}
}
}
};
how to make directory file when upload file process?
You are trying to use to use java.io.File in the client side which is not supported by the set of packages in the GWT jre emulation.
If you want to do this in client side you have to use the javascript File Api which is not supported by old browsers, and is not implemented in gwt-core. Using elemental you could use the Api only with Chrome, but I'm not positive. So it is better to wrap it via jsni, it is planned in gwtupload, but there is no a timeframe yet. Be aware that using js File Api, you dont have access to your real filesystem, but a virtual one inside your browser. To save created files in the local filesystem you have to download it using and iframe so as it asks the user where to save it.
Otherwise, If you wanted to do this work at server side, do it overriding the executeAction in your servlet if you are extending UploadAction.
You cannot do this on client side. You can perform this on server side in the following ways
before you upload the files to server by another rpc/http call.
after you upload the files to server when the file upload servlet is being executed on the srever side.
HTML5 FILE API are restricted to readonly behavior in even modern browser.
Reference -
1. Basic File upload in GWT
2. How to retrieve file from GWT FileUpload component?

how can I check for an existing web folder

I work as software tester entry level and I was given a task to save my log files to the specific folder on my company website and this website only can be accessed internally by the company employees. So far I know how to save file onto the site, but how would I check which specific folder is already there before I save the file to it?
private void SaveLogsTogWeb(string file)
{
try
{
//create WebClient object
WebClient client = new WebClient();
client.Credentials = CredentialCache.DefaultCredentials;
client.UploadFile(#"http://myCompnay/MyProjects/TestLogs/" + file, "PUT", file);
client.Dispose();
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
Thanks in advance for the helps
Use this code:
if(!Directory.Exists({path}))
{
//create the directory
}
It checks to see if the directory doesn't exist. And if it doesn't then you can create it!
One way would be to put a dummy file in that folder (dummy.txt) and do an HTTP GET of the file. If you can successfully do that, you can then assume the folder exists (barring any virtual folders, etc.)