--- LDAPTransformer.java	2002-12-05 12:25:55 +0300
+++ ./patched/LDAPTransformer.java	2003-05-28 16:49:11 +0400
@@ -87,6 +87,10 @@
  * &lt;!ELEMENT execute-query (attribute+ | show-attribute? | scope? | initializer? | authentication? | error-element? | sax-error?  doc-element? | row-element? | version? | serverurl? | rootdn? | password? | deref-link? | count-limit? | searchbase, filter)&gt;<br>
  * &lt;!ELEMENT execute-increment (attribute | show-attribute? | scope? | initializer? | authentication? | error-element? | sax-error? | doc-element? | row-element? | version? | serverurl? | rootdn? | password? | deref-link? | count-limit? | searchbase, filter)&gt;<br>
  * increments (+1) an integer attribute on a directory-server (ldap)<br>
+ * &lt;!ELEMENT execute-replace (attribute | show-attribute? | scope? | initializer? | authentication? | error-element? | sax-error? | doc-element? | row-element? | version? | serverurl? | rootdn? | password? | deref-link? | count-limit? | searchbase, filter)&gt;<br>
+ * replace attribute on a directory-server (ldap)<br>
+ * &lt;!ELEMENT execute-add (attribute | show-attribute? | scope? | initializer? | authentication? | error-element? | sax-error? | doc-element? | row-element? | version? | serverurl? | rootdn? | password? | deref-link? | count-limit? | searchbase, filter)&gt;<br>
+ * add attribute on a directory-server (ldap)<br>
  * <br>
  * &lt;!ELEMENT initializer (#PCDATA)&gt;+ (default: "com.sun.jndi.ldap.LdapCtxFactory")<br>
  * &lt;!ELEMENT authentication (#PCDATA)&gt;+ (default: "simple")<br>
@@ -102,6 +106,8 @@
  * &lt;!ELEMENT error-element (#PCDATA)&gt;+ (default: "ldap-error") (in case of error returned error tag)<br>
  * &lt;!ELEMENT sax_error (TRUE  | FALSE)&gt+; (default: FALSE) (throws SAX-Exception instead of error tag)<br>
  * &lt;!ELEMENT attribute (#PCDATA)&gt;<br>
+ * &lt;!ATTLIST attribute name	CDATA	#IMPLIED &gt; (in case execute-replace or execute-add elements using) <br>
+
  * &lt;!ELEMENT show-attribute (TRUE | FALSE)&gt; (default: TRUE)<br>
  * &lt;!ELEMENT filter (#PCDATA | execute-query)&gt;<br>
  * &lt;!ELEMENT deref-link (TRUE | FALSE)&gt; (default: FALSE)<br>
@@ -131,6 +137,7 @@
     public static final String MAGIC_ERROR_ELEMENT = "error-element";
     public static final String MAGIC_SAX_ERROR = "sax-error";
     public static final String MAGIC_ATTRIBUTE_ELEMENT = "attribute";
+    public static final String MAGIC_ATTRIBUTE_ELEMENT_ATTRIBUTE = "name";
     public static final String MAGIC_SERVERURL_ELEMENT = "serverurl";
     public static final String MAGIC_PORT_ELEMENT = "port";
     public static final String MAGIC_SEARCHBASE_ELEMENT = "searchbase";
@@ -145,7 +152,10 @@
     public static final String MAGIC_COUNT_LIMIT_ELEMENT = "count-limit";
     public static final String MAGIC_TIME_LIMIT_ELEMENT = "time-limit";
     public static final String MAGIC_DEBUG_ELEMENT = "debug";
-
+    public static final String MAGIC_ENCODING_ELEMENT = "encoding";
+    public static final String MAGIC_EXECUTE_REPLACE = "execute-replace";
+    public static final String MAGIC_EXECUTE_ADD = "execute-add";
+    
     /** The states we are allowed to be in **/
     public static final int STATE_OUTSIDE = 0;
     public static final int STATE_INSIDE_EXECUTE_QUERY = 1;
@@ -171,6 +181,8 @@
     public static final int STATE_INSIDE_TIME_LIMIT_ELEMENT = 21;
     public static final int STATE_INSIDE_DEBUG_ELEMENT = 22;
     public static final int STATE_INSIDE_SAX_ERROR_ELEMENT = 23;
+    public static final int STATE_INSIDE_EXECUTE_REPLACE = 24;
+    public static final int STATE_INSIDE_EXECUTE_ADD = 25;
 
     /** Default parameters that might apply to all queries **/
     protected Properties default_properties = new Properties();
@@ -286,6 +298,14 @@
         if (parameter != null) {
             default_properties.setProperty(MAGIC_DEBUG_ELEMENT, parameter);
         }
+        // Check the encoding
+        parameter = parameters.getParameter(MAGIC_ENCODING_ELEMENT, null);
+        if (parameter != null) {
+	getLogger().debug("Get the sitemap parameter " + MAGIC_ENCODING_ELEMENT + "(" + parameter + ")");
+            default_properties.setProperty(MAGIC_ENCODING_ELEMENT, parameter);
+        }
+
+
     }
 
     /** END SitemapComponent methods **/
@@ -399,6 +419,92 @@
         }
     }
 
+/* add EXECUTE REPLACE (yuryx) */
+    protected void startExecuteReplace(Attributes attributes) {
+        LDAPQuery query;
+        switch (current_state) {
+            case LDAPTransformer.STATE_OUTSIDE:
+                current_state = LDAPTransformer.STATE_INSIDE_EXECUTE_REPLACE;
+                current_query_index = queries.size();
+                query = new LDAPQuery(this);
+                queries.addElement(query);
+                getCurrentQuery().toDo = LDAPTransformer.STATE_INSIDE_EXECUTE_REPLACE;
+                getCurrentQuery().query_index = current_query_index;
+                break;
+            case LDAPTransformer.STATE_INSIDE_EXECUTE_QUERY:
+                current_state = LDAPTransformer.STATE_INSIDE_EXECUTE_REPLACE;
+                current_query_index = queries.size();
+                query = new LDAPQuery(this);
+                queries.addElement(query);
+                getCurrentQuery().toDo = LDAPTransformer.STATE_INSIDE_EXECUTE_REPLACE;
+                getCurrentQuery().query_index = current_query_index;
+                break;
+            default:
+                throwIllegalStateException("Not expecting a start execute-replace element");
+        }
+    }
+
+    protected void endExecuteReplace() throws SAXException {
+        switch (current_state) {
+            case LDAPTransformer.STATE_INSIDE_EXECUTE_REPLACE:
+                executeQuery(current_query_index);
+                queries.remove(current_query_index);
+                --current_query_index;
+                if (current_query_index > 1) {
+                    current_state = getCurrentQuery().toDo;
+                } else {
+                    queries.removeAllElements();
+                    current_state = LDAPTransformer.STATE_OUTSIDE;
+                }
+                break;
+            default:
+                throwIllegalStateException("Not expecting a end execute-replace element");
+        }
+    }
+
+/* add EXECUTE ADD (yuryx) */
+    protected void startExecuteAdd(Attributes attributes) {
+        LDAPQuery query;
+        switch (current_state) {
+            case LDAPTransformer.STATE_OUTSIDE:
+                current_state = LDAPTransformer.STATE_INSIDE_EXECUTE_ADD;
+                current_query_index = queries.size();
+                query = new LDAPQuery(this);
+                queries.addElement(query);
+                getCurrentQuery().toDo = LDAPTransformer.STATE_INSIDE_EXECUTE_ADD;
+                getCurrentQuery().query_index = current_query_index;
+                break;
+            case LDAPTransformer.STATE_INSIDE_EXECUTE_QUERY:
+                current_state = LDAPTransformer.STATE_INSIDE_EXECUTE_ADD;
+                current_query_index = queries.size();
+                query = new LDAPQuery(this);
+                queries.addElement(query);
+                getCurrentQuery().toDo = LDAPTransformer.STATE_INSIDE_EXECUTE_ADD;
+                getCurrentQuery().query_index = current_query_index;
+                break;
+            default:
+                throwIllegalStateException("Not expecting a start execute-add element");
+        }
+    }
+
+    protected void endExecuteAdd() throws SAXException {
+        switch (current_state) {
+            case LDAPTransformer.STATE_INSIDE_EXECUTE_ADD:
+                executeQuery(current_query_index);
+                queries.remove(current_query_index);
+                --current_query_index;
+                if (current_query_index > 1) {
+                    current_state = getCurrentQuery().toDo;
+                } else {
+                    queries.removeAllElements();
+                    current_state = LDAPTransformer.STATE_OUTSIDE;
+                }
+                break;
+            default:
+                throwIllegalStateException("Not expecting a end execute-add element");
+        }
+    }
+
     protected void startInitializerElement(Attributes attributes) {
         switch (current_state) {
             case STATE_INSIDE_EXECUTE_QUERY:
@@ -411,6 +517,17 @@
                 current_state = LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT;
                 getCurrentQuery().current_state = LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT;
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT;
+                getCurrentQuery().current_state = LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT;
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT;
+                getCurrentQuery().current_state = LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT;
+                break;
+		
             default:
                 throwIllegalStateException("Not expecting a start initializer element");
         }
@@ -439,6 +556,17 @@
                 current_state = LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT;
                 getCurrentQuery().current_state = LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT;
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT;
+                getCurrentQuery().current_state = LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT;
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT;
+                getCurrentQuery().current_state = LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT;
+                break;
+
             default:
                 throwIllegalStateException("Not expecting a start scope element");
         }
@@ -467,6 +595,17 @@
                 current_state = LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT;
                 getCurrentQuery().current_state = LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT;
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT;
+                getCurrentQuery().current_state = LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT;
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT;
+                getCurrentQuery().current_state = LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT;
+                break;
+
             default:
                 throwIllegalStateException("Not expecting a start authentication element");
         }
@@ -493,6 +632,15 @@
                 current_value.setLength(0);
                 current_state = LDAPTransformer.STATE_INSIDE_SERVERURL_ELEMENT;
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_SERVERURL_ELEMENT;
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_SERVERURL_ELEMENT;
+                break;
+
             default:
                 throwIllegalStateException("Not expecting a start serverurl element");
         }
@@ -519,6 +667,15 @@
                 current_value.setLength(0);
                 current_state = LDAPTransformer.STATE_INSIDE_PORT_ELEMENT;
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_PORT_ELEMENT;
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_PORT_ELEMENT;
+                break;
+
             default:
                 throwIllegalStateException("Not expecting a start port element");
         }
@@ -545,6 +702,12 @@
                 current_value.setLength(0);
                 current_state = LDAPTransformer.STATE_INSIDE_SHOW_ATTRIBUTE_ELEMENT;
                 break;
+/*		
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_SHOW_ATTRIBUTE_ELEMENT;
+                break;
+*/
             default:
                 throwIllegalStateException("Not expecting a start show-attribute element");
         }
@@ -573,6 +736,15 @@
                 current_value.setLength(0);
                 current_state = LDAPTransformer.STATE_INSIDE_SEARCHBASE_ELEMENT;
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_SEARCHBASE_ELEMENT;
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_SEARCHBASE_ELEMENT;
+                break;
+
             default:
                 throwIllegalStateException("Not expecting a start searchbase element");
         }
@@ -599,6 +771,15 @@
                 current_value.setLength(0);
                 current_state = LDAPTransformer.STATE_INSIDE_DOC_ELEMENT;
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_DOC_ELEMENT;
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_DOC_ELEMENT;
+                break;
+
             default:
                 throwIllegalStateException("Not expecting a start doc-element element");
         }
