bloritsch 01/10/25 13:22:22
Modified: src/org/apache/cocoon/transformation Tag: cocoon_20_branch
LDAPTransformer.java
Log:
Optimize critical path And fix indentation
Revision Changes Path
No revision
No revision
1.1.2.8 +758 -757
xml-cocoon2/src/org/apache/cocoon/transformation/LDAPTransformer.java
Index: LDAPTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/transformation/LDAPTransformer.java,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -r1.1.2.7 -r1.1.2.8
--- LDAPTransformer.java 2001/10/11 08:56:15 1.1.2.7
+++ LDAPTransformer.java 2001/10/25 20:22:22 1.1.2.8
@@ -73,7 +73,7 @@
*
* @author Felix Knecht
*/
-
+
public class LDAPTransformer extends AbstractTransformer implements Poolable
{
/** The LDAP namespace ("http://apache.org/cocoon/LDAP/1.0")**/
@@ -129,7 +129,7 @@
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;
-
+
/** Default parameters that might apply to all queries **/
protected Properties default_properties = new Properties();
@@ -147,103 +147,103 @@
/** The offset of the current query in the queries list **/
protected int current_query_index = -1;
-
+
/** SAX producing state information */
protected XMLConsumer xml_consumer;
protected LexicalHandler lexical_handler;
/** BEGIN SitemapComponent methods **/
- public void setup(SourceResolver resolver, Map objectModel,
- String source, Parameters parameters)
+ public void setup( SourceResolver resolver, Map objectModel,
+ String source, Parameters parameters )
throws ProcessingException, SAXException, IOException {
current_state = LDAPTransformer.STATE_OUTSIDE;
- // Check the initializer
- String parameter =
parameters.getParameter(LDAPTransformer.MAGIC_INITIALIZER_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_INITIALIZER_ELEMENT,
parameter);
- }
- // Check the version
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_VERSION_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_VERSION_ELEMENT, parameter);
- }
- // Check the authentication
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_AUTHENTICATION_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_AUTHENTICATION_ELEMENT,
parameter);
- }
- // Check the scope
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_SCOPE_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_SCOPE_ELEMENT, parameter);
- }
- // Check the serverurl
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_SERVERURL_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_SERVERURL_ELEMENT,
parameter);
- }
- // Check the ldap-root_dn
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_ROOT_DN_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_ROOT_DN_ELEMENT, parameter);
- }
- // Check the ldap-pwd
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_PASSWORD_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_PASSWORD_ELEMENT, parameter);
- }
- // Check the port
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_PORT_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_PORT_ELEMENT, parameter);
- }
- // Check the searchbase
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_SEARCHBASE_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_SEARCHBASE_ELEMENT,
parameter);
- }
- // Check the doc-element
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_DOC_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_DOC_ELEMENT, parameter);
- }
- // Check the row-element
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_ROW_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_ROW_ELEMENT, parameter);
- }
- // Check the error-element
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_ERROR_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_ERROR_ELEMENT, parameter);
- }
- // Check the sax-error
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_SAX_ERROR,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_SAX_ERROR, parameter);
- }
- // Check the deref-link-element
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_DEREF_LINK_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_DEREF_LINK_ELEMENT,
parameter.toUpperCase());
- }
- // Check the count-limit-element
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_COUNT_LIMIT_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_COUNT_LIMIT_ELEMENT,
parameter);
- }
- // Check the time-limit-element
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_TIME_LIMIT_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_TIME_LIMIT_ELEMENT,
parameter);
- }
- // Check the debug-element
- parameter =
parameters.getParameter(LDAPTransformer.MAGIC_DEBUG_ELEMENT,null);
- if (parameter != null) {
- default_properties.setProperty(MAGIC_DEBUG_ELEMENT, parameter);
- }
+ // Check the initializer
+ String parameter = parameters.getParameter(
LDAPTransformer.MAGIC_INITIALIZER_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_INITIALIZER_ELEMENT,
parameter );
+ }
+ // Check the version
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_VERSION_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_VERSION_ELEMENT, parameter
);
+ }
+ // Check the authentication
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_AUTHENTICATION_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_AUTHENTICATION_ELEMENT,
parameter );
+ }
+ // Check the scope
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_SCOPE_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_SCOPE_ELEMENT, parameter );
+ }
+ // Check the serverurl
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_SERVERURL_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_SERVERURL_ELEMENT,
parameter );
+ }
+ // Check the ldap-root_dn
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_ROOT_DN_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_ROOT_DN_ELEMENT, parameter
);
+ }
+ // Check the ldap-pwd
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_PASSWORD_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_PASSWORD_ELEMENT,
parameter );
+ }
+ // Check the port
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_PORT_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_PORT_ELEMENT, parameter );
+ }
+ // Check the searchbase
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_SEARCHBASE_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_SEARCHBASE_ELEMENT,
parameter );
+ }
+ // Check the doc-element
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_DOC_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_DOC_ELEMENT, parameter );
+ }
+ // Check the row-element
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_ROW_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_ROW_ELEMENT, parameter );
+ }
+ // Check the error-element
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_ERROR_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_ERROR_ELEMENT, parameter );
+ }
+ // Check the sax-error
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_SAX_ERROR, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_SAX_ERROR, parameter );
+ }
+ // Check the deref-link-element
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_DEREF_LINK_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_DEREF_LINK_ELEMENT,
parameter.toUpperCase() );
+ }
+ // Check the count-limit-element
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_COUNT_LIMIT_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_COUNT_LIMIT_ELEMENT,
parameter );
+ }
+ // Check the time-limit-element
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_TIME_LIMIT_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_TIME_LIMIT_ELEMENT,
parameter );
+ }
+ // Check the debug-element
+ parameter = parameters.getParameter(
LDAPTransformer.MAGIC_DEBUG_ELEMENT, null );
+ if ( parameter != null ) {
+ default_properties.setProperty( MAGIC_DEBUG_ELEMENT, parameter );
+ }
}
/** END SitemapComponent methods **/
@@ -253,58 +253,58 @@
/**
* This will be the meat of LDAPTransformer, where the query is run.
*/
- protected void executeQuery(int index) throws SAXException {
- this.contentHandler.startPrefixMapping("", LDAPTransformer.my_uri);
+ protected void executeQuery( int index ) throws SAXException {
+ this.contentHandler.startPrefixMapping( "", LDAPTransformer.my_uri );
AttributesImpl attr = new AttributesImpl();
- LDAPQuery query = (LDAPQuery) queries.elementAt(index);
- try {
- query.execute();
- } catch (NamingException e) {
- getLogger().error(e.toString());
- throw new SAXException (e);
- } catch (Exception e) {
- getLogger().error(e.toString());
- throw new SAXException (e);
+ LDAPQuery query = (LDAPQuery) queries.elementAt( index );
+ try {
+ query.execute();
+ } catch ( NamingException e ) {
+ getLogger().error( e.toString() );
+ throw new SAXException( e );
+ } catch ( Exception e ) {
+ getLogger().error( e.toString() );
+ throw new SAXException( e );
}
-
- this.contentHandler.endPrefixMapping("");
+
+ this.contentHandler.endPrefixMapping( "" );
}
- protected static void throwIllegalStateException(String message) {
- throw new IllegalStateException(my_name + ": "+message);
+ protected static void throwIllegalStateException( String message ) {
+ throw new IllegalStateException( my_name + ": " + message );
}
- protected void startExecuteQuery(Attributes attributes) {
+ protected void startExecuteQuery( Attributes attributes ) {
LDAPQuery query;
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_OUTSIDE:
current_state = LDAPTransformer.STATE_INSIDE_EXECUTE_QUERY;
current_query_index = queries.size();
- query = new LDAPQuery(this);
- queries.addElement(query);
+ query = new LDAPQuery( this );
+ queries.addElement( query );
getCurrentQuery().toDo =
LDAPTransformer.STATE_INSIDE_EXECUTE_QUERY;
getCurrentQuery().query_index = current_query_index;
break;
case LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT:
current_state = LDAPTransformer.STATE_INSIDE_EXECUTE_QUERY;
current_query_index = queries.size();
- query = new LDAPQuery(this);
- queries.addElement(query);
+ query = new LDAPQuery( this );
+ queries.addElement( query );
getCurrentQuery().toDo =
LDAPTransformer.STATE_INSIDE_EXECUTE_QUERY;
getCurrentQuery().query_index = current_query_index;
break;
default:
- throwIllegalStateException("Not expecting a start
execute-query element");
+ throwIllegalStateException( "Not expecting a start
execute-query element" );
}
}
protected void endExecuteQuery() throws SAXException {
- switch (current_state) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- executeQuery(current_query_index);
- queries.remove(current_query_index);
+ executeQuery( current_query_index );
+ queries.remove( current_query_index );
--current_query_index;
- if (current_query_index > -1) {
+ if ( current_query_index > -1 ) {
current_state = getCurrentQuery().toDo;
} else {
queries.removeAllElements();
@@ -312,1101 +312,1102 @@
}
break;
default:
- throwIllegalStateException("Not expecting a end
execute-query element");
+ throwIllegalStateException( "Not expecting a end
execute-query element" );
}
}
- protected void startExecuteIncrement(Attributes attributes) {
+ protected void startExecuteIncrement( Attributes attributes ) {
LDAPQuery query;
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_OUTSIDE:
current_state =
LDAPTransformer.STATE_INSIDE_EXECUTE_INCREMENT;
current_query_index = queries.size();
- query = new LDAPQuery(this);
- queries.addElement(query);
+ query = new LDAPQuery( this );
+ queries.addElement( query );
getCurrentQuery().toDo =
LDAPTransformer.STATE_INSIDE_EXECUTE_INCREMENT;
getCurrentQuery().query_index = current_query_index;
break;
case LDAPTransformer.STATE_INSIDE_EXECUTE_QUERY:
current_state =
LDAPTransformer.STATE_INSIDE_EXECUTE_INCREMENT;
current_query_index = queries.size();
- query = new LDAPQuery(this);
- queries.addElement(query);
+ query = new LDAPQuery( this );
+ queries.addElement( query );
getCurrentQuery().toDo =
LDAPTransformer.STATE_INSIDE_EXECUTE_INCREMENT;
getCurrentQuery().query_index = current_query_index;
break;
default:
- throwIllegalStateException("Not expecting a start
execute-increment element");
+ throwIllegalStateException( "Not expecting a start
execute-increment element" );
}
}
protected void endExecuteIncrement() throws SAXException {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_EXECUTE_INCREMENT:
- executeQuery(current_query_index);
- queries.remove(current_query_index);
+ executeQuery( current_query_index );
+ queries.remove( current_query_index );
--current_query_index;
- if (current_query_index > 1) {
+ if ( current_query_index > 1 ) {
current_state = getCurrentQuery().toDo;
} else {
- queries.removeAllElements();
+ queries.removeAllElements();
current_state = LDAPTransformer.STATE_OUTSIDE;
}
break;
default:
- throwIllegalStateException("Not expecting a end
execute-increment element");
+ throwIllegalStateException( "Not expecting a end
execute-increment element" );
}
}
- protected void startInitializerElement(Attributes attributes) {
- switch (current_state) {
+ protected void startInitializerElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state =
LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT;
- getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT;
- break;
+ getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT;
+ break;
case STATE_INSIDE_EXECUTE_INCREMENT:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state =
LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT;
- getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT;
+ getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT;
break;
default:
- throwIllegalStateException("Not expecting a start
initializer element");
+ throwIllegalStateException( "Not expecting a start
initializer element" );
}
}
protected void endInitializerElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT:
- getCurrentQuery().initializer = current_value.toString();
- current_state = getCurrentQuery().toDo;
+ getCurrentQuery().initializer = current_value.toString();
+ current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end initializer
element");
+ throwIllegalStateException( "Not expecting a end initializer
element" );
}
}
- protected void startScopeElement(Attributes attributes) {
- switch (current_state) {
+ protected void startScopeElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state = LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT;
- getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT;
+ getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT;
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state = LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT;
- getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT;
+ getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT;
break;
default:
- throwIllegalStateException("Not expecting a start scope
element");
+ throwIllegalStateException( "Not expecting a start scope
element" );
}
}
protected void endScopeElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT:
- getCurrentQuery().scope = current_value.toString();
- current_state = getCurrentQuery().toDo;
+ getCurrentQuery().scope = current_value.toString();
+ current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end scope
element");
+ throwIllegalStateException( "Not expecting a end scope
element" );
}
}
- protected void startAuthenticationElement(Attributes attributes) {
- switch (current_state) {
+ protected void startAuthenticationElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state =
LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT;
- getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT;
+ getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT;
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state =
LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT;
- getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT;
+ getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT;
break;
default:
- throwIllegalStateException("Not expecting a start
authentication element");
+ throwIllegalStateException( "Not expecting a start
authentication element" );
}
}
protected void endAuthenticationElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT:
- getCurrentQuery().authentication =
current_value.toString();
- current_state = getCurrentQuery().toDo;
+ getCurrentQuery().authentication = current_value.toString();
+ current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end
authentication element");
+ throwIllegalStateException( "Not expecting a end
authentication element" );
}
}
- protected void startServerurlElement(Attributes attributes) {
- switch (current_state) {
+ protected void startServerurlElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state =
LDAPTransformer.STATE_INSIDE_SERVERURL_ELEMENT;
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state =
LDAPTransformer.STATE_INSIDE_SERVERURL_ELEMENT;
break;
default:
- throwIllegalStateException("Not expecting a start serverurl
element");
+ throwIllegalStateException( "Not expecting a start serverurl
element" );
}
}
protected void endServerurlElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_SERVERURL_ELEMENT:
- getCurrentQuery().serverurl = current_value.toString();
- current_state = getCurrentQuery().toDo;
+ getCurrentQuery().serverurl = current_value.toString();
+ current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end serverurl
element");
+ throwIllegalStateException( "Not expecting a end serverurl
element" );
}
}
- protected void startPortElement(Attributes attributes) {
- switch (current_state) {
+ protected void startPortElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state = LDAPTransformer.STATE_INSIDE_PORT_ELEMENT;
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state = LDAPTransformer.STATE_INSIDE_PORT_ELEMENT;
break;
default:
- throwIllegalStateException("Not expecting a start port
element");
+ throwIllegalStateException( "Not expecting a start port
element" );
}
}
protected void endPortElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_PORT_ELEMENT:
- getCurrentQuery().port =
Integer.parseInt(current_value.toString());
+ getCurrentQuery().port = Integer.parseInt(
current_value.toString() );
current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end server
element");
+ throwIllegalStateException( "Not expecting a end server
element" );
}
}
- protected void startShowAttributeElement(Attributes attributes) {
- switch (current_state) {
+ protected void startShowAttributeElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state =
LDAPTransformer.STATE_INSIDE_SHOW_ATTRIBUTE_ELEMENT;
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state =
LDAPTransformer.STATE_INSIDE_SHOW_ATTRIBUTE_ELEMENT;
break;
default:
- throwIllegalStateException("Not expecting a start
show-attribute element");
+ throwIllegalStateException( "Not expecting a start
show-attribute element" );
}
}
protected void endShowAttributeElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_SHOW_ATTRIBUTE_ELEMENT:
- if
(current_value.toString().toUpperCase().equals("FALSE")) {
+ if ( current_value.toString().toUpperCase().equals( "FALSE"
) ) {
getCurrentQuery().showAttribute = false;
- }
+ }
current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end
show-attribute element");
+ throwIllegalStateException( "Not expecting a end
show-attribute element" );
}
}
- protected void startSearchbaseElement(Attributes attributes) {
- switch (current_state) {
+ protected void startSearchbaseElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state =
LDAPTransformer.STATE_INSIDE_SEARCHBASE_ELEMENT;
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state =
LDAPTransformer.STATE_INSIDE_SEARCHBASE_ELEMENT;
break;
default:
- throwIllegalStateException("Not expecting a start searchbase
element");
+ throwIllegalStateException( "Not expecting a start
searchbase element" );
}
}
protected void endSearchbaseElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_SEARCHBASE_ELEMENT:
- getCurrentQuery().searchbase = current_value.toString();
- current_state = getCurrentQuery().toDo;
+ getCurrentQuery().searchbase = current_value.toString();
+ current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end searchbase
element");
+ throwIllegalStateException( "Not expecting a end searchbase
element" );
}
}
- protected void startDocElement(Attributes attributes) {
- switch (current_state) {
+ protected void startDocElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state = LDAPTransformer.STATE_INSIDE_DOC_ELEMENT;
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state = LDAPTransformer.STATE_INSIDE_DOC_ELEMENT;
break;
default:
- throwIllegalStateException("Not expecting a start
doc-element element");
+ throwIllegalStateException( "Not expecting a start
doc-element element" );
}
}
protected void endDocElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_DOC_ELEMENT:
- getCurrentQuery().doc_element = current_value.toString();
- current_state = getCurrentQuery().toDo;
+ getCurrentQuery().doc_element = current_value.toString();
+ current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end doc-element
element");
+ throwIllegalStateException( "Not expecting a end doc-element
element" );
}
}
- protected void startRowElement(Attributes attributes) {
- switch (current_state) {
+ protected void startRowElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state = LDAPTransformer.STATE_INSIDE_ROW_ELEMENT;
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state = LDAPTransformer.STATE_INSIDE_ROW_ELEMENT;
break;
default:
- throwIllegalStateException("Not expecting a start
row-element element");
+ throwIllegalStateException( "Not expecting a start
row-element element" );
}
}
protected void endRowElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_ROW_ELEMENT:
- getCurrentQuery().row_element = current_value.toString();
- current_state = getCurrentQuery().toDo;
+ getCurrentQuery().row_element = current_value.toString();
+ current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end row-element
element");
+ throwIllegalStateException( "Not expecting a end row-element
element" );
}
}
- protected void startErrorElement(Attributes attributes) {
- switch (current_state) {
+ protected void startErrorElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state = LDAPTransformer.STATE_INSIDE_ERROR_ELEMENT;
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state = LDAPTransformer.STATE_INSIDE_ERROR_ELEMENT;
break;
default:
- throwIllegalStateException("Not expecting a start
error-element element");
+ throwIllegalStateException( "Not expecting a start
error-element element" );
}
}
protected void endErrorElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_ERROR_ELEMENT:
- getCurrentQuery().error_element = current_value.toString();
- current_state = getCurrentQuery().toDo;
+ getCurrentQuery().error_element = current_value.toString();
+ current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end
error-element element");
+ throwIllegalStateException( "Not expecting a end
error-element element" );
}
}
- protected void startSaxError(Attributes attributes) {
- switch (current_state) {
+ protected void startSaxError( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state =
LDAPTransformer.STATE_INSIDE_SAX_ERROR_ELEMENT;
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state =
LDAPTransformer.STATE_INSIDE_SAX_ERROR_ELEMENT;
break;
default:
- throwIllegalStateException("Not expecting a start sax-error
element");
+ throwIllegalStateException( "Not expecting a start sax-error
element" );
}
}
protected void endSaxError() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_SAX_ERROR_ELEMENT:
- if
(current_value.toString().toUpperCase().equals("TRUE")) {
+ if ( current_value.toString().toUpperCase().equals( "TRUE" )
) {
getCurrentQuery().sax_error = true;
- }
- current_state = getCurrentQuery().toDo;
+ }
+ current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end sax-error
element");
+ throwIllegalStateException( "Not expecting a end sax-error
element" );
}
}
- protected void startRootDnElement(Attributes attributes) {
- switch (current_state) {
+ protected void startRootDnElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state = LDAPTransformer.STATE_INSIDE_ROOT_DN_ELEMENT;
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state = LDAPTransformer.STATE_INSIDE_ROOT_DN_ELEMENT;
break;
default:
- throwIllegalStateException("Not expecting a start root-dn
element");
+ throwIllegalStateException( "Not expecting a start root-dn
element" );
}
}
protected void endRootDnElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_ROOT_DN_ELEMENT:
- getCurrentQuery().root_dn = current_value.toString( );
- current_state = getCurrentQuery().toDo;
+ getCurrentQuery().root_dn = current_value.toString();
+ current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end root-dn
element");
+ throwIllegalStateException( "Not expecting a end root-dn
element" );
}
}
- protected void startPasswordElement(Attributes attributes) {
- switch (current_state) {
+
+ protected void startPasswordElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state =
LDAPTransformer.STATE_INSIDE_PASSWORD_ELEMENT;
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state =
LDAPTransformer.STATE_INSIDE_PASSWORD_ELEMENT;
break;
default:
- throwIllegalStateException("Not expecting a start password
element");
+ throwIllegalStateException( "Not expecting a start password
element" );
}
}
protected void endPasswordElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_PASSWORD_ELEMENT:
- getCurrentQuery().password = current_value.toString();
- current_state = getCurrentQuery().toDo;
+ getCurrentQuery().password = current_value.toString();
+ current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end password
element");
+ throwIllegalStateException( "Not expecting a end password
element" );
}
}
- protected void startAttributeElement(Attributes attributes) {
- switch (current_state) {
+ protected void startAttributeElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
current_state =
LDAPTransformer.STATE_INSIDE_ATTRIBUTE_ELEMENT;
- current_value.setLength(0);
+ current_value.setLength( 0 );
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
current_state =
LDAPTransformer.STATE_INSIDE_ATTRIBUTE_ELEMENT;
- current_value.setLength(0);
+ current_value.setLength( 0 );
break;
default:
- throwIllegalStateException("Not expecting a start attribute
element");
+ throwIllegalStateException( "Not expecting a start attribute
element" );
}
}
protected void endAttributeElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_ATTRIBUTE_ELEMENT:
- getCurrentQuery().addAttrList(current_value.toString());
+ getCurrentQuery().addAttrList( current_value.toString() );
current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end attribute
element");
+ throwIllegalStateException( "Not expecting a end attribute
element" );
}
}
- protected void startVersionElement(Attributes attributes) {
- switch (current_state) {
+ protected void startVersionElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
current_state = LDAPTransformer.STATE_INSIDE_VERSION_ELEMENT;
- current_value.setLength(0);
+ current_value.setLength( 0 );
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
current_state = LDAPTransformer.STATE_INSIDE_VERSION_ELEMENT;
- current_value.setLength(0);
+ current_value.setLength( 0 );
break;
default:
- throwIllegalStateException("Not expecting a start version
element");
+ throwIllegalStateException( "Not expecting a start version
element" );
}
}
protected void endVersionElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_VERSION_ELEMENT:
- getCurrentQuery().version = current_value.toString();
+ getCurrentQuery().version = current_value.toString();
current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end version
element");
+ throwIllegalStateException( "Not expecting a end version
element" );
}
}
- protected void startFilterElement(Attributes attributes) {
- switch (current_state) {
+ protected void startFilterElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
current_state = LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT;
- getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT;
- current_value.setLength(0);
+ getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT;
+ current_value.setLength( 0 );
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
current_state = LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT;
- getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT;
- current_value.setLength(0);
+ getCurrentQuery().current_state =
LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT;
+ current_value.setLength( 0 );
break;
default:
- throwIllegalStateException("Not expecting a start filter
element");
+ throwIllegalStateException( "Not expecting a start filter
element" );
}
}
protected void endFilterElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT:
- getCurrentQuery().filter = current_value.toString();
+ getCurrentQuery().filter = current_value.toString();
current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end filter
element");
+ throwIllegalStateException( "Not expecting a end filter
element" );
}
}
- protected void startDerefLinkElement(Attributes attributes) {
- switch (current_state) {
+ protected void startDerefLinkElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
current_state =
LDAPTransformer.STATE_INSIDE_DEREF_LINK_ELEMENT;
- current_value.setLength(0);
+ current_value.setLength( 0 );
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
current_state =
LDAPTransformer.STATE_INSIDE_DEREF_LINK_ELEMENT;
- current_value.setLength(0);
+ current_value.setLength( 0 );
break;
default:
- throwIllegalStateException("Not expecting a start deref-link
element");
+ throwIllegalStateException( "Not expecting a start
deref-link element" );
}
}
protected void endDerefLinkElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_DEREF_LINK_ELEMENT:
- if
(current_value.toString().toUpperCase().equals("TRUE")) {
+ if ( current_value.toString().toUpperCase().equals( "TRUE" )
) {
getCurrentQuery().deref_link = true;
- }
+ }
current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end deref-link
element");
+ throwIllegalStateException( "Not expecting a end deref-link
element" );
}
}
- protected void startCountLimitElement(Attributes attributes) {
- switch (current_state) {
+ protected void startCountLimitElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
current_state =
LDAPTransformer.STATE_INSIDE_COUNT_LIMIT_ELEMENT;
- current_value.setLength(0);
+ current_value.setLength( 0 );
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
current_state =
LDAPTransformer.STATE_INSIDE_COUNT_LIMIT_ELEMENT;
- current_value.setLength(0);
+ current_value.setLength( 0 );
break;
default:
- throwIllegalStateException("Not expecting a start
count-limit element");
+ throwIllegalStateException( "Not expecting a start
count-limit element" );
}
}
protected void endCountLimitElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_COUNT_LIMIT_ELEMENT:
- getCurrentQuery().count_limit =
Integer.parseInt(current_value.toString());
+ getCurrentQuery().count_limit = Integer.parseInt(
current_value.toString() );
current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end count-limit
element");
+ throwIllegalStateException( "Not expecting a end count-limit
element" );
}
}
- protected void startTimeLimitElement(Attributes attributes) {
- switch (current_state) {
+ protected void startTimeLimitElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
current_state =
LDAPTransformer.STATE_INSIDE_TIME_LIMIT_ELEMENT;
- current_value.setLength(0);
+ current_value.setLength( 0 );
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
current_state =
LDAPTransformer.STATE_INSIDE_TIME_LIMIT_ELEMENT;
- current_value.setLength(0);
+ current_value.setLength( 0 );
break;
default:
- throwIllegalStateException("Not expecting a start time-limit
element");
+ throwIllegalStateException( "Not expecting a start
time-limit element" );
}
}
protected void endTimeLimitElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_TIME_LIMIT_ELEMENT:
- getCurrentQuery().time_limit =
Integer.parseInt(current_value.toString());
+ getCurrentQuery().time_limit = Integer.parseInt(
current_value.toString() );
current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end time-limit
element");
+ throwIllegalStateException( "Not expecting a end time-limit
element" );
}
}
- protected void startDebugElement(Attributes attributes) {
- switch (current_state) {
+ protected void startDebugElement( Attributes attributes ) {
+ switch ( current_state ) {
case STATE_INSIDE_EXECUTE_QUERY:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state = LDAPTransformer.STATE_INSIDE_DEBUG_ELEMENT;
break;
case STATE_INSIDE_EXECUTE_INCREMENT:
- current_value.setLength(0);
+ current_value.setLength( 0 );
current_state = LDAPTransformer.STATE_INSIDE_DEBUG_ELEMENT;
break;
default:
- throwIllegalStateException("Not expecting a start debug
element");
+ throwIllegalStateException( "Not expecting a start debug
element" );
}
}
protected void endDebugElement() {
- switch (current_state) {
+ switch ( current_state ) {
case LDAPTransformer.STATE_INSIDE_DEBUG_ELEMENT:
- if
(current_value.toString().toUpperCase().equals("TRUE")) {
+ if ( current_value.toString().toUpperCase().equals( "TRUE" )
) {
getCurrentQuery().debug = true;
- }
+ }
current_state = getCurrentQuery().toDo;
break;
default:
- throwIllegalStateException("Not expecting a end debug
element");
+ throwIllegalStateException( "Not expecting a end debug
element" );
}
}
protected LDAPQuery getCurrentQuery() {
- return (LDAPQuery) queries.elementAt(current_query_index);
+ return (LDAPQuery) queries.elementAt( current_query_index );
}
- protected LDAPQuery getQuery(int i) {
- return (LDAPQuery) queries.elementAt(i);
+ protected LDAPQuery getQuery( int i ) {
+ return (LDAPQuery) queries.elementAt( i );
}
/** END my very own methods **/
/** BEGIN SAX ContentHandler handlers **/
- public void setDocumentLocator(Locator locator) {
- getLogger().info("PUBLIC ID"+locator.getPublicId());
- getLogger().info("SYSTEM ID"+locator.getSystemId());
- if (super.contentHandler != null)
- super.contentHandler.setDocumentLocator(locator);
+ public void setDocumentLocator( Locator locator ) {
+ getLogger().info( "PUBLIC ID" + locator.getPublicId() );
+ getLogger().info( "SYSTEM ID" + locator.getSystemId() );
+ if ( super.contentHandler != null )
+ super.contentHandler.setDocumentLocator( locator );
}
- public void startElement(String uri, String name, String raw,
- Attributes attributes) throws SAXException {
- if (!uri.equals(my_uri)) {
- super.startElement(uri, name, raw, attributes);
+ public void startElement( String uri, String name, String raw,
+ Attributes attributes ) throws SAXException {
+ if ( !uri.equals( my_uri ) ) {
+ super.startElement( uri, name, raw, attributes );
return;
}
- getLogger().debug("RECEIVED START ELEMENT " + name + "(" + uri +
")");
+ getLogger().debug( "RECEIVED START ELEMENT " + name + "(" + uri +
")" );
- if (name.equals(LDAPTransformer.MAGIC_EXECUTE_QUERY)) {
- startExecuteQuery(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_EXECUTE_INCREMENT)) {
- startExecuteIncrement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_INITIALIZER_ELEMENT)) {
- startInitializerElement(attributes);
- } else if
(name.equals(LDAPTransformer.MAGIC_AUTHENTICATION_ELEMENT)) {
- startAuthenticationElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_SCOPE_ELEMENT)) {
- startScopeElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_VERSION_ELEMENT)) {
- startVersionElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_SERVERURL_ELEMENT)) {
- startServerurlElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_PORT_ELEMENT)) {
- startPortElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_DOC_ELEMENT)) {
- startDocElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_ROW_ELEMENT)) {
- startRowElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_ERROR_ELEMENT)) {
- startErrorElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_SAX_ERROR)) {
- startSaxError(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_ROOT_DN_ELEMENT)) {
- startRootDnElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_PASSWORD_ELEMENT)) {
- startPasswordElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_ATTRIBUTE_ELEMENT)) {
- startAttributeElement(attributes);
- } else if
(name.equals(LDAPTransformer.MAGIC_SHOW_ATTRIBUTE_ELEMENT)) {
- startShowAttributeElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_SEARCHBASE_ELEMENT)) {
- startSearchbaseElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_FILTER_ELEMENT)) {
- startFilterElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_DEREF_LINK_ELEMENT)) {
- startDerefLinkElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_COUNT_LIMIT_ELEMENT)) {
- startCountLimitElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_TIME_LIMIT_ELEMENT)) {
- startTimeLimitElement(attributes);
- } else if (name.equals(LDAPTransformer.MAGIC_DEBUG_ELEMENT)) {
- startDebugElement(attributes);
+ if ( name.equals( LDAPTransformer.MAGIC_EXECUTE_QUERY ) ) {
+ startExecuteQuery( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_EXECUTE_INCREMENT ) )
{
+ startExecuteIncrement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_INITIALIZER_ELEMENT )
) {
+ startInitializerElement( attributes );
+ } else if ( name.equals(
LDAPTransformer.MAGIC_AUTHENTICATION_ELEMENT ) ) {
+ startAuthenticationElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_SCOPE_ELEMENT ) ) {
+ startScopeElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_VERSION_ELEMENT ) ) {
+ startVersionElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_SERVERURL_ELEMENT ) )
{
+ startServerurlElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_PORT_ELEMENT ) ) {
+ startPortElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_DOC_ELEMENT ) ) {
+ startDocElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_ROW_ELEMENT ) ) {
+ startRowElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_ERROR_ELEMENT ) ) {
+ startErrorElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_SAX_ERROR ) ) {
+ startSaxError( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_ROOT_DN_ELEMENT ) ) {
+ startRootDnElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_PASSWORD_ELEMENT ) ) {
+ startPasswordElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_ATTRIBUTE_ELEMENT ) )
{
+ startAttributeElement( attributes );
+ } else if ( name.equals(
LDAPTransformer.MAGIC_SHOW_ATTRIBUTE_ELEMENT ) ) {
+ startShowAttributeElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_SEARCHBASE_ELEMENT )
) {
+ startSearchbaseElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_FILTER_ELEMENT ) ) {
+ startFilterElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_DEREF_LINK_ELEMENT )
) {
+ startDerefLinkElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_COUNT_LIMIT_ELEMENT )
) {
+ startCountLimitElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_TIME_LIMIT_ELEMENT )
) {
+ startTimeLimitElement( attributes );
+ } else if ( name.equals( LDAPTransformer.MAGIC_DEBUG_ELEMENT ) ) {
+ startDebugElement( attributes );
}
}
- public void endElement(String uri, String name,
- String raw) throws SAXException {
- if (!uri.equals(my_uri)) {
- super.endElement(uri, name, raw);
+ public void endElement( String uri, String name,
+ String raw ) throws SAXException {
+ if ( !uri.equals( my_uri ) ) {
+ super.endElement( uri, name, raw );
return;
}
- getLogger().debug("RECEIVED END ELEMENT "+ name + "(" + uri + ")");
+ getLogger().debug( "RECEIVED END ELEMENT " + name + "(" + uri + ")"
);
- if (name.equals(LDAPTransformer.MAGIC_EXECUTE_QUERY)) {
+ if ( name.equals( LDAPTransformer.MAGIC_EXECUTE_QUERY ) ) {
endExecuteQuery();
- } else if (name.equals(LDAPTransformer.MAGIC_EXECUTE_INCREMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_EXECUTE_INCREMENT ) )
{
endExecuteIncrement();
- } else if (name.equals(LDAPTransformer.MAGIC_INITIALIZER_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_INITIALIZER_ELEMENT )
) {
endInitializerElement();
- } else if
(name.equals(LDAPTransformer.MAGIC_AUTHENTICATION_ELEMENT)) {
+ } else if ( name.equals(
LDAPTransformer.MAGIC_AUTHENTICATION_ELEMENT ) ) {
endAuthenticationElement();
- } else if (name.equals(LDAPTransformer.MAGIC_SCOPE_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_SCOPE_ELEMENT ) ) {
endScopeElement();
- } else if (name.equals(LDAPTransformer.MAGIC_VERSION_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_VERSION_ELEMENT ) ) {
endVersionElement();
- } else if (name.equals(LDAPTransformer.MAGIC_SERVERURL_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_SERVERURL_ELEMENT ) )
{
endServerurlElement();
- } else if (name.equals(LDAPTransformer.MAGIC_PORT_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_PORT_ELEMENT ) ) {
endPortElement();
- } else if (name.equals(LDAPTransformer.MAGIC_DOC_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_DOC_ELEMENT ) ) {
endDocElement();
- } else if (name.equals(LDAPTransformer.MAGIC_ROW_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_ROW_ELEMENT ) ) {
endRowElement();
- } else if (name.equals(LDAPTransformer.MAGIC_ERROR_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_ERROR_ELEMENT ) ) {
endErrorElement();
- } else if (name.equals(LDAPTransformer.MAGIC_SAX_ERROR)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_SAX_ERROR ) ) {
endSaxError();
- } else if (name.equals(LDAPTransformer.MAGIC_ROOT_DN_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_ROOT_DN_ELEMENT ) ) {
endRootDnElement();
- } else if (name.equals(LDAPTransformer.MAGIC_PASSWORD_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_PASSWORD_ELEMENT ) ) {
endPasswordElement();
- } else if (name.equals(LDAPTransformer.MAGIC_ATTRIBUTE_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_ATTRIBUTE_ELEMENT ) )
{
endAttributeElement();
- } else if
(name.equals(LDAPTransformer.MAGIC_SHOW_ATTRIBUTE_ELEMENT)) {
+ } else if ( name.equals(
LDAPTransformer.MAGIC_SHOW_ATTRIBUTE_ELEMENT ) ) {
endShowAttributeElement();
- } else if (name.equals(LDAPTransformer.MAGIC_SEARCHBASE_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_SEARCHBASE_ELEMENT )
) {
endSearchbaseElement();
- } else if (name.equals(LDAPTransformer.MAGIC_FILTER_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_FILTER_ELEMENT ) ) {
endFilterElement();
- } else if (name.equals(LDAPTransformer.MAGIC_DEREF_LINK_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_DEREF_LINK_ELEMENT )
) {
endDerefLinkElement();
- } else if (name.equals(LDAPTransformer.MAGIC_COUNT_LIMIT_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_COUNT_LIMIT_ELEMENT )
) {
endCountLimitElement();
- } else if (name.equals(LDAPTransformer.MAGIC_TIME_LIMIT_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_TIME_LIMIT_ELEMENT )
) {
endTimeLimitElement();
- } else if (name.equals(LDAPTransformer.MAGIC_DEBUG_ELEMENT)) {
+ } else if ( name.equals( LDAPTransformer.MAGIC_DEBUG_ELEMENT ) ) {
endDebugElement();
}
}
- public void characters(char ary[], int start, int length) throws
SAXException {
- if (current_state !=
LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT &&
- current_state !=
LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT &&
- current_state != LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT &&
- current_state != LDAPTransformer.STATE_INSIDE_VERSION_ELEMENT &&
- current_state != LDAPTransformer.STATE_INSIDE_SERVERURL_ELEMENT
&&
- current_state != LDAPTransformer.STATE_INSIDE_PORT_ELEMENT &&
- current_state != LDAPTransformer.STATE_INSIDE_DOC_ELEMENT &&
- current_state != LDAPTransformer.STATE_INSIDE_ROW_ELEMENT &&
- current_state != LDAPTransformer.STATE_INSIDE_ERROR_ELEMENT &&
- current_state != LDAPTransformer.STATE_INSIDE_SAX_ERROR_ELEMENT
&&
- current_state != LDAPTransformer.STATE_INSIDE_ROOT_DN_ELEMENT &&
- current_state != LDAPTransformer.STATE_INSIDE_PASSWORD_ELEMENT &&
- current_state != LDAPTransformer.STATE_INSIDE_ATTRIBUTE_ELEMENT
&&
- current_state !=
LDAPTransformer.STATE_INSIDE_SHOW_ATTRIBUTE_ELEMENT &&
- current_state != LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT &&
- current_state != LDAPTransformer.STATE_INSIDE_DEREF_LINK_ELEMENT
&&
- current_state !=
LDAPTransformer.STATE_INSIDE_COUNT_LIMIT_ELEMENT &&
- current_state != LDAPTransformer.STATE_INSIDE_TIME_LIMIT_ELEMENT
&&
- current_state != LDAPTransformer.STATE_INSIDE_DEBUG_ELEMENT &&
- current_state !=
LDAPTransformer.STATE_INSIDE_SEARCHBASE_ELEMENT) {
- super.characters(ary, start, length);
- }
- getLogger().debug("RECEIVED CHARACTERS: " + new String(ary, start,
length));
- current_value.append(ary, start, length);
+ public void characters( char ary[], int start, int length ) throws
SAXException {
+ if ( current_state !=
LDAPTransformer.STATE_INSIDE_INITIALIZER_ELEMENT &&
+ current_state !=
LDAPTransformer.STATE_INSIDE_AUTHENTICATION_ELEMENT &&
+ current_state != LDAPTransformer.STATE_INSIDE_SCOPE_ELEMENT
&&
+ current_state !=
LDAPTransformer.STATE_INSIDE_VERSION_ELEMENT &&
+ current_state !=
LDAPTransformer.STATE_INSIDE_SERVERURL_ELEMENT &&
+ current_state != LDAPTransformer.STATE_INSIDE_PORT_ELEMENT &&
+ current_state != LDAPTransformer.STATE_INSIDE_DOC_ELEMENT &&
+ current_state != LDAPTransformer.STATE_INSIDE_ROW_ELEMENT &&
+ current_state != LDAPTransformer.STATE_INSIDE_ERROR_ELEMENT
&&
+ current_state !=
LDAPTransformer.STATE_INSIDE_SAX_ERROR_ELEMENT &&
+ current_state !=
LDAPTransformer.STATE_INSIDE_ROOT_DN_ELEMENT &&
+ current_state !=
LDAPTransformer.STATE_INSIDE_PASSWORD_ELEMENT &&
+ current_state !=
LDAPTransformer.STATE_INSIDE_ATTRIBUTE_ELEMENT &&
+ current_state !=
LDAPTransformer.STATE_INSIDE_SHOW_ATTRIBUTE_ELEMENT &&
+ current_state != LDAPTransformer.STATE_INSIDE_FILTER_ELEMENT
&&
+ current_state !=
LDAPTransformer.STATE_INSIDE_DEREF_LINK_ELEMENT &&
+ current_state !=
LDAPTransformer.STATE_INSIDE_COUNT_LIMIT_ELEMENT &&
+ current_state !=
LDAPTransformer.STATE_INSIDE_TIME_LIMIT_ELEMENT &&
+ current_state != LDAPTransformer.STATE_INSIDE_DEBUG_ELEMENT
&&
+ current_state !=
LDAPTransformer.STATE_INSIDE_SEARCHBASE_ELEMENT ) {
+ super.characters( ary, start, length );
+ }
+ getLogger().debug( "RECEIVED CHARACTERS: " + new String( ary, start,
length ) );
+ current_value.append( ary, start, length );
}
- private void attribute(AttributesImpl attr, String name, String value) {
- attr.addAttribute("", name, name, "CDATA", value);
+ private void attribute( AttributesImpl attr, String name, String value )
{
+ attr.addAttribute( "", name, name, "CDATA", value );
}
- private void start(String name, AttributesImpl attr) throws SAXException
{
- super.contentHandler.startElement("", name, name, attr);
+ private void start( String name, AttributesImpl attr ) throws
SAXException {
+ super.contentHandler.startElement( "", name, name, attr );
attr.clear();
}
- private void end(String name) throws SAXException {
- super.contentHandler.endElement("", name, name);
+ private void end( String name ) throws SAXException {
+ super.contentHandler.endElement( "", name, name );
}
- private void data(String data) throws SAXException {
- if (data != null)
- super.contentHandler.characters(data.toCharArray(), 0,
data.length());
+ private void data( String data ) throws SAXException {
+ if ( data != null )
+ super.contentHandler.characters( data.toCharArray(), 0,
data.length() );
}
- protected static String getStringValue(Object object) {
- if (object instanceof byte[]) {
- return new String((byte[]) object);
- } else if (object instanceof char[]) {
- return new String((char[]) object);
- } else if (object != null) {
+ protected static String getStringValue( Object object ) {
+ if ( object instanceof byte[] ) {
+ return new String( (byte[]) object );
+ } else if ( object instanceof char[] ) {
+ return new String( (char[]) object );
+ } else if ( object != null ) {
return object.toString();
} else {
return "";
}
}
- public final Logger getTheLogger()
- {
+ public final Logger getTheLogger() {
return getLogger();
}
-class LDAPQuery {
+ class LDAPQuery {
- /** What index are you in daddy's queries list **/
- protected int query_index;
+ /** What index are you in daddy's queries list **/
+ protected int query_index;
- /** The current state of the event receiving FSM **/
- protected int current_state;
+ /** The current state of the event receiving FSM **/
+ protected int current_state;
- /** Who's your daddy? **/
- protected LDAPTransformer transformer;
+ /** Who's your daddy? **/
+ protected LDAPTransformer transformer;
+
+ /** LDAP configuration information **/
+ protected String initializer = "com.sun.jndi.ldap.LdapCtxFactory";
+ protected String serverurl = "";
+ protected int port = 389;
+ protected String root_dn = "";
+ protected String password = "";
+ protected String version = "2";
+ protected String scope = "ONELEVEL_SCOPE";
+ protected String authentication = "simple";
+
+ /** LDAP environment information **/
+ protected Properties env = new Properties();
+ protected DirContext ctx;
+
+ /** LDAP Query **/
+ protected int toDo;
+ protected String searchbase = "";
+ protected List attrListe = new LinkedList();
+ protected boolean showAttribute = true;
+ protected String filter = "";
+ protected String doc_element = "doc-element";
+ protected String row_element = "row-element";
+ protected String error_element = "ldap-error";
+ protected boolean sax_error = false;
+ protected boolean deref_link = false; // Dereference: true ->
dereference the link during search
+ protected long count_limit = 0; // Maximum number of
entries to return: 0 -> no limit
+ protected int time_limit = 0; // Number of
milliseconds to wait before return: 0 -> infinite
+ protected boolean debug = false;
+
+ protected LDAPQuery( LDAPTransformer transformer ) {
+ this.transformer = transformer;
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_INITIALIZER_ELEMENT ) ) {
+ initializer = transformer.default_properties.getProperty(
transformer.MAGIC_INITIALIZER_ELEMENT );
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_SERVERURL_ELEMENT ) ) {
+ serverurl = transformer.default_properties.getProperty(
transformer.MAGIC_SERVERURL_ELEMENT );
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_PORT_ELEMENT ) ) {
+ port = Integer.parseInt(
transformer.default_properties.getProperty(
transformer.MAGIC_INITIALIZER_ELEMENT ) );
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_ROOT_DN_ELEMENT ) ) {
+ root_dn = transformer.default_properties.getProperty(
transformer.MAGIC_ROOT_DN_ELEMENT );
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_PASSWORD_ELEMENT ) ) {
+ password = transformer.default_properties.getProperty(
transformer.MAGIC_PASSWORD_ELEMENT );
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_VERSION_ELEMENT ) ) {
+ version = transformer.default_properties.getProperty(
transformer.MAGIC_VERSION_ELEMENT );
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_SCOPE_ELEMENT ) ) {
+ scope = transformer.default_properties.getProperty(
transformer.MAGIC_SCOPE_ELEMENT );
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_AUTHENTICATION_ELEMENT ) ) {
+ authentication = transformer.default_properties.getProperty(
transformer.MAGIC_AUTHENTICATION_ELEMENT );
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_SEARCHBASE_ELEMENT ) ) {
+ searchbase = transformer.default_properties.getProperty(
transformer.MAGIC_SEARCHBASE_ELEMENT );
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_SHOW_ATTRIBUTE_ELEMENT ) ) {
+ showAttribute = transformer.default_properties.getProperty(
transformer.MAGIC_SHOW_ATTRIBUTE_ELEMENT ).equals( "FALSE" ) ? false : true;
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_DOC_ELEMENT ) ) {
+ doc_element = transformer.default_properties.getProperty(
transformer.MAGIC_DOC_ELEMENT );
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_ROW_ELEMENT ) ) {
+ row_element = transformer.default_properties.getProperty(
transformer.MAGIC_ROW_ELEMENT );
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_ERROR_ELEMENT ) ) {
+ error_element = transformer.default_properties.getProperty(
transformer.MAGIC_ERROR_ELEMENT );
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_SAX_ERROR ) ) {
+ sax_error = transformer.default_properties.getProperty(
transformer.MAGIC_SAX_ERROR ).equals( "TRUE" ) ? true : false;
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_DEREF_LINK_ELEMENT ) ) {
+ deref_link = transformer.default_properties.getProperty(
transformer.MAGIC_DEREF_LINK_ELEMENT ).equals( "TRUE" ) ? true : false;
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_COUNT_LIMIT_ELEMENT ) ) {
+ count_limit = Long.parseLong(
transformer.default_properties.getProperty(
transformer.MAGIC_COUNT_LIMIT_ELEMENT ) );
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_TIME_LIMIT_ELEMENT ) ) {
+ time_limit = Integer.parseInt(
transformer.default_properties.getProperty(
transformer.MAGIC_TIME_LIMIT_ELEMENT ) );
+ }
+ if ( null != transformer.default_properties.getProperty(
transformer.MAGIC_DEBUG_ELEMENT ) ) {
+ debug = transformer.default_properties.getProperty(
transformer.MAGIC_DEBUG_ELEMENT ).equals( "TRUE" ) ? true : false;
+ }
+ }
+
+ protected void execute() throws Exception, NamingException {
+ String[] attrList = new String[attrListe.size()];
+ AttributesImpl attr = new AttributesImpl();
+ if ( debug ) {
+ debugPrint();
+ }
+ SearchControls constraints = new SearchControls();
+ attrListe.toArray( attrList );
+ attrListe.clear();
+ try {
+ connect();
+ switch ( toDo ) {
+ case LDAPTransformer.STATE_INSIDE_EXECUTE_QUERY:
+ try {
+ 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 > 0 ) {
+ constraints.setReturningAttributes( attrList
);
+ }
+ NamingEnumeration ldapresults = ctx.search(
searchbase, filter, constraints );
+
+ if ( !doc_element.equals( "" ) ) {
+ transformer.start( doc_element, attr );
+ }
+
+ while ( ldapresults != null &&
ldapresults.hasMore() ) {
+ if ( !row_element.equals( "" ) ) {
+ transformer.start( row_element, attr );
+ }
+ SearchResult 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();
+ Enumeration vals = at.getAll();
+ String attrID = (String) at.getID();
+ if ( showAttribute ) {
+ transformer.start( attrID, attr
);
+ }
+ String attrVal = (String)
vals.nextElement();
+ 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() );
+ } else {
+ transformer.start( error_element, attr );
+ transformer.data( "[LDAPTransformer] Error
in LDAP-Query: " + e );
+ transformer.end( error_element );
+ transformer.getTheLogger().error(
"[LDAPTransformer] Exception: " + e.toString() );
+ }
+ }
+ break;
+ case LDAPTransformer.STATE_INSIDE_EXECUTE_INCREMENT:
+ try {
+ 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( "Increment must reference
exactly 1 attribute." );
+ transformer.end( error_element );
+ } else {
+ constraints.setReturningAttributes( attrList
);
+ NamingEnumeration ldapresults = ctx.search(
searchbase, filter, constraints );
+ int attrVal = 0;
+ String attrID = "";
+ SearchResult si = null;
+ while ( ldapresults != null &&
ldapresults.hasMore() ) {
+ 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();
+ Enumeration vals = at.getAll();
+ attrID = (String) at.getID();
+ attrVal = Integer.parseInt(
(String) vals.nextElement() );
+ }
+ }
+ }
+ ++attrVal;
+ // Specify the changes to make
+ ModificationItem[] mods = new
ModificationItem[1];
+ // Replace the "mail" attribute with a new
value
+ mods[0] = new ModificationItem(
DirContext.REPLACE_ATTRIBUTE,
+ new
BasicAttribute( attrID, Integer.toString( attrVal ) ) );
+ // Perform the requested modifications on
the named object
+ ctx.modifyAttributes( new StringBuffer(
si.toString().substring( 0, si.toString().indexOf( ":" ) ) )
+ .append( "," ).append(
searchbase ).toString(), mods );
+ }
+ } catch ( Exception e ) {
+ if ( sax_error ) {
+ throw new Exception( "[LDAPTransformer]
Error incrementing an attribute: " + e.toString() );
+ } else {
+ transformer.start( error_element, attr );
+ transformer.data( "[LDAPTransformer] Error
incrementing an attribute: " + e.toString() );
+ transformer.end( error_element );
+ transformer.getTheLogger().error(
"[LDAPTransformer] Error incrementing an attribute: " + e.toString() );
+ }
+ }
+ break;
+ default:
+ } //end switch
+ } catch ( NamingException e ) {
+ if ( sax_error ) {
+ throw new NamingException( "[LDAPTransformer] Failed
ldap-connection to directory service: " + e.toString() );
+ } else {
+ transformer.start( error_element, attr );
+ transformer.data( "[LDAPTransformer] Failed
ldap-connection to directory service." );
+ transformer.end( error_element );
+ transformer.getTheLogger().error( "[LDAPTransformer]
Failed to connect to " + serverurl + e.toString() );
+ }
+ }
+ try {
+ disconnect();
+ } catch ( NamingException e ) {
+ if ( sax_error ) {
+ throw new NamingException( "[LDAPTransformer] Failed
ldap-disconnection from directory service: " + e.toString() );
+ } else {
+ transformer.start( error_element, attr );
+ transformer.data( "[LDAPTransformer] Failed
ldap-disconnection to directory service." );
+ transformer.end( error_element );
+ transformer.getTheLogger().error( "[LDAPTransformer]
Failed to disconnect from " + serverurl + e.toString() );
+ }
+ }
+ }
- /** LDAP configuration information **/
- protected String initializer = "com.sun.jndi.ldap.LdapCtxFactory";
- protected String serverurl = "";
- protected int port = 389;
- protected String root_dn = "";
- protected String password = "";
- protected String version = "2";
- protected String scope = "ONELEVEL_SCOPE";
- protected String authentication = "simple";
-
- /** LDAP environment information **/
- protected Properties env = new Properties();
- protected DirContext ctx;
-
- /** LDAP Query **/
- protected int toDo;
- protected String searchbase = "";
- protected List attrListe = new LinkedList();
- protected boolean showAttribute = true;
- protected String filter = "";
- protected String doc_element = "doc-element";
- protected String row_element = "row-element";
- protected String error_element = "ldap-error";
- protected boolean sax_error = false;
- protected boolean deref_link = false; // Dereference: true ->
dereference the link during search
- protected long count_limit = 0; // Maximum number of entries to
return: 0 -> no limit
- protected int time_limit = 0; // Number of milliseconds to
wait before return: 0 -> infinite
- protected boolean debug = false;
-
- protected LDAPQuery (LDAPTransformer transformer) {
- this.transformer = transformer;
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_INITIALIZER_ELEMENT))
{
- initializer =
transformer.default_properties.getProperty(transformer.MAGIC_INITIALIZER_ELEMENT);
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_SERVERURL_ELEMENT))
{
- serverurl =
transformer.default_properties.getProperty(transformer.MAGIC_SERVERURL_ELEMENT);
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_PORT_ELEMENT)) {
- port =
Integer.parseInt(transformer.default_properties.getProperty(transformer.MAGIC_INITIALIZER_ELEMENT));
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_ROOT_DN_ELEMENT)) {
- root_dn =
transformer.default_properties.getProperty(transformer.MAGIC_ROOT_DN_ELEMENT);
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_PASSWORD_ELEMENT))
{
- password =
transformer.default_properties.getProperty(transformer.MAGIC_PASSWORD_ELEMENT);
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_VERSION_ELEMENT)) {
- version =
transformer.default_properties.getProperty(transformer.MAGIC_VERSION_ELEMENT);
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_SCOPE_ELEMENT)) {
- scope =
transformer.default_properties.getProperty(transformer.MAGIC_SCOPE_ELEMENT);
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_AUTHENTICATION_ELEMENT))
{
- authentication =
transformer.default_properties.getProperty(transformer.MAGIC_AUTHENTICATION_ELEMENT);
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_SEARCHBASE_ELEMENT))
{
- searchbase =
transformer.default_properties.getProperty(transformer.MAGIC_SEARCHBASE_ELEMENT);
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_SHOW_ATTRIBUTE_ELEMENT))
{
- showAttribute =
transformer.default_properties.getProperty(transformer.MAGIC_SHOW_ATTRIBUTE_ELEMENT).equals("FALSE")
? false : true;
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_DOC_ELEMENT)) {
- doc_element =
transformer.default_properties.getProperty(transformer.MAGIC_DOC_ELEMENT);
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_ROW_ELEMENT)) {
- row_element =
transformer.default_properties.getProperty(transformer.MAGIC_ROW_ELEMENT);
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_ERROR_ELEMENT)) {
- error_element =
transformer.default_properties.getProperty(transformer.MAGIC_ERROR_ELEMENT);
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_SAX_ERROR)) {
- sax_error =
transformer.default_properties.getProperty(transformer.MAGIC_SAX_ERROR).equals("TRUE")
? true : false;
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_DEREF_LINK_ELEMENT))
{
- deref_link =
transformer.default_properties.getProperty(transformer.MAGIC_DEREF_LINK_ELEMENT).equals("TRUE")
? true : false;
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_COUNT_LIMIT_ELEMENT))
{
- count_limit =
Long.parseLong(transformer.default_properties.getProperty(transformer.MAGIC_COUNT_LIMIT_ELEMENT));
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_TIME_LIMIT_ELEMENT))
{
- time_limit =
Integer.parseInt(transformer.default_properties.getProperty(transformer.MAGIC_TIME_LIMIT_ELEMENT));
- }
- if (null !=
transformer.default_properties.getProperty(transformer.MAGIC_DEBUG_ELEMENT)) {
- debug =
transformer.default_properties.getProperty(transformer.MAGIC_DEBUG_ELEMENT).equals("TRUE")
? true : false;
- }
- }
-
- protected void execute() throws Exception, NamingException {
- String[] attrList = new String[attrListe.size()];
- AttributesImpl attr = new AttributesImpl();
- if (debug) {
- debugPrint();
+ protected void addAttrList( String attr ) {
+ attrListe.add( attr );
}
- SearchControls constraints = new SearchControls();
- attrListe.toArray(attrList);
- attrListe.clear();
- try {
- connect();
- switch (toDo) {
- case LDAPTransformer.STATE_INSIDE_EXECUTE_QUERY:
- try {
- 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 > 0) {
-
constraints.setReturningAttributes(attrList);
- }
- NamingEnumeration ldapresults =
ctx.search(searchbase, filter, constraints);
-
- if (!doc_element.equals("")) {
- transformer.start(doc_element, attr);
- }
-
- while (ldapresults != null &&
ldapresults.hasMore()) {
- if (!row_element.equals("")) {
- transformer.start(row_element,
attr);
- }
- SearchResult 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();
- Enumeration vals =
at.getAll();
- String attrID =
(String)at.getID();
- if (showAttribute) {
-
transformer.start(attrID, attr);
- }
- String attrVal =
(String)vals.nextElement();
- 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());
- } else {
- transformer.start(error_element, attr);
- transformer.data("[LDAPTransformer] Error in
LDAP-Query: " + e);
- transformer.end(error_element);
-
transformer.getTheLogger().error("[LDAPTransformer] Exception: " +
e.toString());
- }
- }
- break;
- case LDAPTransformer.STATE_INSIDE_EXECUTE_INCREMENT:
- try {
- 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("Increment must
reference exactly 1 attribute.");
- transformer.end(error_element);
- } else {
-
constraints.setReturningAttributes(attrList);
- NamingEnumeration ldapresults =
ctx.search(searchbase, filter, constraints);
- int attrVal = 0;
- String attrID = "";
- SearchResult si = null;
- while (ldapresults != null &&
ldapresults.hasMore()) {
- 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();
- Enumeration
vals = at.getAll();
- attrID =
(String)at.getID();
- attrVal =
Integer.parseInt((String)vals.nextElement());
- }
- }
- }
- ++attrVal;
- // Specify the changes to make
- ModificationItem[] mods = new
ModificationItem[1];
- // Replace the "mail" attribute with a
new value
- mods[0] = new
ModificationItem(DirContext.REPLACE_ATTRIBUTE,
- new BasicAttribute(attrID,
Integer.toString(attrVal)));
- // Perform the requested modifications
on the named object
-
ctx.modifyAttributes(si.toString().substring(0,si.toString().indexOf(":")) +
"," + searchbase, mods);
- }
- } catch(Exception e) {
- if (sax_error) {
- throw new Exception ("[LDAPTransformer] Error
incrementing an attribute: " + e.toString());
- } else {
- transformer.start(error_element, attr);
- transformer.data("[LDAPTransformer] Error
incrementing an attribute: " + e.toString());
- transformer.end(error_element);
-
transformer.getTheLogger().error("[LDAPTransformer] Error incrementing an
attribute: " + e.toString());
- }
- }
- break;
- default:
- } //end switch
- } catch (NamingException e) {
- if (sax_error) {
- throw new NamingException ("[LDAPTransformer] Failed
ldap-connection to directory service: " + e.toString());
- } else {
- transformer.start(error_element, attr);
- transformer.data("[LDAPTransformer] Failed ldap-connection
to directory service.");
- transformer.end(error_element);
- transformer.getTheLogger().error("[LDAPTransformer] Failed
to connect to " + serverurl + e.toString());
- }
- }
- try {
- disconnect();
- } catch (NamingException e) {
- if (sax_error) {
- throw new NamingException ("[LDAPTransformer] Failed
ldap-disconnection from directory service: " + e.toString());
- } else {
- transformer.start(error_element, attr);
- transformer.data("[LDAPTransformer] Failed ldap-disconnection
to directory service.");
- transformer.end(error_element);
- transformer.getTheLogger().error("[LDAPTransformer] Failed to
disconnect from " + serverurl + e.toString());
- }
- }
- }
-
- protected void addAttrList(String attr) {
- attrListe.add(attr);
- }
-
- protected void connect() throws NamingException {
- if (root_dn != null && password != null) {
- env.put(Context.SECURITY_AUTHENTICATION, authentication);
- env.put(Context.SECURITY_PRINCIPAL, root_dn);
- env.put(Context.SECURITY_CREDENTIALS, password);
- }
-
- env.put("java.naming.ldap.version", version );
- env.put(Context.INITIAL_CONTEXT_FACTORY, initializer);
- env.put(Context.PROVIDER_URL, serverurl + ":" + port);
-
- try {
- ctx = new InitialDirContext(env);
- } catch (NamingException e) {
- env.clear();
- throw new NamingException (e.toString());
+
+ protected void connect() throws NamingException {
+ if ( root_dn != null && password != null ) {
+ env.put( Context.SECURITY_AUTHENTICATION, authentication );
+ env.put( Context.SECURITY_PRINCIPAL, root_dn );
+ env.put( Context.SECURITY_CREDENTIALS, password );
+ }
+
+ env.put( "java.naming.ldap.version", version );
+ env.put( Context.INITIAL_CONTEXT_FACTORY, initializer );
+ env.put( Context.PROVIDER_URL, new StringBuffer( serverurl
).append( ":" ).append( port ).toString() );
+
+ try {
+ ctx = new InitialDirContext( env );
+ } catch ( NamingException e ) {
+ env.clear();
+ throw new NamingException( e.toString() );
+ }
+ }
+
+ protected void disconnect() throws NamingException {
+ try {
+ if ( ctx != null ) ctx.close();
+ } catch ( NamingException e ) {
+ ctx = null;
+ env.clear();
+ throw new NamingException( e.toString() );
+ }
+ ctx = null;
+ env.clear();
+ }
+
+ protected void debugPrint() {
+ transformer.getTheLogger().debug( "[LDAPTransformer]
query_index: " + query_index );
+ transformer.getTheLogger().debug( "[LDAPTransformer]
current_state: " + current_state );
+ transformer.getTheLogger().debug( "[LDAPTransformer] serverurl:
" + serverurl );
+ transformer.getTheLogger().debug( "[LDAPTransformer] port: " +
port );
+ transformer.getTheLogger().debug( "[LDAPTransformer] root_dn: "
+ root_dn );
+ transformer.getTheLogger().debug( "[LDAPTransformer] password: "
+ password );
+ transformer.getTheLogger().debug( "[LDAPTransformer] version: "
+ version );
+ transformer.getTheLogger().debug( "[LDAPTransformer] scope: " +
scope );
+ transformer.getTheLogger().debug( "[LDAPTransformer]
authentication: " + authentication );
+ transformer.getTheLogger().debug( "[LDAPTransformer] toDo: " +
toDo );
+ transformer.getTheLogger().debug( "[LDAPTransformer] searchbase:
" + searchbase );
+ transformer.getTheLogger().debug( "[LDAPTransformer]
showAttribute: " + showAttribute );
+ transformer.getTheLogger().debug( "[LDAPTransformer] attribute:
" + attrListe.toString() );
+ transformer.getTheLogger().debug( "[LDAPTransformer] filter: " +
filter );
+ transformer.getTheLogger().debug( "[LDAPTransformer]
doc_element: " + doc_element );
+ transformer.getTheLogger().debug( "[LDAPTransformer]
row_element: " + row_element );
+ transformer.getTheLogger().debug( "[LDAPTransformer]
error_element: " + error_element );
+ transformer.getTheLogger().debug( "[LDAPTransformer] sax-error:
" + sax_error );
+ transformer.getTheLogger().debug( "[LDAPTransformer] deref_link:
" + deref_link );
+ transformer.getTheLogger().debug( "[LDAPTransformer]
count_limit: " + count_limit );
+ transformer.getTheLogger().debug( "[LDAPTransformer] time_limit:
" + time_limit );
}
}
-
- protected void disconnect() throws NamingException {
- try {
- if (ctx != null) ctx.close();
- } catch (NamingException e) {
- ctx = null;
- env.clear();
- throw new NamingException (e.toString());
- }
- ctx = null;
- env.clear();
- }
-
- protected void debugPrint() {
- transformer.getTheLogger().debug("[LDAPTransformer] query_index: " +
query_index);
- transformer.getTheLogger().debug("[LDAPTransformer] current_state: " +
current_state);
- transformer.getTheLogger().debug("[LDAPTransformer] serverurl: " +
serverurl);
- transformer.getTheLogger().debug("[LDAPTransformer] port: " + port);
- transformer.getTheLogger().debug("[LDAPTransformer] root_dn: " +
root_dn);
- transformer.getTheLogger().debug("[LDAPTransformer] password: " +
password);
- transformer.getTheLogger().debug("[LDAPTransformer] version: " +
version);
- transformer.getTheLogger().debug("[LDAPTransformer] scope: " + scope);
- transformer.getTheLogger().debug("[LDAPTransformer] authentication: " +
authentication);
- transformer.getTheLogger().debug("[LDAPTransformer] toDo: " + toDo);
- transformer.getTheLogger().debug("[LDAPTransformer] searchbase: " +
searchbase);
- transformer.getTheLogger().debug("[LDAPTransformer] showAttribute: " +
showAttribute);
- transformer.getTheLogger().debug("[LDAPTransformer] attribute: " +
attrListe.toString());
- transformer.getTheLogger().debug("[LDAPTransformer] filter: " + filter);
- transformer.getTheLogger().debug("[LDAPTransformer] doc_element: " +
doc_element);
- transformer.getTheLogger().debug("[LDAPTransformer] row_element: " +
row_element);
- transformer.getTheLogger().debug("[LDAPTransformer] error_element: " +
error_element);
- transformer.getTheLogger().debug("[LDAPTransformer] sax-error: " +
sax_error);
- transformer.getTheLogger().debug("[LDAPTransformer] deref_link: " +
deref_link);
- transformer.getTheLogger().debug("[LDAPTransformer] count_limit: " +
count_limit);
- transformer.getTheLogger().debug("[LDAPTransformer] time_limit: " +
time_limit);
- }
-}
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]