Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2014-2015 Philip Helger (www.helger.com) philip[at]helger[dot]com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package com.helger.webbasics.resource;
 
 
This encapsulates a WebSiteResource together with an optional conditional comment.

Author(s):
Philip Helger
 
 {
   private final WebSiteResource m_aResource;
   private final String m_sConditionalComment;
   private final boolean m_bCanBeBundled;
   private final CSSMediaList m_aMediaList;

  
Constructor for JavaScript resources.

Parameters:
aPP The path provider.
bRegular true for regular version, false for the minified/optimized version.
 
   public WebSiteResourceWithCondition (@Nonnull final IJSPathProvider aPPfinal boolean bRegular)
   {
     // IWebURIToURLConverter is not needed for JS
     this (.,
           aPP.getJSItemPath (bRegular),
           aPP.getConditionalComment (),
           aPP.canBeBundled (),
           (CSSMediaListnull);
   }

  
Constructor for CSS resources.

Parameters:
aPP The path provider.
bRegular true for regular version, false for the minified/optimized version.
 
   public WebSiteResourceWithCondition (@Nonnull final ICSSPathProvider aPPfinal boolean bRegular)
   {
     this (.,
           aPP.getCSSItemPath (bRegular),
           aPP.getConditionalComment (),
           true,
           aPP.getMediaList ());
   }
 
                                         @Nonnull @Nonempty final String sPath,
                                         @Nullable final String sConditionalComment,
                                         final boolean bCanBeBundled,
                                         @Nullable final CSSMediaList aMediaList)
   {
      = WebSiteResourceCache.getOrCreateResource (eTypesPath);
      = sConditionalComment;
      = bCanBeBundled;
      = aMediaList == null || aMediaList.isEmpty () ? null : aMediaList;
   }
 
   @Nonnull
   public WebSiteResource getResource ()
  {
    return ;
  }

  
Check if this resource can be bundled with the passed resource.

Parameters:
aOther The resource to check against. May not be null.
Returns:
true if this resource can be bundled with the passed resource, false if not.
  public boolean canBeBundledWith (@Nonnull final WebSiteResourceWithCondition aOther)
  {
    ValueEnforcer.notNull (aOther"Other");
    // Resource cannot be bundled at all
    if (!)
      return false;
    // Can only bundle resources of the same type
    if (!.getResourceType ().equals (aOther.m_aResource.getResourceType ()))
      return false;
    // If the conditional comment is different, items cannot be bundled!
    if (!EqualsUtils.equals (aOther.m_sConditionalComment))
      return false;
    // If the CSS media list is different, items cannot be bundled!
    if (!EqualsUtils.equals (aOther.m_aMediaList))
      return false;
    return true;
  }

  

Returns:
true if a conditional comment is present, false if not.
  public boolean hasConditionalComment ()
  {
    return StringHelper.hasText ();
  }

  

Returns:
The conditional comment to use or null if no such conditional comment is present.
  {
    return ;
  }

  
Check if this resource can be bundled, independent of the conditional comment.

Returns:
true if this resource can be bundled, false if not.
  public boolean canBeBundled ()
  {
    return ;
  }
  public CSSMediaList getMediaList ()
  {
    return ;
  }
  {
      throw new IllegalStateException ("This can only be performed on a CSS resource!");
  }
  {
      throw new IllegalStateException ("This can only be performed on a JS resource!");
  }
  public boolean equals (final Object o)
  {
    if (o == this)
      return true;
    if (o == null || !getClass ().equals (o.getClass ()))
      return false;
    return .equals (rhs.m_aResource) &&
           EqualsUtils.equals (rhs.m_sConditionalComment) &&
            == rhs.m_bCanBeBundled &&
           EqualsUtils.equals (rhs.m_aMediaList);
  }
  public int hashCode ()
  {
    return new HashCodeGenerator (this).append ()
                                       .append ()
                                       .append ()
                                       .append ()
                                       .getHashCode ();
  }
  public String toString ()
  {
    return new ToStringGenerator (this).append ("resource")
                                       .appendIfNotNull ("conditionalComment")
                                       .append ("canBeBundled")
                                       .appendIfNotNull ("mediaList")
                                       .toString ();
  }
New to GrepCode? Check out our FAQ X