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  it.tidalwave.util.Finder;
 import  it.tidalwave.util.Key;
 import  it.tidalwave.util.NotFoundException;
 import static it.tidalwave.northernwind.core.impl.model.DefaultContent.*;
 
 // FIXME: reimplement with an Aspect
   {
     @Nonnull
     private final RequestContext requestContext;
 
     @Nonnull
     private final Content content;
 
     interface Exclusions
       {
         public <Type> Type getProperty(Key<Type> keythrows NotFoundException, IOException;
         public <Type> Type getProperty(Key<Type> key, Type defaultValuethrows IOException;
       }
 
     @Nonnull @Delegate(types=ResourceProperties.class, excludes=Exclusions.class)
     private final ResourceProperties delegate;
 
     @Override
     public <Type> Type getProperty (final @Nonnull Key<Type> key)
       throws NotFoundException, IOException
       {
         try
           {
             .setContent();
             return .getProperty(key);
           }
         finally
           {
             .clearContent();
           }
       }
 
     @Override
     public <Type> Type getProperty (final @Nonnull Key<Type> keyfinal @Nonnull Type defaultValue)
       throws IOException
       {
         try
           {
             .setContent();
             return .getProperty(keydefaultValue);
           }
         finally
           {
             .clearContent();
           }
       }
   }

A piece of content to be composed into a Node.

Author(s):
Fabrizio Giudici
Version:
$Id$ /
@Configurable @Slf4j @ToString(callSuper = true, exclude="requestContext")
/* package */ class DefaultContent extends ContentSupport
  {
    @Inject @Nonnull
    private RequestContext requestContext;

    
Creates a new DefaultContent with the given configuration file.

Parameters:
file the configuration file /
    public DefaultContent (final @Nonnull Content.Builder builder)
      {
        super(builder);
      }

    
/
    @Override @Nonnull
    public Finder<ContentfindChildren()
      {
        return new FolderBasedFinderSupport<Content>(this);
      }

    
/
    @Override @Nonnull
    public ResourcePath getExposedUri()
      throws NotFoundException, IOException
      {
        try
          {
            return new ResourcePath(getProperties().getProperty(PROPERTY_EXPOSED_URI));
          }
        catch (NotFoundException e)
          {
            return getDefaultExposedUri();
          }
      }
    // FIXME: this is declared in Frontend Components. Either move some properties in this module, or the next
    // method can't stay here.
    public static final Key<StringPROPERTY_TITLE = new Key<>("title");

    
/
    @Nonnull
      throws NotFoundException, IOException
      {
        String title = getResource().getProperties().getProperty();
        title = deAccent(title);
        title = title.replaceAll(" ""-")
                     .replaceAll(",""")
                     .replaceAll("\\.""")
                     .replaceAll(";""")
                     .replaceAll("/""")
                     .replaceAll("!""")
                     .replaceAll("\\?""")
                     .replaceAll(":""")
                     .replaceAll("[^\\w-]*""");
        return new ResourcePath(title.toLowerCase());
      }

    
See http://stackoverflow.com/questions/1008802/converting-symbols-accent-letters-to-english-alphabet /
    @Nonnull
    public String deAccent (final @Nonnull String string)
      {
        final String nfdNormalizedString = Normalizer.normalize(string..);
        final Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
        return pattern.matcher(nfdNormalizedString).replaceAll("");
      }
    @Override @Nonnull
      {
        return new ResourcePropertiesDelegate(thisgetResource().getProperties());
      }
  }
New to GrepCode? Check out our FAQ X