@Override public synchronized void start() throws Exception { // restlet servlet engine will pass parameters from web.xml via the context parameters Series<Parameter> parameters = getContext().getParameters(); dataSource = PSCPDataSource.createDataSource(parameters); daoFactory = PGDaoFactory.createPGDaoFactory(dataSource); lookupCache = new LookupCache(daoFactory); secretResolver = new SecretResolver(); adminPage = parameters.getFirstValue("pscp.web.admin"); urls = new URLS(adminPage); // links out to website urls.putStatic( new Template(getSlashedURL(parameters, "pscp.web.products")), URLS.Name.PRODUCT_LOCATION); urls.putStatic( new Template(getSlashedURL(parameters, "pscp.web.root")), URLS.Name.STATIC_MEDIA); // @todo how to deal with this? baseURIs = new ArrayList<String>(Arrays.asList("localhost:8080")); Map<String, Object> contextAttributes = getContext().getAttributes(); contextAttributes.put(BaseResource.CONTEXT_ATTRIBUTE_DAO_FACTORY, daoFactory); contextAttributes.put(BaseResource.CONTEXT_ATTRIBUTE_URL_MAPPER, urls); contextAttributes.put(BaseResource.CONTEXT_ATTRIBUTE_LOOKUP_CACHE, lookupCache); contextAttributes.put( BaseResource.CONTEXT_ATTRIBUTE_PRODUCT_ROOT, getRootDir(BaseResource.CONTEXT_ATTRIBUTE_PRODUCT_ROOT, "pscp-products")); contextAttributes.put( BaseResource.CONTEXT_ATTRIBUTE_UPLOAD_ROOT, getRootDir(BaseResource.CONTEXT_ATTRIBUTE_UPLOAD_ROOT, "pscp-uploads")); super.start(); }
@Override public Restlet createRoot() { Router root = new Router(getContext()); root.setDefaultMatchingMode(Router.BEST); root.setDefaultMatchQuery(false); RouterBuilder routes = new RouterBuilder(root); RootDirectory rootDirectory = new RootDirectory(root); root.attach("", guard(rootDirectory)).setMatchingMode(Template.MODE_EQUALS); root.attach("/", guard(rootDirectory)).setMatchingMode(Template.MODE_EQUALS); // root.attach("", new RootDirectory(root)).getTemplate().setMatchingMode(Template.MODE_EQUALS); // root.attach("/", new // RootDirectory(root)).getTemplate().setMatchingMode(Template.MODE_EQUALS); routes.addPage("", DirectoryService.class, null, false); routes.addPage("/contacts/form/{id}", ContactForm.class, URLS.Name.CONTACT_FORM); routes.addPage("/contacts/form/", ContactForm.class); routes.addPage("/contacts", ContactService.class, URLS.Name.CONTACT); routes.add("/library", LibraryResource.class); routes.addPage("/library/", LibraryResource.class); routes.addPage("/library/upload", CitationUploadForm.class); routes.addPage("/library/{id}", CitationFileForm.class); routes .add("/productpage/{id}", ProductPageService.class) .getTemplate() .getDefaultVariable() .setType(Variable.TYPE_ALL); routes.addPage( "/products/revisions/form/{id}/{rev}", ProductRevisionForm.class, URLS.Name.PRODUCT_REVISIONS_FORM); routes.addPage("/products/revisions/form/{id}/", ProductRevisionForm.class); routes.addPage( "/products/revisions/{id}/{rev}", ProductRevisionService.class, URLS.Name.PRODUCT_REVISIONS); routes.addPage("/products/revisions/{id}/", ProductRevisionService.class); routes.addPage("/products/form/{id}", ProductForm.class, URLS.Name.PRODUCT_FORM); routes.addPage("/products/form/", ProductForm.class); routes.addPage("/products/upload", ProductUploadForm.class); routes.add("/products", ProductService.class, URLS.Name.PRODUCT); routes.add( "/productnames/ac", AutoCompleteResource.ProductName.class, URLS.Name.AC_PRODUCT_NAME); routes.add("/producttypes", ProductTypeService.class); routes.add( "/producttypes/ac", AutoCompleteResource.ProductType.class, URLS.Name.AC_PRODUCT_TYPE); root.attach("/producttypes/{id}", ProductTypeService.class); routes.add("/stations", StationService.class); routes.add("/stations/ac", AutoCompleteResource.Station.class, URLS.Name.AC_STATION); routes.add( "/stations/types/ac", AutoCompleteResource.StationType.class, URLS.Name.AC_STATION_TYPE); routes.add("/stations/locations", StationLocationService.class); routes.add("/stations/overview", StationOverviewService.class); // @see ext comment in BaseResource routes.add("/stations/locations.{ext}", StationLocationService.class); routes.add("/stations/page/{id}", StationPageService.class, URLS.Name.STATION_PAGE); routes.addPage("/stations/upload", StationUploadForm.class); routes.add("/stations/all/products", ProductLinkService.class); routes.add("/stations/{id}/products", ProductLinkService.class, URLS.Name.PRODUCT_LINK); routes.add("/stations/{id}", StationService.class, URLS.Name.STATION); routes.add("/stations/", StationService.class); routes.addPage("/stations/form/{id}", StationForm.class, URLS.Name.STATION_FORM); routes.addPage("/stations/form/", StationForm.class); routes.addPage("/batches", BatchMonitorResource.class); routes.add("/nations/ac", AutoCompleteResource.Nation.class, URLS.Name.AC_NATIONS); routes.add("/regions/ac", AutoCompleteResource.Region.class); root.attach("/admin/debug", guard(new DebugRestlet())); root.attach( "/admin/refresh", guard( new Restlet() { public static final String PSCP_DESCRIPTION = "Refresh internal DB and Modified-Since caches"; @Override public void handle(Request request, Response response) { getLogger().info("Refresh issued"); lookupCache.refreshAll(); ModifiedCache.clear(); response.setEntity("Refresh Complete", MediaType.TEXT_HTML); } })); root.attach( "/login", guard( new Restlet() { public static final String PSCP_DESCRIPTION = "Provide Login Features"; @Override public void handle(Request request, Response response) { if (request.getChallengeResponse() != null) { Reference referrer = request.getReferrerRef(); String ret = request.getOriginalRef().getQueryAsForm().getFirstValue("ret"); if (ret != null) { response.redirectSeeOther(ret); } else if (referrer != null) { response.redirectSeeOther(referrer); } } } })); urls.put( root.attach( "/logout", new Restlet() { public static final String PSCP_DESCRIPTION = "Provide Logout Features"; @Override public void handle(Request request, Response response) { if (request.getChallengeResponse() != null) { String userName = request.getChallengeResponse().getParameters().getFirstValue("username"); if ("logout".equals(userName)) { response.setStatus(Status.SUCCESS_OK); response.setEntity("Logged Out", MediaType.ALL); CookieSetting cookie = new CookieSetting("u", ""); cookie.setPath("/"); response.getCookieSettings().add(cookie); response.redirectSeeOther(urls.getURL(URLS.Name.STATIC_MEDIA)); } else { response.setStatus(Status.SUCCESS_OK); response.setEntity("Logged Out", MediaType.ALL); CookieSetting cookie = new CookieSetting("u", ""); cookie.setPath("/"); response.getCookieSettings().add(cookie); } } else { ChallengeRequest cr = new ChallengeRequest(ChallengeScheme.HTTP_DIGEST, "PSCP"); response.setChallengeRequest(cr); response.setStatus(Status.CLIENT_ERROR_UNAUTHORIZED); } } }) .getTemplate(), URLS.Name.LOGOUT); return new HeaderFilter(getContext(), root); }
public Javascript() { LangName = "Javascript"; CommentSingle = new HashMap<Integer, String>(); CommentSingle.put(1, "//"); CommentMulti = new HashMap<String, String>(); CommentMulti.put("/*", "*/"); CommentRegexp = new HashMap<Integer, String>(); CommentRegexp.put( 2, "(?i)(?<=[\\s^])s\\/(?:\\\\.|[^\\/\\\\])+\\/(?:\\\\.|[^\\/\\\\])+\\/[gimsu]*(?=[\\s$\\.\\;])|(?<=[\\s^(=])m?\\/(?:\\\\.|[^\\/\\\\])+\\/[gimsu]*(?=[\\s$\\.\\,\\;\\)])"); CaseKeywords = Global.GESHI_CAPS_NO_CHANGE; Quotemarks = new ArrayList<String>(); Quotemarks.add("\'"); Quotemarks.add("\""); EscapeChar = '\\'; Keywords = new HashMap<Integer, ArrayList<String>>(); ArrayList<String> KeyStrList1 = new ArrayList<String>(); KeyStrList1.add("as"); KeyStrList1.add("break"); KeyStrList1.add("case"); KeyStrList1.add("catch"); KeyStrList1.add("continue"); KeyStrList1.add("decodeURI"); KeyStrList1.add("delete"); KeyStrList1.add("do"); KeyStrList1.add("else"); KeyStrList1.add("encodeURI"); KeyStrList1.add("eval"); KeyStrList1.add("finally"); KeyStrList1.add("for"); KeyStrList1.add("if"); KeyStrList1.add("in"); KeyStrList1.add("is"); KeyStrList1.add("item"); KeyStrList1.add("instanceof"); KeyStrList1.add("return"); KeyStrList1.add("switch"); KeyStrList1.add("this"); KeyStrList1.add("throw"); KeyStrList1.add("try"); KeyStrList1.add("typeof"); KeyStrList1.add("void"); KeyStrList1.add("while"); KeyStrList1.add("write"); KeyStrList1.add("with"); Keywords.put(1, KeyStrList1); ArrayList<String> KeyStrList2 = new ArrayList<String>(); KeyStrList2.add("class"); KeyStrList2.add("const"); KeyStrList2.add("default"); KeyStrList2.add("debugger"); KeyStrList2.add("export"); KeyStrList2.add("extends"); KeyStrList2.add("false"); KeyStrList2.add("function"); KeyStrList2.add("import"); KeyStrList2.add("namespace"); KeyStrList2.add("new"); KeyStrList2.add("null"); KeyStrList2.add("package"); KeyStrList2.add("private"); KeyStrList2.add("protected"); KeyStrList2.add("public"); KeyStrList2.add("super"); KeyStrList2.add("true"); KeyStrList2.add("use"); KeyStrList2.add("var"); Keywords.put(2, KeyStrList2); ArrayList<String> KeyStrList3 = new ArrayList<String>(); KeyStrList3.add("alert"); KeyStrList3.add("back"); KeyStrList3.add("blur"); KeyStrList3.add("close"); KeyStrList3.add("confirm"); KeyStrList3.add("focus"); KeyStrList3.add("forward"); KeyStrList3.add("home"); KeyStrList3.add("name"); KeyStrList3.add("navigate"); KeyStrList3.add("onblur"); KeyStrList3.add("onerror"); KeyStrList3.add("onfocus"); KeyStrList3.add("onload"); KeyStrList3.add("onmove"); KeyStrList3.add("onresize"); KeyStrList3.add("onunload"); KeyStrList3.add("open"); KeyStrList3.add("print"); KeyStrList3.add("prompt"); KeyStrList3.add("scroll"); KeyStrList3.add("status"); KeyStrList3.add("stop"); Keywords.put(3, KeyStrList3); Symbols = new HashMap<Integer, ArrayList<String>>(); ArrayList<String> SymStrList = new ArrayList<String>(); SymStrList.add("("); SymStrList.add(")"); SymStrList.add("["); SymStrList.add("]"); SymStrList.add("{"); SymStrList.add("}"); SymStrList.add("+"); SymStrList.add("-"); SymStrList.add("*"); SymStrList.add("/"); SymStrList.add("%"); SymStrList.add("!"); SymStrList.add("@"); SymStrList.add("&"); SymStrList.add("|"); SymStrList.add("^"); SymStrList.add("<"); SymStrList.add(">"); SymStrList.add("="); SymStrList.add(","); SymStrList.add(";"); SymStrList.add("?"); SymStrList.add(":"); Symbols.put(Global.JASHI_STUBINDEX, SymStrList); CaseSensitive = new HashMap<Integer, Boolean>(); CaseSensitive.put(Global.GESHI_COMMENTS, false); CaseSensitive.put(1, false); CaseSensitive.put(2, false); CaseSensitive.put(3, false); Styles.Keywords.put(1, "color:#000066;font-weight:bold;"); Styles.Keywords.put(2, "color:#003366;font-weight:bold;"); Styles.Keywords.put(3, "color:#000066;"); Styles.Comments.put(1, "color:#006600;font-style:italic;"); Styles.Comments.put(2, "color:#009966;font-style:italic;"); Styles.Comments.put(Global.MULTI, "color:#006600;font-style:italic;"); Styles.EscapeChar.put(0, "color:#000099;font-weight:bold;"); Styles.Brackets.put(0, "color:#009900;"); Styles.Strings.put(0, "color:#3366CC;"); Styles.Numbers.put(0, "color:#CC0000;"); Styles.Methods.put(1, "color:#006600;"); Styles.Symbols.put(0, "color:#339933;"); Styles.Script.put(0, ""); Styles.Script.put(1, ""); Styles.Script.put(2, ""); Styles.Script.put(3, ""); URLS = new HashMap<Integer, String>(); URLS.put(1, ""); URLS.put(2, ""); URLS.put(3, ""); OOLANG = true; ObjectSplitters = new HashMap<Integer, String>(); ObjectSplitters.put(1, "."); Regexps = new HashMap<Integer, HashMap<Integer, String>>(); StrictModeApplies = Global.GESHI_MAYBE; ScriptDelimiters = new HashMap<Integer, HashMap<String, String>>(); HashMap<String, String> DelStrMap0 = new HashMap<String, String>(); DelStrMap0.put("<scripttype=\"text/javascript\">", "</script>"); ScriptDelimiters.put(0, DelStrMap0); HashMap<String, String> DelStrMap1 = new HashMap<String, String>(); DelStrMap1.put("<scriptlanguage=\"javascript\">", "</script>"); ScriptDelimiters.put(1, DelStrMap1); HighlightStrictBlock = new HashMap<Integer, Boolean>(); HighlightStrictBlock.put(0, true); HighlightStrictBlock.put(1, true); }