📄 xmlconfigwriter.java
字号:
}
if (cv.getEnvelope() != null) {
GeneralEnvelope e = cv.getEnvelope();
m = new HashMap();
if ((cv.getSrsName() != null) && (cv.getSrsName() != "")) {
m.put("srsName", cv.getSrsName());
}
m.put("crs", cv.getCrs().toWKT().replaceAll("\"", "'").replaceAll("\r\n", "\n"));
if (!e.isNull()) {
cw.openTag("envelope", m);
cw.textTag("pos",
e.getLowerCorner().getOrdinate(0) + " " + e.getLowerCorner().getOrdinate(1));
cw.textTag("pos",
e.getUpperCorner().getOrdinate(0) + " " + e.getUpperCorner().getOrdinate(1));
cw.closeTag("envelope");
}
}
if (cv.getGrid() != null) {
GridGeometry g = cv.getGrid();
InternationalString[] dimNames = cv.getDimensionNames();
m = new HashMap();
m.put("dimension", new Integer(g.getGridRange().getDimension()));
String lowers = "";
String upers = "";
for (int r = 0; r < g.getGridRange().getDimension(); r++) {
lowers += (g.getGridRange().getLower(r) + " ");
upers += (g.getGridRange().getUpper(r) + " ");
}
cw.openTag("grid", m);
cw.textTag("low", lowers);
cw.textTag("high", upers);
if (dimNames != null) {
for (int dn = 0; dn < dimNames.length; dn++)
cw.textTag("axisName", dimNames[dn].toString());
}
cw.closeTag("grid");
}
if (cv.getDimensions() != null) {
CoverageDimension[] dims = cv.getDimensions();
for (int d = 0; d < dims.length; d++) {
Double[] nulls = dims[d].getNullValues();
cw.openTag("CoverageDimension");
cw.textTag("name", dims[d].getName());
cw.textTag("description", dims[d].getDescription());
if (dims[d].getRange() != null) {
cw.openTag("interval");
cw.textTag("min", Double.toString(dims[d].getRange().getMinimum(true)));
cw.textTag("max", Double.toString(dims[d].getRange().getMaximum(true)));
cw.closeTag("interval");
}
if (nulls != null) {
cw.openTag("nullValues");
for (int n = 0; n < nulls.length; n++) {
cw.textTag("value", nulls[n].toString());
}
cw.closeTag("nullValues");
}
cw.closeTag("CoverageDimension");
}
}
cw.openTag("supportedCRSs");
if ((cv.getRequestCRSs() != null) && (cv.getRequestCRSs().size() != 0)) {
String s = "";
Iterator i = cv.getRequestCRSs().iterator();
if (i.hasNext()) {
s = i.next().toString();
while (i.hasNext()) {
s = s + "," + i.next().toString();
}
}
cw.textTag("requestCRSs", s);
}
if ((cv.getResponseCRSs() != null) && (cv.getResponseCRSs().size() != 0)) {
String s = "";
Iterator i = cv.getResponseCRSs().iterator();
if (i.hasNext()) {
s = i.next().toString();
while (i.hasNext()) {
s = s + "," + i.next().toString();
}
}
cw.textTag("responseCRSs", s);
}
cw.closeTag("supportedCRSs");
m = new HashMap();
if ((cv.getNativeFormat() != null) && (cv.getNativeFormat() != "")) {
m.put("nativeFormat", cv.getNativeFormat());
}
cw.openTag("supportedFormats", m);
if ((cv.getSupportedFormats() != null) && (cv.getSupportedFormats().size() != 0)) {
String s = "";
Iterator i = cv.getSupportedFormats().iterator();
if (i.hasNext()) {
s = i.next().toString();
while (i.hasNext()) {
s = s + "," + i.next().toString();
}
}
cw.textTag("formats", s);
}
cw.closeTag("supportedFormats");
m = new HashMap();
if ((cv.getDefaultInterpolationMethod() != null)
&& (cv.getDefaultInterpolationMethod() != "")) {
m.put("default", cv.getDefaultInterpolationMethod());
}
cw.openTag("supportedInterpolations", m);
if ((cv.getInterpolationMethods() != null)
&& (cv.getInterpolationMethods().size() != 0)) {
String s = "";
Iterator i = cv.getInterpolationMethods().iterator();
if (i.hasNext()) {
s = i.next().toString();
while (i.hasNext()) {
s = s + "," + i.next().toString();
}
}
cw.textTag("interpolationMethods", s);
}
cw.closeTag("supportedInterpolations");
// ///////////////////////////////////////////////////////////////////////
//
// STORING READ PARAMETERS
//
// ///////////////////////////////////////////////////////////////////////
if ((cv.getParameters() != null) && (cv.getParameters().size() != 0)) {
cw.openTag("parameters");
final Iterator i = cv.getParameters().keySet().iterator();
final HashMap temp = new HashMap();
while (i.hasNext()) {
String key = (String) i.next();
if ("values_palette".equalsIgnoreCase(key)) {
String text = "";
Object palVal = cv.getParameters().get(key);
if (palVal instanceof Color[]) {
for (int col = 0; col < ((Color[]) palVal).length; col++) {
String colString = "#"
+ ((Integer.toHexString(((Color) ((Color[]) palVal)[col]).getRed())
.length() > 1)
? Integer.toHexString(((Color) ((Color[]) palVal)[col]).getRed())
: ("0"
+ Integer.toHexString(((Color) ((Color[]) palVal)[col]).getRed())))
+ ((Integer.toHexString(((Color) ((Color[]) palVal)[col])
.getGreen()).length() > 1)
? Integer.toHexString(((Color) ((Color[]) palVal)[col]).getGreen())
: ("0"
+ Integer.toHexString(((Color) ((Color[]) palVal)[col]).getGreen())))
+ ((Integer.toHexString(((Color) ((Color[]) palVal)[col])
.getBlue()).length() > 1)
? Integer.toHexString(((Color) ((Color[]) palVal)[col]).getBlue())
: ("0"
+ Integer.toHexString(((Color) ((Color[]) palVal)[col]).getBlue())));
text += (((col > 0) ? ";" : "") + colString);
}
} else if (palVal instanceof String) {
text = (String) palVal;
}
temp.put("name", key);
temp.put("value", text);
} else {
temp.put("name", key);
temp.put("value",
cv.getParameters().get(key).toString().replaceAll("\"", "'"));
}
cw.attrTag("parameter", temp);
}
cw.closeTag("parameters");
}
cw.closeTag("coverage");
fw.close();
} catch (IOException e) {
throw new ConfigurationException(e);
}
}
/**
* WriterUtils purpose.
*
* <p>
* This is a static class which is used by XMLConfigWriter for File IO
* validation tests.
* </p>
*
* <p></p>
*
* @author dzwiers, Refractions Research, Inc.
* @version $Id: XMLConfigWriter.java 7746 2007-11-13 15:38:35Z aaime $
*/
public static class WriterUtils {
/** Used internally to create log information to detect errors. */
private static final Logger LOGGER = Logger.getLogger("org.vfny.geoserver.global");
/**
* WriterUtils constructor.
*
* <p>
* Static class, should never be used.
* </p>
*/
private WriterUtils() {
}
/**
* initFile purpose.
*
* <p>
* Checks to ensure the handle exists. If the handle is a directory and not
* created, it is created
* </p>
*
* @param f the File handle
* @param isDir true when the handle is intended to be a directory.
*
* @return The file passed in.
*
* @throws ConfigurationException When an IO error occurs or the handle is
* invalid.
*/
public static File initFile(File f, boolean isDir)
throws ConfigurationException {
if (!f.exists()) {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(new StringBuffer("Creating File: ").append(f.toString()).toString());
}
if (isDir) {
if (!f.mkdir()) {
throw new ConfigurationException(
"Path specified does not have a valid file.\n" + f + "\n\n");
}
} else {
try {
if (LOGGER.isLoggable(Level.SEVERE)) {
LOGGER.severe(new StringBuffer("Attempting to create file:").append(
f.getAbsolutePath()).toString());
}
if (!f.createNewFile()) {
throw new ConfigurationException(
"Path specified does not have a valid file.\n" + f + "\n\n");
}
} catch (IOException e) {
throw new ConfigurationException(e);
}
}
}
if (isDir && !f.isDirectory()) {
throw new ConfigurationException("Path specified does not have a valid file.\n" + f
+ "\n\n");
}
if (!isDir && !f.isFile()) {
throw new ConfigurationException("Path specified does not have a valid file.\n" + f
+ "\n\n");
}
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(new StringBuffer("File is valid: ").append(f).toString());
}
return f;
}
/**
* initFile purpose.
*
* <p>
* Checks to ensure the handle exists and can be writen to. If the handle
* is a directory and not created, it is created
* </p>
*
* @param f the File handle
* @param isDir true when the handle is intended to be a directory.
*
* @return The file passed in.
*
* @throws ConfigurationException When an IO error occurs or the handle is
* invalid.
*/
public static File initWriteFile(File f, boolean isDir)
throws ConfigurationException {
initFile(f, isDir);
if (!f.canWrite()) {
throw new ConfigurationException("Cannot Write to file: " + f.toString());
}
return f;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -