private String source(StoreInfo store) {
   if (store instanceof CoverageStoreInfo) {
     CoverageStoreInfo coverage = (CoverageStoreInfo) store;
     return sourceURL(coverage.getURL());
   }
   GeoServerResourceLoader resourceLoader = geoServer.getCatalog().getResourceLoader();
   Map<String, Serializable> params =
       ResourcePool.getParams(store.getConnectionParameters(), resourceLoader);
   if (params.containsKey("dbtype")) {
     // See JDBCDataStoreFactory for details
     String host = Converters.convert(params.get("host"), String.class);
     String port = Converters.convert(params.get("port"), String.class);
     String dbtype = Converters.convert(params.get("dbtype"), String.class);
     String schema = Converters.convert(params.get("schema"), String.class);
     String database = Converters.convert(params.get("database"), String.class);
     StringBuilder source = new StringBuilder();
     source.append(host);
     if (port != null) {
       source.append(':').append(port);
     }
     source.append('/').append(dbtype).append('/').append(database);
     if (schema != null) {
       source.append('/').append(schema);
     }
     return source.toString();
   } else if (store instanceof WMSStoreInfo) {
     String url = ((WMSStoreInfo) store).getCapabilitiesURL();
     return url;
   } else if (params.keySet().contains("directory")) {
     String directory = Converters.convert(params.get("directory"), String.class);
     return sourceFile(directory);
   } else if (params.keySet().contains("file")) {
     String file = Converters.convert(params.get("file"), String.class);
     return sourceFile(file);
   }
   if (params.containsKey("url")) {
     String url = Converters.convert(params.get("url"), String.class);
     return sourceURL(url);
   }
   for (Object value : params.values()) {
     if (value instanceof URL) {
       return source((URL) value);
     }
     if (value instanceof File) {
       return source((File) value);
     }
     if (value instanceof String) {
       String text = (String) value;
       if (text.startsWith("file:")) {
         return sourceURL(text);
       } else if (text.startsWith("http:")
           || text.startsWith("https:")
           || text.startsWith("ftp:")) {
         return text;
       }
     }
   }
   return "undertermined";
 }
Beispiel #2
0
 public void setValue(Object value) {
   String txt = (String) Converters.convert(value, String.class);
   if (txt == null) {
     txt = "";
   }
   text.setText(txt);
 }
  private void testNearest(
      String typeName, String attributeName, Object target, Object... validResults)
      throws IOException {
    FilterFactory ff = CommonFactoryFinder.getFilterFactory();
    PropertyName expr = ff.property(aname(attributeName));

    MyNearestVisitor v = new MyNearestVisitor(expr, target);
    dataStore.getFeatureSource(tname(typeName)).accepts(Query.ALL, v, null);
    assertFalse(visited);
    Object nearestMatch = v.getNearestMatch();
    if (validResults.length == 0) {
      assertNull(nearestMatch);
    } else {
      boolean found = false;
      for (Object object : validResults) {
        if (object.equals(Converters.convert(nearestMatch, object.getClass()))) {
          found = true;
          break;
        }
      }
      assertTrue(
          "Could not match nearest "
              + nearestMatch
              + " among valid values "
              + Arrays.asList(validResults),
          found);
    }
  }
Beispiel #4
0
 /**
  * Overrides to handle the case of encoding {@code java.util.Date} and its date/time/timestamp
  * descendants, as well as {@code java.util.Calendar} instances as ISO 8601 strings. In addition
  * handles rounding numbers to the specified number of decimal points.
  *
  * @see net.sf.json.util.JSONBuilder#value(java.lang.Object)
  */
 @Override
 public GeoJSONBuilder value(Object value) {
   if (value instanceof java.util.Date || value instanceof Calendar) {
     value = Converters.convert(value, String.class);
   }
   super.value(value);
   return this;
 }
  public <T> T get(String key, Class<T> clazz) {
    Object obj = get(key);
    if (obj == null) {
      return null;
    }

    return Converters.convert(obj, clazz);
  }
 /**
  * Encode the simpleContent property of a ComplexAttribute (if any) as an XML text node.
  *
  * <p>A property named simpleContent is a convention for representing XSD complexType with
  * simpleContent in GeoAPI.
  *
  * @param complex the ComplexAttribute to be searched for simpleContent
  * @param document the containing document
  * @param element the element to which text node should be added
  */
 public static void encodeSimpleContent(
     ComplexAttribute complex, Document document, Element element) {
   Object value = getSimpleContent(complex);
   if (value != null) {
     Text text = document.createTextNode(Converters.convert(value, String.class));
     element.appendChild(text);
   }
 }
Beispiel #7
0
 /**
  * Returns the the kmplacemark value (either specified in the request, or the default one)
  *
  * @param mapContent
  * @return
  */
 public static boolean getKmplacemark(GetMapRequest request, WMS wms) {
   Object kmplacemark = request.getFormatOptions().get("kmplacemark");
   if (kmplacemark != null) {
     return Converters.convert(kmplacemark, Boolean.class);
   } else {
     return wms.getKmlPlacemark();
   }
 }
Beispiel #8
0
 /**
  * Returns the the kmscore value (either specified in the request, or the default one)
  *
  * @param mapContent
  * @return
  */
 public static int getKmScore(GetMapRequest request, WMS wms) {
   Object kmscore = request.getFormatOptions().get("kmscore");
   if (kmscore != null) {
     return Converters.convert(kmscore, Integer.class);
   } else {
     return wms.getKmScore();
   }
 }
