Changeset 6632


Ignore:
Timestamp:
Nov 28, 2014, 11:28:38 AM (8 years ago)
Author:
Nicklas Nordborg
Message:

References #1886: Extension point for "skinning" web gui

Adding support for re-mapping images to images provided by the skins. Basic support is added to the FixedSkinActionFactor which can be given a configuration parameter <image-remap-dir> that points to a path in the extension JAR file that simply mirrors the BASE web server (eg. /images directory) and re-maps images that are found.

Location:
trunk
Files:
3 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/config/dist/web.xml

    r6629 r6632  
    369369    <url-pattern>/csp-report</url-pattern>
    370370  </servlet-mapping>
     371 
     372  <!-- A filter that remaps requests to images to skin-controlled variants -->
     373  <filter>
     374    <description>
     375      This filter is used to support provide support for skins to re-map
     376      images to their own versions. If this filter is disabled, skins will
     377      not be able to remap images. Use the cachce-control parameter to control
     378      the time client browsers are allowed to cache images. Skin changes
     379      may not be visible until after this time (seconds) has passed.
     380    </description>
     381    <display-name>Image remap filter</display-name>
     382    <filter-name>ImageRemap</filter-name>
     383    <filter-class>net.sf.basedb.clients.web.servlet.ImageRemapFilter</filter-class>
     384    <init-param>
     385      <!-- max-age=time in seconds -->
     386      <param-name>cache-control</param-name>
     387      <param-value>max-age=3600</param-value>
     388    </init-param>
     389  </filter>
     390  <filter-mapping>
     391    <filter-name>ImageRemap</filter-name>
     392    <url-pattern>*.png</url-pattern>
     393  </filter-mapping>
     394  <filter-mapping>
     395    <filter-name>ImageRemap</filter-name>
     396    <url-pattern>*.gif</url-pattern>
     397  </filter-mapping>
    371398
    372399</web-app>
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/ExtensionsControl.java

    r6627 r6632  
    3737import net.sf.basedb.clients.web.extensions.list.ListColumnUtil;
    3838import net.sf.basedb.clients.web.extensions.service.Services;
     39import net.sf.basedb.clients.web.extensions.skin.ImageRemapperUtil;
    3940import net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil;
    4041import net.sf.basedb.clients.web.servlet.ContentSecurityPolicyFilter;
     
    167168    scan(null, null);
    168169    initialised = true;
     170   
     171    ImageRemapperUtil.init(context);
    169172   
    170173    Services.init();
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/skin/FixedSkinActionFactory.java

    r6596 r6632  
    2323
    2424import net.sf.basedb.clients.web.extensions.AbstractJspActionFactory;
     25import net.sf.basedb.clients.web.extensions.ExtensionsControl;
    2526import net.sf.basedb.util.extensions.InvokationContext;
    2627import net.sf.basedb.util.extensions.xml.PathSetter;
     
    2930/**
    3031  A simple action factory implementation that always include the
    31   given skin on all pages. It supports dynamic attributes and
    32   favicon.
     32  given skin on all pages. It supports dynamic attributes, favicon
     33  and image re-mapping. To use image remapping, set the
     34  &lt;image-remap-dir&gt; parameter in the configuration file to
     35  a path in the /resources dir in the JAR file but without the /resources
     36  prefix. For example, if the images to remap are in the
     37  /resources/images/remap directory set the parameter to /images/remap.
    3338 
    3439  @author nicklas
     
    3742public class FixedSkinActionFactory
    3843  extends AbstractJspActionFactory<SkinAction>
    39   implements SkinAction
    4044{
    4145 
     
    4347 
    4448  private String favicon;
     49 
     50  private String remapDir;
    4551 
    4652  /**
     
    5561  */
    5662  /**
    57     @return Always an array with a single element to this instance
     63    @return Always an array with a single element
    5864  */
    5965  @Override
    6066  public SkinAction[] getActions(InvokationContext<? super SkinAction> context)
    6167  {
    62     return new SkinAction[] { this };
     68    return new SkinAction[] { new MySkinAction(this, context.getExtension().getId()) };
    6369  }
    6470  // ----------------------------------
    6571
    66   @Override
    6772  public String getId()
    6873  {
     
    7580  }
    7681 
    77   @Override
    7882  public String getFavicon()
    7983  {
     
    8791    this.favicon = favicon;
    8892  }
     93 
     94  public void setImageRemapDir(String remapDir)
     95  {
     96    this.remapDir = remapDir;
     97  }
     98 
     99  public String getImageRemapDir()
     100  {
     101    return remapDir;
     102  }
     103 
     104  static class MySkinAction
     105    implements SkinAction
     106  {
     107    private final FixedSkinActionFactory factory;
     108    private final String xtId;
     109   
     110    MySkinAction(FixedSkinActionFactory factory, String xtId)
     111    {
     112      this.factory = factory;
     113      this.xtId = xtId;
     114    }
     115
     116    @Override
     117    public String getId()
     118    {
     119      return factory.getId();
     120    }
     121
     122    @Override
     123    public String getFavicon()
     124    {
     125      return factory.getFavicon();
     126    }
     127
     128    @Override
     129    public void remapImages(ImageRemapper mapper)
     130    {
     131      if (factory.getImageRemapDir() != null)
     132      {
     133        String path = ExtensionsControl.getHomeUrl(xtId) + factory.getImageRemapDir();
     134        ImageRemapperUtil.remapAllTo(mapper, path);
     135      }
     136    }
     137
     138   
     139  }
    89140}
  • trunk/src/clients/web/net/sf/basedb/clients/web/extensions/skin/SkinAction.java

    r6596 r6632  
    5858  public String getFavicon();
    5959 
     60  /**
     61    Remap images to another location. Use {@link ImageRemapper#map(String, String)}
     62    to re-map an image from a source location to a destination location. Note that
     63    this method is not called on every use of the skin, but only after
     64    something has changed due to installation/uninstallation or enabling/disabled
     65    skins. The re-mapped images are then cached.
     66  */
     67  public void remapImages(ImageRemapper mapper);
     68 
    6069}
  • trunk/src/clients/web/net/sf/basedb/clients/web/taglib/Page.java

    r6626 r6632  
    3232import net.sf.basedb.clients.web.extensions.ExtensionsControl;
    3333import net.sf.basedb.clients.web.extensions.JspContext;
     34import net.sf.basedb.clients.web.extensions.skin.ImageRemapper;
     35import net.sf.basedb.clients.web.extensions.skin.ImageRemapperUtil;
    3436import net.sf.basedb.clients.web.extensions.skin.SkinAction;
    3537import net.sf.basedb.util.Values;
     
    373375      ActionIterator<SkinAction> it = invoker.iterate();
    374376      skinActions = new ArrayList<SkinAction>();
     377      ImageRemapper remapper = ImageRemapperUtil.getNewImageRemapperIfNeeded(pageContext.getServletContext());
    375378      while (it.hasNext())
    376379      {
    377380        SkinAction skin = it.next();
     381        if (remapper != null) skin.remapImages(remapper);
    378382        skinActions.add(skin);
    379383        if (favicon == null)
     
    383387        }
    384388      }
     389      if (remapper != null) ImageRemapperUtil.setCurrentMapper(remapper);
    385390     
    386391      StringBuilder sb = new StringBuilder();
  • trunk/www/exception/not_logged_in.jsp

    r6617 r6632  
    116116        <table style="width: 100%; margin-top: 1em; border-collapse: separate;">
    117117        <tr>
    118           <td class="base-logo"></td>
     118          <td class="base-logo"><img src="images/baselogo.png" alt="BASE logo"></td>
    119119          <td style="width: 515px;">
    120120            <div id="loginform">
  • trunk/www/include/styles/login.css

    r6613 r6632  
    8080  border-radius: 4px 0px 0px 4px;
    8181  background-color: #000000;
    82   background-image: url('../../images/baselogo.png');
    83   background-repeat: no-repeat;
    84   background-position: 50%;
     82  text-align: center;
     83  vertical-align: middle;
    8584}
    8685
  • trunk/www/main.jsp

    r6617 r6632  
    134134      <table style="width: 100%; margin-top: 1em; border-collapse: separate;">
    135135      <tr>
    136         <td class="base-logo"></td>
     136        <td class="base-logo"><img src="images/baselogo.png" alt="BASE logo"></td>
    137137        <td style="width: 515px;">
    138138          <div id="loginform">
Note: See TracChangeset for help on using the changeset viewer.