@@ -625,6 +806,15 @@
                 current_value.setLength(0);
                 current_state = LDAPTransformer.STATE_INSIDE_ROW_ELEMENT;
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_ROW_ELEMENT;
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_ROW_ELEMENT;
+                break;
+
             default:
                 throwIllegalStateException("Not expecting a start row-element element");
         }
@@ -651,6 +841,14 @@
                 current_value.setLength(0);
                 current_state = LDAPTransformer.STATE_INSIDE_ERROR_ELEMENT;
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_ERROR_ELEMENT;
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_ERROR_ELEMENT;
+                break;
             default:
                 throwIllegalStateException("Not expecting a start error-element element");
         }
@@ -677,6 +875,15 @@
                 current_value.setLength(0);
                 current_state = LDAPTransformer.STATE_INSIDE_SAX_ERROR_ELEMENT;
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_SAX_ERROR_ELEMENT;
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_SAX_ERROR_ELEMENT;
+                break;
+
             default:
                 throwIllegalStateException("Not expecting a start sax-error element");
         }
@@ -705,6 +912,15 @@
                 current_value.setLength(0);
                 current_state = LDAPTransformer.STATE_INSIDE_ROOT_DN_ELEMENT;
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_ROOT_DN_ELEMENT;
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_ROOT_DN_ELEMENT;
+                break;
+
             default:
                 throwIllegalStateException("Not expecting a start root-dn element");
         }
@@ -730,6 +946,15 @@
                 current_value.setLength(0);
                 current_state = LDAPTransformer.STATE_INSIDE_PASSWORD_ELEMENT;
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_PASSWORD_ELEMENT;
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_PASSWORD_ELEMENT;
+                break;
+
             default:
                 throwIllegalStateException("Not expecting a start password element");
         }
@@ -756,6 +981,55 @@
                 current_state = LDAPTransformer.STATE_INSIDE_ATTRIBUTE_ELEMENT;
                 current_value.setLength(0);
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+	         if (attributes != null && attributes.getLength() > 0) {
+                     AttributesImpl new_attributes = new AttributesImpl(attributes);
+                     for (int i = 0; i < new_attributes.getLength(); i++) {
+                         String attr_name = new_attributes.getLocalName(i);
+                         if(attr_name.equals(MAGIC_ATTRIBUTE_ELEMENT_ATTRIBUTE))
+			 {
+                          String value = new_attributes.getValue(i);
+			  getCurrentQuery().addAttrList(value);
+			 }else
+			 {
+			  this.getLogger().debug("Invalid attribute match: " + attr_name);
+			  throwIllegalStateException("Invalid attribute match in start attribute element");
+			 }
+		     }
+		 }else
+		 {
+		  this.getLogger().debug("Do not match 'value' attribute");
+		  throwIllegalStateException("Do not match 'value' attribute in start attribute element");
+		 };
+
+                current_state = LDAPTransformer.STATE_INSIDE_ATTRIBUTE_ELEMENT;
+                current_value.setLength(0);
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+	         if (attributes != null && attributes.getLength() > 0) {
+                     AttributesImpl new_attributes = new AttributesImpl(attributes);
+                     for (int i = 0; i < new_attributes.getLength(); i++) {
+                         String attr_name = new_attributes.getLocalName(i);
+                         if(attr_name.equals(MAGIC_ATTRIBUTE_ELEMENT_ATTRIBUTE))
+			 {
+                          String value = new_attributes.getValue(i);
+			  getCurrentQuery().addAttrList(value);
+			 }else
+			 {
+			  this.getLogger().debug("Invalid attribute match: " + attr_name);
+			  throwIllegalStateException("Invalid attribute match in start attribute element");
+			 }
+		     }
+		 }else
+		 {
+		  this.getLogger().debug("Do not match 'value' attribute");
+		  throwIllegalStateException("Do not match 'value' attribute in start attribute element");
+		 };
+
+                current_state = LDAPTransformer.STATE_INSIDE_ATTRIBUTE_ELEMENT;
+                current_value.setLength(0);
+                break;
+
             default:
                 throwIllegalStateException("Not expecting a start attribute element");
         }