Beispiel #9
0
 public Object getValue() {
   String txt = text.getText();
   if (txt.length() == 0) {
     return null;
   }
   Object value = Converters.convert(txt, parameter.type);
   return value;
 }
Beispiel #10
0
 /**
  * Returns the the kmattr value (either specified in the request, or the default one)
  *
  * @param mapContent
  * @return
  */
 public static boolean getKMAttr(GetMapRequest request, WMS wms) {
   Object kmattr = request.getFormatOptions().get("kmattr");
   if (kmattr != null) {
     return Converters.convert(kmattr, Boolean.class);
   } else {
     return wms.getKmlKmAttr();
   }
 }
Beispiel #11
0
  int getMetadataPercentage(MetadataMap metadata, String key, int defaultValue) {
    Integer parsedValue = Converters.convert(metadata.get(key), Integer.class);
    if (parsedValue == null) return defaultValue;
    int value = parsedValue.intValue();
    if (value < 0 || value > 100) {
      LOGGER.warning("Invalid percertage value for '" + key + "', it should be between 0 and 100");
      return defaultValue;
    }

    return value;
  }
Beispiel #12
0
  <T> T getMetadataValue(String key, T defaultValue, Class<T> clazz) {
    if (getServiceInfo() == null) {
      return defaultValue;
    }

    MetadataMap metadata = getServiceInfo().getMetadata();

    T parsedValue = Converters.convert(metadata.get(key), clazz);
    if (parsedValue == null) return defaultValue;

    return parsedValue;
  }
  public void visit(Binding binding) {
    // TODO: visit should return a boolena to signify wether to continue
    if (child != null) {
      return;
    }

    if (binding instanceof ComplexBinding) {
      ComplexBinding complex = (ComplexBinding) binding;

      if (binding.getType() == null) {
        LOGGER.warning("Binding for: " + binding.getTarget() + " does not declare type");
      }

      Object parent = this.parent;

      if ((binding.getType() != null) && !binding.getType().isAssignableFrom(parent.getClass())) {
        LOGGER.fine(
            parent
                + " ("
                + parent.getClass().getName()
                + ") "
                + " is not of type "
                + binding.getType().getName());

        // try to convert
        Object converted = Converters.convert(parent, binding.getType());

        if (converted != null) {
          parent = converted;
        } else {
          LOGGER.fine("Could not convert " + parent + " to " + binding.getType().getName());
          // For complex feature, if the feature can't be converted to the binding type,
          // exit the route to avoid ClassCastException raised in
          // child = complex.getProperty(parent, name);
          // For example, MeasureTypeBinding.getProperty(parent, name) throws
          // ClassCastException when 'uom' is not set.
          if (parent instanceof ComplexAttributeImpl) {
            return;
          }
        }
      }

      try {
        child = complex.getProperty(parent, name);
      } catch (Exception e) {
        throw new RuntimeException("Failed to get property: " + name, e);
      }
    }
  }
Beispiel #14
0
 public boolean validate() {
   String txt = text.getText();
   if (txt.length() == 0) {
     return true;
   }
   Object value = Converters.convert(txt, parameter.type);
   if (value == null) {
     text.setToolTipText("Could not create " + parameter.type);
     text.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
     return false;
   } else {
     text.setToolTipText(null);
     text.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
     return true;
   }
 }
 /**
  * Parses the value of the current attribute, parser cursor shall be on a feature attribute
  * START_TAG event.
  *
  * @return
  * @throws IOException
  * @throws XmlPullParserException
  * @throws FactoryException
  * @throws NoSuchAuthorityCodeException
  */
 @SuppressWarnings("unchecked")
 private Object parseAttributeValue() throws XmlPullParserException, IOException {
   final String name = parser.getName();
   final AttributeDescriptor attribute = expectedProperties.get(name);
   final AttributeType type = attribute.getType();
   Object parsedValue;
   if (type instanceof GeometryType) {
     parser.nextTag();
     try {
       parsedValue = parseGeom();
     } catch (NoSuchAuthorityCodeException e) {
       throw new DataSourceException(e);
     } catch (FactoryException e) {
       throw new DataSourceException(e);
     }
   } else {
     String rawTextValue = parser.nextText();
     Class binding = type.getBinding();
     parsedValue = Converters.convert(rawTextValue, binding);
   }
   return parsedValue;
 }
Beispiel #16
0
 public boolean isSvgAntiAlias() {
   WMSInfo serviceInfo = getServiceInfo();
   Boolean svgAntiAlias =
       Converters.convert(serviceInfo.getMetadata().get("svgAntiAlias"), Boolean.class);
   return svgAntiAlias == null ? true : svgAntiAlias.booleanValue();
 }
Beispiel #17
0
 /** Parses the string into a numberic value. */
 public Object parse(String value) throws Exception {
   return Converters.convert(value, getBinding());
 }
Beispiel #18
0
 public boolean getKmlKmAttr() {
   Boolean kmAttr =
       Converters.convert(getServiceInfo().getMetadata().get(KML_KMLATTR), Boolean.class);
   return kmAttr == null ? KML_KMLATTR_DEFAULT : kmAttr.booleanValue();
 }
Beispiel #19
0
 public boolean getKmlPlacemark() {
   Boolean kmAttr =
       Converters.convert(getServiceInfo().getMetadata().get(KML_KMLPLACEMARK), Boolean.class);
   return kmAttr == null ? KML_KMLPLACEMARK_DEFAULT : kmAttr.booleanValue();
 }