protected String validateMetadata(Object source, AVList params) { StringBuilder sb = new StringBuilder(); String message = super.validateMetadata(source, params); if (message != null) sb.append(message); Object o = (params != null) ? params.getValue(AVKey.BYTE_ORDER) : null; if (o == null || !(o instanceof String)) sb.append(sb.length() > 0 ? ", " : "") .append(Logging.getMessage("WorldFile.NoByteOrderSpecified", source)); o = (params != null) ? params.getValue(AVKey.PIXEL_FORMAT) : null; if (o == null) { sb.append(sb.length() > 0 ? ", " : "") .append(Logging.getMessage("WorldFile.NoPixelFormatSpecified", source)); } else if (!AVKey.ELEVATION.equals(o)) { sb.append(sb.length() > 0 ? ", " : "") .append(Logging.getMessage("WorldFile.InvalidPixelFormat", source)); } o = (params != null) ? params.getValue(AVKey.PIXEL_TYPE) : null; if (o == null) { o = (params != null) ? params.getValue(AVKey.DATA_TYPE) : null; if (o == null) { sb.append(sb.length() > 0 ? ", " : "") .append(Logging.getMessage("WorldFile.NoPixelTypeSpecified", source)); } } if (sb.length() == 0) return null; return sb.toString(); }
private java.nio.ByteBuffer readElevations(Object source) throws java.io.IOException { if (!(source instanceof java.io.File) && !(source instanceof java.net.URL)) { String message = Logging.getMessage("DataRaster.CannotRead", source); Logging.logger().severe(message); throw new java.io.IOException(message); } if (source instanceof java.io.File) { java.io.File file = (java.io.File) source; // handle .bil.zip, .bil16.zip, and .bil32.gz files if (file.getName().toLowerCase().endsWith(".zip")) { return WWIO.readZipEntryToBuffer(file, null); } // handle bil.gz, bil16.gz, and bil32.gz files else if (file.getName().toLowerCase().endsWith(".gz")) { return WWIO.readGZipFileToBuffer(file); } else if (!this.isMapLargeFiles() || (this.getLargeFileThreshold() > file.length())) { return WWIO.readFileToBuffer(file); } else { return WWIO.mapFile(file); } } else // (source instanceof java.net.URL) { java.net.URL url = (java.net.URL) source; return WWIO.readURLContentToBuffer(url); } }
/** * Specifies the units in which to display length values. Units subsequently formatted by the * instance are converted from meters to the desired units prior to formatting. * * @param lengthUnits the desired length units. See {@link #UnitsFormat(String, String, boolean)} * for the list of those available. * @throws IllegalArgumentException if <code>lengthUnits</code> is null. */ public void setLengthUnits(String lengthUnits) { if (lengthUnits == null) { String msg = Logging.getMessage("nullValue.LengthUnit"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } this.lengthUnits = lengthUnits; if (lengthUnits.equals(UnitsFormat.KILOMETERS)) { this.lengthUnitsMultiplier = WWMath.METERS_TO_KILOMETERS; this.lengthUnitsSymbol = UnitsFormat.SYMBOL_KILOMETERS; } else if (lengthUnits.equals(UnitsFormat.MILES)) { this.lengthUnitsMultiplier = WWMath.METERS_TO_MILES; this.lengthUnitsSymbol = UnitsFormat.SYMBOL_MILES; } else if (lengthUnits.equals(UnitsFormat.NAUTICAL_MILES)) { this.lengthUnitsMultiplier = WWMath.METERS_TO_NAUTICAL_MILES; this.lengthUnitsSymbol = UnitsFormat.SYMBOL_NAUTICAL_MILES; } else if (lengthUnits.equals(UnitsFormat.YARDS)) { this.lengthUnitsMultiplier = WWMath.METERS_TO_YARDS; this.lengthUnitsSymbol = UnitsFormat.SYMBOL_YARDS; } else if (lengthUnits.equals(UnitsFormat.FEET)) { this.lengthUnitsMultiplier = WWMath.METERS_TO_FEET; this.lengthUnitsSymbol = UnitsFormat.SYMBOL_FEET; } else { this.lengthUnitsMultiplier = 1d; this.lengthUnitsSymbol = UnitsFormat.SYMBOL_METERS; } }
/** * Appends elevation model parameters as elements to a specified context. If a parameter key * exists, that parameter is appended to the context. Supported key and element paths are: * * <table> <th><td>Key</td><td>Name</td><td>Type</td></th> * <tr><td>{@link AVKey#DISPLAY_NAME}</td><td>DisplayName</td><td>String</td></tr> <tr><td>{@link * AVKey#NETWORK_RETRIEVAL_ENABLED}</td><td>NetworkRetrievalEnabled</td><td>Boolean</td></tr> <tr><td>{@link * AVKey#MISSING_DATA_SIGNAL}</td><td>MissingData/@signal</td><td>Double</td></tr> <tr><td>{@link * AVKey#MISSING_DATA_REPLACEMENT}</td><td>MissingData/@replacement</td><td>Double</td></tr> <tr><td>{@link * AVKey#DETAIL_HINT}</td><td>DataDetailHint</td><td>Double</td></tr> </table> * * @param params the key-value pairs which define the elevation model parameters. * @param context the XML document root on which to append parameter elements. * @return a reference to context. * @throws IllegalArgumentException if either the parameters or the context are null. */ public static Element createElevationModelElements(AVList params, Element context) { if (params == null) { String message = Logging.getMessage("nullValue.ParametersIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (context == null) { String message = Logging.getMessage("nullValue.ContextIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } WWXML.checkAndAppendTextElement(params, AVKey.DISPLAY_NAME, context, "DisplayName"); WWXML.checkAndAppendBooleanElement( params, AVKey.NETWORK_RETRIEVAL_ENABLED, context, "NetworkRetrievalEnabled"); if (params.getValue(AVKey.MISSING_DATA_SIGNAL) != null || params.getValue(AVKey.MISSING_DATA_REPLACEMENT) != null) { Element el = WWXML.getElement(context, "MissingData", null); if (el == null) el = WWXML.appendElementPath(context, "MissingData"); Double d = AVListImpl.getDoubleValue(params, AVKey.MISSING_DATA_SIGNAL); if (d != null) el.setAttribute("signal", Double.toString(d)); d = AVListImpl.getDoubleValue(params, AVKey.MISSING_DATA_REPLACEMENT); if (d != null) el.setAttribute("replacement", Double.toString(d)); } WWXML.checkAndAppendDoubleElement(params, AVKey.DETAIL_HINT, context, "DataDetailHint"); return context; }
/** * @param placeNameServiceSet the set of PlaceNameService objects that PlaceNameLayer will render. * @throws IllegalArgumentException if {@link * gov.nasa.worldwind.layers.placename.PlaceNameServiceSet} is null */ public PlaceNameLayer(PlaceNameServiceSet placeNameServiceSet) { if (placeNameServiceSet == null) { String message = Logging.getMessage("nullValue.PlaceNameServiceSetIsNull"); Logging.logger().fine(message); throw new IllegalArgumentException(message); } // this.placeNameServiceSet = placeNameServiceSet.deepCopy(); for (int i = 0; i < this.placeNameServiceSet.getServiceCount(); i++) { // todo do this for long as well and pick min int calc1 = (int) (PlaceNameService.TILING_SECTOR.getDeltaLatDegrees() / this.placeNameServiceSet .getService(i) .getTileDelta() .getLatitude() .getDegrees()); int numLevels = (int) Math.log(calc1); navTiles.add( new NavigationTile( this.placeNameServiceSet.getService(i), PlaceNameService.TILING_SECTOR, numLevels, "top")); } if (!WorldWind.getMemoryCacheSet().containsCache(Tile.class.getName())) { long size = Configuration.getLongValue(AVKey.PLACENAME_LAYER_CACHE_SIZE, 2000000L); MemoryCache cache = new BasicMemoryCache((long) (0.85 * size), size); cache.setName("Placename Tiles"); WorldWind.getMemoryCacheSet().addCache(Tile.class.getName(), cache); } }
/** * @param fileName the name to give the newly created file * @return a handle to the newly created file if it could be created and added to the file store, * otherwise null * @throws IllegalArgumentException if <code>fileName</code> is null */ public java.io.File newFile(String fileName) { if (fileName == null) { String message = Logging.getMessage("nullValue.FilePathIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (this.writeLocation != null) { String fullPath = makeAbsolutePath(this.writeLocation.getFile(), fileName); java.io.File file = new java.io.File(fullPath); boolean canCreateFile = false; // This block of code must be synchronized for proper operation. A thread may check that // file.getParentFile() does not exist, and become immediately suspended. A second thread may // then create // the parent and ancestor directories. When the first thread wakes up, // file.getParentFile().mkdirs() // fails, resulting in an erroneous log message: The log reports that the file cannot be // created. synchronized (this.fileLock) { if (file.getParentFile().exists()) canCreateFile = true; else if (file.getParentFile().mkdirs()) canCreateFile = true; } if (canCreateFile) return file; else { String msg = Logging.getMessage("generic.CannotCreateFile", fullPath); Logging.logger().severe(msg); } } return null; }
/** * @param url the "file:" URL of the file to remove from the file store. Only files in the * writable World Wind disk cache or temp file directory are removed by this method. * @throws IllegalArgumentException if <code>url</code> is null */ @SuppressWarnings({"ResultOfMethodCallIgnored"}) public void removeFile(java.net.URL url) { if (url == null) { String msg = Logging.getMessage("nullValue.URLIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } try { java.io.File file = new java.io.File(url.toURI()); // This block of code must be synchronized for proper operation. A thread may check that the // file exists, // and become immediately suspended. A second thread may then delete that file. When the first // thread // wakes up, file.delete() fails. synchronized (this.fileLock) { if (file.exists()) { // Don't remove files outside the cache or temp directory. String parent = file.getParent(); if (!(parent.startsWith(this.getWriteLocation().getPath()) || parent.startsWith(Configuration.getSystemTempDirectory()))) return; file.delete(); } } } catch (java.net.URISyntaxException e) { Logging.logger() .log( Level.SEVERE, Logging.getMessage("FileStore.ExceptionRemovingFile", url.toString()), e); } }
/** * Specifies the units in which to display area values. Units subsequently formatted by the * instance are converted from square meters to the desired units prior to formatting. * * @param areaUnits the desired length units. See {@link #UnitsFormat(String, String, boolean)} * for the list of those available. * @throws IllegalArgumentException if <code>areaUnits</code> is null. */ public void setAreaUnits(String areaUnits) { if (areaUnits == null) { String msg = Logging.getMessage("nullValue.AreaUnit"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } this.areaUnits = areaUnits; if (areaUnits.equals(UnitsFormat.SQUARE_KILOMETERS)) { this.areaUnitsMultiplier = WWMath.SQUARE_METERS_TO_SQUARE_KILOMETERS; this.areaUnitsSymbol = UnitsFormat.SYMBOL_SQUARE_KILOMETERS; } else if (areaUnits.equals(UnitsFormat.SQUARE_MILES)) { this.areaUnitsMultiplier = WWMath.SQUARE_METERS_TO_SQUARE_MILES; this.areaUnitsSymbol = UnitsFormat.SYMBOL_SQUARE_MILES; } else if (areaUnits.equals(UnitsFormat.HECTARE)) { this.areaUnitsMultiplier = WWMath.SQUARE_METERS_TO_HECTARES; this.areaUnitsSymbol = UnitsFormat.SYMBOL_HECTARE; } else if (areaUnits.equals(UnitsFormat.ACRE)) { this.areaUnitsMultiplier = WWMath.SQUARE_METERS_TO_ACRES; this.areaUnitsSymbol = UnitsFormat.SYMBOL_ACRE; } else if (areaUnits.equals(UnitsFormat.SQUARE_YARDS)) { this.areaUnitsMultiplier = WWMath.SQUARE_METERS_TO_SQUARE_YARDS; this.areaUnitsSymbol = UnitsFormat.SYMBOL_SQUARE_YARDS; } else if (areaUnits.equals(UnitsFormat.SQUARE_FEET)) { this.areaUnitsMultiplier = WWMath.SQUARE_METERS_TO_SQUARE_FEET; this.areaUnitsSymbol = UnitsFormat.SYMBOL_SQUARE_FEET; } else { this.areaUnitsMultiplier = 1d; this.areaUnitsSymbol = UnitsFormat.SYMBOL_SQUARE_METERS; } }
protected static String determineSingleUserLocation() { String home = getUserHomeDir(); if (home == null) { Logging.logger().warning("generic.UsersHomeDirectoryNotKnown"); return null; } String path = null; if (gov.nasa.worldwind.Configuration.isMacOS()) { path = "/Library/Caches"; } else if (gov.nasa.worldwind.Configuration.isWindowsOS()) { // This produces an incorrect path with duplicate parts, // like "C:\Users\PatC:\Users\Pat\Application Data". // path = System.getenv("USERPROFILE"); // if (path == null) // { // Logging.logger().fine("generic.UsersWindowsProfileNotKnown"); // return null; // } // path += "\\Application Data"; path = "\\Application Data"; } else if (gov.nasa.worldwind.Configuration.isLinuxOS() || gov.nasa.worldwind.Configuration.isUnixOS() || gov.nasa.worldwind.Configuration.isSolarisOS()) { path = "/var/cache/"; } else { Logging.logger().fine("generic.UnknownOperatingSystem"); } if (path == null) return null; return home + path; }
public synchronized void logUnavailableHost(URL url) { if (this.offlineMode) return; if (url == null) { String message = Logging.getMessage("nullValue.URLIsNull"); Logging.error(message); throw new IllegalArgumentException(message); } String hostName = url.getHost(); HostInfo hi = this.hostMap.get(hostName); if (hi != null) { if (!hi.isUnavailable()) { hi.logCount.incrementAndGet(); if (hi.isUnavailable()) // host just became unavailable this.firePropertyChange(NetworkStatus.HOST_UNAVAILABLE, null, url); } hi.lastLogTime.set(System.currentTimeMillis()); } else { hi = new HostInfo(this.attemptLimit.get(), this.tryAgainInterval.get()); hi.logCount.set(1); if (hi.isUnavailable()) // the attempt limit may be as low as 1, so handle that case here this.firePropertyChange(NetworkStatus.HOST_UNAVAILABLE, null, url); this.hostMap.put(hostName, hi); } this.lastUnavailableLogTime.set(System.currentTimeMillis()); }
protected boolean loadTile(Tile tile, java.net.URL url) { if (WWIO.isFileOutOfDate(url, this.placeNameServiceSet.getExpiryTime())) { // The file has expired. Delete it then request download of newer. this.getDataFileStore().removeFile(url); String message = Logging.getMessage("generic.DataFileExpired", url); Logging.logger().fine(message); return false; } PlaceNameChunk tileData; synchronized (this.fileLock) { tileData = readTileData(tile, url); } if (tileData == null) { // Assume that something's wrong with the file and delete it. this.getDataFileStore().removeFile(url); tile.getPlaceNameService() .markResourceAbsent(tile.getPlaceNameService().getTileNumber(tile.row, tile.column)); String message = Logging.getMessage("generic.DeletedCorruptDataFile", url); Logging.logger().fine(message); return false; } tile.setDataChunk(tileData); WorldWind.getMemoryCache(Tile.class.getName()).add(tile.getFileCachePath(), tile); return true; }
@Override protected Layer doCreateFromCapabilities(OGCCapabilities caps, AVList params) { String serviceName = caps.getServiceInformation().getServiceName(); if (serviceName == null || !(serviceName.equalsIgnoreCase(OGCConstants.WMS_SERVICE_NAME) || serviceName.equalsIgnoreCase("WMS"))) { String message = Logging.getMessage("WMS.NotWMSService", serviceName != null ? serviceName : "null"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } if (params == null) params = new AVListImpl(); if (params.getStringValue(AVKey.LAYER_NAMES) == null) { // Use the first named layer since no other guidance given List<WMSLayerCapabilities> namedLayers = ((WMSCapabilities) caps).getNamedLayers(); if (namedLayers == null || namedLayers.size() == 0 || namedLayers.get(0) == null) { String message = Logging.getMessage("WMS.NoLayersFound"); Logging.logger().severe(message); throw new IllegalStateException(message); } params.setValue(AVKey.LAYER_NAMES, namedLayers.get(0).getName()); } return new WMSTiledImageLayer((WMSCapabilities) caps, params); }
static Angle computeColumnLongitude(int column, Angle delta) { if (delta == null) { String msg = Logging.getMessage("nullValue.AngleIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } return Angle.fromDegrees(-180 + delta.getDegrees() * column); }
static Angle computeRowLatitude(int row, Angle delta) { if (delta == null) { String msg = Logging.getMessage("nullValue.AngleIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } return Angle.fromDegrees(-90d + delta.getDegrees() * row); }
static int computeColumn(Angle delta, Angle longitude) { if (delta == null || longitude == null) { String msg = Logging.getMessage("nullValue.AngleIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } return (int) ((longitude.getDegrees() + 180d) / delta.getDegrees()); }
public GeotiffWriter(File file) throws IOException { if (null == file) { String msg = Logging.getMessage("nullValue.FileIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } commonInitializer(file); }
public void setTryAgainInterval(long interval) { if (interval < 0) { String message = Logging.getMessage("NetworkStatus.InvalidTryAgainInterval"); Logging.error(message); throw new IllegalArgumentException(message); } this.tryAgainInterval.set(interval); }
public void setLargeFileThreshold(long largeFileThreshold) { if (largeFileThreshold < 0L) { String message = Logging.getMessage("generic.ArgumentOutOfRange", "largeFileThreshold < 0"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } this.largeFileThreshold = largeFileThreshold; }
/** * Format an angle according to the current angle format. Prepend a specified label and append a * new-line character. * * @param label a label to prepend to the formatted angle. May be null to indicate no label. * @param angle the angle to format. * @return a string containing the formatted angle prepended with the specified label and ending * with the new-line character. * @throws IllegalArgumentException if the angle is null. */ public String angleNL(String label, Angle angle) { if (angle == null) { String msg = Logging.getMessage("nullValue.AngleIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } return this.angle(label, angle) + NL; }
/** * Format angles of latitude and longitude according to the current angle format, and append a * new-line character. * * <p>The values are formatted using the current {@link #LABEL_LATLON_LAT}, {@link * #LABEL_LATLON_LON} and angle format. * * @param latlon the angles to format. * @return a string containing the formatted angles and ending with the new-line character. * @throws IllegalArgumentException if <code>latlon</code> is null. */ public String latLonNL(LatLon latlon) { if (latlon == null) { String msg = Logging.getMessage("nullValue.LatLonIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } return this.latLon(latlon) + NL; }
public void setAttemptLimit(int limit) { if (limit < 1) { String message = Logging.getMessage("NetworkStatus.InvalidAttemptLimit"); Logging.error(message); throw new IllegalArgumentException(message); } this.attemptLimit.set(limit); }
/** * Format an angle of longitude and append a new-line character. * * <p>The value is formatted using the current {@link #LABEL_LONGITUDE} and angle format. * * @param angle the angle to format. * @return a string containing the formatted angle and ending with the new-line character. */ public String longitudeNL(Angle angle) { if (angle == null) { String msg = Logging.getMessage("nullValue.AngleIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } return this.angleNL(this.getLabel(LABEL_LONGITUDE), angle); }
/** * Format an angle of heading according to the current angle format. * * <p>The value is formatted using the current {@link #LABEL_HEADING} and angle format. * * @param angle the heading angle to format. * @return a string containing the formatted angle. * @throws IllegalArgumentException if the angle is null. */ public String heading(Angle angle) { if (angle == null) { String msg = Logging.getMessage("nullValue.AngleIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } return this.angle(this.getLabel(LABEL_HEADING), angle); }
/** * Returns the format for a spcified value type. * * @param formatName the name of the value type whose format is desired. * @return the format, or null if the format does not exist. * @throws IllegalArgumentException if the format name is null. */ public String getFormat(String formatName) { if (formatName == null) { String msg = Logging.getMessage("nullValue.FormatKey"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } return this.getStringValue(formatName); }
/** * Returns the label for a spcified label name. * * @param labelName the name of the label to return. * @return the label, or null if the label does not exist. * @throws IllegalArgumentException if the label name is null. */ public String getLabel(String labelName) { if (labelName == null) { String msg = Logging.getMessage("nullValue.LabelKey"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } return this.getStringValue(labelName); }
public boolean isInstallLocation(String path) { if (path == null || path.length() == 0) { String message = Logging.getMessage("nullValue.FileStorePathIsNull"); Logging.logger().severe(message); throw new IllegalArgumentException(message); } StoreLocation location = this.storeLocationFor(path); return location != null && location.isInstall(); }
public String[] listFileNames(String pathName, FileStoreFilter filter) { if (filter == null) { String msg = Logging.getMessage("nullValue.FilterIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } // Do not recurse. return this.doListFileNames(pathName, filter, false, false); }
public String[] listTopFileNames(String pathName, FileStoreFilter filter) { if (filter == null) { String msg = Logging.getMessage("nullValue.FilterIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } // Recurse, but stop searching a branch after a match is found. return this.doListFileNames(pathName, filter, true, true); }
public GeotiffWriter(String filename) throws IOException { if (null == filename || 0 == filename.trim().length()) { String msg = Logging.getMessage("generic.FileNameIsMissing"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } // the initializer does the validity checking... commonInitializer(new File(filename)); }
/** * @param that the task to compare * @return -1 if <code>this</code> less than <code>that</code>, 1 if greater than, 0 if equal * @throws IllegalArgumentException if <code>that</code> is null */ public int compareTo(RequestTask that) { if (that == null) { String msg = Logging.getMessage("nullValue.RequestTaskIsNull"); Logging.logger().severe(msg); throw new IllegalArgumentException(msg); } return this.tile.getPriority() == that.tile.getPriority() ? 0 : this.tile.getPriority() < that.tile.getPriority() ? -1 : 1; }