fixing ImageMosaic pubblication. Still something wrong in coverage config/removal.
This commit is contained in:
parent
04449f8bdb
commit
3fa1545019
@ -40,7 +40,9 @@ import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.Priority;
|
||||
|
||||
/**
|
||||
* Connect to a GeoServer instance to publish or modify data.
|
||||
@ -509,12 +511,14 @@ public class GeoServerRESTPublisher {
|
||||
return null;
|
||||
}
|
||||
String coverageName = covList.get(0).getName();
|
||||
|
||||
configureCoverage(coverageEncoder, store.getWorkspaceName(), storeName, coverageName);
|
||||
coverageEncoder.setName(FilenameUtils.getBaseName(mosaicDir.getName()));
|
||||
configureCoverage(coverageEncoder, workspace, storeName, coverageName);
|
||||
|
||||
configureLayer(workspace, storeName, layerEncoder);
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Could not configure external mosaic:" + storeName, e);
|
||||
if (LOGGER.isEnabledFor(Level.WARN))
|
||||
LOGGER.warn("Could not configure external mosaic:" + storeName, e);
|
||||
store = null; // TODO: should we remove the configured store?
|
||||
}
|
||||
}
|
||||
@ -735,6 +739,43 @@ public class GeoServerRESTPublisher {
|
||||
return configureLayer(null, layerName, layer);
|
||||
}
|
||||
|
||||
public boolean removeLayer(final String workspace, final String layerName) {
|
||||
|
||||
final String fqLayerName;
|
||||
|
||||
// this null check is here only for backward compatibility. workspace shall be mandatory.
|
||||
if(workspace == null) {
|
||||
|
||||
fqLayerName = layerName;
|
||||
|
||||
if (LOGGER.isEnabledFor(Level.WARN)){
|
||||
LOGGER.warn("Null workspace while removing layer : " + layerName + " -- This behavior is deprecated.");
|
||||
}
|
||||
} else {
|
||||
fqLayerName = workspace + ":" + layerName;
|
||||
}
|
||||
if (layerName==null) {
|
||||
if (LOGGER.isEnabledFor(Level.ERROR)){
|
||||
LOGGER.error("Null layerName : " + layerName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
final String url = restURL + "/rest/layers/" + fqLayerName;
|
||||
|
||||
boolean result=HTTPUtils.delete(url, gsuser, gspass);
|
||||
if (result) {
|
||||
if (LOGGER.isInfoEnabled()) {
|
||||
LOGGER.info("Layer successfully removed: " + fqLayerName);
|
||||
}
|
||||
} else {
|
||||
if (LOGGER.isEnabledFor(Level.WARN))
|
||||
LOGGER.warn("Error removing layer " + fqLayerName);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to configure some layer attributes such as WmsPath and DefaultStyle
|
||||
*
|
||||
@ -743,16 +784,23 @@ public class GeoServerRESTPublisher {
|
||||
|
||||
// TODO: check this usecase, layer should always be defined
|
||||
if (layer.isEmpty()) {
|
||||
LOGGER.warn("Null layer name while configuring layer -- This behavior is suspicious.");
|
||||
if (LOGGER.isEnabledFor(Level.WARN))
|
||||
LOGGER.warn("Null layer name while configuring layer -- This behavior is suspicious.");
|
||||
return true;
|
||||
}
|
||||
|
||||
String fqLayerName = workspace + ":" + layerName;
|
||||
final String fqLayerName;
|
||||
|
||||
// this null check is here only for backward compatibility. workspace shall be mandatory.
|
||||
if(workspace == null) {
|
||||
LOGGER.warn("Null workspace while configuring layer : " + layerName + " -- This behavior is deprecated.");
|
||||
|
||||
fqLayerName = layerName;
|
||||
|
||||
if (LOGGER.isEnabledFor(Level.WARN)){
|
||||
LOGGER.warn("Null workspace while configuring layer : " + layerName + " -- This behavior is deprecated.");
|
||||
}
|
||||
} else {
|
||||
fqLayerName = workspace + ":" + layerName;
|
||||
}
|
||||
|
||||
final String url = restURL + "/rest/layers/" + fqLayerName;
|
||||
@ -764,7 +812,8 @@ public class GeoServerRESTPublisher {
|
||||
LOGGER.info("Layer successfully configured: " + fqLayerName);
|
||||
}
|
||||
} else {
|
||||
LOGGER.warn("Error configuring layer " + fqLayerName + " (" + sendResult + ")");
|
||||
if (LOGGER.isEnabledFor(Level.WARN))
|
||||
LOGGER.warn("Error configuring layer " + fqLayerName + " (" + sendResult + ")");
|
||||
}
|
||||
|
||||
return sendResult != null;
|
||||
@ -785,7 +834,8 @@ public class GeoServerRESTPublisher {
|
||||
LOGGER.debug("Coverage successfully configured " + wsname + ":" + csname + ":" + cname);
|
||||
}
|
||||
} else {
|
||||
LOGGER.warn("Error configuring coverage " + wsname + ":" + csname + ":" + cname + " (" + sendResult + ")");
|
||||
if (LOGGER.isEnabledFor(Level.WARN))
|
||||
LOGGER.warn("Error configuring coverage " + wsname + ":" + csname + ":" + cname + " (" + sendResult + ")");
|
||||
}
|
||||
|
||||
return sendResult != null;
|
||||
|
||||
@ -41,9 +41,10 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder {
|
||||
|
||||
public GSPostGISDatastoreEncoder() {
|
||||
super("dataStore");
|
||||
addContent(connectionParameters.getRoot());
|
||||
|
||||
addType("PostGIS"); // may be overwritten with e.g. "PostGIS (JNDI)"
|
||||
addDatabaseType("postgis");
|
||||
addContent(connectionParameters.getRoot());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -161,6 +161,14 @@ public abstract class GSResourceEncoder<T extends GSDimensionInfoEncoder>
|
||||
public void setName(final String name) {
|
||||
set(NAME, name);
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
final Element nameNode=get(NAME);
|
||||
if (nameNode!=null)
|
||||
return nameNode.getText();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
private final static String TITLE="title";
|
||||
/**
|
||||
|
||||
@ -43,6 +43,9 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder {
|
||||
super(WORKSPACE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the workspace name
|
||||
*/
|
||||
public GSWorkspaceEncoder(String name) {
|
||||
super(WORKSPACE);
|
||||
addName(name);
|
||||
@ -54,7 +57,7 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder {
|
||||
* @throws IllegalStateException if name is already set
|
||||
* @deprecated will be set to protected in the next release
|
||||
*/
|
||||
public void addName(String name) {
|
||||
public void addName(final String name) {
|
||||
final Element el=ElementUtils.contains(getRoot(),NAME);
|
||||
if (el==null)
|
||||
add(NAME, name);
|
||||
@ -66,7 +69,7 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder {
|
||||
* add or change (if already set) the workspace name
|
||||
* @param name
|
||||
*/
|
||||
public void setName(String name) {
|
||||
public void setName(final String name) {
|
||||
final Element el=ElementUtils.contains(getRoot(),NAME);
|
||||
if (el==null)
|
||||
add(NAME, name);
|
||||
|
||||
@ -27,7 +27,9 @@ package it.geosolutions.geoserver.rest.encoder.coverage;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jdom.Element;
|
||||
import org.jdom.filter.Filter;
|
||||
@ -60,6 +62,8 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
||||
if (obj instanceof Element) {
|
||||
if (((Element)obj).getName().equals(ENTRY)){
|
||||
final Element el=((Element)obj).getChild(STRING);
|
||||
if (el==null)
|
||||
return false;
|
||||
if (el.getText().equals(this.name)){
|
||||
return true;
|
||||
}
|
||||
@ -87,10 +91,11 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
||||
* @param val
|
||||
*/
|
||||
public void addAllowMultithreading(final boolean val){
|
||||
final Element param=new Element(ENTRY);
|
||||
param.addContent(new Element(STRING).setText(allowMultithreading));
|
||||
param.addContent(new Element(STRING).setText((val)?"true":"false"));
|
||||
parameters.addContent(param);
|
||||
final List<Element> list=new ArrayList<Element>(2);
|
||||
list.add(new Element(STRING).setText(allowMultithreading));
|
||||
list.add(new Element(STRING).setText((val)?"true":"false"));
|
||||
|
||||
parameters.add(null,list);
|
||||
}
|
||||
|
||||
private final static Filter allowMultithreadingFilter=new parametersFilter(allowMultithreading);
|
||||
@ -108,7 +113,7 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
||||
final Element param=new Element(ENTRY);
|
||||
param.addContent(new Element(STRING).setText(filter));
|
||||
param.addContent(new Element(STRING).setText(val));
|
||||
parameters.addContent(param);
|
||||
parameters.add(null,param);
|
||||
}
|
||||
|
||||
private final static Filter filterFilter=new parametersFilter(filter);
|
||||
@ -123,10 +128,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
||||
* @param val
|
||||
*/
|
||||
public void addMaxAllowedTiles(final int val){
|
||||
final Element param=new Element(ENTRY);
|
||||
param.addContent(new Element(STRING).setText(maxAllowedTiles));
|
||||
param.addContent(new Element(STRING).setText(String.valueOf(val)));
|
||||
parameters.addContent(param);
|
||||
final List<Element> list=new ArrayList<Element>(2);
|
||||
list.add(new Element(STRING).setText(maxAllowedTiles));
|
||||
list.add(new Element(STRING).setText(String.valueOf(val)));
|
||||
parameters.add(null,list);
|
||||
}
|
||||
|
||||
private final static Filter maxAllowedTilesFilter=new parametersFilter(maxAllowedTiles);
|
||||
@ -141,10 +146,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
||||
* @param val
|
||||
*/
|
||||
public void addInputTransparentColor(final String val){
|
||||
final Element param=new Element(ENTRY);
|
||||
param.addContent(new Element(STRING).setText(inputTransparentColor));
|
||||
param.addContent(new Element(STRING).setText(val));
|
||||
parameters.addContent(param);
|
||||
final List<Element> list=new ArrayList<Element>(2);
|
||||
list.add(new Element(STRING).setText(inputTransparentColor));
|
||||
list.add(new Element(STRING).setText(val));
|
||||
parameters.add(null,list);
|
||||
}
|
||||
|
||||
private final static Filter inputTransparentColorFilter=new parametersFilter(inputTransparentColor);
|
||||
@ -159,10 +164,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
||||
* @param val
|
||||
*/
|
||||
public void addOutputTransparentColor(final String val){
|
||||
final Element param=new Element(ENTRY);
|
||||
param.addContent(new Element(STRING).setText(outputTransparentColor));
|
||||
param.addContent(new Element(STRING).setText(val));
|
||||
parameters.addContent(param);
|
||||
final List<Element> list=new ArrayList<Element>(2);
|
||||
list.add(new Element(STRING).setText(outputTransparentColor));
|
||||
list.add(new Element(STRING).setText(val));
|
||||
parameters.add(null,list);
|
||||
}
|
||||
|
||||
private final static Filter outputTransparentColorFilter=new parametersFilter(outputTransparentColor);
|
||||
@ -178,10 +183,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
||||
* @deprecated will be set to protected in the next release
|
||||
*/
|
||||
public void addSUGGESTED_TILE_SIZE(final String val){
|
||||
final Element param=new Element(ENTRY);
|
||||
param.addContent(new Element(STRING).setText(SUGGESTED_TILE_SIZE));
|
||||
param.addContent(new Element(STRING).setText(val));
|
||||
parameters.addContent(param);
|
||||
final List<Element> list=new ArrayList<Element>(2);
|
||||
list.add(new Element(STRING).setText(SUGGESTED_TILE_SIZE));
|
||||
list.add(new Element(STRING).setText(val));
|
||||
parameters.add(null,list);
|
||||
}
|
||||
|
||||
private final static Filter SUGGESTED_TILE_SIZEFilter=new parametersFilter(SUGGESTED_TILE_SIZE);
|
||||
@ -196,10 +201,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
||||
* @param val
|
||||
*/
|
||||
public void addUSE_JAI_IMAGEREAD(final boolean val){
|
||||
final Element param=new Element(ENTRY);
|
||||
param.addContent(new Element(STRING).setText(USE_JAI_IMAGEREAD));
|
||||
param.addContent(new Element(STRING).setText((val)?"true":"false"));
|
||||
parameters.addContent(param);
|
||||
final List<Element> list=new ArrayList<Element>(2);
|
||||
list.add(new Element(STRING).setText(USE_JAI_IMAGEREAD));
|
||||
list.add(new Element(STRING).setText((val)?"true":"false"));
|
||||
parameters.add(null,list);
|
||||
}
|
||||
|
||||
private final static Filter USE_JAI_IMAGEREADFilter=new parametersFilter(USE_JAI_IMAGEREAD);
|
||||
@ -214,10 +219,10 @@ public class GSImageMosaicEncoder extends GSCoverageEncoder {
|
||||
* @param val
|
||||
*/
|
||||
public void addBackgroundValues(final String val){
|
||||
final Element param=new Element(ENTRY);
|
||||
param.addContent(new Element(STRING).setText(backgroundValues));
|
||||
param.addContent(new Element(STRING).setText(val));
|
||||
parameters.addContent(param);
|
||||
final List<Element> list=new ArrayList<Element>(2);
|
||||
list.add(new Element(STRING).setText(backgroundValues));
|
||||
list.add(new Element(STRING).setText(val));
|
||||
parameters.add(null,list);
|
||||
}
|
||||
|
||||
private final static Filter backgroundValuesFilter=new parametersFilter(backgroundValues);
|
||||
|
||||
@ -25,6 +25,9 @@
|
||||
|
||||
package it.geosolutions.geoserver.rest.encoder.utils;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jdom.Content;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.filter.Filter;
|
||||
@ -63,6 +66,22 @@ import org.jdom.filter.Filter;
|
||||
* </entry>
|
||||
* </listName>}
|
||||
*
|
||||
* This can be also add list of compounded Elements <br/>
|
||||
*
|
||||
* <listName>
|
||||
* <entry>
|
||||
* <String>AllowMultithreading</String>
|
||||
* <enabled>false</enabled>
|
||||
* </entry>
|
||||
* <entry>
|
||||
*
|
||||
* <enabled>true</enabled>
|
||||
* <attribute>ele</attribute>
|
||||
* <presentation>LIST</presentation>
|
||||
* </dimensionInfo>
|
||||
* </entry>
|
||||
* </listName>}
|
||||
*
|
||||
* <PRE>
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
@ -72,100 +91,145 @@ import org.jdom.filter.Filter;
|
||||
public class NestedElementEncoder extends XmlElement {
|
||||
public final static String ENTRY = "entry";
|
||||
public final static String KEY = "key";
|
||||
|
||||
|
||||
static class NestedElementFilter implements Filter {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final String key;
|
||||
private final String value;
|
||||
private final Element root;
|
||||
public NestedElementFilter(Element root, String key) {
|
||||
this.key=key;
|
||||
this.root=root;
|
||||
|
||||
/**
|
||||
* if key is null we only check for children name if value is null we
|
||||
* only check for key attribute
|
||||
*
|
||||
* @param root
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
public NestedElementFilter(Element root, String key, String value) {
|
||||
this.key = key;
|
||||
this.root = root;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean matches(Object obj) {
|
||||
if (obj instanceof Element) {
|
||||
final Element el = ((Element) obj);
|
||||
if (root.isAncestor(el)){
|
||||
if (root.isAncestor(el)) {
|
||||
if (el.getName().equals(ENTRY)/* && el.getText().equals(value) */) {
|
||||
boolean keyCheck=true;
|
||||
if (key != null) {
|
||||
if (el.getAttribute(KEY).getValue().equals(key))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
if (el.getAttribute(KEY).getValue().equals(key)) {
|
||||
keyCheck=true;
|
||||
} else {
|
||||
keyCheck=false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
if (value != null)
|
||||
return keyCheck&&checkChilds(el, value);
|
||||
else
|
||||
return keyCheck;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean checkChilds(Element el, String value) {
|
||||
final List<Element> childList = el.getChildren();
|
||||
final Iterator<Element> childIt = childList.iterator();
|
||||
while (childIt.hasNext()) {
|
||||
final Element child = childIt.next();
|
||||
if (child.getName().equals(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
public NestedElementEncoder(String listName) {
|
||||
super(listName);
|
||||
}
|
||||
|
||||
// public void set(final String key, final String value) {
|
||||
// // if some previous similar object is found
|
||||
// final Element search;
|
||||
// if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(getRoot(), key))) != null) {
|
||||
// // remove it
|
||||
// ElementUtils.remove(getRoot(), search);
|
||||
// }
|
||||
// // add the new entry
|
||||
// add(key,value);
|
||||
// }
|
||||
public void set(final String key, final String value) {
|
||||
// if some previous similar object is found
|
||||
final Element search;
|
||||
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(
|
||||
getRoot(), key, value))) != null) {
|
||||
// remove it
|
||||
ElementUtils.remove(getRoot(), search);
|
||||
}
|
||||
// add the new entry
|
||||
add(key, value);
|
||||
}
|
||||
|
||||
// public void add(final String key, final Element value) {
|
||||
// final Element entryElem = new Element(ENTRY);
|
||||
// if (key != null)
|
||||
// entryElem.setAttribute(KEY, key);
|
||||
//
|
||||
// entryElem.addContent(value);
|
||||
//
|
||||
// this.addContent(entryElem);
|
||||
// }
|
||||
|
||||
// public void add(final String key, final String value) {
|
||||
// final Element entryElem = new Element(ENTRY);
|
||||
//
|
||||
// if (key != null)
|
||||
// entryElem.setAttribute(KEY, key);
|
||||
//
|
||||
// entryElem.setText(value);
|
||||
//
|
||||
// this.addContent(entryElem);
|
||||
// }
|
||||
public void set(final String key, final Element value) {
|
||||
// if some previous similar object is found
|
||||
final Element search;
|
||||
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(
|
||||
getRoot(), key, value.getName()))) != null) {
|
||||
// remove it
|
||||
ElementUtils.remove(getRoot(), search);
|
||||
}
|
||||
// add the new entry
|
||||
add(key, value);
|
||||
}
|
||||
|
||||
public void add(final String key, final Content value) {
|
||||
public void add(final String key, final Element value) {
|
||||
final Element entryElem = new Element(ENTRY);
|
||||
if (key != null)
|
||||
entryElem.setAttribute(KEY, key);
|
||||
|
||||
entryElem.setContent(value);
|
||||
entryElem.addContent(value);
|
||||
|
||||
this.addContent(entryElem);
|
||||
}
|
||||
|
||||
public void set(final String key, final Content value) {
|
||||
|
||||
public void add(final String key, final String value) {
|
||||
final Element entryElem = new Element(ENTRY);
|
||||
|
||||
if (key != null)
|
||||
entryElem.setAttribute(KEY, key);
|
||||
|
||||
entryElem.setText(value);
|
||||
|
||||
this.addContent(entryElem);
|
||||
}
|
||||
|
||||
public void add(final String key, final List<Element> list) {
|
||||
final Element entryElem = new Element(ENTRY);
|
||||
if (key != null)
|
||||
entryElem.setAttribute(KEY, key);
|
||||
|
||||
// final Iterator<Element> it=list.iterator();
|
||||
// while (it.hasNext()){
|
||||
// final Element child=it.next();
|
||||
entryElem.addContent(list);
|
||||
// }
|
||||
|
||||
this.addContent(entryElem);
|
||||
}
|
||||
|
||||
public void set(final String key, final List<Element> value) {
|
||||
// if some previous similar object is found
|
||||
final Element search;
|
||||
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(getRoot(), key))) != null) {
|
||||
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(
|
||||
getRoot(), key, value.get(0).getValue()))) != null) {
|
||||
// remove it
|
||||
ElementUtils.remove(search, search);
|
||||
}
|
||||
// add the new entry
|
||||
add(key,value);
|
||||
add(key, value);
|
||||
}
|
||||
|
||||
public boolean remove(final String key){
|
||||
|
||||
public boolean remove(final String key) {
|
||||
// if some previous similar object is found
|
||||
final Element search;
|
||||
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(getRoot(), key))) != null) {
|
||||
return ElementUtils.remove(search,search);
|
||||
}
|
||||
else
|
||||
if ((search = ElementUtils.contains(getRoot(), new NestedElementFilter(
|
||||
getRoot(), key, null))) != null) {
|
||||
return ElementUtils.remove(search, search);
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -56,15 +56,35 @@ public class PropertyXMLEncoder extends XmlElement {
|
||||
public PropertyXMLEncoder(final String rootName) {
|
||||
super(rootName);
|
||||
}
|
||||
|
||||
protected void get(final String key, final String value) {
|
||||
|
||||
}
|
||||
|
||||
protected Element get(final String key) {
|
||||
return get(getRoot(), key);
|
||||
}
|
||||
|
||||
|
||||
public void set(final String key, final String value) {
|
||||
private Element get(final Element el, final String key) {
|
||||
if (el==null)
|
||||
return null;
|
||||
if (key.contains("/")) {
|
||||
final int i = key.indexOf("/");
|
||||
final String parentName = key.substring(0, i);
|
||||
final String newkey = key.substring(i + 1);
|
||||
return get(ElementUtils.contains(el, parentName),newkey);
|
||||
} else {
|
||||
return ElementUtils.contains(el, key);
|
||||
}
|
||||
}
|
||||
|
||||
protected void set(final String key, final String value) {
|
||||
if (key != null && value != null) {
|
||||
set(getRoot(), key, value);
|
||||
}
|
||||
}
|
||||
|
||||
private void set(final Element e, final String key, final String value){
|
||||
|
||||
private void set(final Element e, final String key, final String value) {
|
||||
if (key.contains("/")) {
|
||||
final int i = key.indexOf("/");
|
||||
final String childName = key.substring(0, i);
|
||||
@ -74,21 +94,21 @@ public class PropertyXMLEncoder extends XmlElement {
|
||||
if (child == null) {
|
||||
child = new Element(childName);
|
||||
e.addContent(child);
|
||||
add(child,newkey,value);
|
||||
add(child, newkey, value);
|
||||
}
|
||||
set(child, newkey, value);
|
||||
set(child, newkey, value);
|
||||
} else {
|
||||
Element pp = null;
|
||||
if ((pp = ElementUtils.contains(e,key)) == null)
|
||||
add(e,key, value);
|
||||
if ((pp = ElementUtils.contains(e, key)) == null)
|
||||
add(e, key, value);
|
||||
else {
|
||||
ElementUtils.remove(e,pp);
|
||||
add(e,key, value);
|
||||
ElementUtils.remove(e, pp);
|
||||
add(e, key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void add(final String key, final String value) {
|
||||
protected void add(final String key, final String value) {
|
||||
if (key != null && value != null) {
|
||||
add(this.getRoot(), key, value);
|
||||
}
|
||||
@ -113,60 +133,60 @@ public class PropertyXMLEncoder extends XmlElement {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// public void set(final String key, final String value) {
|
||||
// if (key != null && value != null) {
|
||||
// set(getRoot(), key, value);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void set(final Element e, final String key, final String value){
|
||||
// if (!key.contains("/")) {
|
||||
// Element pp = null;
|
||||
// if ((pp = contains(key)) == null)
|
||||
// add(e,key, value);
|
||||
// else {
|
||||
// remove(pp);
|
||||
// add(e,key, value);
|
||||
// }
|
||||
// } else {
|
||||
// final int i = key.indexOf("/");
|
||||
// final String childName = key.substring(0, i);
|
||||
// final String newkey = key.substring(i + 1);
|
||||
//
|
||||
// Element child = e.getChild(childName);
|
||||
// if (child == null) {
|
||||
// child = new Element(childName);
|
||||
// e.addContent(child);
|
||||
// add(child,newkey,value);
|
||||
// }
|
||||
// set(child, newkey, value);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void add(final String key, final String value) {
|
||||
// if (key != null && value != null) {
|
||||
// add(this.getRoot(), key, value);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void add(Element e, String key, String value) {
|
||||
// if (!key.contains("/")) {
|
||||
// e.addContent(new Element(key).setText(value));
|
||||
// } else {
|
||||
// final int i = key.indexOf("/");
|
||||
// final String childName = key.substring(0, i);
|
||||
// final String newkey = key.substring(i + 1);
|
||||
//
|
||||
// Element child = e.getChild(childName);
|
||||
// if (child == null) {
|
||||
// child = new Element(childName);
|
||||
// e.addContent(child);
|
||||
// }
|
||||
//
|
||||
// add(child, newkey, value);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
// public void set(final String key, final String value) {
|
||||
// if (key != null && value != null) {
|
||||
// set(getRoot(), key, value);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void set(final Element e, final String key, final String value){
|
||||
// if (!key.contains("/")) {
|
||||
// Element pp = null;
|
||||
// if ((pp = contains(key)) == null)
|
||||
// add(e,key, value);
|
||||
// else {
|
||||
// remove(pp);
|
||||
// add(e,key, value);
|
||||
// }
|
||||
// } else {
|
||||
// final int i = key.indexOf("/");
|
||||
// final String childName = key.substring(0, i);
|
||||
// final String newkey = key.substring(i + 1);
|
||||
//
|
||||
// Element child = e.getChild(childName);
|
||||
// if (child == null) {
|
||||
// child = new Element(childName);
|
||||
// e.addContent(child);
|
||||
// add(child,newkey,value);
|
||||
// }
|
||||
// set(child, newkey, value);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void add(final String key, final String value) {
|
||||
// if (key != null && value != null) {
|
||||
// add(this.getRoot(), key, value);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private void add(Element e, String key, String value) {
|
||||
// if (!key.contains("/")) {
|
||||
// e.addContent(new Element(key).setText(value));
|
||||
// } else {
|
||||
// final int i = key.indexOf("/");
|
||||
// final String childName = key.substring(0, i);
|
||||
// final String newkey = key.substring(i + 1);
|
||||
//
|
||||
// Element child = e.getChild(childName);
|
||||
// if (child == null) {
|
||||
// child = new Element(childName);
|
||||
// e.addContent(child);
|
||||
// }
|
||||
//
|
||||
// add(child, newkey, value);
|
||||
// }
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@ -56,21 +56,21 @@ public class XmlElement{
|
||||
@SuppressWarnings("unused")
|
||||
private XmlElement(){root=null;};
|
||||
|
||||
public void add(final String nodename, final String nodetext) {
|
||||
protected void add(final String nodename, final String nodetext) {
|
||||
add(nodename,new Text(nodetext));
|
||||
}
|
||||
|
||||
public void add(final String nodename, final Content nodetext) {
|
||||
protected void add(final String nodename, final Content nodetext) {
|
||||
final Element el=new Element(nodename);
|
||||
el.setContent(nodetext);
|
||||
this.addContent(el);
|
||||
}
|
||||
|
||||
public void set(final String nodename, final String nodetext) {
|
||||
protected void set(final String nodename, final String nodetext) {
|
||||
set(nodename,new Text(nodetext));
|
||||
}
|
||||
|
||||
public void set(final String nodename, final Content nodeContent) {
|
||||
protected void set(final String nodename, final Content nodeContent) {
|
||||
final Element el=ElementUtils.contains(getRoot(),nodename);
|
||||
if (el==null){
|
||||
add(nodename,nodeContent);
|
||||
@ -80,7 +80,7 @@ public class XmlElement{
|
||||
}
|
||||
}
|
||||
|
||||
public Element addContent(Content child){
|
||||
protected Element addContent(Content child){
|
||||
return root.addContent(child);
|
||||
}
|
||||
|
||||
|
||||
@ -44,13 +44,8 @@ public class GSWorkspaceEncoderTest extends TestCase {
|
||||
final GSWorkspaceEncoder wsenc = new GSWorkspaceEncoder("WS1");
|
||||
LOGGER.info(wsenc.toString());
|
||||
|
||||
try{
|
||||
wsenc.addName("test_name");
|
||||
// NEVER HERE
|
||||
Assert.assertTrue(false);
|
||||
}catch (IllegalStateException e){
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
wsenc.setName("test_name");
|
||||
LOGGER.info(wsenc.toString());
|
||||
wsenc.setName("new_name");
|
||||
LOGGER.info(wsenc.toString());
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user