Package org.geoforge.worldwindogc.factory

Source Code of org.geoforge.worldwindogc.factory.InfoChildWms

/*
*  Copyright (C) 2011-2014 GeoForge Project
*
*  This program 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
*  of the License, or (at your option) any later version.
*
*  This program 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 program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

package org.geoforge.worldwindogc.factory;

import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.avlist.AVListImpl;

import gov.nasa.worldwind.ogc.wms.WMSLayerCapabilities;
import gov.nasa.worldwind.ogc.wms.WMSLayerStyle;
import gov.nasa.worldwind.util.WWUtil;
import org.geoforge.worldwindogc.capabilities.GfrWMSCapabilities;

/**
*
* @author bantchao
*/
public class InfoChildWms
{
   // beg static
  
   static public InfoChildWms s_create(
           GfrWMSCapabilities capWms,
            WMSLayerCapabilities capChild,
            WMSLayerStyle styStyleChild)
    {
        // Create the layer info specified by the layer's capabilities entry

        InfoChildWms linfo = new InfoChildWms(capWms);
       
        // ---- child cap
        String strLayerNames = capChild.getName();
        linfo.setLayerNames(strLayerNames);
       
        String strLayerAbstract = capChild.getLayerAbstract();
       
        if (! WWUtil.isEmpty(strLayerAbstract)) // !!!!
            linfo.setLayerAbstract(strLayerAbstract);
       
        // ---- child style
       
        String strStyleNames = null;
       
        if (styStyleChild != null)
        {
           strStyleNames = styStyleChild.getName();
           linfo.setStyleNames(strStyleNames);
        }
       
        // ----
       
       
        String strDisplayName = InfoChildWms._s_makeTitle_(
                strLayerNames, strStyleNames, capWms);
       

        linfo.setDisplayName(strDisplayName);

        return linfo;
    }
  
   static private String _s_makeTitle_(
           String strLayerNames,
           String strStyleNames,
           GfrWMSCapabilities caps)
    {
        String[] strsLayerNames = strLayerNames.split(",");
        String[] strsStyleNames = strStyleNames != null ? strStyleNames.split(",") : null;

        StringBuilder sb = new StringBuilder();
       
        for (int i = 0; i < strsLayerNames.length; i++)
        {
            if (sb.length() > 0)
                sb.append(", ");

            String layerName = strsLayerNames[i];
            WMSLayerCapabilities lc = caps.getLayerByName(layerName);
            String layerTitle = lc.getTitle();
            sb.append(layerTitle != null ? layerTitle : layerName);

            if (strsStyleNames == null || strsStyleNames.length <= i)
                continue;

            String styleName = strsStyleNames[i];
            WMSLayerStyle style = lc.getStyleByName(styleName);
           
            if (style == null)
                continue;

            sb.append(" : ");
            String styleTitle = style.getTitle();
            sb.append(styleTitle != null ? styleTitle : styleName);
        }

        return sb.toString();
    }
  
   // end static
  

   private GfrWMSCapabilities _caps_ = null;
   private AVListImpl _params_ = null;

   public GfrWMSCapabilities getCaps()
   {
      return this._caps_;
   }

   public AVListImpl getParams()
   {
      return this._params_;
   }
  
   //
  
   public void setStyleNames(String str)
   {
      this._params_.setValue(AVKey.STYLE_NAMES, str);
   }
  
   public void setDisplayName(String str)
   {
      this._params_.setValue(AVKey.DISPLAY_NAME, str);
   }
  
   public void setLayerNames(String str)
   {
      this._params_.setValue(AVKey.LAYER_NAMES, str);
   }
  
   public void setLayerAbstract(String str)
   {
      this._params_.setValue(AVKey.LAYER_ABSTRACT, str);
   }
  
   public String getStyleNames()
   {
      return _params_.getStringValue(AVKey.STYLE_NAMES);
   }

   public String getDisplayName()
   {
      return _params_.getStringValue(AVKey.DISPLAY_NAME);
   }

   public String getLayerNames()
   {
      return _params_.getStringValue(AVKey.LAYER_NAMES);
   }

   public String getLayerAbstract()
   {
      return _params_.getStringValue(AVKey.LAYER_ABSTRACT);
   }

   private InfoChildWms(GfrWMSCapabilities caps)
   {
      this._caps_ = caps;
      this._params_ = new AVListImpl();
   }
}
TOP

Related Classes of org.geoforge.worldwindogc.factory.InfoChildWms

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.