Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * #%L
   * *********************************************************************************************************************
   *
   * NorthernWind - lightweight CMS
   * http://northernwind.tidalwave.it - hg clone https://bitbucket.org/tidalwave/northernwind-src
   * %%
   * Copyright (C) 2011 - 2013 Tidalwave s.a.s. (http://tidalwave.it)
   * %%
  * *********************************************************************************************************************
  *
  * 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.
  *
  * *********************************************************************************************************************
  *
  * $Id$
  *
  * *********************************************************************************************************************
  * #L%
  */
 package it.tidalwave.northernwind.core.impl.model;
 
 import  javax.annotation.Nonnull;
 import java.util.Map;
 import  it.tidalwave.util.Id;
 import  it.tidalwave.util.Key;
 import  it.tidalwave.util.NotFoundException;
 import lombok.Cleanup;
 import lombok.Getter;
 import static it.tidalwave.northernwind.core.model.Resource.PROPERTY_PLACE_HOLDER;
 import static it.tidalwave.role.Unmarshallable.Unmarshallable;

The default implementation for Resource.

Author(s):
Fabrizio Giudici
Version:
$Id$ /
 
 @Configurable @Slf4j @ToString(callSuper = true, of = "placeHolder")
 /* package */ class DefaultResource extends ResourceSupport
   {
     @Inject @Nonnull
 
     @Inject @Nonnull
 
     private final Map<LocaleResourcePropertiespropertyMapByLocale = new HashMap<>();
 
     @Getter
     private boolean placeHolder;
 
     private final ResourceProperties.PropertyResolver propertyResolver;

    
/
 
     public DefaultResource (final @Nonnull Resource.Builder builder)
       {
         super(builder);
       }

    
/
 
     @Override @Nonnull
     public ResourceProperties getProperties()
       {
       }

    
/
    /* package */ void loadProperties()
      throws IOException
      {
        final ResourceFile file = getFile();
        log.debug("loadProperties() for {}"file.getPath().asString());
        boolean tmpPlaceHolder = true;
        for (final Locale locale : .getLocales())
          {
            ResourceProperties properties = modelFactory.createProperties().withPropertyResolver().build();
            if (file.isData())
              {
                tmpPlaceHolder = false;
              }
            else
              {
                for (final ResourceFile propertyFile : .getInheritedPropertyFiles(filelocale"Properties"))
                  {
                    log.trace(">>>> reading properties from {} ({})..."propertyFile.getPath().asString(), locale);
                    @Cleanup final InputStream is = propertyFile.getInputStream();
                    final ResourceProperties tempProperties =
                        modelFactory.createProperties().build().as(Unmarshallable).unmarshal(is);
        //                modelFactory.createProperties().withPropertyResolver(propertyResolver).build().as(Unmarshallable).unmarshal(is);
                    log.trace(">>>>>>>> read properties: {} ({})"tempPropertieslocale);
                    properties = properties.merged(tempProperties);
                    tmpPlaceHolder &= !propertyFile.getParent().equals(file);
                  }
              }
             = Boolean.parseBoolean(properties.getProperty("" + tmpPlaceHolder));
            if (log.isDebugEnabled())
              {
                log.debug(">>>> properties for {} ({}):"file.getPath().asString(), locale);
                logProperties(">>>>>>>>"properties);
              }
            .put(localeproperties);
          }
      }

    
FIXME: move to ResourceProperties! /
    private void logProperties (final @Nonnull String indent,
                                final @Nonnull ResourceProperties properties)
      {
        log.debug("{} property items:"indent);
        for (final Key<?> key : properties.getKeys())
          {
            try
              {
                log.debug("{}>>>> {} = {}"indentkeyproperties.getProperty(key));
              }
            catch (NotFoundException | IOException e)
              {
                log.error(""e);
              }
          }
        log.debug("{} property groups: {}"indentproperties.getGroupIds());
        for (final Id groupId : properties.getGroupIds())
          {
            log.debug("{}>>>> group: {}"indentgroupId);
            logProperties(indent + ">>>>"properties.getGroup(groupId));
          }
      }
  }
New to GrepCode? Check out our FAQ X