@@ -764,6 +1038,13 @@
     protected void endAttributeElement() {
         switch (current_state) {
             case LDAPTransformer.STATE_INSIDE_ATTRIBUTE_ELEMENT:
+	        if((getCurrentQuery().toDo == STATE_INSIDE_EXECUTE_REPLACE) || 
+		   (getCurrentQuery().toDo == STATE_INSIDE_EXECUTE_ADD))
+		{
+		 getCurrentQuery().addAttrVal(current_value.toString());
+		 current_state = getCurrentQuery().toDo;
+		 break;
+		};
                 getCurrentQuery().addAttrList(current_value.toString());
                 current_state = getCurrentQuery().toDo;
                 break;
@@ -782,6 +1063,15 @@
                 current_state = LDAPTransformer.STATE_INSIDE_VERSION_ELEMENT;
                 current_value.setLength(0);
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_state = LDAPTransformer.STATE_INSIDE_VERSION_ELEMENT;
+                current_value.setLength(0);
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_state = LDAPTransformer.STATE_INSIDE_VERSION_ELEMENT;
+                current_value.setLength(0);
+                break;
+
             default:
                 throwIllegalStateException("Not expecting a start version element");
         }
@@ -810,6 +1100,17 @@
                 getCurrentQuery().current_state = LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT;
                 current_value.setLength(0);
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_state = LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT;
+                getCurrentQuery().current_state = LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT;
+                current_value.setLength(0);
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_state = LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT;
+                getCurrentQuery().current_state = LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT;
+                current_value.setLength(0);
+                break;
+
             default:
                 throwIllegalStateException("Not expecting a start filter element");
         }
@@ -836,6 +1137,15 @@
                 current_state = LDAPTransformer.STATE_INSIDE_DEREF_LINK_ELEMENT;
                 current_value.setLength(0);
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_state = LDAPTransformer.STATE_INSIDE_DEREF_LINK_ELEMENT;
+                current_value.setLength(0);
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_state = LDAPTransformer.STATE_INSIDE_DEREF_LINK_ELEMENT;
+                current_value.setLength(0);
+                break;
+
             default:
                 throwIllegalStateException("Not expecting a start deref-link element");
         }
@@ -864,6 +1174,14 @@
                 current_state = LDAPTransformer.STATE_INSIDE_COUNT_LIMIT_ELEMENT;
                 current_value.setLength(0);
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_state = LDAPTransformer.STATE_INSIDE_COUNT_LIMIT_ELEMENT;
+                current_value.setLength(0);
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_state = LDAPTransformer.STATE_INSIDE_COUNT_LIMIT_ELEMENT;
+                current_value.setLength(0);
+                break;
             default:
                 throwIllegalStateException("Not expecting a start count-limit element");
         }
@@ -890,6 +1208,14 @@
                 current_state = LDAPTransformer.STATE_INSIDE_TIME_LIMIT_ELEMENT;
                 current_value.setLength(0);
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_state = LDAPTransformer.STATE_INSIDE_TIME_LIMIT_ELEMENT;
+                current_value.setLength(0);
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_state = LDAPTransformer.STATE_INSIDE_TIME_LIMIT_ELEMENT;
+                current_value.setLength(0);
+                break;
             default:
                 throwIllegalStateException("Not expecting a start time-limit element");
         }
@@ -916,6 +1242,14 @@
                 current_value.setLength(0);
                 current_state = LDAPTransformer.STATE_INSIDE_DEBUG_ELEMENT;
                 break;
+            case STATE_INSIDE_EXECUTE_REPLACE:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_DEBUG_ELEMENT;
+                break;
+            case STATE_INSIDE_EXECUTE_ADD:
+                current_value.setLength(0);
+                current_state = LDAPTransformer.STATE_INSIDE_DEBUG_ELEMENT;
+                break;
             default:
                 throwIllegalStateException("Not expecting a start debug element");
         }
