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.CheckForNull;
 import  javax.annotation.Nonnull;
 import java.util.List;
 import java.util.Map;
 import  it.tidalwave.util.Finder;
 import  it.tidalwave.util.Id;
 import  it.tidalwave.util.NotFoundException;
 import lombok.Cleanup;
 import static java.net.URLDecoder.*;
 import static it.tidalwave.role.Unmarshallable.Unmarshallable;
 import static it.tidalwave.northernwind.core.model.SiteNode.PROPERTY_EXPOSED_URI;
A node of the site, mapped to a given URL.

Author(s):
Fabrizio Giudici
Version:
$Id$ /
 
 @Configurable(preConstruction = true) @Slf4j @ToString(callSuper = true, of = "relativeUri")
 /* package */ class DefaultSiteNode extends SiteNodeSupport
   {
     @Nonnull
     private final Map<LocaleLayoutlayoutMapByLocale = new HashMap<>();
 
     @Nonnull
     /* package */ InternalSite site;
 
     @Inject @Nonnull
 
     @Inject @Nonnull
 
     @CheckForNull
     private ResourcePath relativeUri;
 
     /* package */ int uriComputationCounter;

    
Creates a new instance with the given configuration file and mapped to the given URI.

Parameters:
file the file with the configuration
relativeUri the bound URI /
 
     public DefaultSiteNode (final @Nonnull ModelFactory modelFactory,
                             final @Nonnull InternalSite site,
                             final @Nonnull ResourceFile file)
       throws IOException, NotFoundException
      {
        super(modelFactoryfile);
        this. = site;
        loadLayouts();
      }

    
/
    @Nonnull @Override
    public synchronized ResourcePath getRelativeUri()
      {
        if ( == null// FIXME: is lazy evaluation really needed?
          {
            ++;
             = new ResourcePath();
            final ResourceFile file = getResource().getFile();
            if (!file.equals(.getNodeFolder()))
              {
                try
                  {
                    final String segment = getResource().getProperties()
                                                        .getProperty(decode(file.getName(), "UTF-8"));
                     = .appendedWith(getParent().getRelativeUri()).appendedWith(segment);
                  }
                catch (IOException | NotFoundException e)
                  {
                    log.error(""e); // should never occur
                    throw new RuntimeException(e);
                  }
              }
          }
        log.debug(">>>> relativeUri: {}".asString());
        return ;
      }

    
/
    @Override @Nonnull
    public Layout getLayout()
      {
      }

    
/
    @Override @Nonnull
    public Finder<SiteNodefindChildren()
      {
        throw new UnsupportedOperationException("Not supported yet.");
      }

    
/
    @Nonnull
    private void loadLayouts()
      throws IOException, NotFoundException
      {
        for (final Locale locale : .getLocales())
          {
            Layout layout = null;
            // Cannot be implemented by recursion, since each SiteNode could have a local override for its Layout -
            // local overrides are not inherited. Perhaps you could do if you keep two layouts per Node, one without the override.
            // On the other hand, inheritanceHelper encapsulates the local ovverride policy, which applies also to Properties...
            final List<ResourceFilelayoutFiles = .getInheritedPropertyFiles(getResource().getFile(),
                                                                                               locale,
                                                                                               "Components");
            for (final ResourceFile layoutFile : layoutFiles)
              {
                final DefaultLayout overridingLayout = loadLayout(layoutFile);
                layout = (layout == null) ? overridingLayout : layout.withOverride(overridingLayout);
                if (log.isDebugEnabled())
                  {
                    overridingLayout.accept(new LayoutLoggerVisitor(..));
                  }
              }
            layout = (layout != null) ? layout : modelFactory.createLayout()
                                                             .withId(new Id(""))
                                                             .withType("emptyPlaceholder")
                                                             .build();
            if (.isLogConfigurationEnabled() || log.isDebugEnabled())
              {
                log.debug(">>>> layout for {} ():"getResource().getFile().getPath().asString(), locale);
                layout.accept(new LayoutLoggerVisitor(..));
              }
            .put(localelayout);
          }
      }

    
Returns the parent SiteNode.

Returns:
the parent node
Throws:
NotFoundException if the parent doesn't exist
UnsupportedEncodingException /
    @Nonnull
    private SiteNode getParent()
      throws NotFoundException
      {
        final ResourcePath parentRelativePath = getResource().getFile().getParent().getPath().urlDecoded()
                                              .relativeTo(.getNodeFolder().getPath());
        return .find(SiteNode.class).withRelativePath(parentRelativePath.asString()).result();
      }

    
/
    @Nonnull
    private DefaultLayout loadLayout (final @Nonnull ResourceFile layoutFile)
      throws IOException
      {
        log.trace(">>>> reading layout from {}..."layoutFile.getPath().asString());
        final @Cleanup InputStream is = layoutFile.getInputStream();
        return modelFactory.createLayout().build().as(Unmarshallable).unmarshal(is);
      }
  }
New to GrepCode? Check out our FAQ X