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 - 2014 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: DefaultInheritanceHelper.java,v f214f4c8488f 2014/01/03 18:03:50 fabrizio $
  *
  * *********************************************************************************************************************
  * #L%
  */
 package it.tidalwave.northernwind.core.impl.model;
 
 import  javax.annotation.Nonnull;
 import java.util.List;
 import  it.tidalwave.util.NotFoundException;
Implements the default inheritance policy for properties. The sequence of loaded file is:
  • parent default
  • parent localized
  • this level default
  • this level localized
  • override default
  • override localized

Author(s):
Fabrizio Giudici
Version:
$Id: DefaultInheritanceHelper.java,v f214f4c8488f 2014/01/03 18:03:50 fabrizio $ /
 
 public class DefaultInheritanceHelper implements InheritanceHelper
   {
    
/
 
     @Override @Nonnull
     public List<ResourceFilegetInheritedPropertyFiles (final @Nonnull ResourceFile folder,
                                                          final @Nonnull Locale locale,
                                                          final @Nonnull String propertyFileName)
       {
         log.trace("getInheritedPropertyFiles({}, {})"folder.getPath(), propertyFileName);
 
         final List<Stringsuffixes = new ArrayList<>();
         suffixes.add("");
         suffixes.add("_" + locale.getLanguage());
         final List<ResourceFilefiles = new ArrayList<>();
 
         for (final ResourceFile parentFolder : getHierarchyFolders(folder))
           {
             files.addAll(getFiles(""propertyFileNameparentFoldersuffixes));
           }
 
         files.addAll(getFiles("Override"propertyFileNamefoldersuffixes));
 
         log.trace(">>>> property file candidates: {}"files);
 
         return files;
       }

    
/
 
     private List<ResourceFilegetFiles (final @Nonnull String prefix,
                                          final @Nonnull String propertyFileName,
                                          final @Nonnull ResourceFile folder,
                                          final @Nonnull List<Stringsuffixes)
       {
         final List<ResourceFilefiles = new ArrayList<>();
 
         for (final String localeSuffix : suffixes)
           {
             final String fileName = prefix + propertyFileName + localeSuffix + ".xml";
             log.trace(">>>> probing {} ..."folder.getPath().asString() + "/" + fileName);
            try
              {
                files.add(folder.findChildren().withName(fileName).result());
              }
            catch (NotFoundException e)
              {
                // ok. do nothing
              }
          }
        return files;
      }

    
/
    @Nonnull
    private List<ResourceFilegetHierarchyFolders (final @Nonnull ResourceFile folder)
      {
        final List<ResourceFilefolders = new ArrayList<>();
        for (ResourceFile parent = folderparent.getParent() != nullparent = parent.getParent()) // TODO: refactor with recursion?
          {
            folders.add(parent);
          }
        Collections.reverse(folders);
        return folders;
      }
  }
New to GrepCode? Check out our FAQ X