@@ -1007,7 +1341,11 @@
             startTimeLimitElement(attributes);
         } else if (name.equals(LDAPTransformer.MAGIC_DEBUG_ELEMENT)) {
             startDebugElement(attributes);
-        }
+        }else if (name.equals(LDAPTransformer.MAGIC_EXECUTE_REPLACE)) {
+            startExecuteReplace(attributes);
+	}else if (name.equals(LDAPTransformer.MAGIC_EXECUTE_ADD)) {
+            startExecuteAdd(attributes);
+	}
     }
 
     public void endElement(String uri, String name,
@@ -1062,7 +1400,11 @@
             endTimeLimitElement();
         } else if (name.equals(LDAPTransformer.MAGIC_DEBUG_ELEMENT)) {
             endDebugElement();
-        }
+        }else if (name.equals(LDAPTransformer.MAGIC_EXECUTE_REPLACE)) {
+            endExecuteReplace();
+	}else if (name.equals(LDAPTransformer.MAGIC_EXECUTE_ADD)) {
+            endExecuteAdd();
+	}
     }
 
     public void characters(char ary[], int start, int length) throws SAXException {
@@ -1147,6 +1489,7 @@
         protected String version = "2";
         protected String scope = "ONELEVEL_SCOPE";
         protected String authentication = "simple";
+	protected String encoding = "ISO-8859-1";
 
         /** LDAP environment information **/
         protected Properties env = new Properties();
@@ -1156,9 +1499,11 @@
         protected int toDo;
         protected String searchbase = "";
         protected List attrListe = new LinkedList();
+	protected List attrVale = new LinkedList();
         protected boolean showAttribute = true;
         protected String filter = "";
         protected String doc_element = "doc-element";
+        protected String exec_element = "exec-element";
         protected String row_element = "row-element";
         protected String error_element = "ldap-error";
         protected boolean sax_error = false;
@@ -1223,10 +1568,15 @@
             if (null != transformer.default_properties.getProperty(transformer.MAGIC_DEBUG_ELEMENT)) {
                 debug = transformer.default_properties.getProperty(transformer.MAGIC_DEBUG_ELEMENT).equals("TRUE") ? true : false;
             }
+            if (null != transformer.default_properties.getProperty(transformer.MAGIC_ENCODING_ELEMENT)) {
+                encoding = transformer.default_properties.getProperty(transformer.MAGIC_ENCODING_ELEMENT);
+            }
+
         }
 
         protected void execute() throws Exception, NamingException {
             String[] attrList = new String[attrListe.size()];
+	    
             AttributesImpl attr = new AttributesImpl();
             if (debug) {
                 debugPrint();
@@ -1252,12 +1602,15 @@
                             if (attrList.length > 0) {
                                 constraints.setReturningAttributes(attrList);
                             }
-                            NamingEnumeration ldapresults = ctx.search(searchbase, filter, constraints);
 
+			    if(!filter.equals(""))
+			    {
+                             //filter is present
                             if (!doc_element.equals("")) {
                                 transformer.start(doc_element, attr);
-                            }
-
+                            };
+                            NamingEnumeration ldapresults = ctx.search(searchbase, filter, constraints);
+			    
                             while (ldapresults != null && ldapresults.hasMore()) {
                                 if (!row_element.equals("")) {
                                     transformer.start(row_element, attr);
@@ -1274,6 +1627,13 @@
                                             transformer.start(attrID, attr);
                                         }
                                         String attrVal = (String)vals.nextElement();
+					
+					//Changed by yuryx (encode string value to UTF characters from base encoding)
+					if(!encoding.equals("ISO-8859-1"))
+					{
+					 attrVal = new String(attrVal.getBytes("ISO-8859-1"), encoding);
+					};
+					//end
                                         if (query_index > 0) {
                                             switch (transformer.getQuery(query_index-1).current_state) {
                                                 case LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT:
@@ -1300,6 +1660,65 @@
                             if (!doc_element.equals("")) {
                                 transformer.end(doc_element);
                             }
+
+			    }else
+			    {
+			    //filter not present, get the values from absolete path
+			    javax.naming.directory.Attributes attrs = ctx.getAttributes(searchbase,attrList);
+                            if (!doc_element.equals("")) {
+                                transformer.start(doc_element, attr);
+			    };
+                            if (!row_element.equals("")) {
+                                transformer.start(row_element, attr);
+                            }
+    
+			      if (attrs != null) {
+				
+                                    NamingEnumeration ae = attrs.getAll();
+                                    while (ae.hasMoreElements()) {
+                                        Attribute at = (Attribute)ae.next();
+                                        Enumeration vals = at.getAll();
+                                        String attrID = at.getID();
+                                        if (showAttribute) {
+                                            transformer.start(attrID, attr);
+                                        }
+                                        String attrVal = (String)vals.nextElement();
+					
+					//Changed by yuryx (encode string value to UTF characters from base encoding)
+					if(!encoding.equals("ISO-8859-1"))
+					{
+					 attrVal = new String(attrVal.getBytes("ISO-8859-1"), encoding);
+					};
+					//end
+                                        if (query_index > 0) {
+                                            switch (transformer.getQuery(query_index-1).current_state) {
+                                                case LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT:
+                                                    if (!transformer.getQuery(query_index-1).filter.equals("")) {
+                                                        transformer.getQuery(query_index-1).filter.concat(", ");
+                                                    }
+                                                    transformer.getQuery(query_index-1).filter.concat(attrID).concat("=").concat(attrVal);
+                                                    break;
+                                                default:
+                                                    transformer.start(attrID, attr);
+                                            }
+                                        } else {
+                                            transformer.data(String.valueOf(attrVal));
+                                        }
+                                        if (showAttribute) {
+                                            transformer.end(attrID);
+                                        }
+                                    }
+                                }
+				
+                            if (!row_element.equals("")) {
+                                transformer.end(row_element);
+                            }
+                            if (!doc_element.equals("")) {
+                                transformer.end(doc_element);
+                            }
+
+			    
+			    };
                         } catch(Exception e) {
                             if (sax_error) {
                                 throw new Exception ("[LDAPTransformer] Error in LDAP-Query: " + e.toString());
@@ -1367,6 +1786,391 @@
                             }
                         }
                         break;
+		    case LDAPTransformer.STATE_INSIDE_EXECUTE_REPLACE:
+		        
+                        try {
+			    String[] attrVal = new String[attrVale.size()];
+			    attrVale.toArray(attrVal);
+                            attrVale.clear();
+			    if(attrVal.length != attrList.length)
+			    {
+                             transformer.start(error_element, attr);
+                             transformer.data("Attribute values must have the some number as a names");
+                             transformer.end(error_element);
+			     break;
+			    };
+                            HashMap attrMap = new HashMap(attrVal.length);
+			    
+			    for(int i = 0;i < attrVal.length; i++)
+				attrMap.put(attrList[i], attrVal[i]);
+				
+                            if (scope.equals("OBJECT_SCOPE")) {
+                                constraints.setSearchScope(SearchControls.OBJECT_SCOPE);
+                            } else if (scope.equals("SUBTREE_SCOPE")) {
+                                constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
+                            } else {
+                                constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+                            }
+                            constraints.setTimeLimit(time_limit);
+                            constraints.setDerefLinkFlag(deref_link);
+                            constraints.setCountLimit(count_limit);
+                            if (attrList.length < 1) {
+                                transformer.start(error_element, attr);
+                                transformer.data("Modify must reference 1 or more attribute.");
+                                transformer.end(error_element);
+                            } else {
+			     if(!filter.equals(""))
+			     {
+                                constraints.setReturningAttributes(attrList);
+                                NamingEnumeration ldapresults = ctx.search(searchbase, filter, constraints);
+                                String attrID = "";
+                                SearchResult si = null;
+				/* start indicate element of executing query */
+				if (!exec_element.equals("")) {
+                                   transformer.start(exec_element, attr);
+                                }
+                                while (ldapresults != null && ldapresults.hasMore()) {
+				 if (!row_element.equals("")) {
+                                    transformer.start(row_element, attr);
+                                 };
+
+                                    si = (SearchResult)ldapresults.next();
+                                    javax.naming.directory.Attributes attrs = si.getAttributes();
+                                    if (attrs != null) {
+                                        NamingEnumeration ae = attrs.getAll();
+                                        while (ae.hasMoreElements()) {
+                                            Attribute at = (Attribute)ae.next();
+                                            attrID = at.getID();
+                                            // Specify the changes to make
+                                            ModificationItem[] mods = new ModificationItem[1];
+					    //Changed by yuryx (encode string value to UTF characters from base encoding)
+					    
+					    if(!encoding.equals("ISO-8859-1"))
+					    {
+                                             mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
+					     new BasicAttribute(attrID, 
+					         new String (((String) attrMap.get(attrID)).getBytes(encoding), "ISO-8859-1")));
+					     
+					    }else
+					    {
+                                             mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
+                                             new BasicAttribute(attrID, (String) attrMap.get(attrID)));
+					    };
+                                            // Perform the requested modifications on the named object
+                                            ctx.modifyAttributes(new StringBuffer(si.toString().substring(0,si.toString().indexOf(":")))
+                                             .append(",").append(searchbase).toString(), mods);
+					     
+					    /* confirm of success */
+					    transformer.start(attrID, attr);
+					    transformer.data(new String("replaced"));
+                                            transformer.end(attrID);
+                                        }
+                                    };
+				   
+				   if (!row_element.equals("")) {
+                                    transformer.end(row_element);
+                                   }
+
+                                };
+		                if (!exec_element.equals("")) {
+                                   transformer.end(exec_element);
+                                }
+			      }else
+			      {
+			       //filter is not present
+			       javax.naming.directory.Attributes attrs = ctx.getAttributes(searchbase,attrList);
+			       String attrID = "";
+				/* start indicate element of executing query */
+				if (!exec_element.equals("")) {
+                                   transformer.start(exec_element, attr);
+                                };
+				if (!row_element.equals("")) {
+                                   transformer.start(row_element, attr);
+                                };
+
+                                    if (attrs != null) {
+                                        NamingEnumeration ae = attrs.getAll();
+                                        while (ae.hasMoreElements()) {
+                                            Attribute at = (Attribute)ae.next();
+                                            attrID = at.getID();
+                                            // Specify the changes to make
+                                            ModificationItem[] mods = new ModificationItem[1];
+					    //Changed by yuryx (encode string value to UTF characters from base encoding)
+					    
+					    if(!encoding.equals("ISO-8859-1"))
+					    {
+                                             mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
+					     new BasicAttribute(attrID, 
+					         new String (((String) attrMap.get(attrID)).getBytes(encoding), "ISO-8859-1")));
+					     
+					    }else
+					    {
+                                             mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
+                                             new BasicAttribute(attrID, (String) attrMap.get(attrID)));
+					    };
+                                            // Perform the requested modifications on the named object
+                                            ctx.modifyAttributes(searchbase, mods);
+					     
+					    /* confirm of success */
+					    transformer.start(attrID, attr);
+					    transformer.data(new String("replaced"));
+                                            transformer.end(attrID);
+                                        }
+                                    };
+				    
+				if (!row_element.equals("")) {
+                                   transformer.end(row_element);
+                                };
+
+				/* end indicate element of executing query */
+		                if (!exec_element.equals("")) {
+                                   transformer.end(exec_element);
+                                }
+			      };
+                            };
+			    
+			    
+                        } catch(Exception e) {
+                            if (sax_error) {
+                                throw new Exception ("[LDAPTransformer] Error replacing an attribute: " + e.toString());
+                            } else {
+                                transformer.start(error_element, attr);
+                                transformer.data("[LDAPTransformer] Error replacing an attribute: " + e.toString());
+                                transformer.end(error_element);
+                                transformer.getTheLogger().error("[LDAPTransformer] Error replacing an attribute: " + e.toString());
+				if (!row_element.equals("")) {
+                                 transformer.end(row_element);
+                                };
+				if (!exec_element.equals("")) {
+                                 transformer.end(exec_element);
+                                }
+                            }
+                        }
+                        break;
+		    case LDAPTransformer.STATE_INSIDE_EXECUTE_ADD:
+		        
+                        try {
+			    String[] attrVal = new String[attrVale.size()];
+			    attrVale.toArray(attrVal);
+                            attrVale.clear();
+			    if(attrVal.length != attrList.length)
+			    {
+                             transformer.start(error_element, attr);
+                             transformer.data("Attribute values must have the some number as a names");
+                             transformer.end(error_element);
+			     break;
+			    };
+                            HashMap attrMap = new HashMap(attrVal.length);
+			    
+			    for(int i = 0;i < attrVal.length; i++)
+				attrMap.put(attrList[i], attrVal[i]);
+				
+                            if (scope.equals("OBJECT_SCOPE")) {
+                                constraints.setSearchScope(SearchControls.OBJECT_SCOPE);
+                            } else if (scope.equals("SUBTREE_SCOPE")) {
+                                constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
+                            } else {
+                                constraints.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+                            }
+                            constraints.setTimeLimit(time_limit);
+                            constraints.setDerefLinkFlag(deref_link);
+                            constraints.setCountLimit(count_limit);
+                            if (attrList.length < 1) {
+                                transformer.start(error_element, attr);
+                                transformer.data("Modify must reference 1 or more attribute.");
+                                transformer.end(error_element);
+                            } else {
+			     if(!filter.equals(""))
+			     {
+                                constraints.setReturningAttributes(attrList);
+                                NamingEnumeration ldapresults = ctx.search(searchbase, filter, constraints);
+                                String attrID = "";
+                                SearchResult si = null;
+				/* start indicate element of executing query */
+				if (!exec_element.equals("")) {
+                                   transformer.start(exec_element, attr);
+                                }
+                                while (ldapresults != null && ldapresults.hasMore()) {
+				 if (!row_element.equals("")) {
+                                    transformer.start(row_element, attr);
+                                 };
+
+                                    si = (SearchResult)ldapresults.next();
+                                    javax.naming.directory.Attributes attrs = si.getAttributes();
+                                    if (attrs != null) {
+				     /* Replace the attribute if attribute already exist */
+                                        NamingEnumeration ae = attrs.getAll();
+                                        while (ae.hasMoreElements()) {
+                                            Attribute at = (Attribute)ae.next();
+                                            attrID = at.getID();
+                                            // Specify the changes to make
+                                            ModificationItem[] mods = new ModificationItem[1];
+					    //Changed by yuryx (encode string value to UTF characters from base encoding)
+					    
+					    if(!encoding.equals("ISO-8859-1"))
+					    {
+                                             mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
+					     new BasicAttribute(attrID, 
+					         new String (((String) attrMap.get(attrID)).getBytes(encoding), "ISO-8859-1")));
+					     
+					    }else
+					    {
+                                             mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
+                                             new BasicAttribute(attrID, (String) attrMap.get(attrID)));
+					    };
+                                            // Perform the requested modifications on the named object
+                                            ctx.modifyAttributes(new StringBuffer(si.toString().substring(0,si.toString().indexOf(":")))
+                                             .append(",").append(searchbase).toString(), mods);
+					     
+					    /* confirm of success */
+					    transformer.start(attrID, attr);
+					    transformer.data(new String("replaced"));
+                                            transformer.end(attrID);
+					    /* Remove the attribute from map after replacing */
+					    attrMap.remove(attrID);
+                                        }
+                                    };
+				    /* Add the attributes */
+				    if(attrMap.size() > 0)
+				    {
+				     ModificationItem[] mods = new ModificationItem[1];
+				     for(int i = 0;i < attrList.length;i++)
+				     {
+				      if(attrMap.containsKey(attrList[i]))
+				      {
+					if(!encoding.equals("ISO-8859-1"))
+					{
+                                         mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
+					 new BasicAttribute(attrList[i], 
+					     new String (((String) attrMap.get(attrList[i])).getBytes(encoding), "ISO-8859-1")));
+					}else
+					{
+                                         mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
+                                         new BasicAttribute(attrList[i], (String) attrMap.get(attrList[i])));
+					};
+                                        // Perform the requested modifications on the named object
+                                        ctx.modifyAttributes(new StringBuffer(si.toString().substring(0,si.toString().indexOf(":")))
+                                         .append(",").append(searchbase).toString(), mods);
+					 
+					/* confirm of success */
+					transformer.start(attrList[i], attr);
+					transformer.data(new String("add"));
+                                        transformer.end(attrList[i]);
+				      }
+				     }
+				    };
+				   if (!row_element.equals("")) {
+                                    transformer.end(row_element);
+                                   }
+
+                                };
+		                if (!exec_element.equals("")) {
+                                   transformer.end(exec_element);
+                                }
+			      }else
+			      {
+			       //filter is not present
+			       javax.naming.directory.Attributes attrs = ctx.getAttributes(searchbase,attrList);
+			       String attrID = "";
+				/* start indicate element of executing query */
+				if (!exec_element.equals("")) {
+                                   transformer.start(exec_element, attr);
+                                };
+				if (!row_element.equals("")) {
+                                   transformer.start(row_element, attr);
+                                };
+
+                                    if (attrs != null) {
+                                        NamingEnumeration ae = attrs.getAll();
+                                        while (ae.hasMoreElements()) {
+                                            Attribute at = (Attribute)ae.next();
+                                            attrID = at.getID();
+                                            // Specify the changes to make
+                                            ModificationItem[] mods = new ModificationItem[1];
+					    //Changed by yuryx (encode string value to UTF characters from base encoding)
+					    
+					    if(!encoding.equals("ISO-8859-1"))
+					    {
+                                             mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
+					     new BasicAttribute(attrID, 
+					         new String (((String) attrMap.get(attrID)).getBytes(encoding), "ISO-8859-1")));
+					     
+					    }else
+					    {
+                                             mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
+                                             new BasicAttribute(attrID, (String) attrMap.get(attrID)));
+					    };
+                                            // Perform the requested modifications on the named object
+                                            ctx.modifyAttributes(searchbase, mods);
+					     
+					    /* confirm of success */
+					    transformer.start(attrID, attr);
+					    transformer.data(new String("replaced"));
+                                            transformer.end(attrID);
+    					    /* Remove the attribute from map after replacing */
+					    attrMap.remove(attrID);
+
+                                        }
+                                    };
+				    /* Add the attributes */
+				    if(attrMap.size() > 0)
+				    {
+				     ModificationItem[] mods = new ModificationItem[1];
+				     for(int i = 0;i < attrList.length;i++)
+				     {
+				      if(attrMap.containsKey(attrList[i]))
+				      {
+					if(!encoding.equals("ISO-8859-1"))
+					{
+                                         mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
+					 new BasicAttribute(attrList[i], 
+					     new String (((String) attrMap.get(attrList[i])).getBytes(encoding), "ISO-8859-1")));
+					}else
+					{
+                                         mods[0] = new ModificationItem(DirContext.ADD_ATTRIBUTE,
+                                         new BasicAttribute(attrList[i], (String) attrMap.get(attrList[i])));
+					};
+                                        // Perform the requested modifications on the named object
+					ctx.modifyAttributes(searchbase, mods); 
+					/* confirm of success */
+					transformer.start(attrList[i], attr);
+					transformer.data(new String("add"));
+                                        transformer.end(attrList[i]);
+				      }
+				     }
+				    };
+
+				    
+				if (!row_element.equals("")) {
+                                   transformer.end(row_element);
+                                };
+
+				/* end indicate element of executing query */
+		                if (!exec_element.equals("")) {
+                                   transformer.end(exec_element);
+                                }
+			      };
+                            };
+			    
+			    
+                        } catch(Exception e) {
+                            if (sax_error) {
+                                throw new Exception ("[LDAPTransformer] Error replacing an attribute: " + e.toString());
+                            } else {
+                                transformer.start(error_element, attr);
+                                transformer.data("[LDAPTransformer] Error replacing an attribute: " + e.toString());
+                                transformer.end(error_element);
+                                transformer.getTheLogger().error("[LDAPTransformer] Error replacing an attribute: " + e.toString());
+				if (!row_element.equals("")) {
+                                 transformer.end(row_element);
+                                };
+				if (!exec_element.equals("")) {
+                                 transformer.end(exec_element);
+                                }
+                            }
+                        }
+                        break;
+		     
                     default:
                 } //end switch
             } catch (NamingException e) {
@@ -1397,6 +2201,10 @@
             attrListe.add(attr);
         }
 
+        protected void addAttrVal(String val) {
+            attrVale.add(val);
+        }
+
         protected void connect() throws NamingException {
             if (root_dn != null && password != null) {
                 env.put(Context.SECURITY_AUTHENTICATION, authentication);
