Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (C) 2009 eXo Platform SAS.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
   * the License, or (at your option) any later version.
   *
   * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.exoplatform.services.jcr.ext.resource;
 
 import  org.picocontainer.Startable;
 
 import java.util.List;
 import java.util.Map;
 
 import javax.jcr.Node;
Created by The eXo Platform SAS .

Author(s):
Gennady Azarenkov
Version:
$Id: $
Since:
1.9
 
 
 public class NodeRepresentationService implements Startable
 {
 
 
 
 
    private static final Log log = ExoLogger.getLogger("exo.jcr.component.ext.NodeRepresentationService");
 
    public NodeRepresentationService(ExoContainerContext containerContext)
    {
       this. = new HashMap<StringNodeRepresentationFactory>();
       this. = containerContext;
    }

   
Add new NodeRepresentationFactory for node type.

Parameters:
nodeType the node type.
representationFactory the NodeRepresentationFactory.
 
    public void addNodeRepresentationFactory(String nodeTypeNodeRepresentationFactory representationFactory)
    {
       .put(nodeTyperepresentationFactory);
    }

   
Get NodeRepresentation for given node. String mediaTypeHint can be used as external information for representation. By default node will be represented as doc-view.

Parameters:
node the jcr node.
mediaTypeHint the mimetype hint or null if not known.
Returns:
the NodeRepresentation.
Throws:
RepositoryException
 
    public NodeRepresentation getNodeRepresentation(Node nodeString mediaTypeHintthrows RepositoryException
    {
 
       NodeRepresentationFactory factory = factory(node);
       if (factory != null)
          return factory.createNodeRepresentation(nodemediaTypeHint);
       else
          return new DocumentViewNodeRepresentation(node);
    }

   

Returns:
served node types.
 
   {
      return .keySet();
   }

   

Returns:
served keys.
   public Collection<StringgetKeys()
   {
      return .keySet();
   }

   
   public void start()
   {
      ExoContainer container = .getContainer();
      for (NodeRepresentationFactory f : list)
      {
         addNodeRepresentationFactory(f.getNodeType(), f);
         .info("NodeRepresentationFactory added " + f.getNodeType() + " " + f.getClass().getName());
      }
   }

   
   public void stop()
   {
   }
   {
      if (f == null)
      {
         for (String nt : .keySet())
         {
            if (node.isNodeType(nt))
            {
               f = .get(nt);
               break;
            }
         }
      }
      if (f == null)
      {
         for (NodeType mixin : node.getMixinNodeTypes())
         {
            f = .get(mixin.getName());
            if (f != null)
               return f;
         }
      }
      return f;
   }
New to GrepCode? Check out our FAQ X