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;
 
 import java.io.Writer;
 
 
 
This class combines a WebSiteResourceBundle with an internal ID and a creation date time. It is so to say the serialized version of a WebSiteResourceBundle.

Author(s):
Philip Helger
 
 {
   public static final Charset CHARSET_TO_USE = .;
 
   private static final Logger s_aLogger = LoggerFactory.getLogger (WebSiteResourceBundleSerialized.class);
 
   private final String m_sBundleID;
   private final WebSiteResourceBundle m_aBundle;
   private final LocalDateTime m_aCreationDT;
 
   public WebSiteResourceBundleSerialized (@Nonnull @Nonempty final String sBundleID,
                                           @Nonnull final WebSiteResourceBundle aBundle,
                                           final boolean bRegular,
                                           @Nullable final IWebURIToURLConverter aConverter)
   {
     this (sBundleIDaBundle, PDTFactory.getCurrentLocalDateTime ());
     // Always serialize new bundles
     _ensureSerialized (bRegularaConverter);
   }
 
                                    @Nonnull final WebSiteResourceBundle aBundle,
                                    @Nonnull final LocalDateTime aCreationDT)
   {
      = ValueEnforcer.notEmpty (sBundleID"BundleID");
      = ValueEnforcer.notNull (aBundle"Bundle");
      = ValueEnforcer.notNull (aCreationDT"CreationDT");
   }
 
   private void _ensureSerialized (final boolean bRegular, @Nullable final IWebURIToURLConverter aConverter)
   {
                                                                  );
     if (!aTargetRes.exists ())
     {
       // persist file by merging all items
       final Writer aWriter = StreamUtils.getBuffered (aTargetRes.getWriter (.,
                                                                             .));
       try
       {
         // Write all used files into the result file (at least for now)
         for (final WebSiteResource aRes : .getAllResources ())
         {
           // This type of comment works for CSS and JS!
           final String sMetaInfo = "/* " + aRes.getPath () + " - " + aRes.getContentHashAsString () + " */\n";
           aWriter.write (sMetaInfo);
        }
        // Write all resources themselves
        for (final WebSiteResource aRes : .getAllResources ())
        {
          aWriter.write (aRes.getContent (bRegularaConverter));
        }
        .info ("Serialized " +
                        .getResourceType ().getID () +
                        " bundle '" +
                         +
                        "' with " +
                        .getAllResourcePaths () +
                        (.hasConditionalComment () ? " and conditional comment '" +
                                                              .getConditionalComment () +
                                                              "'" : ""));
      }
      catch (final Throwable t)
      {
        .error ("Error serializing bundle '" +  + "' with " + .getAllResourcePaths (), t);
        throw new IllegalStateException (t);
      }
      finally
      {
        StreamUtils.close (aWriter);
      }
    }
  }
  public String getBundleID ()
  {
    return ;
  }
  {
    return ;
  }
  public static InputStream getInputStream (@Nonnull @Nonempty final String sBundleID)
  {
    ValueEnforcer.notEmpty (sBundleID"BundleID");
    return WebFileIO.getInputStream (. + sBundleID);
  }
  {
    return getInputStream ();
  }
  public IMimeType getMimeType ()
  {
    return .getMimeType ();
  }
  {
    return ;
  }
  public IHCNode createNode (@Nonnull final IRequestWebScopeWithoutResponse aRequestScope)
  {
    final ISimpleURL aURL = LinkUtils.getURLWithContext (aRequestScope. +
                                                                        "/" +
                                                                         +
                                                                        .getResourceType ()
                                                                                 .getFileExtension ());
    // Create the main node
    final IHCNode aNode = .getResourceType ().createNode (aURL.getMediaList ());
    // Wrap in conditional comment
    return .getWrapped (aNode);
  }
  public String toString ()
  {
    return new ToStringGenerator (this).append ("bundleID")
                                       .append ("bundle")
                                       .append ("creationDT")
                                       .toString ();
  }
New to GrepCode? Check out our FAQ X