THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
New SubdomainURLStrategy object
Note: For now this still uses properties to override the default subdomain URL. In "phase II" we'll look at moving this property into the Weblog object/table itself.
Code Block |
---|
package org.apache.roller.weblogger.business; import org.apache.roller.weblogger.business.MultiWeblogURLStrategy; import org.apache.roller.weblogger.config.WebloggerConfig; import org.apache.roller.weblogger.config.WebloggerRuntimeConfig; import org.apache.roller.weblogger.pojos.Weblog; /** Multi-domain URL strategy. */ public class SubdomainURLStrategy extends MultiWeblogURLStrategy { /** Get root url for a given weblog. Optionally for a certain locale. */ public String getWeblogURL(Weblog weblog, String locale, boolean absolute) { if(weblog == null) return null; StringBuffer url = new StringBuffer(); if(absolute) { String weblogAbsoluteURL = WebloggerConfig.getProperty("weblog.absoluteurl." + weblog.getHandle()); if (weblogAbsoluteURL != null) { url.append(weblogAbsoluteURL); } else { String subDomainURL = replaceSubdomain(WebloggerRuntimeConfig.getAbsoluteContextURL(), weblog.getHandle()); url.append(subDomainURL); } } else { url.append(WebloggerRuntimeConfig.getRelativeContextURL()); } // TODO: Remove this, the handle shouldn't be in the hostname and in the path url.append("/").append(weblog.getHandle()).append("/"); if(locale != null) { url.append(locale).append("/"); } return url.toString(); } private String replaceSubdomain(String url, String newSub) { String baseURL; // Base URL for subdomains StringBuffer newURL = new StringBuffer(newSub); // URL for this subdomain // For backward compatibility we leave site.absoluteurl property as the full URL of // the main blog, e.g. roller.domain.com, so we'll have to remove the subdomain and re-add it int firstDot = url.indexOf('.'); if ((firstDot == -1) || (firstDot + 2 > url.length())) { // URL without a dot (!?) or dot is last character - Use the full URL // Maybe we should throw an exception here? baseURL = url; } else { // Take everthing after the first dot baseURL = url.substring(firstDot + 1); } newURL.append(newSub).append('.').append(baseURL); return newURL.toString(); } } |
...