All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.geosolutions.geoserver.rest.decoder.RESTStructuredCoverageGranulesList Maven / Gradle / Ivy

/*
 *  GeoServer-Manager - Simple Manager Library for GeoServer
 *  
 *  Copyright (C) 2007,2011 GeoSolutions S.A.S.
 *  http://www.geo-solutions.it
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package it.geosolutions.geoserver.rest.decoder;

import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.jdom.Element;
import org.jdom.Namespace;

/**
 * This decode turns index format for a GeoServer StructuredGridCoverageReader into something
 * useful, giving access to the definition of the single attributes.
 * 
 * 

This is the XML REST representation: *

  {@code



  
    
      
        5.0
        45.0
      
      
        14.875
        50.9375
      
    
  
  
    
      
        
          
            
              5.0,45.0 5.0,50.9375 14.875,50.9375 14.875,45.0 5.0,45.0
            
          
        
      
      ..\\polyphemus\\polyphemus_20130302.nc
      672
      2013-03-01T23:00:00Z
      10.0
      2013-03-01T23:00:00Z
      2013-04-08T05:40:29.061Z
    
  


}
* @author Simone Giannecchini, GeoSolutions SAS * */ public class RESTStructuredCoverageGranulesList implements Iterable { /** GML_NAMESPACE */ private static final Namespace GML_NAMESPACE = Namespace.getNamespace("gml", "http://www.opengis.net/gml"); private final List granulesList; private final Element bbox; /** * @return the bbox */ public Element getBbox() { return bbox; } /** * @param list */ @SuppressWarnings("unchecked") protected RESTStructuredCoverageGranulesList(Element featureCollection) { // check ordering of elements if(!featureCollection.getName().equals("FeatureCollection")){ throw new IllegalStateException("Root element should be wfs:FeatureCollection"); } Element boundedBy = featureCollection.getChild("boundedBy",GML_NAMESPACE); if(boundedBy==null){ throw new IllegalStateException("Unable to find boundedBy element"); } // save bbox bbox=boundedBy.getChild("Box",GML_NAMESPACE); // now get the feature members List tmpList = new ArrayList(); for(Element el : (List)featureCollection.getChildren("featureMember",GML_NAMESPACE)){ tmpList.add(new RESTStructuredCoverageGranule(el)); } granulesList = Collections.unmodifiableList(tmpList); } public static RESTStructuredCoverageGranulesList build(String response) { if(response == null) return null; Element pb = JDOMBuilder.buildElement(response); if(pb != null){ return new RESTStructuredCoverageGranulesList(pb); } else { return null; } } public int size() { return granulesList.size(); } public boolean isEmpty() { return granulesList.isEmpty(); } public RESTStructuredCoverageGranule get(int index) { return granulesList.get(index); } /* (non-Javadoc) * @see java.lang.Iterable#iterator() */ @Override public Iterator iterator() { return granulesList.iterator(); } /** * Generic granule of the index. * *

This is the XML REST representation: *

  {@code
  
    
      
        
          
            
              5.0,45.0 5.0,50.9375 14.875,50.9375 14.875,45.0 5.0,45.0
            
          
        
      
      polyphemus_20130301.nc
      672
      2013-02-28T23:00:00Z
      10.0
      2013-02-28T23:00:00Z
      2013-04-08T06:18:41.597Z
    
  

     * @author Simone Giannecchini, GeoSolutions SAS
     *
     */
    public static class RESTStructuredCoverageGranule {

        protected final Element granule;
        
        private final String fid;

        private final List children;

        @SuppressWarnings("unchecked")
        public RESTStructuredCoverageGranule(Element elem) {
            if(!elem.getName().equals("featureMember")){
                throw new IllegalStateException("Root element should be gml:featureMember for a granule");
            }
            Element feature = (Element) elem.getChildren().get(0);
            if(feature==null){
                throw new IllegalStateException("Unable to find feature element for this granule");
            }    
            this.granule = feature;
            this.fid=granule.getAttribute("fid").getValue();
            this.children=granule.getChildren();
            
        }

        public String getAttributeByName(String name) {
            return granule.getChildTextTrim(name,null);
        }   

        public String getAttributeByIndex(int index) {
            return children.get(index).getValue();
        }   
        
        @SuppressWarnings("unchecked")
        public Iterator getAttributesIterator() {
            return granule.getChildren().iterator();
        }  
        
        /**
         * @return the fid
         */
        public String getFid() {
            return fid;
        }

        @Override
        public String toString() {
            StringBuilder sb = new StringBuilder();
            sb.append(this.getClass().getSimpleName()).append('[');

            for (Element c : (List)granule.getChildren()) {
                String text = c.getText();
                if(text!= null) {
                    text = text.replace("\n", "");
                    text = text.trim();
                }
                sb.append('(').append(c.getName()).append("=").append(text).append(')');
            }
            sb.append(']');
            return sb.toString();
        }


    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append("RESTStructuredCoverageGranulesList [");
        if (bbox != null) {
            builder.append("bbox=");
            builder.append(bbox);
        }
        if (granulesList != null) {
            builder.append("granulesList={");
            for(RESTStructuredCoverageGranule granule:granulesList){
                builder.append(granule);
            }
            builder.append("}, ");
        }
        builder.append("]");
        return builder.toString();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy