java - Having a static "sub-site" in Wicket (i.e.: mounting a directory in Wicket) -


i'm developing web application using wicket.

while of website dynamically generated through wicket, need have portion of site normal "static" html website. small "subsite" inside main website not managed wicket @ all, that, instead, collection of static content (html pages, css, images).

can done? idea "mount" subpath point sub-site, don't know if possible, mountresource() method wants resource input.

edit: need solution allow me modify static html files directly on filesystem, reason trying "mount directory" via wicket. cannot put pages in webapp folder, since way end inside app's war file , every modification static pages need full deploy every time.

any ideas?

well, implementet myself in end, using dynamic resource. i'm not expert of wicket, may "bad" solution reason, seems work. posting code here other people can use if want:

what did create resource:

public class directoryresolverresource implements iresource {     private static final long serialversionuid = 1l;      private file serveddirectory;     private string urlprefix;      //served directory directory want mount static sub-site     //urlprefix mountpoint you're going mount resource, without leading "/". e.g.: if mount directory in "/help" sub-site url www.yoursite.com/pages/help urlprefix value must "help"     public directoryresolverresource(file serveddirectory, string urlprefix) {         super();         if (serveddirectory == null || !serveddirectory.isdirectory()) {             throw new illegalargumentexception("directory null or doesn't exist");         }         this.serveddirectory = serveddirectory;         this.urlprefix = urlprefix;     }      @override     public void respond(attributes attributes) {         url url = attributes.getrequest().geturl();         string subpath = "";         try {             //we decode url reversing percent-encoding, filenames resolved             subpath = urldecoder.decode(url.tostring(), "utf-8");         } catch (unsupportedencodingexception e) {             throw new abortwithhttperrorcodeexception(httpservletresponse.sc_bad_request, "encoding invalid");         }          if (subpath.startswith(urlprefix)) {             subpath = subpath.substring(urlprefix.length());         } else {             throw new abortwithhttperrorcodeexception(httpservletresponse.sc_internal_server_error, "url invalid");         }          file file = new file(serveddirectory.getabsolutepath() + (subpath.startswith("/") ? "" : "/") + subpath);         if (file.isdirectory()) {             // in case of directory, redirect path ending in "/", otherwise browsers fail resolve relative paths in page             if (!subpath.endswith("/")) {                 throw new redirecttourlexception("." + (subpath.isempty() ? "/" + urlprefix : subpath) + "/", httpservletresponse.sc_moved_permanently);             }             // no specific file specified, try return index.html             file = new file(file.getabsolutepath(), "index.html");         }         if (!file.exists() || file.isdirectory()) {             // file not found             throw new abortwithhttperrorcodeexception(httpservletresponse.sc_not_found, "resource not found");         }          if (!fsmanager.isinsubdirectory(serveddirectory, file)) {             // security check: user trying escape served directory via non-canonical path             throw new abortwithhttperrorcodeexception(httpservletresponse.sc_forbidden, "access resource forbidden");         }          // serve file         fileresourcestream fileresourcestream = new fileresourcestream(file);         resourcestreamresource resource = new resourcestreamresource(fileresourcestream);         resource.respond(attributes);     }  } 

you can mount resource this:

mountresource("/help", new resourcereference("helpres") {                 private static final long serialversionuid = 1l;                  @override                 public iresource getresource() {                     return new directoryresolverresource(helpdir, "help");                 }             }); 

hope helpful someone. improvements/comments/corrections/constructive criticisms higly appreciated!

note: isinsubdirectory() method checks if file inside directory tree. won't bore details, can find implementations of such method here: check if file in (sub)directory


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -