[jboss-cvs] jboss-portal/core/src/main/org/jboss/portal/core/metadata/portlet ...

Chris Laprun chris.laprun at jboss.com
Mon Aug 14 16:34:51 EDT 2006


  User: claprun 
  Date: 06/08/14 16:34:51

  Modified:    core/src/main/org/jboss/portal/core/metadata/portlet 
                        HeaderContentMetaData.java
  Log:
  JBPORTAL-981:
  - Added support for named meta tag. No current support for http-equiv meta tags.
  - Re-factored HeaderContentMetaData.
  - Cleaned-up HeaderInterceptor.
  
  Revision  Changes    Path
  1.2       +171 -47   jboss-portal/core/src/main/org/jboss/portal/core/metadata/portlet/HeaderContentMetaData.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: HeaderContentMetaData.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-portal/core/src/main/org/jboss/portal/core/metadata/portlet/HeaderContentMetaData.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- HeaderContentMetaData.java	4 May 2006 00:51:15 -0000	1.1
  +++ HeaderContentMetaData.java	14 Aug 2006 20:34:51 -0000	1.2
  @@ -21,13 +21,13 @@
   */
   package org.jboss.portal.core.metadata.portlet;
   
  -import java.util.List;
   import java.util.ArrayList;
  +import java.util.List;
   
   /**
  - * Meta data to describe a portlet's data to inject into the header of the page.
  - * <p>A portlet can define additional script or link tags in its descriptor (jboss-portlet.xml) that will be injected
  - * into the head (via a separtate jsp tag)</p>
  + * Meta data to describe a portlet's data to inject into the header of the page. <p>A portlet can define additional
  + * script or link tags in its descriptor (jboss-portlet.xml) that will be injected into the head (via a separtate jsp
  + * tag)</p>
    *
    * @author <a href="mailto:mholzner at novell.com>Martin Holzner</a>
    * @version $LastChangedRevision$, $LastChangedDate$
  @@ -53,20 +53,16 @@
         return elements;
      }
   
  -   /**
  -    * representation of an header element.
  -    */
  -   public static class Element
  +   /** representation of an header element. */
  +   public static abstract class Element
      {
   
  -      private final String type;
  -      private final String elementType;
  -      private String rel;
  -      private String href;
  -      private String title;
  -      private String media;
  +      protected final String type;
  +      protected final String elementType;
         private String bodyContent;
  -      private String src;
  +      public static final String LINK = "link";
  +      public static final String SCRIPT = "script";
  +      public static final String META = "meta";
   
         public String getElementType()
         {
  @@ -78,6 +74,124 @@
            return type;
         }
   
  +
  +      protected Element(String elementType, String type)
  +      {
  +         this.type = type;
  +         this.elementType = elementType;
  +      }
  +
  +      /**
  +       * Create a link header element. <p>This element will create a link tag.</p>
  +       *
  +       * @param type  the type attribute of the link
  +       * @param rel   the rel attribute of the link
  +       * @param href  the href attribute of the link
  +       * @param title the title attribute of the link
  +       * @param media the media attribute of the link
  +       * @return a new link header element
  +       */
  +      public static Element createLinkElement(String type, String rel, String href, String title, String media)
  +      {
  +         return new LinkElement(rel, type, href, title, media);
  +      }
  +
  +      /**
  +       * Create a script header element. <p>This element will create a script tag.</p>
  +       *
  +       * @param type the type attribute of this script
  +       * @param src  the src attribute of this script
  +       * @return a new script header element
  +       */
  +      public static Element createScriptElement(String type, String src)
  +      {
  +         return new ScriptElement(type, src);
  +      }
  +
  +      /**
  +       * Create a meta header element. <p>This element will create a meta tag.</p>
  +       *
  +       * @param name    name attribute of the meta element
  +       * @param content content attribute of the meta element
  +       * @return a new meta header element
  +       */
  +      public static Element createNamedMetaElement(String name, String content)
  +      {
  +         return new NamedMetaElement(name, content);
  +      }
  +
  +      public String getBodyContent()
  +      {
  +         return bodyContent;
  +      }
  +
  +      public void setBodyContent(String bodyContent)
  +      {
  +         this.bodyContent = bodyContent;
  +      }
  +
  +
  +      public String outputToStringWith(String contextPath)
  +      {
  +         StringBuffer buffer = new StringBuffer(64);
  +         buffer.append("<").append(elementType);
  +         outputAttribute("type", type, buffer);
  +
  +         // sub-class specific output
  +         outputSpecificWith(contextPath, buffer);
  +
  +         if (bodyContent != null && !"".equals(bodyContent))
  +         {
  +            buffer.append(">").append(bodyContent).append("</").append(elementType).append(">\n");
  +         }
  +         else
  +         {
  +            buffer.append(" />\n");
  +         }
  +         return buffer.toString();
  +      }
  +
  +      protected void outputAttribute(String name, String value, StringBuffer buffer)
  +      {
  +         if (value != null && value.length() > 0)
  +         {
  +            buffer.append(" ").append(name).append("='").append(value).append("'");
  +         }
  +      }
  +
  +      protected void outputLocationAttribute(String name, String value, String contextPath, StringBuffer buffer)
  +      {
  +         if (value != null)
  +         {
  +            buffer.append(" ").append(name).append("='");
  +            if (value.startsWith("/"))
  +            {
  +               buffer.append(contextPath);
  +            }
  +            buffer.append(value).append("'");
  +         }
  +      }
  +
  +      protected abstract void outputSpecificWith(String contextPath, StringBuffer buffer);
  +   }
  +
  +   static class LinkElement extends Element
  +   {
  +      private String rel;
  +      private String href;
  +      private String title;
  +      private String media;
  +
  +
  +      public LinkElement(String rel, String type, String href, String title, String media)
  +      {
  +         super(LINK, type);
  +         this.rel = rel;
  +         this.href = href;
  +         this.title = title;
  +         this.media = media;
  +      }
  +
         public String getRel()
         {
            return rel;
  @@ -98,53 +212,63 @@
            return media;
         }
   
  +      protected void outputSpecificWith(String contextPath, StringBuffer buffer)
  +      {
  +         outputAttribute("rel", rel, buffer);
  +         outputLocationAttribute("href", href, contextPath, buffer);
  +         outputAttribute("title", title, buffer);
  +         outputAttribute("media", media, buffer);
  +      }
  +   }
  +
  +   static class ScriptElement extends Element
  +   {
  +      private String src;
  +
  +
  +      public ScriptElement(String type, String src)
  +      {
  +         super(SCRIPT, type);
  +         this.src = src;
  +      }
  +
  +      protected void outputSpecificWith(String contextPath, StringBuffer buffer)
  +      {
  +         outputLocationAttribute("src", src, contextPath, buffer);
  +      }
  +
         public String getSrc()
         {
            return src;
         }
  +   }
   
  -      /**
  -       * Create a link header element. <p>This element will create a link tag.</p>
  -       *
  -       * @param rel         the rel attribute of the link
  -       * @param type        the type attribute of the link
  -       * @param href        the href attribute of the link
  -       * @param title       the title attribute of the link
  -       * @param media       the media attribute of the link
  -       */
  -      public Element(String rel, String type, String href, String title, String media)
  +   static class NamedMetaElement extends Element
         {
  -         // log.debug("building header link...");
  -         this.elementType = "link";
  -         this.rel = rel;
  -         this.type = type;
  -         this.href = href;
  -         this.title = title;
  -         this.media = media;
  +      private String name;
  +      private String content;
  +
  +      public NamedMetaElement(String name, String content)
  +      {
  +         super(META, null);
  +         this.name = name;
  +         this.content = content;
         }
   
  -      /**
  -       * Create a script header element. <p>This element will create a script tag.</p>
  -       *
  -       * @param src         the src attribute of this script
  -       * @param type        the type attribute of this script
  -       */
  -      public Element(String src, String type)
  +      protected void outputSpecificWith(String contextPath, StringBuffer buffer)
         {
  -         // log.debug("building header script...");
  -         this.elementType = "script";
  -         this.src = src;
  -         this.type = type;
  +         outputAttribute("name", name, buffer);
  +         outputAttribute("content", content, buffer);
         }
   
  -      public String getBodyContent()
  +      public String getName()
         {
  -         return bodyContent;
  +         return name;
         }
   
  -      public void setBodyContent(String bodyContent)
  +      public String getContent()
         {
  -         this.bodyContent = bodyContent;
  +         return content;
         }
      }
   }
  
  
  



More information about the jboss-cvs-commits mailing list