return;
}
/*
* Getting host object form the session
*/
Host host;
try {
host = whostAPI.getCurrentHost(request);
} catch (Exception e) {
Logger.warn(this, "Unable to retrieve current request host for URI " + uri);
throw new ServletException(e.getMessage(), e);
}
// http://jira.dotmarketing.net/browse/DOTCMS-6079
if (uri.endsWith("/"))
uri = uri.substring(0, uri.length() - 1);
String pointer = null;
if(host!=null){
pointer = VirtualLinksCache.getPathFromCache(host.getHostname() + ":" + uri);
}
if (!UtilMethods.isSet(pointer)) {
pointer = VirtualLinksCache.getPathFromCache(uri);
}
if(UtilMethods.isSet(pointer)){
uri = pointer;
}
String mastRegEx = null;
StringBuilder query = null;
try {
mastRegEx = StructureCache.getURLMasterPattern();
} catch (DotCacheException e2) {
Logger.error(URLMapFilter.class, e2.getMessage(), e2);
}
if (mastRegEx == null) {
synchronized (StructureCache.MASTER_STRUCTURE) {
try {
mastRegEx = buildCacheObjects();
} catch (DotDataException e) {
Logger.error(URLMapFilter.class, e.getMessage(), e);
throw new ServletException("Unable to build URLMap patterns", e);
}
}
}
boolean trailSlash = uri.endsWith("/");
boolean isDotPage = uri.substring(uri.lastIndexOf(".")+1).equals(Config.getStringProperty("VELOCITY_PAGE_EXTENSION"));
String url = (!trailSlash && !isDotPage)?uri+'/':uri;
if (!UtilMethods.isSet(mastRegEx) || uri.startsWith("/webdav")) {
chain.doFilter(req, res);
return;
}
if (RegEX.contains(url, mastRegEx)) {
boolean ADMIN_MODE = (session.getAttribute(com.dotmarketing.util.WebKeys.ADMIN_MODE_SESSION) != null);
boolean EDIT_MODE = ((session.getAttribute(com.dotmarketing.util.WebKeys.EDIT_MODE_SESSION) != null) && ADMIN_MODE);
Structure structure = null;
User user = null;
try {
user = wuserAPI.getLoggedInUser(request);
} catch (Exception e1) {
Logger.error(URLMapFilter.class, e1.getMessage(), e1);
}
List<ContentletSearch> cons = null;
Collections.sort(patternsCache, new Comparator<PatternCache>(){
public int compare(PatternCache o1, PatternCache o2) {
String regex1 = o1.getRegEx();
String regex2 = o2.getRegEx();
if(!regex1.endsWith("/")){
regex1+="/";
}
if(!regex2.endsWith("/")){
regex2+="/";
}
int regExLength1 = getSlashCount(regex1);
int regExLength2 = getSlashCount(regex2);
if(regExLength1 < regExLength2){
return 1;
}else if(regExLength1 > regExLength2){
return -1;
}else{
return 0;
}
}
});
for (PatternCache pc : patternsCache) {
List<RegExMatch> matches = RegEX.findForUrlMap(url, pc.getRegEx());
if (matches != null && matches.size() > 0) {
query = new StringBuilder();
List<RegExMatch> groups = matches.get(0).getGroups();
List<String> fieldMatches = pc.getFieldMatches();
structure = StructureCache.getStructureByInode(pc.getStructureInode());
List<Field> fields = FieldsCache.getFieldsByStructureInode(structure.getInode());
query.append("+structureName:").append(structure.getVelocityVarName()).append(" +deleted:false ");
if (EDIT_MODE || ADMIN_MODE) {
query.append("+working:true ");
} else {
query.append("+live:true ");
}
// Set Host Stuff
boolean hasHostField = false;
Boolean hostIsRequired = false;
for (Field field : fields) {
if (field.getFieldType().equals(Field.FieldType.HOST_OR_FOLDER.toString())) {
hasHostField = true;
if (field.isRequired()) {
hostIsRequired = true;
}
break;
}
}
if (hasHostField) {
if (host != null) {
//if (hostIsRequired) {
//query.append("+conhost:" + host.getIdentifier() + " ");
//} else {
try {
query.append("+(conhost:").append(host.getIdentifier()).append(" ")
.append("conhost:").append(whostAPI.findSystemHost(wuserAPI.getSystemUser(), true).getIdentifier()).append(") ");
} catch (Exception e) {
Logger.error(URLMapFilter.class, e.getMessage()
+ " : Unable to build host in query : ", e);
}