how to load html files within the application in javafx - webview

i am using jdk1.7.0_45 for building javafx project,loads pre created html site from my application,found passing this url file:///E:/web/index.html
but which is not my requirement,need to load from my app,so please tell me anyone,the folder name need to place in javafx app.
thanks

I'm assuming that the question is that you want to package a static HTML file with your application and display it in a WebView.
You can do it with code like this (Scala syntax but the meaning should be clear):
val url = getClass getResource "index.html"
webView.getEngine load url.toString
In this example, the index.html file (and any related content) must reside in the same package as the class of the code. E.g. if the class is mypackage.myapp.MyApp, the file must be in the mypackage.myapp package.
If your build system provides an e.g. resources folder, it would be good practice to use that for static content such as this. I.e., for this example, create a package mypackage.myapp in the resources folder and place the html file there.

Related

How can I reference a script that is in my pages directory?

I'm trying to keep a good practice of keeping context together and in that regard, I like how Razor Pages forces you to place your view models next to its view. I'd like to do this with script files as well.
For example, if script is a bit large and is only used on this particular page, it may not be the cleanest thing to have it in a render section in the cshtml. Instead, I'd want to place it into its own .js file. But to keep the project easy to navigate for team members, I'd like to place that .js file in the same folder next to its view and view model. I'm not sure how to link that file, or if I even can. If I give src a path to the file, it is not found. Assuming that's because wwwroot is the only folder setup to host static files.
Suggestions?
You can add an option to the StaticFilesProvider in your Configure method:
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(),"Pages")), RequestPath="/Pages"
});
See the documentation on Static Files in ASP.NET Core: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-2.1

Generate URL of resources that are handled by Grails AssetPipeline

I need to access a local JSON file. Since Grails 2.4 implements the AssetPipeline plugin by default, I saved my local JSON file at:
/grails-app/assets/javascript/vendor/me/json/local.json
Now what I need is to generate a URL to this JSON file, to be used as a function parameter on my JavaScript's $.getJSON() . I've tried using:
var URL.local = ""${ raw(asset.assetPath(src: "local.json")) }";
but it generates an invalid link:
console.log(URL.local);
// prints /project/assets/local.json
// instead of /project/assets/vendor/me/json/local.json
I also encountered the same scenario with images that are handled by AssetPipeline1.9.9— that are supposed to be inserted dynamically on the page. How can I generate the URL pointing this resource? I know, I can always provide a static String for the URL, but it seems there would be a more proper solution.
EDIT
I was asked if I could move the local JSON file directly under the assets/javascript root directory instead of placing it under a subdirectory to for an easier solution. I prefer not to, for organization purposes.
Have you tried asset.assetPath(src: "/me/json/local.json")
The assets plugin looks in all of the immediate children of assets/. Your local.json file would need to be placed in /project/assets/foo/ for your current code to pick it up.
Check out the relevant documentation here which contains an example.
The first level deep within the assets folder is simply used for organization purposes and can contain folders of any name you wish. File types also don't need to be in any specific folder. These folders are omitted from the URL mappings and relative path calculations.

How to reference a JavaScript file in Lib from an HTML file in Data?

I decided to give Mozilla's Add-on Builder a try. My directory structure looks something like this:
The problem is that the file popup.html needs to reference stackapi.js. But I have absolutely no clue how to do that. Looking through the Mozilla docs, there seems to be a way to do the opposite:
var data = require("self").data;
var url_of_popup = data.url("popup.html");
This allows scripts in Lib to access data files in Data. But I need to do the opposite.
In add-ons built with the Add-on SDK (and the Builder is merely a web interface for the SDK) web pages cannot access extension modules directly - they don't have the necessary privileges. If you simply need to include a JavaScript file from the web page then you should put that file into the data directory. However, it won't have any special privileges then (like being able to call require()).
You don't tell how you are using popup.html but I guess that it is a panel. If you want that page to communicate with your add-on you need to use content scripts. Put a content script file into the data directory, assign it to your panel via contentScriptFile parameter. See documentation on content scripts, the content script will be able to use self.postMessage() to send messages to the extension, the extension can perform the necessary operations and send a message back then.
You can get the url of the stackapi.js file by navigating up from the /data folder and back down the /lib folder like so:
var url=require("sdk/self").data.url("../lib/stackapi.js");
Then use that resource url in the contentScriptFile parameter when attaching scripts to what I assume is going to be popup.html.
You'll need to check which environment you're currently in to determine if you need to add any references to the exports object to make them accessible from within the addon.
if(typeof(exports)!="undefined"){
exports.something=function(){...};
}
Had to go through the same scenario, but solution by jongo45 does not seem to work anymore. Somehow found a solution which worked for me. Posting below as it might help someone in need.
Below code obtains list of all files under "lib/subdir".
const fileIO = require("sdk/io/file");
const fspath = require("sdk/fs/path");
const {Cc, Ci} = require("chrome");
const currDir = Cc["#mozilla.org/file/directory_service;1"]
.getService(Ci.nsIDirectoryServiceProvider)
.getFile("CurWorkD", {}).path;
const listOfFiles = fileIO.list(fspath.resolve(currDir,'lib/subdir'));

