View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  package org.apache.portals.applications.springmvc;
    18
    19  import java.util.HashMap;
    20  import java.util.Map;
    21  import java.util.List;
    22  import java.util.ArrayList;
    23  import java.util.SortedSet;
    24
    25  import javax.portlet.RenderRequest;
    26  import javax.portlet.RenderResponse;
    27  import javax.portlet.PortletConfig;
    28
    29  import org.apache.commons.logging.Log;
    30  import org.apache.commons.logging.LogFactory;
    31  import org.springframework.beans.factory.InitializingBean;
    32  import org.springframework.web.portlet.mvc.AbstractController;
    33  import org.springframework.web.portlet.ModelAndView;
    34  import org.springframework.web.portlet.context.PortletConfigAware;
    35
    36  public class DOMTreeViewController extends AbstractController implements InitializingBean, PortletConfigAware
    37  {
    38      private static final Log        log = LogFactory.getLog( DOMTreeViewController.class);
    39
    40      private DOMTreeService domTreeService ;
    41      private PortletConfig portletConfig ;
    42
    43      private String xmlFilePath = null ;
    44      private String xmlFileName = null ;
    45
    46      public void afterPropertiesSet() throws Exception {
    47          if (this.domTreeService == null)
    48              throw new IllegalArgumentException("A DOMTreeService is required");
    49      }
    50
    51  	public ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception
    52  	{
    53  		List addTo = new ArrayList();
    54  		if ( getXmlFilePath() != null )
    55  		{
    56  			addTo.add( new DOMTree( getXmlFileName(), getXmlFilePath() ) );
    57  		}
    58  		SortedSet domTreeSet = domTreeService.parseAllDOMTrees( request, this.getPortletContext(), addTo );
    59
    60  		Map model = new HashMap();
    61  		model.put( "messages", portletConfig.getResourceBundle( request.getLocale() ) );
    62  		model.put( "domTreeList", domTreeSet );
    63  		model.put( "domNodeHelper", new DOMTreeService.DOMNodeHelper() );
    64
    65          return new ModelAndView("domTreeView", "model", model);
    66  	}
    67
    68      public void setDomTreeService(DOMTreeService domTreeService)
    69      {
    70          this.domTreeService = domTreeService;
    71      }
    72
    73      public String getXmlFilePath()
    74      {
    75          return this.xmlFilePath ;
    76      }
    77      public void setXmlFilePath(String xmlFile)
    78      {
    79          this.xmlFilePath = xmlFile;
    80      }
    81      public String getXmlFileName()
    82      {
    83          return this.xmlFileName;
    84      }
    85      public void setXmlFileName(String xmlFileName)
    86      {
    87          this.xmlFileName = xmlFileName;
    88      }
    89      public void setPortletConfig(PortletConfig portletConfig)
    90      {
    91
    92          this.portletConfig = portletConfig;
    93      }
    94  }