public CacheFile findFilePath(CommonPath path, boolean isPreview) { // figure out which section we are looking in String sect = "www"; if ("files".equals(path.getName(0)) || "galleries".equals(path.getName(0))) { sect = path.getName(0); path = path.subpath(1); } if (Logger.isDebug()) Logger.debug("find file path: " + path + " in " + sect); // ===================================================== // if request has an extension do specific file lookup // ===================================================== // if we have an extension then we don't have to do the search below // never go up a level past a file (or folder) with an extension if (path.hasFileExtension()) return this.findSectionFile(sect, path.toString(), isPreview); // ===================================================== // if request does not have an extension look for files // that might match this path or one of its parents // using the special extensions // ===================================================== if (Logger.isDebug()) Logger.debug("find file path dyn: " + path + " in " + sect); // we get here if we have no extension - thus we need to look for path match with specials int pdepth = path.getNameCount(); // check file system while (pdepth > 0) { CommonPath ppath = path.subpath(0, pdepth); for (String ext : this.domain.getSpecialExtensions()) { CacheFile cfile = this.findSectionFile(sect, ppath.toString() + ext, isPreview); if (cfile != null) return cfile; } pdepth--; } OperationContext.get().errorTr(150007); return null; }
public IOutputAdapter findFile(CommonPath path, boolean isPreview) { // ===================================================== // if request has an extension do specific file lookup // ===================================================== if (Logger.isDebug()) Logger.debug("find file before ext check: " + path + " - " + isPreview); // if we have an extension then we don't have to do the search below // never go up a level past a file (or folder) with an extension if (path.hasFileExtension()) { CacheFile wpath = this.findFilePath(path, isPreview); if (wpath != null) return this.pathToAdapter(isPreview, path, wpath); // TODO not found file!! OperationContext.get().errorTr(150007); return null; } // ===================================================== // if request does not have an extension look for files // that might match this path or one of its parents // using the special extensions // ===================================================== if (Logger.isDebug()) Logger.debug("find file before dyn check: " + path + " - " + isPreview); // we get here if we have no extension - thus we need to look for path match with specials int pdepth = path.getNameCount(); // check path maps first - hopefully the request has been mapped at one of the levels while (pdepth > 0) { CommonPath ppath = path.subpath(0, pdepth); if (isPreview) { IOutputAdapter ioa = this.dynpreviewcache.get(ppath.toString()); if (ioa != null) return ioa; } IOutputAdapter ioa = this.dyncache.get(ppath.toString()); if (ioa != null) return ioa; pdepth--; } if (Logger.isDebug()) Logger.debug("find file not cached: " + path + " - " + isPreview); // if not in dyncache then look on file system CacheFile wpath = this.findFilePath(path, isPreview); if (wpath == null) { OperationContext.get().errorTr(150007); return null; } if (Logger.isDebug()) Logger.debug("find file path: " + wpath + " - " + path + " - " + isPreview); return this.pathToAdapter(isPreview, path, wpath); }
public Cookie resolveLocale(HttpContext context, UserContext usr, OperationContextBuilder ctxb) { if (this.locales.size() == 0) { // make sure we have at least 1 locale listed for the site String lvalue = this.getDefaultLocale(); // add the list of locales supported for this site this.locales.put(lvalue, this.getLocaleDefinition(lvalue)); } LocaleDefinition locale = null; // see if the path indicates a language CommonPath path = context.getRequest().getPath(); if (path.getNameCount() > 0) { String lvalue = path.getName(0); locale = this.locales.get(lvalue); // extract the language from the path if (locale != null) context.getRequest().setPath(path.subpath(1)); } // but respect the cookie if it matches something though Cookie langcookie = context.getRequest().getCookie("dcLang"); if (locale == null) { if (langcookie != null) { String lvalue = langcookie.value(); // if everything checks out set the op locale and done if (this.locales.containsKey(lvalue)) { ctxb.withOperatingLocale(lvalue); return null; } locale = this.getLocaleDefinition(lvalue); // use language if variant - still ok and done if (locale.hasVariant()) { if (this.locales.containsKey(locale.getLanguage())) { ctxb.withOperatingLocale( lvalue); // keep the variant part, it may be used in places on site - supporting a // lang implicitly allows all variants return null; } } // otherwise ignore the cookie, will replace it } } // see if the domain is set for a specific language if (locale == null) { String domain = context.getRequest().getHeader("Host"); if (domain.indexOf(':') > -1) domain = domain.substring(0, domain.indexOf(':')); locale = this.domainlocales.get(domain); } // see if the user has a preference if (locale == null) { String lvalue = usr.getLocale(); if (StringUtil.isNotEmpty(lvalue)) locale = this.locales.get(lvalue); } // if we find any locale at all then to see if it is the default // if not use it, else use the default if ((locale != null) && !locale.equals(this.getDefaultLocaleDefinition())) { ctxb.withOperatingLocale(locale.getName()); return new DefaultCookie("dcLang", locale.getName()); } // clear the cookie if we are to use default locale if (langcookie != null) return new DefaultCookie("dcLang", ""); // we are using default locale, nothing more to do return null; }