How to get static URL Links in GWT for different pages

I want to build a multi page website and I need a way to refer to another GWT page (panel) how can I do it such that the links are static?
There are three issues in your questions:
how to specify the url of a gwt page.
how to ensure that url is static.
how to create a link to that gwt page from another gwt page.
A GWT url is effected by the module name and package namespace and can be modified by the rename-to attribute. Say, the GWT module description file is named whatever.gwt.xml; and whatever module is placed at package namespace zoom.wonderful.world . The url of the module would be http ://hostnamespace:port/zoom.wonderful.world.whatever. But you can use the rename-to attribute to change it , the url would be http ://hostnamespace:port/holycow.
But ... your module is not accessible by url unless you have an entrypoint - i.e. a gwt java file that implements EntryPoint.
You can have more than one entry point in a module, but under most circumstances my opinion says that you should not unless you wish to begin a career into the most confusgated GWT code contest. The ui representations of all the entry points in a module would overlap. A similar confusgating overlap effect is available if you inherit an entry point.
Behind my mind, I keep asking why you deliberately ask "static url", because the url of the entry point of a module is indeed static.
Then in your other "gwt page", you merely include list the "static urls" of all the "gwt pages" either
- in the hosting html file (which launches the module javascript-compiled files)
- or, within a gwt widget that allows url links or html code to be included.
http://h2g2java.blessedgeek.com/2011/02/uibinder-check-list.html

Actionscript - combining AS2 assets into a single SWF

I have a flash project that I'm trying to export as a single SWF. There's a main SWF file that loads about 6 other SWFs, and both the main and the child SWFs reference other external assets (images, sounds, etc). I'd like to package everything as a single .swf file so I don't have to tote the other assets around with the .swf.
All the coding is done in the timeline, but the assets haven't been imported into the Flash Authoring environment and I don't have time to do that right now (there are too many references to them everywhere). I'm hoping that there's just an option I'm missing that allows this sort of packaged export, but I haven't found anything like that.
I don't have access to Flex or mxmlc (and as the AS is timeline-based, they wouldn't necessarily help me). Any thoughts?
Thanks!
PS...if there's no way of doing exactly what I'm saying, I could deal with having all the assets in a "assets" folder or something like that, so I'd just be toting around main.swf and an assets folder. The problem here is that all the references to the assets assume that they're in the same folder as the main.swf file, so everything's assumed to be local...is there a way to change the scope of all external references in Flash (so, for example, all local references in the code are actually searched in /assets)?
You might be able to decompile your swfs into XML with swfmill/mtasc and use a fancy XSLT to recombine them and recompile with swfmill/mtasc.
If that doesn't work and if you're using MovieClip.loadMovie or MovieClipLoader.loadMovie you can overload their methods and intercept the url:
var realLoadMovie:Function = MovieClip.prototype.loadMovie;
MovieClip.prototype.loadMovie = function(url:String, method:String) {
return realLoadMovie("assets/" + url, method);
}
var test:MovieClip = createEmptyMovieClip("testclip", getNextHighestDepth());
test.loadMovie("test.swf");
You'll need to do some additional string parsing if the urls have a resource-type prefix such as file://
There's a base parameter you can add when you embed the swf, just like align, scale, etc. If base is set, all relative urls will be prefixed with whatever path you define (well, almost all; videos and file reference objects being the exception here).
Other than that, I'd go with nikaji's solution.
HI Justin,
It sounds like you need to look into using shared libraries. Check out:
http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_14767

Resources