rrenkert@41: package de.intevation.mxd.writer;
rrenkert@41:
rrenkert@41: import org.apache.log4j.Logger;
rrenkert@41:
raimund@179: import java.awt.Color;
raimund@179:
rrenkert@41: import org.w3c.dom.Document;
rrenkert@41: import org.w3c.dom.Element;
rrenkert@41: import org.w3c.dom.NodeList;
rrenkert@42:
rrenkert@98: import java.io.File;
rrenkert@98:
rrenkert@41: import javax.xml.xpath.XPathConstants;
rrenkert@41:
rrenkert@41: import edu.umn.gis.mapscript.mapObj;
rrenkert@41: import edu.umn.gis.mapscript.layerObj;
rrenkert@42: import edu.umn.gis.mapscript.classObj;
raimund@179: import edu.umn.gis.mapscript.labelObj;
raimund@179: import edu.umn.gis.mapscript.colorObj;
raimund@179: import edu.umn.gis.mapscript.fontSetObj;
raimund@179: import edu.umn.gis.mapscript.hashTableObj;
rrenkert@42:
rrenkert@41: import edu.umn.gis.mapscript.MS_UNITS;
rrenkert@42: import edu.umn.gis.mapscript.MS_LAYER_TYPE;
vc11884admin@130: import edu.umn.gis.mapscript.MS_CONNECTION_TYPE;
raimund@179: import edu.umn.gis.mapscript.MS_FONT_TYPE;
raimund@179: import edu.umn.gis.mapscript.MS_POSITIONS_ENUM;
rrenkert@41:
rrenkert@41: import de.intevation.mxd.utils.XMLUtils;
rrenkert@41:
rrenkert@41: /**
rrenkert@43: * The Mapfile Writer.
rrenkert@43: * This Writer uses the MapScript Java API to create Mapfiles from a DOM.
rrenkert@41: *
rrenkert@41: * @author Raimund Renkert
rrenkert@41: */
rrenkert@41: public class MapScriptWriter
rrenkert@41: implements IWriter
rrenkert@41: {
rrenkert@43: /**
rrenkert@43: * The Logger.
rrenkert@43: */
rrenkert@43: private static final Logger logger = Logger.getLogger(MapScriptWriter.class);
rrenkert@43:
rrenkert@43: /**
rrenkert@43: * Private member.
rrenkert@43: */
rrenkert@41: private Document root;
rrenkert@41: private mapObj map;
rrenkert@55: private String mapFilename;
vc11884admin@130: private String MS_BINDIR = "c:/ms_6.1-dev/bin";
vc11884admin@134: private String prefix = "";
vc11884admin@170: private MS_UNITS units = MS_UNITS.MS_METERS;
rrenkert@41:
rrenkert@181: /**
rrenkert@181: * Default constructor.
rrenkert@181: * Creates a mapscript writer object with an empty map.
rrenkert@181: */
rrenkert@41: public MapScriptWriter() {
rrenkert@55: map = new mapObj("");
rrenkert@55: mapFilename = "";
rrenkert@41: }
rrenkert@41:
rrenkert@181: /**
rrenkert@181: * Contructor with template and output filename.
rrenkert@181: * Creates a mapscript writer object with the given template that saves the
rrenkert@181: * map to the filename.
rrenkert@181: *
rrenkert@181: * @param templ Mapfile template.
rrenkert@181: * @param filename Output file name.
rrenkert@181: */
rrenkert@55: public MapScriptWriter(String templ, String filename) {
rrenkert@180: String path = System.getProperty("user.dir");
rrenkert@55: map = new mapObj(templ);
rrenkert@180: File f = new File(filename);
rrenkert@180: mapFilename = filename;
rrenkert@180: if(f.isAbsolute()) {
raimund@174: map.setMappath(mapFilename);
rrenkert@180: }
rrenkert@180: else {
rrenkert@180: map.setMappath(
rrenkert@180: System.getProperty("user.dir") +
rrenkert@180: File.separator +
rrenkert@180: mapFilename);
rrenkert@180: mapFilename = System.getProperty("user.dir") +
rrenkert@180: File.separator +
rrenkert@180: mapFilename;
rrenkert@180: }
rrenkert@180: String fontSetPath = map.getFontset().getFilename();
rrenkert@180: File fonts = new File(fontSetPath);
rrenkert@180: String fontSet = fonts.getAbsolutePath();
rrenkert@180: fontSet = fontSet.replaceAll("\\\\", "/");
rrenkert@180: map.setFontSet(fontSet);
rrenkert@41: }
rrenkert@41:
rrenkert@43: /**
rrenkert@43: * Write the mapfile.
rrenkert@43: * @param doc The root document containin the map attributes.
rrenkert@43: *
rrenkert@43: * @return Currently always true.
rrenkert@43: */
rrenkert@120: public boolean write(Document doc) {
rrenkert@41: logger.debug("write()");
rrenkert@41: this.root = doc;
rrenkert@41:
rrenkert@41: //Get the filename.
rrenkert@41: Element fileNode = (Element)XMLUtils.xpath(
rrenkert@41: root,
rrenkert@41: "/mxd/file",
rrenkert@41: XPathConstants.NODE);
rrenkert@41: //Write the map attributes.
rrenkert@41: writeMap();
rrenkert@42: //Write the layers.
raimund@196: boolean ret = writeLayer();
rrenkert@41: //Save the map.
raimund@196: if (ret) {
raimund@196: mapObj cloneMap = map.cloneMap();
raimund@196: cloneMap.save(mapFilename);
raimund@196: logger.info("Mapfile created: " + mapFilename);
raimund@196: return true;
raimund@196: }
raimund@196: return false;
rrenkert@41: }
rrenkert@41:
rrenkert@43: /**
rrenkert@43: * Create the map object and set the attributes.
rrenkert@43: */
rrenkert@41: private void writeMap() {
rrenkert@41: logger.debug("writeMap()");
rrenkert@41: //Get the map.
rrenkert@41: Element mapNode = (Element)XMLUtils.xpath(
rrenkert@41: root,
rrenkert@41: "/mxd/map",
rrenkert@41: XPathConstants.NODE);
rrenkert@41:
rrenkert@41: //Set the name.
rrenkert@41: map.setName(mapNode.getAttribute("name"));
rrenkert@42: map.setMetaData("wms_title", mapNode.getAttribute("name"));
rrenkert@41: //Set the extent.
rrenkert@41: map.setExtent(
rrenkert@41: Double.parseDouble(mapNode.getAttribute("extent_min_x")),
rrenkert@41: Double.parseDouble(mapNode.getAttribute("extent_min_y")),
rrenkert@41: Double.parseDouble(mapNode.getAttribute("extent_max_x")),
rrenkert@41: Double.parseDouble(mapNode.getAttribute("extent_max_y")));
rrenkert@41:
vc11884admin@172: //Set the units and projection.
rrenkert@180: int proj = Integer.parseInt(mapNode.getAttribute("projection"));
rrenkert@180: if(proj != 0) {
rrenkert@180: map.setProjection("epsg:" + mapNode.getAttribute("projection"));
rrenkert@180: }
vc11884admin@170: String u = mapNode.getAttribute("units");
vc11884admin@170: if(u.equals("feet")) {
vc11884admin@170: units = MS_UNITS.MS_FEET;
rrenkert@41: }
vc11884admin@170: else if(u.equals("inches")) {
vc11884admin@170: units = MS_UNITS.MS_INCHES;
rrenkert@41: }
vc11884admin@170: else if(u.equals("kilometers")) {
vc11884admin@170: units = MS_UNITS.MS_KILOMETERS;
rrenkert@41: }
vc11884admin@170: else if(u.equals("meters")) {
vc11884admin@170: units = MS_UNITS.MS_METERS;
rrenkert@41: }
vc11884admin@170: else if(u.equals("miles")) {
vc11884admin@170: units = MS_UNITS.MS_MILES;
vc11884admin@170: }
vc11884admin@170: else if(u.equals("nauticalmiles")) {
vc11884admin@170: units = MS_UNITS.MS_NAUTICALMILES;
vc11884admin@170: }
vc11884admin@170: else if(u.equals("points")) {
vc11884admin@170: units = MS_UNITS.MS_PIXELS;
vc11884admin@170: }
rrenkert@180: else if(u.equals("degree")) {
rrenkert@180: units = MS_UNITS.MS_DD;
rrenkert@180: }
rrenkert@41: else {
vc11884admin@170: units = MS_UNITS.MS_METERS;
rrenkert@41: }
vc11884admin@170: map.setUnits(units);
rrenkert@41: }
rrenkert@41:
rrenkert@43: /**
rrenkert@43: * Create layer objects and set the attributes.
rrenkert@43: */
raimund@196: private boolean writeLayer() {
rrenkert@42: logger.debug("writeLayer()");
rrenkert@42: Element mapNode = (Element)XMLUtils.xpath(
rrenkert@42: root,
rrenkert@42: "/mxd/map",
rrenkert@42: XPathConstants.NODE);
rrenkert@42: NodeList list = mapNode.getElementsByTagName("layer");
rrenkert@42: for(int i = 0; i < list.getLength(); i++) {
rrenkert@42: Element layerElement = (Element)list.item(i);
rrenkert@42: layerObj layer = new layerObj(map);
raimund@190: NodeList renderer = layerElement.getElementsByTagName("renderer");
raimund@190: if (renderer.getLength() == 0) {
raimund@190: continue;
raimund@190: }
rrenkert@42:
rrenkert@42: //The layer name.
rrenkert@137: String lname = layerElement.getAttribute("name");
rrenkert@137: lname = lname.replaceAll(" ", "");
raimund@189: layer.setName(validateString(lname));
rrenkert@180: layer.setUnits(units.swigValue());
raimund@189: layer.setMetaData("wms_title", validateString(lname));
vc11884admin@148: if(layerElement.hasAttribute("group")) {
raimund@189: String group = layerElement.getAttribute("group");
raimund@200: group = validateString(group);
raimund@200: group = group.replaceAll (" ", "");
raimund@200: layer.setGroup(group);
rrenkert@180: }
rrenkert@180:
rrenkert@42: //The layer status.
rrenkert@42: String stat = layerElement.getAttribute("status");
rrenkert@42: if (stat.equals("on")) {
rrenkert@42: layer.setStatus(1);
rrenkert@42: }
rrenkert@42: else {
rrenkert@42: layer.setStatus(0);
rrenkert@42: }
rrenkert@42:
rrenkert@42: //The scale.
rrenkert@145: double maxScale = 0;
rrenkert@145: double minScale = 0;
rrenkert@145: try {
rrenkert@145: maxScale =
vc11884admin@153: Double.parseDouble(layerElement.getAttribute("min_scale"));
vc11884admin@153: minScale =
rrenkert@145: Double.parseDouble(layerElement.getAttribute("max_scale"));
rrenkert@145: }
rrenkert@145: catch(NumberFormatException nfe) {
rrenkert@145: logger.warn("Error setting scale.");
rrenkert@145: maxScale = 0;
rrenkert@145: minScale = 0;
rrenkert@145: }
rrenkert@42: layer.setMaxscaledenom(maxScale);
rrenkert@42: layer.setMinscaledenom(minScale);
rrenkert@42:
rrenkert@42: //The layer type.
rrenkert@42: String type = layerElement.getAttribute("type");
rrenkert@42: if(type.equals("point")) {
rrenkert@42: layer.setType(MS_LAYER_TYPE.MS_LAYER_POINT);
rrenkert@42: }
rrenkert@62: else if (type.equals("line")) {
rrenkert@62: layer.setType(MS_LAYER_TYPE.MS_LAYER_LINE);
rrenkert@62: }
rrenkert@97: else if (type.equals("polygon")) {
rrenkert@97: layer.setType(MS_LAYER_TYPE.MS_LAYER_POLYGON);
rrenkert@97: }
rrenkert@102: layer.setTileitem("");
rrenkert@42:
rrenkert@42: //The layer datasource.
rrenkert@137: String con_type = layerElement.getAttribute("connection_type");
vc11884admin@134: if(con_type.equals("local")) {
rrenkert@181: // The data source is a local file. (.shp)
vc11884admin@130: String datasource = "";
vc11884admin@130: if(layerElement.hasAttribute("workspace")) {
vc11884admin@130: datasource = layerElement.getAttribute("workspace");
vc11884admin@130: datasource += File.separator;
vc11884admin@130: }
vc11884admin@130: datasource += layerElement.getAttribute("data_source");
rrenkert@180: datasource = datasource.replaceAll("\\\\", "/");
vc11884admin@130: layer.setData(datasource);
rrenkert@137: }
rrenkert@137: else if(con_type.equals("SDE")) {
rrenkert@181: // The data source is a sde database.
rrenkert@137: logger.info(
rrenkert@137: "SDE datasource found." +
rrenkert@137: " Please edit password in mapfile.");
rrenkert@137: layer.setConnectionType(
rrenkert@137: MS_CONNECTION_TYPE.MS_PLUGIN.swigValue(),
rrenkert@137: MS_BINDIR + "/ms/plugins/msplugin_sde_93.dll");
raimund@197: String database_auth = layerElement.getAttribute("database");
raimund@197: if (database_auth.equals("") || database_auth == null) {
raimund@197: logger.warn("Could not set the database connection user." +
raimund@197: " Setting to \"sde\" as default.");
raimund@197: database_auth = "sde";
raimund@197: }
vc11884admin@130: layer.setConnection(
rrenkert@137: layerElement.getAttribute("server") + "," +
rrenkert@137: "port:" + layerElement.getAttribute("instance") + "," +
raimund@197: database_auth + "," +
rrenkert@137: layerElement.getAttribute("user") + ",");
rrenkert@137: layer.setData(
rrenkert@137: layerElement.getAttribute("data_source") +
rrenkert@137: ",SHAPE," +
rrenkert@137: layerElement.getAttribute("version"));
rrenkert@137: layer.setProcessing("CLOSE_CONNECTION=defer");
vc11884admin@134: layer.setProcessing("ATTRIBUTE_QUALIFIED=TRUE");
rrenkert@137: if(layerElement.hasAttribute("join_table")) {
raimund@196: String join = layerElement.getAttribute("join_table");
raimund@203:
vc11884admin@134: layer.setProcessing(
rrenkert@137: "JOINTABLE=" +
rrenkert@137: layerElement.getAttribute("join_table"));
vc11884admin@134: layer.setFilter(
vc11884admin@134: "where " +
vc11884admin@134: layerElement.getAttribute("definition_query") +
vc11884admin@134: " AND " +
vc11884admin@134: layerElement.getAttribute("join_table_target") + "." +
vc11884admin@134: layerElement.getAttribute("join_field_target") + "=" +
vc11884admin@134: layerElement.getAttribute("join_table") + "." +
vc11884admin@134: layerElement.getAttribute("join_field"));
rrenkert@137: }
rrenkert@137: else {
rrenkert@137: prefix = layerElement.getAttribute("data_source");
rrenkert@180: if(layerElement.hasAttribute("definition_query") &&
rrenkert@180: !layerElement.getAttribute("definition_query")
rrenkert@180: .equals("")) {
rrenkert@180: layer.setFilter("where " +
rrenkert@180: layerElement.getAttribute("definition_query"));
rrenkert@180: }
rrenkert@137: }
rrenkert@137: }
rrenkert@129: layer.setTemplate("PleaseInsertAValidTemplateForGFI");
raimund@179:
rrenkert@181: // Create labelitem
rrenkert@180: NodeList labels = layerElement.getElementsByTagName("label");
rrenkert@180: if(labels.getLength() > 0) {
rrenkert@180: Element label = (Element)labels.item(0);
raimund@179: String expr = label.getAttribute("expression");
rrenkert@180: expr = expr.replaceAll("\\[", "");
rrenkert@180: expr = expr.replaceAll("\\]", "");
rrenkert@180: if(!prefix.equals("")) {
rrenkert@180: expr = prefix + "." + expr;
rrenkert@180: }
raimund@199: layer.setLabelitem(expr.trim());
rrenkert@180: }
rrenkert@180:
rrenkert@42: //Write classes.
rrenkert@42: writeClass(layer, layerElement);
rrenkert@42: }
raimund@196: return true;
rrenkert@41: }
rrenkert@41:
rrenkert@42: /**
rrenkert@42: * Adds the classes to the layer.
rrenkert@42: * @param layer Mapscript layer object.
rrenkert@42: * @param layerElement Dom element containing the class attributes.
rrenkert@42: */
rrenkert@120: private void writeClass(layerObj layer, Element layerElement) {
rrenkert@87: logger.debug("writeClass(layerObj, Element)");
rrenkert@42: //Get all renderer elements (renderer in arcgis equals class in the
rrenkert@42: //mapfile.)
rrenkert@42: NodeList list = layerElement.getElementsByTagName("renderer");
rrenkert@41:
rrenkert@42: //Create all found class objects and write the symbols and styles for
rrenkert@42: //each class.
rrenkert@42: for(int i = 0; i < list.getLength(); i++) {
rrenkert@42: Element classElement = (Element)list.item(i);
rrenkert@42: classObj co = new classObj(layer);
rrenkert@124: String name = classElement.getAttribute("label");
raimund@189: name = validateString(name);
rrenkert@99: if (name.equals("")) {
rrenkert@99: name = layerElement.getAttribute("name");
raimund@189: name = validateString(name);
rrenkert@99: if (list.getLength() > 1) {
rrenkert@99: name += "-" + i;
rrenkert@99: }
rrenkert@99: }
rrenkert@99: co.setName (name);
raimund@179:
rrenkert@181: //Create label object.
rrenkert@180: NodeList labels = layerElement.getElementsByTagName("label");
rrenkert@180: if(labels.getLength() > 0) {
rrenkert@180: Element labelElement = (Element)labels.item(0);
rrenkert@180: String layerType = layerElement.getAttribute("type");
rrenkert@180: writeLabel(co, labelElement, layerType);
rrenkert@180: }
rrenkert@181:
rrenkert@181: //Create definition expression.
rrenkert@44: if(classElement.hasAttribute("field_count")) {
vc11884admin@152: co.setExpression(createExpression(classElement, i));
rrenkert@44: }
rrenkert@181:
rrenkert@42: //Write symbols and styles.
rrenkert@97: NodeList l = classElement.getChildNodes();
vc11884admin@141: for (int j = l.getLength() - 1; j >= 0; j--) {
rrenkert@97: Element elem = (Element)l.item(j);
rrenkert@97:
rrenkert@97: String type = layerElement.getAttribute("type");
rrenkert@180: if(type.equals("point") &&
rrenkert@180: elem.getTagName().equals("symbol")) {
rrenkert@180: MarkerStyleWriter swriter =
rrenkert@180: new MarkerStyleWriter (this.map, co);
rrenkert@97: swriter.write (elem);
rrenkert@87: }
rrenkert@180: else if(type.equals("line") &&
rrenkert@180: elem.getTagName().equals("symbol")) {
rrenkert@180: LineStyleWriter swriter =
rrenkert@180: new LineStyleWriter (this.map, co);
rrenkert@97: swriter.write (elem);
rrenkert@97: }
rrenkert@180: else if(type.equals("polygon") &&
rrenkert@180: elem.getTagName().equals("symbol")) {
rrenkert@180: FillStyleWriter swriter =
rrenkert@180: new FillStyleWriter (this.map, co);
rrenkert@97: swriter.write (elem);
rrenkert@87: }
rrenkert@87: }
rrenkert@42: }
rrenkert@41: }
rrenkert@126:
rrenkert@181: /**
rrenkert@181: * Create a label object in a class object.
rrenkert@181: *
rrenkert@181: * @param co Class object.
rrenkert@181: * @param labelElement DOM element containing label attributes.
rrenkert@181: * @param layertype The layer type. Used to define the label position.
rrenkert@181: */
raimund@179: private void writeLabel(
rrenkert@180: classObj co,
rrenkert@180: Element labelElement,
rrenkert@180: String layerType) {
raimund@179:
rrenkert@181: //Get the label object. Each class has a predefined labelobject.
raimund@179: labelObj label = co.getLabel();
rrenkert@181:
rrenkert@181: //Get the label text symbol attributes from DOM.
rrenkert@180: Element symbol = (Element)labelElement.getFirstChild();
rrenkert@180: if(symbol != null && symbol.getTagName().equals("symbol")) {
rrenkert@180: String type = symbol.getAttribute("type");
rrenkert@180: if(type.equals("text")) {
rrenkert@180: label.setType(MS_FONT_TYPE.MS_TRUETYPE);
rrenkert@180: }
rrenkert@180: label.setSize(Double.parseDouble(symbol.getAttribute("size")));
rrenkert@180:
raimund@179: if(symbol.hasAttribute("color")) {
raimund@179: String c = symbol.getAttribute("color");
raimund@179: Color col = Color.decode(c);
raimund@179: colorObj color = new colorObj(
raimund@179: col.getRed(),
raimund@179: col.getGreen(),
raimund@179: col.getBlue(),
raimund@179: -4);
raimund@179: label.setColor(color);
rrenkert@180: }
rrenkert@180: if(symbol.hasAttribute("font")) {
rrenkert@180: String font = symbol.getAttribute("font");
rrenkert@180: fontSetObj fso = this.map.getFontset();
rrenkert@180: hashTableObj fonts = fso.getFonts();
rrenkert@180: String mapFont = fonts.get(font,"");
rrenkert@180: if(mapFont != null && !mapFont.equals("")) {
rrenkert@180: label.setFont(font);
rrenkert@180: }
rrenkert@180: else {
rrenkert@180: logger.info(
rrenkert@180: "Could not find font " + font + " in font set. " +
rrenkert@180: "Using FreeSans for labels.");
rrenkert@180: label.setFont("FreeSans");
rrenkert@180: }
rrenkert@180: }
raimund@179:
raimund@179: if(labelElement.hasAttribute("max_scale")) {
rrenkert@180: double min =
rrenkert@180: Double.parseDouble(labelElement.getAttribute("max_scale"));
rrenkert@180: if(min > 0) {
rrenkert@180: label.setMinscaledenom(min);
rrenkert@180: }
rrenkert@180: }
rrenkert@180: if(labelElement.hasAttribute("min_scale")) {
rrenkert@180: double max =
rrenkert@180: Double.parseDouble(labelElement.getAttribute("min_scale"));
rrenkert@180: if(max > 0) {
rrenkert@180: label.setMaxscaledenom(max);
rrenkert@180: }
rrenkert@180: }
raimund@179:
rrenkert@181: //Set the label position.
rrenkert@180: if(layerType.equals("point")) {
rrenkert@180: label.setPosition(MS_POSITIONS_ENUM.MS_UC.swigValue());
rrenkert@180: }
rrenkert@180: }
raimund@179: }
raimund@179:
rrenkert@181: /**
rrenkert@181: * Create definition expression.
rrenkert@181: *
rrenkert@181: * @param ce DOM elementcontaining the class expression information.
rrenkert@181: * @param index Index to determine the correct expression operator.
rrenkert@181: */
vc11884admin@152: private String createExpression(Element ce, int index) {
rrenkert@137: String expression = "(";
rrenkert@137: int count = 0;
rrenkert@137: try {
rrenkert@137: count = Integer.parseInt(ce.getAttribute("field_count"));
rrenkert@137: }
rrenkert@137: catch(NumberFormatException nfe) {
rrenkert@137: return "";
rrenkert@137: }
rrenkert@181:
rrenkert@137: if(count == 1) {
rrenkert@181: //Create single field expression.
rrenkert@181: try {
rrenkert@181: //If no exception is thrown, the expression value is a number.
vc11884admin@134: Double.parseDouble(ce.getAttribute("value"));
rrenkert@137: String exp = ce.getAttribute("expression_field_0");
rrenkert@137: String pre = "";
rrenkert@137: if (!prefix.equals("") && !exp.startsWith(prefix)) {
vc11884admin@134: pre = prefix + ".";
rrenkert@137: }
rrenkert@137: expression += "[" + pre;
rrenkert@137: expression += ce.getAttribute("expression_field_0") + "]";
rrenkert@137: if(ce.hasAttribute("min_value")) {
rrenkert@180: if(index == 0) {
rrenkert@180: expression += " >= " + ce.getAttribute("min_value");
rrenkert@180: }
rrenkert@180: else {
vc11884admin@152: expression += " > " + ce.getAttribute("min_value");
rrenkert@180: }
rrenkert@181: expression += " AND [" + pre;
rrenkert@181: expression += ce.getAttribute("expression_field_0");
rrenkert@181: expression += "]";
rrenkert@137: }
rrenkert@137: expression += " " + ce.getAttribute("expression_operator");
rrenkert@137: expression += " " + ce.getAttribute("value") + ")";
rrenkert@137: }
rrenkert@137: catch(NumberFormatException nfe) {
rrenkert@181: //The expression value is a strings.
rrenkert@137: String exp = ce.getAttribute("expression_field_0");
rrenkert@137: String pre = "";
rrenkert@137: if (!prefix.equals("") && !exp.startsWith(prefix)) {
vc11884admin@134: pre = prefix + ".";
rrenkert@137: }
rrenkert@137: expression += "\"[" + pre;
rrenkert@137: expression += ce.getAttribute("expression_field_0") + "]\"";
rrenkert@137: expression += " " + ce.getAttribute("expression_operator");
rrenkert@137: expression += " \"" + ce.getAttribute("value") + "\")";
rrenkert@137: }
rrenkert@137: catch(Exception e) {
rrenkert@137: e.printStackTrace();
rrenkert@137: }
rrenkert@137: }
rrenkert@137: else {
rrenkert@181: //Create a multi field expression.
vc11884admin@134: for (int i = 0; i < count; i++) {
vc11884admin@134: try {
rrenkert@181: //If no exception is thrown, the expression values are
rrenkert@181: //numbers.
vc11884admin@134: Double.parseDouble(ce.getAttribute("value_" + i));
vc11884admin@134: String exp = ce.getAttribute("expression_field_" + i);
vc11884admin@134: String pre = "";
vc11884admin@134: if (!prefix.equals("") && !exp.startsWith(prefix)) {
vc11884admin@134: pre = prefix + ".";
vc11884admin@134: }
vc11884admin@134: expression += "[" + pre;
rrenkert@180: expression += ce.getAttribute("expression_field_" + i);
rrenkert@180: expression += "]";
vc11884admin@134: expression += " " + ce.getAttribute("expression_operator");
vc11884admin@134: expression += " " + ce.getAttribute("value_" + i);
rrenkert@137: if (i < count - 1) {
rrenkert@137: expression += " AND ";
rrenkert@137: }
rrenkert@137: else {
rrenkert@137: expression += ")";
rrenkert@137: }
rrenkert@137: }
rrenkert@137: catch (NumberFormatException nfe) {
rrenkert@181: //The expression values are strings.
rrenkert@137: String exp = ce.getAttribute("expression_field_" + i);
vc11884admin@134: String pre = "";
vc11884admin@134: if (!prefix.equals("") && !exp.startsWith(prefix)) {
vc11884admin@134: pre = prefix + ".";
vc11884admin@134: }
vc11884admin@134: expression += "\"[" + pre;
rrenkert@180: expression += ce.getAttribute("expression_field_" + i);
rrenkert@180: expression += "]\"";
vc11884admin@134: expression += " " + ce.getAttribute("expression_operator");
raimund@186: expression += " \"" + ce.getAttribute("value_" + i);
rrenkert@137: if (i < count - 1) {
raimund@186: expression += "\" AND ";
rrenkert@137: }
rrenkert@137: else {
raimund@186: expression += "\")";
rrenkert@137: }
rrenkert@126: }
rrenkert@126: }
rrenkert@126: }
rrenkert@137: return expression;
rrenkert@127: }
raimund@189:
raimund@189: /**
raimund@189: * Replaces german umlauts and removes leading and trailing whitespaces.
raimund@189: *
raimund@189: * @param s String
raimund@189: */
raimund@189: private String validateString (String s) {
raimund@189: if (s.equals("")) {
raimund@189: return "";
raimund@189: }
raimund@189: String tmp = s.trim();
raimund@189: tmp = tmp.replace ("ö", "oe");
raimund@189: tmp = tmp.replace ("ä", "ae");
raimund@189: tmp = tmp.replace ("ü", "ue");
raimund@189: tmp = tmp.replace ("ß", "ss");
raimund@189: return tmp;
raimund@189: }
rrenkert@41: }