Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

For example, on rollerweblogger.org, I wanted my dad's photo-physics blog to have it's own unique URL. So, I added this property to my roller-custom.properties file:

Code Block
   weblog.absoluteurl.photophys=http://photophys.com
   guice.backend.module=org.rollerweblogger.roller.JPAWebloggerModule

...

  • Weblog.java: changed to return correct weblog URL based on weblog.absolute.* property
  • MutliDomainURLModel.java: new class to return correct URLs
  • MultiDomainURLStrategy.java: new class to return correct URLs
  • WeblogRequestMapper.java: changes to prevent weblogs from being referred to by two URLs
  • MutliDomainURLModelJPAWebloggerModule.java: new class to hook in MultiDomainURLStrategy.java

Now let's discuss each change.

Weblog.java

In this class, the only changes is to return the correct URL if the weblog is one for which a weblog.absolute.* URL is specified. The proposal is to make these changes directly to Roller's Weblog.java.

Seems kinda silly that a weblog's absolute URL is defined in two places, here and in the Weblog object itself. The URLStrategy is probably the right place for this logic.

Code Block

Index: src/java/org/apache/roller/weblogger/pojos/Weblog.java
===================================================================
--- src/java/org/apache/roller/weblogger/pojos/Weblog.java	(revision 618002)
+++ src/java/org/apache/roller/weblogger/pojos/Weblog.java	(working copy)
@@ -30,7 +30,6 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.TimeZone;
-import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.builder.EqualsBuilder;
 import org.apache.commons.lang.builder.HashCodeBuilder;
 import org.apache.roller.weblogger.WebloggerException;
@@ -45,6 +44,7 @@
 import org.apache.roller.weblogger.business.themes.ThemeManager;
 import org.apache.roller.weblogger.business.WeblogManager;
 import org.apache.roller.util.UUIDGenerator;
+import org.apache.roller.weblogger.config.WebloggerConfig;
 import org.apache.roller.weblogger.util.I18nUtils;
 
 
@@ -838,10 +838,14 @@
      * @roller.wrapPojoMethod type="simple"
      */
     public String getAbsoluteURL() {
-        // TODO: ATLAS reconcile entry.getPermaLink() with new URLs
-        String relPath = WebloggerRuntimeConfig.getAbsoluteContextURL();
-        return relPath + "/" + getHandle();
-        //return URLUtilities.getWeblogURL(this, null, true);
+        String weblogAbsoluteURL = 
+            WebloggerConfig.getProperty("weblog.absoluteurl." + getHandle()); 
+        if (weblogAbsoluteURL != null) {
+            return weblogAbsoluteURL + "/" + getHandle();
+        } else {
+            String relPath = WebloggerRuntimeConfig.getAbsoluteContextURL();
+            return relPath + "/" + getHandle();
+        }
     }
     public void setAbsoluteURL(String url) {
         // noop

MutliDomainURLModel.java

In this class, the only changes is to return the correct URL if the weblog is one for which a weblog.absolute.* URL is specified.

Seems kinda silly that a weblog's absolute URL is defined in two places, here and in the Weblog object itself. Shouldn't the URLModel defer to the strategy for this?

...

Code Block

package org.rollerweblogger.roller;

import org.apache.roller.weblogger.config.WebloggerConfig;
import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
import org.apache.roller.weblogger.ui.rendering.model.URLModel;

/** Multi-domain URL model */
public class MultiDomainURLModel extends URLModel {
    
    /** Absolute URL of Roller, e.g. http://localhost:8080/roller */
    public String getAbsoluteSite() {
        String weblogAbsoluteURL = 
            WebloggerConfig.getProperty("weblog.absoluteurl." + weblog.getHandle());
        if (weblogAbsoluteURL != null) {
            return weblogAbsoluteURL;
        } else {
            return WebloggerRuntimeConfig.getAbsoluteContextURL();
        }
    }
}

MultiDomainURLStrategy.java

In this class, the only changes is to return the correct URL if the weblog is one for which a weblog.absolute.* URL is specified. The proposal is to make these changes directly to Roller's URLStrategy.

Seems kinda silly that a weblog's absolute URL is defined in two places, here and in the Weblog object itself. This is probably the right place for the definitive definition.

Code Block

package org.rollerweblogger.roller;
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 MultiDomainURLStrategy 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 {
                url.append(WebloggerRuntimeConfig.getAbsoluteContextURL());
            }
        } else {
            url.append(WebloggerRuntimeConfig.getRelativeContextURL());
        }
        
        url.append("/").append(weblog.getHandle()).append("/");
        
        if(locale != null) {
            url.append(locale).append("/");
        }
        
        return url.toString();
    }
}

WeblogRequestMapper.java

