📄 xmlconfigwriter.java
字号:
* Writes a CoverageStoreInfo into the WriterUtils provided.
* </p>
*
* @param cw The Configuration Writer
* @param ds The Format.
*
* @throws ConfigurationException When an IO exception occurs.
*/
protected static void storeFormat(WriterHelper cw, CoverageStoreInfoDTO df)
throws ConfigurationException {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("In method storeFormat");
}
Map temp = new HashMap();
if (df.getId() != null) {
temp.put("id", df.getId());
}
temp.put("enabled", df.isEnabled() + "");
if (df.getNameSpaceId() != null) {
temp.put("namespace", df.getNameSpaceId());
}
cw.openTag("format", temp);
if ((df.getAbstract() != null) && (df.getAbstract() != "")) {
cw.textTag("description", df.getAbstract());
}
if ((df.getTitle() != null) && (df.getTitle() != "")) {
cw.textTag("title", df.getTitle());
}
if ((df.getType() != null) && (df.getType() != "")) {
cw.textTag("type", df.getType());
}
if ((df.getUrl() != null) && (df.getUrl() != "")) {
cw.textTag("url", df.getUrl());
}
cw.closeTag("format");
}
/**
* storeNameSpace purpose.
*
* <p>
* Writes a NameSpaceInfoDTO into the WriterUtils provided.
* </p>
*
* @param cw The Configuration Writer
* @param ns The NameSpaceInfo.
*
* @throws ConfigurationException When an IO exception occurs.
*/
protected static void storeNameSpace(WriterHelper cw, NameSpaceInfoDTO ns)
throws ConfigurationException {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer("In method storeNameSpace");
}
Map attr = new HashMap();
if ((ns.getUri() != null) && (ns.getUri() != "")) {
attr.put("uri", ns.getUri());
}
if ((ns.getPrefix() != null) && (ns.getPrefix() != "")) {
attr.put("prefix", ns.getPrefix());
}
if (ns.isDefault()) {
attr.put("default", "true");
}
if (attr.size() != 0) {
cw.attrTag("namespace", attr);
}
}
/**
* storeStyle purpose.
*
* <p>
* Writes a StyleDTO into the WriterUtils provided.
* </p>
*
* @param cw The Configuration Writer
* @param s The StyleDTO.
*
* @throws ConfigurationException When an IO exception occurs.
*/
protected static void storeStyle(WriterHelper cw, StyleDTO s)
throws ConfigurationException {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(new StringBuffer("In method storeStyle: ").append(s).toString());
}
Map attr = new HashMap();
if ((s.getId() != null) && (s.getId() != "")) {
attr.put("id", s.getId());
}
if (s.getFilename() != null) {
attr.put("filename", s.getFilename().getName());
}
if (s.isDefault()) {
attr.put("default", "true");
}
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(new StringBuffer("storing style ").append(attr).toString());
}
if (attr.size() != 0) {
cw.attrTag("style", attr);
}
}
/**
* storeStyle purpose.
*
* <p>
* Sets up writing FeatureTypes into their Directories.
* </p>
*
* @param dir The FeatureTypes directory
* @param data DOCUMENT ME!
*
* @throws ConfigurationException When an IO exception occurs.
*
* @see storeFeature(FeatureTypeInfo,File)
*/
protected static void storeFeatures(File dir, DataDTO data)
throws ConfigurationException {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer("In method storeFeatures");
}
// write them
Iterator i = data.getFeaturesTypes().keySet().iterator();
while (i.hasNext()) {
String s = (String) i.next();
FeatureTypeInfoDTO ft = (FeatureTypeInfoDTO) data.getFeaturesTypes().get(s);
if (ft != null) {
String ftDirName = ft.getDirName();
try { // encode the file name (this is to catch colons in FT names)
ftDirName = URLEncoder.encode(ftDirName, getDefaultEncoding());
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(new StringBuffer("Writing encoded URL: ").append(ftDirName)
.toString());
}
} catch (UnsupportedEncodingException e1) {
throw new ConfigurationException(e1);
}
File dir2 = WriterUtils.initWriteFile(new File(dir, ftDirName), true);
storeFeature(ft, dir2);
if (ft.getSchemaAttributes() != null) {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(new StringBuffer(ft.getKey()).append(" writing schema.xml w/ ")
.append(ft.getSchemaAttributes()
.size()).toString());
}
storeFeatureSchema(ft, dir2);
}
}
}
// delete old ones that are not overwritten
//I'm changing this action, as it is directly leading to users not
//being able to create their own shapefiles in the web admin tool.
//since their shit always gets deleted. The behaviour has now changed
//to just getting rid of the geoserver config files, info.xml and
//schema.xml and leaving any others. We should revisit this, I
//do think getting rid of stale featureTypes is a good thing. For 1.3
//I want to look into directly uploading shapefiles, and perhaps they
//would then go in a 'shapefile' directory, next to featureTypes or
//or something, so that the featureTypes directory only contains
//the info, and schema and those sorts of files. But I do kind of like
//being able to access the shapefiles directly from the web app, and
//indeed have had thoughts of expanding that, so that users could
//always download the full shape for a layer, generated automatically
//if it's from another datastore. Though I suppose that is not
//mutually exclusive, just a little wasting of space, for shapefiles
//would be held twice.
File[] fa = dir.listFiles();
for (int j = 0; j < fa.length; j++) {
// find dir name
i = data.getFeaturesTypes().values().iterator();
FeatureTypeInfoDTO fti = null;
while ((fti == null) && i.hasNext()) {
FeatureTypeInfoDTO ft = (FeatureTypeInfoDTO) i.next();
String ftDirName = ft.getDirName();
try { // encode the file name (this is to catch colons in FT names)
ftDirName = URLEncoder.encode(ftDirName, getDefaultEncoding());
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer(new StringBuffer("Decoded URL: ").append(ftDirName).toString());
}
} catch (UnsupportedEncodingException e1) {
throw new ConfigurationException(e1);
}
if (ftDirName.equals(fa[j].getName())) {
fti = ft;
}
}
if (fti == null) {
//delete it
File[] files = fa[j].listFiles();
if (files != null) {
for (int x = 0; x < files.length; x++) {
//hold on to the data, but be sure to get rid of the
//geoserver config shit, as these were deleted.
if (files[x].getName().equals("info.xml")
|| files[x].getName().equals("schema.xml")) {
//sorry for the hardcodes, I don't remember if/where
//we have these file names.
files[x].delete();
}
}
}
if ((files != null) && (files.length == 0)) {
fa[j].delete();
}
}
}
}
/**
* storeStyle purpose.
*
* <p>
* Writes a FeatureTypes into it's Directory.
* </p>
*
* @param ft DOCUMENT ME!
* @param dir The particular FeatureTypeInfo directory
*
* @throws ConfigurationException When an IO exception occurs.
*
* @see storeFeatures(File)
*/
protected static void storeFeature(FeatureTypeInfoDTO ft, File dir)
throws ConfigurationException {
if (LOGGER.isLoggable(Level.FINER)) {
LOGGER.finer("In method storeFeature");
}
File f = WriterUtils.initWriteFile(new File(dir, "info.xml"), false);
try {
Writer fw = new OutputStreamWriter(new FileOutputStream(f), getDefaultEncoding());
WriterHelper cw = new WriterHelper(fw);
Map m = new HashMap();
if ((ft.getDataStoreId() != null) && (ft.getDataStoreId() != "")) {
m.put("datastore", ft.getDataStoreId());
}
cw.openTag("featureType", m);
if ((ft.getName() != null) && (ft.getName() != "")) {
cw.textTag("name", ft.getName());
}
cw.comment("native wich EPGS code for the FeatureTypeInfoDTO");
cw.textTag("SRS", ft.getSRS() + "");
cw.textTag("SRSHandling", String.valueOf(ft.getSRSHandling()));
if ((ft.getTitle() != null) && (ft.getTitle() != "")) {
cw.textTag("title", ft.getTitle());
}
if ((ft.getAbstract() != null) && (ft.getAbstract() != "")) {
cw.textTag("abstract", ft.getAbstract());
}
if ((ft.getWmsPath() != null) && (ft.getWmsPath() != "")) {
cw.textTag("wmspath", ft.getWmsPath());
}
cw.valueTag("numDecimals", ft.getNumDecimals() + "");
if ((ft.getKeywords() != null) && (ft.getKeywords().size() != 0)) {
String s = "";
Iterator i = ft.getKeywords().iterator();
if (i.hasNext()) {
s = i.next().toString();
while (i.hasNext()) {
s = s + ", " + i.next().toString();
}
}
cw.textTag("keywords", s);
}
if ((ft.getMetadataLinks() != null) && (ft.getMetadataLinks().size() != 0)) {
cw.openTag("metadataLinks");
for (Iterator it = ft.getMetadataLinks().iterator(); it.hasNext();) {
MetaDataLink ml = (MetaDataLink) it.next();
Map mlAttr = new HashMap();
mlAttr.put("about", ml.getAbout());
mlAttr.put("type", ml.getType());
mlAttr.put("metadataType", ml.getMetadataType());
cw.textTag("metadataLink", mlAttr, ml.getContent());
}
cw.closeTag("metadataLinks");
}
if (ft.getLatLongBBox() != null) {
m = new HashMap();
Envelope e = ft.getLatLongBBox();
// from creation, isn't stored otherwise
if (!e.isNull()) {
m.put("dynamic", "false");
m.put("minx", e.getMinX() + "");
m.put("miny", e.getMinY() + "");
m.put("maxx", e.getMaxX() + "");
m.put("maxy", e.getMaxY() + "");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -