/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2004 Danet GmbH (www.danet.de), BU BTS.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: DeleteTag.java 1607 2006-09-29 12:32:13Z drmlipp $
*
* $Log$
* Revision 1.2 2005/09/05 09:41:48 drmlipp
* Synchronized with 1.3.2.
*
* Revision 1.1.2.1 2005/09/01 15:21:11 drmlipp
* Delete tag workfing.
*
* Revision 1.1.2.1 2005/09/01 14:47:18 drmlipp
*/
package de.danet.an.util.jellytags.ldap;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import javax.naming.NamingException;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.XMLOutput;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import de.danet.an.util.jellytags.ParseTagSupport;
import de.danet.an.util.sax.HandlerStack;
import de.danet.an.util.sax.StackedHandler;
/**
* A tag that executes an LDAP query.
*/
public class DeleteTag extends ParseTagSupport {
private static final org.apache.commons.logging.Log logger
= org.apache.commons.logging.LogFactory.getLog(DeleteTag.class);
private DirContext ldapContext = null;
/**
* @param context The context to set.
*/
public void setLdapContext(DirContext context) {
this.ldapContext = context;
}
/**
* Execute the tag.
* @param output the query result
* @throws JellyTagException if an error occurs
*/
public void doTag(XMLOutput output) throws JellyTagException {
if (ldapContext == null) {
throw new IllegalStateException
("Attribute \"ldapContext\" must be specified.");
}
try {
HandlerStack handler = new HandlerStack(new ContentHandler ());
getXML (new XMLOutput(handler.contentHandler()));
} catch (SAXException e) {
throw new JellyTagException(e.getException());
}
}
private class ContentHandler extends StackedHandler {
String dn = null;
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#startElement
*/
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if (localName.equals("entry")) {
dn = attributes.getValue("dn");
if (dn == null) {
throw new IllegalArgumentException
("Attribute \"dn\" must be spcified for <entry>");
}
}
}
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#endElement
*/
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (localName.equals("entry")) {
try {
ldapContext.unbind (dn);
} catch (NamingException e) {
throw new SAXException (e);
}
}
}
}
}