This change ensures that a weblog whose URL is specified by a {{weblog.absolute.*} URL is never referred to by it's original URL. The proposal is to make these changes directly to Roller's WeblogRequestMapper.

Code Block

Index: src/java/org/apache/roller/weblogger/ui/rendering/WeblogRequestMapper.java
===================================================================
--- src/java/org/apache/roller/weblogger/ui/rendering/WeblogRequestMapper.java	(revision 618002)
+++ src/java/org/apache/roller/weblogger/ui/rendering/WeblogRequestMapper.java	(working copy)
@@ -136,6 +136,16 @@
             return false;
         }
         
+        String weblogAbsoluteURL = 
+            WebloggerConfig.getProperty("weblog.absoluteurl." + weblogHandle);
+        if (weblogAbsoluteURL != null) {
+            // An absolute URL is specified for this weblog, make sure request URL matches
+            if (!request.getRequestURL().toString().startsWith(weblogAbsoluteURL)) {
+                log.debug("SKIPPED "+weblogHandle);
+                return false;
+            }
+        }
+        
         log.debug("WEBLOG_URL "+request.getServletPath());
         
         // parse the rest of the url and build forward url

JPAWebloggerModule.java

This module is used to allow us to hook in the new URLStrategy defined above.

Code Block

package org.rollerweblogger.roller;

import org.apache.roller.weblogger.business.jpa.*;
import com.google.inject.Binder;
import com.google.inject.Module;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.business.BookmarkManager;
import org.apache.roller.weblogger.business.FileManager;
import org.apache.roller.weblogger.business.FileManagerImpl;
import org.apache.roller.weblogger.business.PropertiesManager;
import org.apache.roller.weblogger.business.URLStrategy;
import org.apache.roller.weblogger.business.Weblogger;
import org.apache.roller.weblogger.business.UserManager;
import org.apache.roller.weblogger.business.WeblogManager;
import org.apache.roller.weblogger.business.pings.AutoPingManager;
import org.apache.roller.weblogger.business.pings.PingQueueManager;
import org.apache.roller.weblogger.business.pings.PingTargetManager;
import org.apache.roller.weblogger.business.plugins.PluginManager;
import org.apache.roller.weblogger.business.plugins.PluginManagerImpl;
import org.apache.roller.weblogger.business.referrers.RefererManager;
import org.apache.roller.weblogger.business.referrers.ReferrerQueueManager;
import org.apache.roller.weblogger.business.referrers.ReferrerQueueManagerImpl;
import org.apache.roller.weblogger.business.runnable.ThreadManager;
import org.apache.roller.weblogger.business.search.IndexManager;
import org.apache.roller.weblogger.business.search.IndexManagerImpl;
import org.apache.roller.weblogger.business.themes.ThemeManager;
import org.apache.roller.weblogger.business.themes.ThemeManagerImpl;

/**
 * Guice module for configuring JPA as Weblogger-backend.
 */
public class JPAWebloggerModule implements Module {
    private static final Log logger = LogFactory.getLog(JPAWebloggerModule.class);
    
    public void configure(Binder binder) {
        logger.info("Configuring Blogging Roller Module with multi-domain support");

        binder.bind(Weblogger.class).to(JPAWebloggerImpl.class);        
        binder.bind(JPAPersistenceStrategy.class);       
        binder.bind(org.apache.roller.weblogger.planet.business.jpa.JPARollerPlanetPersistenceStrategy.class);
        
        binder.bind(AutoPingManager.class).to(     JPAAutoPingManagerImpl.class);   
        binder.bind(BookmarkManager.class).to(     JPABookmarkManagerImpl.class);  
        binder.bind(PingQueueManager.class).to(    JPAPingQueueManagerImpl.class);   
        binder.bind(PingTargetManager.class).to(   JPAPingTargetManagerImpl.class); 
        binder.bind(PropertiesManager.class).to(   JPAPropertiesManagerImpl.class);   
        binder.bind(RefererManager.class).to(      JPARefererManagerImpl.class);
        binder.bind(ThreadManager.class).to(       JPAThreadManagerImpl.class);  
        binder.bind(UserManager.class).to(         JPAUserManagerImpl.class);   
        binder.bind(WeblogManager.class).to(       JPAWeblogManagerImpl.class);   
                
        binder.bind(ReferrerQueueManager.class).to(ReferrerQueueManagerImpl.class); 
        binder.bind(FileManager.class).to(         FileManagerImpl.class);   
        binder.bind(IndexManager.class).to(        IndexManagerImpl.class);
        binder.bind(PluginManager.class).to(       PluginManagerImpl.class);    
        binder.bind(ThemeManager.class).to(        ThemeManagerImpl.class);
        
        binder.bind(URLStrategy.class).to(         MultiDomainURLStrategy.class);
    }
}

...

Comments

Please comment on the Roller dev mailing list.