You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jb...@apache.org on 2006/03/08 09:29:48 UTC

svn commit: r384153 - /cocoon/blocks/naming/trunk/java/org/apache/cocoon/transformation/LDAPTransformer.java

Author: jbq
Date: Wed Mar  8 00:29:41 2006
New Revision: 384153

URL: http://svn.apache.org/viewcvs?rev=384153&view=rev
Log:
Sync with 2.1

Modified:
    cocoon/blocks/naming/trunk/java/org/apache/cocoon/transformation/LDAPTransformer.java

Modified: cocoon/blocks/naming/trunk/java/org/apache/cocoon/transformation/LDAPTransformer.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/naming/trunk/java/org/apache/cocoon/transformation/LDAPTransformer.java?rev=384153&r1=384152&r2=384153&view=diff
==============================================================================
--- cocoon/blocks/naming/trunk/java/org/apache/cocoon/transformation/LDAPTransformer.java (original)
+++ cocoon/blocks/naming/trunk/java/org/apache/cocoon/transformation/LDAPTransformer.java Wed Mar  8 00:29:41 2006
@@ -65,15 +65,18 @@
  * <br>
  *
  * The following DTD is valid:<br>
- * &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>
+ * &lt;!ELEMENT execute-query (attribute+ | show-attribute? | scope? | initializer? | initial-context? | 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? | initial-context? | 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>
+ * &lt;!ELEMENT execute-replace (attribute | show-attribute? | scope? | initializer? | initial-context? | 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>
+ * &lt;!ELEMENT execute-add (attribute | show-attribute? | scope? | initializer? | initial-context? | 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 initial-context (#EMPTY)&gt;<br>
+ * &lt;!ATTLIST initial-context name CDATA #REQUIRED
+                                value CDATA #REQUIRED &gt;<br>
  * &lt;!ELEMENT authentication (#PCDATA)&gt;+ (default: "simple")<br>
  * &lt;!ELEMENT version (#PCDATA)&gt;+ (default: "2")<br>
  * &lt;!ELEMENT serverurl (#PCDATA)&gt;+<br>
@@ -101,9 +104,6 @@
  * + can also be defined as parameter in the sitemap.
  * <br>
  *
- * @author Felix Knecht
- * @author <a href="mailto:unico@hippo.nl">Unico Hommes</a>
- * @author <a href="mailto:yuryx@mobicomk.donpac.ru">Yury Mikhienko</a>
  * @version $Id$
  */
 public class LDAPTransformer extends AbstractTransformer {
@@ -131,6 +131,9 @@
     public static final String MAGIC_EXECUTE_REPLACE = "execute-replace";
     public static final String MAGIC_FILTER_ELEMENT = "filter";
     public static final String MAGIC_INITIALIZER_ELEMENT = "initializer";
+    public static final String MAGIC_INITIAL_CONTEXT_ELEMENT = "initial-context";
+    public static final String MAGIC_INITIAL_CONTEXT_NAME_ATTRIBUTE = "name";
+    public static final String MAGIC_INITIAL_CONTEXT_VALUE_ATTRIBUTE = "value";
     public static final String MAGIC_PASSWORD_ELEMENT = "password";
     public static final String MAGIC_PORT_ELEMENT = "port";
     public static final String MAGIC_ROOT_DN_ELEMENT = "rootdn";
@@ -172,6 +175,7 @@
     public static final int STATE_INSIDE_EXECUTE_REPLACE = 24;
     public static final int STATE_INSIDE_EXECUTE_ADD = 25;
     public static final int STATE_INSIDE_DN_ATTRIBUTE = 26;
+    public static final int STATE_INSIDE_INITIAL_CONTEXT_ELEMENT = 27;
 
     /** Default parameters that might apply to all queries */
     protected HashMap default_properties = new HashMap();
@@ -579,6 +583,51 @@
         }
     }
 
+    protected void startInitialContextElement(Attributes attributes) {
+        switch (current_state) {
+            case STATE_INSIDE_EXECUTE_INCREMENT :
+                current_state = LDAPTransformer.STATE_INSIDE_INITIAL_CONTEXT_ELEMENT;
+                current_value.setLength(0);
+                break;
+            case STATE_INSIDE_EXECUTE_QUERY :
+            case STATE_INSIDE_EXECUTE_ADD :
+            case STATE_INSIDE_EXECUTE_REPLACE :
+                String name = null, value = null;
+
+                if (attributes != null && attributes.getLength() > 0) {
+                		name = attributes.getValue("name");
+                		value = attributes.getValue("value");
+
+                		if (name != null && value != null)
+                			getCurrentQuery().addInitialContextValue(name, value);
+                }
+                if (name == null) {
+                    this.getLogger().debug("Could not find 'name' attribute");
+                    throwIllegalStateException("Could not find 'name' attribute in initial-context element");
+                }
+                if (value == null) {
+                    this.getLogger().debug("Could not find 'value' attribute");
+                    throwIllegalStateException("Could not find 'value' attribute in initial-context element");
+                }
+
+                current_state = LDAPTransformer.STATE_INSIDE_INITIAL_CONTEXT_ELEMENT;
+                current_value.setLength(0);
+                break;
+            default :
+                throwIllegalStateException("Not expecting a start initial-context element");
+        }
+    }
+
+    protected void endInitialContextElement() {
+        switch (current_state) {
+            case LDAPTransformer.STATE_INSIDE_INITIAL_CONTEXT_ELEMENT :
+                current_state = getCurrentQuery().toDo;
+                break;
+            default :
+                throwIllegalStateException("Not expecting a end initial-context element");
+        }
+    }
+
     protected void endVersionElement() {
         switch (current_state) {
             case LDAPTransformer.STATE_INSIDE_VERSION_ELEMENT :
@@ -694,6 +743,8 @@
             startExecuteElement(LDAPTransformer.STATE_INSIDE_EXECUTE_INCREMENT, name);
         } else if (name.equals(LDAPTransformer.MAGIC_INITIALIZER_ELEMENT)) {
             startQueryParameterElement(LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT, name);
+        } else if (name.equals(LDAPTransformer.MAGIC_INITIAL_CONTEXT_ELEMENT)) {
+            startInitialContextElement(attributes);
         } else if (name.equals(LDAPTransformer.MAGIC_AUTHENTICATION_ELEMENT)) {
             startQueryParameterElement(LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT, name);
         } else if (name.equals(LDAPTransformer.MAGIC_SCOPE_ELEMENT)) {
@@ -756,6 +807,8 @@
             endExecuteElement(LDAPTransformer.STATE_INSIDE_EXECUTE_INCREMENT, LDAPTransformer.MAGIC_EXECUTE_INCREMENT);
         } else if (name.equals(LDAPTransformer.MAGIC_INITIALIZER_ELEMENT)) {
             endInitializerElement();
+        } else if (name.equals(LDAPTransformer.MAGIC_INITIAL_CONTEXT_ELEMENT)) {
+            endInitialContextElement();
         } else if (name.equals(LDAPTransformer.MAGIC_AUTHENTICATION_ELEMENT)) {
             endAuthenticationElement();
         } else if (name.equals(LDAPTransformer.MAGIC_SCOPE_ELEMENT)) {
@@ -805,6 +858,7 @@
 
     public void characters(char ary[], int start, int length) throws SAXException {
         if (current_state != LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT
+            && current_state != LDAPTransformer.STATE_INSIDE_INITIAL_CONTEXT_ELEMENT
             && current_state != LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT
             && current_state != LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT
             && current_state != LDAPTransformer.STATE_INSIDE_VERSION_ELEMENT
@@ -891,6 +945,7 @@
         protected List attrVale = new LinkedList();
         protected String REPLACE_MODE_DEFAULT = StringUtils.defaultString(LDAPTransformer.MAGIC_ATTRIBUTE_ELEMENT_MODE_ATTRIBUTE_DEFAULT);
         protected String REPLACE_MODE_APPEND = StringUtils.defaultString(LDAPTransformer.MAGIC_ATTRIBUTE_ELEMENT_MODE_ATTRIBUTE_VALUE_A);
+        protected Map initialContextValues = new HashMap();
         protected boolean showAttribute;
         protected String filter;
         protected String doc_element;
@@ -1509,6 +1564,11 @@
             attrVale.add(val);
         }
 
+        protected void addInitialContextValue(String name, String value)
+        {
+            initialContextValues.put(name, value);
+        }
+
         protected void connect() throws NamingException {
             if (root_dn != null && password != null) {
                 env.put(Context.SECURITY_AUTHENTICATION, authentication);
@@ -1520,6 +1580,9 @@
             env.put(Context.INITIAL_CONTEXT_FACTORY, initializer);
             env.put(Context.PROVIDER_URL, serverurl + ":" + port);
 
+            // Override existing properties or add new properties with values from initial-context
+            env.putAll(initialContextValues);
+
             try {
                 ctx = new InitialDirContext(env);
             } catch (NamingException e) {
@@ -1557,6 +1620,7 @@
                 logger.debug("[LDAPTransformer] searchbase: " + searchbase);
                 logger.debug("[LDAPTransformer] showAttribute: " + showAttribute);
                 logger.debug("[LDAPTransformer] attribute: " + attrListe.toString());
+                logger.debug("[LDAPTransformer] initial-context: " + initialContextValues);
                 logger.debug("[LDAPTransformer] filter: " + filter);
                 logger.debug("[LDAPTransformer] doc_element: " + doc_element);
                 logger.debug("[LDAPTransformer] row_element: " + row_element);



Re: svn commit: r384153 - /cocoon/blocks/naming/trunk/java/org/apache/cocoon/transformation/LDAPTransformer.java

Posted by Jean-Baptiste Quenot <jb...@apache.org>.
* Joerg Heinicke:

> And only  in case of  exceptional circumstances (e.g.  after one
> year of two completely different versions in both branches) fall
> back to such a commit message.

That's the case for LDAPTransformer.
-- 
Jean-Baptiste Quenot
http://caraldi.com/jbq/

Re: svn commit: r384153 - /cocoon/blocks/naming/trunk/java/org/apache/cocoon/transformation/LDAPTransformer.java

Posted by Joerg Heinicke <jo...@gmx.de>.
> URL: http://svn.apache.org/viewcvs?rev=384153&view=rev
> Log: Sync with 2.1

Could you (all) please avoid such useless commit messages. Later on 
nobody knows what actually has changed in this revision. Either copy the 
commit from the other branch or refer to the revision of that commit. 
And only in case of exceptional circumstances (e.g. after one year of 
two completely different versions in both branches) fall back to such a 
commit message.

Thanks.

Jörg