Changeset 6596


Ignore:
Timestamp:
Nov 14, 2014, 2:34:01 PM (8 years ago)
Author:
Nicklas Nordborg
Message:

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

Added extension point, action class and a simple reference factory implementation. The Page/Head/Body? uses the extension to add script and stylesheets to the generated html.

Location:
trunk/src/clients/web
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/clients/web/net/sf/basedb/clients/web/taglib/Body.java

    r6576 r6596  
    2525
    2626import net.sf.basedb.clients.web.Base;
     27import net.sf.basedb.clients.web.extensions.DynamicActionAttributeSupport;
     28import net.sf.basedb.clients.web.extensions.skin.SkinAction;
    2729import net.sf.basedb.clients.web.util.HTML;
    2830import net.sf.basedb.core.Application;
     
    3133
    3234import java.util.Date;
     35import java.util.List;
     36
    3337import javax.servlet.jsp.JspException;
    3438import javax.servlet.jsp.JspTagException;
     
    235239      addDynamicAttributes(sb);
    236240      sb.append(">\n");
     241     
     242      // Output <div> tag with skin extension dynamic attributes
     243      List<SkinAction> skinActions = page.getSkinActions();
     244      if (skinActions != null && skinActions.size() > 0)
     245      {
     246        sb.append("<div id=\"skin-data\" class=\"datacontainer\">\n");
     247        for (SkinAction skin : skinActions)
     248        {
     249          if (skin.getId() != null)
     250          {
     251            sb.append("\t<div id=\"").append(skin.getId()).append("\"");
     252            sb.append(DynamicActionAttributeSupport.getAttributesString(skin));
     253            sb.append("></div>\n");
     254          }
     255        }
     256        sb.append("</div>");
     257      }
    237258    }
    238259   
  • trunk/src/clients/web/net/sf/basedb/clients/web/taglib/Head.java

    r6576 r6596  
    2424
    2525import net.sf.basedb.clients.web.extensions.ExtensionsControl;
     26import net.sf.basedb.clients.web.extensions.JspContext;
    2627import net.sf.basedb.clients.web.util.HTML;
    2728import net.sf.basedb.core.SessionControl;
     
    185186  }
    186187
    187   private void appendStyles(StringBuilder sb, String fontStyles, boolean hideLongTexts)
     188  private void appendStyles(StringBuilder sb, String fontStyles, boolean hideLongTexts, JspContext jspContext)
    188189  {
    189190    LinkedHashSet<String> allStyles = new LinkedHashSet<String>();
     
    198199    allStyles.add(fontStyles);
    199200    if (hideLongTexts) allStyles.add("long_texts.css");
     201    if (jspContext != null && jspContext.getStylesheets() != null)
     202    {
     203      allStyles.addAll(jspContext.getStylesheets());
     204    }
     205   
    200206    String appRoot = page.getRoot();
    201207    for (String style : allStyles)
     
    226232  }
    227233
    228   private void appendScripts(StringBuilder sb)
     234  private void appendScripts(StringBuilder sb, JspContext jspContext)
    229235  {
    230236    SessionControl sc = page.getSessionControl();
     
    245251    {
    246252      allScripts.addAll(Arrays.asList(getScripts().split(",")));
     253    }
     254    if (jspContext != null && jspContext.getScripts() != null)
     255    {
     256      allScripts.addAll(jspContext.getScripts());
    247257    }
    248258   
     
    294304    page = (Page)getParent();
    295305   
     306    SessionControl sc = page.getSessionControl();
     307    int pageType = page.getTypeCode();
     308    JspContext skinContext = page.getSkinContext();
     309   
    296310    StringBuilder sb = new StringBuilder();
    297311    int returnValue = EVAL_BODY_INCLUDE;
    298     if (page.getTypeCode() == Page.PAGE_TYPE_INCLUDE)
    299     {
    300       appendScripts(sb);
     312    if (pageType == Page.PAGE_TYPE_INCLUDE)
     313    {
     314      appendScripts(sb, skinContext);
    301315      returnValue = SKIP_BODY;
    302316    }
    303317    else
    304318    {
    305       SessionControl sc = page.getSessionControl();
    306319      String longTexts = Values.getString(sc != null ? sc.getUserClientSetting("text.long") : null, "display");
    307320      String fontStyles = Values.getString(sc != null ? sc.getUserClientSetting("appearance.fontsize") : null, "size_m.css");
    308321     
    309322      String favicon = page.getFavicon();
    310       if (favicon != null && !favicon.startsWith("/"))
     323      if (favicon == null) favicon = "favicon.ico";
     324      if (!favicon.startsWith("/"))
    311325      {
    312326        favicon = page.getRoot()+favicon;
     
    314328
    315329      sb.append("<head>\n");
    316       if (favicon != null)
    317       {
    318         sb.append("\t<link id=\"fav-icon\" rel=\"SHORTCUT ICON\" href=\"").append(favicon).append("\">\n");
    319       }
    320       appendStyles(sb, fontStyles, !"display".equals(longTexts));
    321       appendScripts(sb);
     330      sb.append("\t<link id=\"fav-icon\" rel=\"SHORTCUT ICON\" href=\"").append(favicon).append("\">\n");
     331      appendStyles(sb, fontStyles, !"display".equals(longTexts), skinContext);
     332      appendScripts(sb, skinContext);
    322333     
    323334      String title = page.getTitle();
  • trunk/src/clients/web/net/sf/basedb/clients/web/taglib/Page.java

    r6540 r6596  
    2323package net.sf.basedb.clients.web.taglib;
    2424
     25import java.util.ArrayList;
     26import java.util.List;
     27
    2528import net.sf.basedb.core.Application;
    2629import net.sf.basedb.core.SessionControl;
    2730import net.sf.basedb.core.Version;
    2831import net.sf.basedb.clients.web.Base;
     32import net.sf.basedb.clients.web.extensions.ExtensionsControl;
     33import net.sf.basedb.clients.web.extensions.JspContext;
     34import net.sf.basedb.clients.web.extensions.skin.SkinAction;
    2935import net.sf.basedb.util.Values;
     36import net.sf.basedb.util.extensions.ActionIterator;
     37import net.sf.basedb.util.extensions.ExtensionsInvoker;
    3038
    3139import javax.servlet.jsp.PageContext;
     
    176184    The 'favicon' to use.
    177185  */
    178   private String favicon = "favicon.ico";
     186  private String favicon = null;
    179187
    180188  private static volatile boolean initialized = false;
     
    201209  */
    202210  private transient SessionControl sc;
     211 
     212  private transient JspContext skinContext;
     213 
     214  private transient List<SkinAction> skinActions;
    203215 
    204216  /**
     
    314326  }
    315327
     328  /**
     329    Get the JSP context used for invoking skin extensions. Needed
     330    by HEAD taglib so that it can include required scripts and stylesheets.
     331    @since 3.4
     332  */
     333  public JspContext getSkinContext()
     334  {
     335    return skinContext;
     336  }
     337 
     338  /**
     339    Get all skin extension actions. Needed in BODY so that
     340    it can include data on the page.
     341    @since 3.4
     342  */
     343  public List<SkinAction> getSkinActions()
     344  {
     345    return skinActions;
     346  }
     347 
    316348  @Override
    317349  public void setPageContext(PageContext pageContext)
    318350  {
    319351    super.setPageContext(pageContext);
     352    favicon = null;
    320353    if (!initialized) initStaticFields(pageContext);
    321354    try
     
    327360  }
    328361
     362  @SuppressWarnings("unchecked")
    329363  @Override
    330364  public int doStartTag()
     
    333367    if (type != PAGE_TYPE_INCLUDE)
    334368    {
     369      // Load skin extensions: net.sf.basedb.clients.web.global-skin
     370      skinContext = ExtensionsControl.createContext(sc, pageContext);
     371      skinContext.setAttribute("page-type", getTypeCode());
     372      ExtensionsInvoker<SkinAction> invoker = (ExtensionsInvoker<SkinAction>)ExtensionsControl.useExtensions(skinContext, "net.sf.basedb.clients.web.global-skin");
     373      ActionIterator<SkinAction> it = invoker.iterate();
     374      skinActions = new ArrayList<SkinAction>();
     375      while (it.hasNext())
     376      {
     377        SkinAction skin = it.next();
     378        if (favicon == null)
     379        {
     380          String skinIcon = skin.getFavicon();
     381          if (skinIcon != null) favicon = skinIcon;
     382        }
     383      }
     384     
    335385      StringBuilder sb = new StringBuilder();
    336386      sb.append("<!doctype ").append(getDoctype()).append(">\n");
  • trunk/src/clients/web/web-extensions.xml

    r6440 r6596  
    155155      and/or password prompts, help texts, etc. Since there is only one login form,
    156156      only the first extension found for this extension point is used.
     157    </description>
     158  </extension-point>
     159 
     160  <extension-point
     161    id="global-skin">
     162    <action-class>net.sf.basedb.clients.web.extensions.skin.SkinAction</action-class>
     163    <name>Skins</name>
     164    <description>
     165      Extension point for GUI customizations. Extensions should implement
     166      the SkinAction interface, which can be used to set the favicon and
     167      add custom data to a hidden div tag on the page. Most work is expected
     168      to be done by stylesheets and/or scripts added to the JspContext
     169      instance passed to factory via the prepareContext method.
    157170    </description>
    158171  </extension-point>
Note: See TracChangeset for help on using the changeset viewer.