portletspec3
  1. portletspec3
  2. PORTLETSPEC3-40

Add new javax.portlet.ResourceComparator annotation in order to identify duplicate resources

    Details

      Description

      I would like to propose the following annotation, which
      would allow portlet developers (and JSF portlet bridge implementors)
      to provide a way to inform the portlet container of duplicate
      resources. This is a common problem with JSF portlets, since each
      JSF portlet on the portal page needs the "jsf.js" resource:

      package javax.portlet;
      /**
      * Annotation for marking a class that compares resource URLs. Such classes are
      * discovered by the portlet container at startup and are required to
      * implement the {@link java.util.Comparator} interface in order to compare
      * resources represented as type {@link java.lang.String}. If the
      * {@link java.util.Comparator#compare(Object, Object)} method returns 0, then
      * the portlet container will consider the resources to be identical and will include
      * only the first resource in the <head/> section of the rendered portal page.
      *
      * @since 3.0
      */
      @Target(ElementType.TYPE)
      @Retention(RetentionPolicy.RUNTIME)
      public @interface ResourceComparator {
      }
      

      Here is an example that a JSF portlet bridge could use in order to prevent duplicate JSF resources:

      public interface FacesResource {
      
      	public enum TYPE {
      		HREF, LINK, SCRIPT
      	}
      	
      	public TYPE getType();
      	
      	public String getName();
      	
      	public String getLibrary();
      }
      
      @ResourceComparator
      public class FacesResourceComparator implements Comparator<String> {
      
      	public int compare(String resourceURL1, String resourceURL2) {
      
      		if (isFacesResource(resourceURL1) && isFacesResource(resourceURL2)) {
      				
      				FacesResource facesResource1 = new FacesResourceImpl(resourceURL1);
      				FacesResource facesResource2 = new FacesResourceImpl(resourceURL2);
      
      				if (facesResource1.equals(facesResource2)) {
      					return 0;
      				}
      				else {
      					return -1;
      				}
      		}
      		else {
      			return -1;
      		}
      	}
      
      	protected boolean isFacesResource(String url) {
      		return ((url != null) && url.contains("javax.faces.resource"));
      	}
      }
      

        Activity

          People

          • Assignee:
            Unassigned
            Reporter:
            Neil Griffin
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: