svn commit: r617035 [3/22] - in /lenya/branches/revolution/1.3.x: ./ src/java/org/apache/lenya/ac/ src/java/org/apache/lenya/ac/cache/ src/java/org/apache/lenya/ac/cifs/ src/java/org/apache/lenya/ac/file/ src/java/org/apache/lenya/ac/impl/ src/java/org...

[email protected]
Newsgroups gmane.comp.cms.lenya.cvs
Message-ID <[email protected]>
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/ldap/LDAPUser.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/ldap/LDAPUser.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/ldap/LDAPUser.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/ac/ldap/LDAPUser.java Wed Jan 30 23:44:03 2008
@@ -12,15 +12,12 @@
  * the License.
  *  
  */
-
 package org.apache.lenya.ac.ldap;
-
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.Hashtable;
 import java.util.Properties;
-
 import javax.naming.AuthenticationException;
 import javax.naming.Context;
 import javax.naming.NamingEnumeration;
@@ -31,567 +28,454 @@
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.InitialLdapContext;
-
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.lenya.ac.AccessControlException;
 import org.apache.lenya.ac.file.FileUser;
-import org.apache.log4j.Category;
 import org.apache.log4j.Logger;
-
 import com.sun.jndi.ldap.LdapCtxFactory;
-
 /**
  * LDAP user.
+ * 
  * @version $Id$
  */
 public class LDAPUser extends FileUser {
-    private static Properties defaultProperties = null;
-    private static Category log =  Logger.getLogger(LDAPUser.class);
-
-    public static final String LDAP_ID = "ldapid";
-    private static String LDAP_PROPERTIES_FILE = "ldap.properties"; 
-    private static String PROVIDER_URL_PROP = "provider-url";
-    private static String MGR_DN_PROP = "mgr-dn";
-    private static String MGR_PW_PROP = "mgr-pw";
-    private static String KEY_STORE_PROP = "key-store";
-    private static String SECURITY_PROTOCOL_PROP = "security-protocol";
-    private static String SECURITY_AUTHENTICATION_PROP = "security-authentication";
-    private static String USR_ATTR_PROP = "usr-attr";
-    private static String USR_ATTR_DEFAULT = "uid";
-    private static String USR_NAME_ATTR_PROP = "usr-name-attr";
-    private static String USR_NAME_ATTR_DEFAULT = "gecos";
-    private static String USR_BRANCH_PROP = "usr-branch";
-    private static String USR_BRANCH_DEFAULT = "ou=People";
-    private static String USR_AUTH_TYPE_PROP = "usr-authentication";
-    private static String USR_AUTH_TYPE_DEFAULT = "simple";
-    private static String BASE_DN_PROP = "base-dn";
-    private static String DOMAIN_NAME_PROP = "domain-name";
-
-    private String ldapId;
-    private String ldapName;
-
-    // deprecated: for backwards compatibility only !
-    private static String PARTIAL_USER_DN_PROP = "partial-user-dn";
-
-    /**
-     * Creates a new LDAPUser object.
-     */
-    public LDAPUser() {
-    }
-
-    /**
-     * Creates a new LDAPUser object.
-     * @param configurationDirectory The configuration directory.
-     */
-    public LDAPUser(File configurationDirectory) {
-        setConfigurationDirectory(configurationDirectory);
-    }
-
-    /**
-     * Create an LDAPUser
-     * 
-     * @param configurationDirectory where the user will be attached to
-     * @param id user id of LDAPUser
-     * @param email of LDAPUser
-     * @param ldapId of LDAPUser
-     * @throws ConfigurationException if the properties could not be read
-     */
-    public LDAPUser(File configurationDirectory, String id, String email, String ldapId)
-            throws ConfigurationException {
-        super(configurationDirectory, id, null, email, null);
-        this.ldapId = ldapId;
-
-        initialize();
-    }
-
-    /**
-     * Create a new LDAPUser from a configuration
-     * 
-     * @param config the <code>Configuration</code> specifying the user details
-     * @throws ConfigurationException if the user could not be instantiated
-     */
-    public void configure(Configuration config) throws ConfigurationException {
-        super.configure(config);
-        ldapId = config.getChild(LDAP_ID).getValue();
-
-        initialize();
-    }
-
-    /**
-     * Checks if a user exists.
-     *
-     * @param ldapId The LDAP id.
-     * @return A boolean value indicating whether the user is found in the directory
-     * @throws AccessControlException when an unexpected error occurs.
-     */
-    public boolean existsUser(String ldapId) throws AccessControlException {
-
-        if (log.isDebugEnabled())
-            log.debug("existsUser() checking id " + ldapId);
-
-        boolean exists = false;
-
-        try {
-            readProperties();
-            SearchResult entry = getDirectoryEntry(ldapId);
-
-            exists = (entry != null);
-
-        } catch (NamingException e) {
-            log.info("LDAPUser.existsUser() got exception while looking up id [" + ldapId + "], so will return false", e);
-            exists = false;
-        } catch (Exception e) {
-            if (log.isDebugEnabled())
-                log.debug("existsUser() for id [" + ldapId + "] got exception: " + e);
-            throw new AccessControlException("Exception during search: ", e);
-        }
-
-        return exists;
-    }
-
-    /**
-     * Initializes this user.
-     *
-     * The current ldapId is queried in the directory, 
-     * in order to retrieve additional information, such as the user name.
-     * In current implementation, only the user name is actually retrieved, but
-     * other attributes may be used in the future (such as groups ?)
-     *
-     * Note: if the user entry could not be retrieved, initialize the
-     * attributes to empty string (they are optional anyway), but do not
-     * throw an exception.
-     */
-    protected void initialize() {
-        DirContext context = null;
-        try {
-	    if (log.isDebugEnabled())
-		log.debug("initialize() getting entry ...");
-
-	    SearchResult entry = getDirectoryEntry(ldapId);
-	    StringBuffer name = new StringBuffer();
-
-	    if (entry != null) {
-		/* users full name */
-		String usrNameAttr = 
-		    defaultProperties.getProperty(USR_NAME_ATTR_PROP, USR_NAME_ATTR_DEFAULT);
-
-		if (log.isDebugEnabled())
-		    log.debug("initialize() got entry, going to look for attribute " + usrNameAttr + " in entry, which is: " + entry);
-		
-		Attributes attributes = entry.getAttributes();
-		if (attributes != null) {
-		    Attribute userNames = attributes.get(usrNameAttr);
-		    if (userNames != null) {
-			for (NamingEnumeration nenum = userNames.getAll(); nenum.hasMore(); nenum.next()) {
-			    name.append((String)userNames.get());
-			}
-		    }
-		}
-	    }
-	    ldapName = name.toString();
-	    if (log.isDebugEnabled())
-		log.debug("initialize() set name to " + ldapName);
-
-        } catch (IOException e) {
-	    log.warn("LDAPUser.initialize() can not read the user name for the id [" + ldapId + "], this is probably a setup error of your user entry.", e);
-	    ldapName = "";
-        } catch (NamingException e) {
-	    log.warn("LDAPUser.initialize() can not read the user name for the id [" + ldapId + "], this is probably a setup error of your user entry.", e);
-	    ldapName = "";
-        } finally {
-            try {
-                if (context != null) {
-                    close(context);
-                }
-            } catch (NamingException e) {
-		log.warn("LDAPUser.initialize() could not close the connection to the directory server, this should not happen", e);
+   private static final long serialVersionUID = 1L;
+   private static Properties defaultProperties = null;
+   private static Logger log = Logger.getLogger(LDAPUser.class);
+   public static final String LDAP_ID = "ldapid";
+   private static String LDAP_PROPERTIES_FILE = "ldap.properties";
+   private static String PROVIDER_URL_PROP = "provider-url";
+   private static String MGR_DN_PROP = "mgr-dn";
+   private static String MGR_PW_PROP = "mgr-pw";
+   private static String KEY_STORE_PROP = "key-store";
+   private static String SECURITY_PROTOCOL_PROP = "security-protocol";
+   private static String SECURITY_AUTHENTICATION_PROP = "security-authentication";
+   private static String USR_ATTR_PROP = "usr-attr";
+   private static String USR_ATTR_DEFAULT = "uid";
+   private static String USR_NAME_ATTR_PROP = "usr-name-attr";
+   private static String USR_NAME_ATTR_DEFAULT = "gecos";
+   private static String USR_BRANCH_PROP = "usr-branch";
+   private static String USR_BRANCH_DEFAULT = "ou=People";
+   private static String USR_AUTH_TYPE_PROP = "usr-authentication";
+   private static String USR_AUTH_TYPE_DEFAULT = "simple";
+   private static String BASE_DN_PROP = "base-dn";
+   private static String DOMAIN_NAME_PROP = "domain-name";
+   private String ldapId;
+   private String ldapName;
+   // deprecated: for backwards compatibility only !
+   private static String PARTIAL_USER_DN_PROP = "partial-user-dn";
+   /**
+    * Creates a new LDAPUser object.
+    */
+   public LDAPUser() {
+   }
+   /**
+    * Creates a new LDAPUser object.
+    * 
+    * @param configurationDirectory
+    *           The configuration directory.
+    */
+   public LDAPUser(File configurationDirectory) {
+      setConfigurationDirectory(configurationDirectory);
+   }
+   /**
+    * Create an LDAPUser
+    * 
+    * @param configurationDirectory
+    *           where the user will be attached to
+    * @param id
+    *           user id of LDAPUser
+    * @param email
+    *           of LDAPUser
+    * @param ldapId
+    *           of LDAPUser
+    * @throws ConfigurationException
+    *            if the properties could not be read
+    */
+   public LDAPUser(File configurationDirectory, String id, String email, String ldapId) throws ConfigurationException {
+      super(configurationDirectory, id, null, email, null);
+      this.ldapId = ldapId;
+      initialize();
+   }
+   /**
+    * Create a new LDAPUser from a configuration
+    * 
+    * @param config
+    *           the <code>Configuration</code> specifying the user details
+    * @throws ConfigurationException
+    *            if the user could not be instantiated
+    */
+   public void configure(Configuration config) throws ConfigurationException {
+      super.configure(config);
+      ldapId = config.getChild(LDAP_ID).getValue();
+      initialize();
+   }
+   /**
+    * Checks if a user exists.
+    * 
+    * @param ldapId
+    *           The LDAP id.
+    * @return A boolean value indicating whether the user is found in the directory
+    * @throws AccessControlException
+    *            when an unexpected error occurs.
+    */
+   public boolean existsUser(String ldapId) throws AccessControlException {
+      if(log.isDebugEnabled())
+         log.debug("existsUser() checking id " + ldapId);
+      boolean exists = false;
+      try{
+         readProperties();
+         SearchResult entry = getDirectoryEntry(ldapId);
+         exists = (entry != null);
+      }catch(NamingException e){
+         log.info("LDAPUser.existsUser() got exception while looking up id [" + ldapId + "], so will return false", e);
+         exists = false;
+      }catch(Exception e){
+         if(log.isDebugEnabled())
+            log.debug("existsUser() for id [" + ldapId + "] got exception: " + e);
+         throw new AccessControlException("Exception during search: ", e);
+      }
+      return exists;
+   }
+   /**
+    * Initializes this user.
+    * 
+    * The current ldapId is queried in the directory, in order to retrieve additional information, such as the user name. In current implementation, only the user name is actually retrieved, but other attributes may be used in the future (such as groups ?)
+    * 
+    * Note: if the user entry could not be retrieved, initialize the attributes to empty string (they are optional anyway), but do not throw an exception.
+    */
+   protected void initialize() {
+      DirContext context = null;
+      try{
+         if(log.isDebugEnabled())
+            log.debug("initialize() getting entry ...");
+         SearchResult entry = getDirectoryEntry(ldapId);
+         StringBuffer name = new StringBuffer();
+         if(entry != null){
+            /* users full name */
+            String usrNameAttr = defaultProperties.getProperty(USR_NAME_ATTR_PROP, USR_NAME_ATTR_DEFAULT);
+            if(log.isDebugEnabled())
+               log.debug("initialize() got entry, going to look for attribute " + usrNameAttr + " in entry, which is: " + entry);
+            Attributes attributes = entry.getAttributes();
+            if(attributes != null){
+               Attribute userNames = attributes.get(usrNameAttr);
+               if(userNames != null){
+                  for(NamingEnumeration nenum = userNames.getAll(); nenum.hasMore(); nenum.next()){
+                     name.append((String) userNames.get());
+                  }
+               }
             }
-        }
-    }
-
-    /**
-     * @see org.apache.lenya.ac.file.FileUser#createConfiguration()
-     */
-    protected Configuration createConfiguration() {
-        DefaultConfiguration config = (DefaultConfiguration) super.createConfiguration();
-
-        // add ldap_id node
-        DefaultConfiguration child = new DefaultConfiguration(LDAP_ID);
-        child.setValue(ldapId);
-        config.addChild(child);
-
-        return config;
-    }
-
-    /**
-     * Get the ldap id
-     * 
-     * @return the ldap id
-     */
-    public String getLdapId() {
-        return ldapId;
-    }
-
-    /**
-     * Set the ldap id
-     * 
-     * @param string the new ldap id
-     */
-    public void setLdapId(String string) {
-        ldapId = string;
-    }
-
-    /**
-     * Authenticate a user against the directory.
-     *
-     * The principal to be authenticated is either constructed by use of the
-     * configured properties, or by lookup of this ID in the directory. 
-     * This principal then attempts to authenticate against the directory with
-     * the provided password.
-     * 
-     * @see org.apache.lenya.ac.User#authenticate(java.lang.String)
-     */
-    public boolean authenticate(String password) {
-
-	boolean authenticated = false;
-	String principal = "";
-	Context ctx = null;
-
-        try {
-	    principal = getPrincipal();
-	    
-	    if (log.isDebugEnabled())
-		log.debug("Authenticating with principal [" + principal + "]");
-
-            ctx = bind(principal, password,
-		       defaultProperties.getProperty(USR_AUTH_TYPE_PROP, 
-						     USR_AUTH_TYPE_DEFAULT));
-            authenticated = true;
-            close(ctx);
-            if (log.isDebugEnabled()) {
-                log.debug("Context closed.");
+         }
+         ldapName = name.toString();
+         if(log.isDebugEnabled())
+            log.debug("initialize() set name to " + ldapName);
+      }catch(IOException e){
+         log.warn("LDAPUser.initialize() can not read the user name for the id [" + ldapId + "], this is probably a setup error of your user entry.", e);
+         ldapName = "";
+      }catch(NamingException e){
+         log.warn("LDAPUser.initialize() can not read the user name for the id [" + ldapId + "], this is probably a setup error of your user entry.", e);
+         ldapName = "";
+      }finally{
+         try{
+            if(context != null){
+               close(context);
             }
-        } catch (IOException e) {
-	    log.warn("authenticate handling IOException, check your setup: " + e);
-        } catch (AuthenticationException e) {
-	    log.info("authenticate failed for principal " + principal + ", exception " + e);
-        } catch (NamingException e) {
-            // log this failure
-            // StringWriter writer = new StringWriter();
-            // e.printStackTrace(new PrintWriter(writer));
-            if (log.isInfoEnabled()) {
-                log.info("Bind for user " + principal + " to Ldap server failed: ", e);
+         }catch(NamingException e){
+            log.warn("LDAPUser.initialize() could not close the connection to the directory server, this should not happen", e);
+         }
+      }
+   }
+   /**
+    * @see org.apache.lenya.ac.file.FileUser#createConfiguration()
+    */
+   protected Configuration createConfiguration() {
+      DefaultConfiguration config = (DefaultConfiguration) super.createConfiguration();
+      // add ldap_id node
+      DefaultConfiguration child = new DefaultConfiguration(LDAP_ID);
+      child.setValue(ldapId);
+      config.addChild(child);
+      return config;
+   }
+   /**
+    * Get the ldap id
+    * 
+    * @return the ldap id
+    */
+   public String getLdapId() {
+      return ldapId;
+   }
+   /**
+    * Set the ldap id
+    * 
+    * @param string
+    *           the new ldap id
+    */
+   public void setLdapId(String string) {
+      ldapId = string;
+   }
+   /**
+    * Authenticate a user against the directory.
+    * 
+    * The principal to be authenticated is either constructed by use of the configured properties, or by lookup of this ID in the directory. This principal then attempts to authenticate against the directory with the provided password.
+    * 
+    * @see org.apache.lenya.ac.User#authenticate(java.lang.String)
+    */
+   public boolean authenticate(String password) {
+      boolean authenticated = false;
+      String principal = "";
+      Context ctx = null;
+      try{
+         principal = getPrincipal();
+         if(log.isDebugEnabled())
+            log.debug("Authenticating with principal [" + principal + "]");
+         ctx = bind(principal, password, defaultProperties.getProperty(USR_AUTH_TYPE_PROP, USR_AUTH_TYPE_DEFAULT));
+         authenticated = true;
+         close(ctx);
+         if(log.isDebugEnabled()){
+            log.debug("Context closed.");
+         }
+      }catch(IOException e){
+         log.warn("authenticate handling IOException, check your setup: " + e);
+      }catch(AuthenticationException e){
+         log.info("authenticate failed for principal " + principal + ", exception " + e);
+      }catch(NamingException e){
+         // log this failure
+         // StringWriter writer = new StringWriter();
+         // e.printStackTrace(new PrintWriter(writer));
+         if(log.isInfoEnabled()){
+            log.info("Bind for user " + principal + " to Ldap server failed: ", e);
+         }
+      }
+      return authenticated;
+   }
+   /**
+    * @see org.apache.lenya.ac.Item#getName()
+    */
+   public String getName() {
+      return ldapName;
+   }
+   /**
+    * LDAP Users fetch their name information from the LDAP server, so we don't store it locally. Since we only have read access we basically can't set the name, i.e. any request to change the name is ignored.
+    * 
+    * @param string
+    *           is ignored
+    */
+   public void setName(String string) {
+      // we do not have write access to LDAP, so we ignore
+      // change request to the name.
+   }
+   /**
+    * The LDAPUser doesn't store any passwords as they are handled by LDAP
+    * 
+    * @param plainTextPassword
+    *           is ignored
+    */
+   public void setPassword(String plainTextPassword) {
+      setEncryptedPassword(null);
+   }
+   /**
+    * The LDAPUser doesn't store any passwords as they are handled by LDAP
+    * 
+    * @param encryptedPassword
+    *           is ignored
+    */
+   protected void setEncryptedPassword(String encryptedPassword) {
+      encryptedPassword = null;
+   }
+   /**
+    * Connect to the LDAP server
+    * 
+    * @param principal
+    *           the principal string for the LDAP connection
+    * @param credentials
+    *           the credentials for the LDAP connection
+    * @param authMethod
+    *           the authentication method
+    * @return a <code>DirContext</code>
+    * @throws NamingException
+    *            if there are problems establishing the Ldap connection
+    */
+   private DirContext bind(String principal, String credentials, String authMethod) throws NamingException {
+      log.info("Binding principal: [" + principal + "]");
+      Hashtable env = new Hashtable();
+      System.setProperty("javax.net.ssl.trustStore", getConfigurationDirectory().getAbsolutePath() + File.separator + defaultProperties.getProperty(KEY_STORE_PROP));
+      env.put(Context.INITIAL_CONTEXT_FACTORY, LdapCtxFactory.class.getName());
+      String prop = defaultProperties.getProperty(PROVIDER_URL_PROP);
+      if(prop == null)
+         throw new RuntimeException("LDAP configuration error: property " + PROVIDER_URL_PROP + " is not set in property file " + LDAP_PROPERTIES_FILE);
+      env.put(Context.PROVIDER_URL, prop);
+      prop = defaultProperties.getProperty(SECURITY_PROTOCOL_PROP);
+      if(prop == null)
+         throw new RuntimeException("LDAP configuration error: property " + SECURITY_PROTOCOL_PROP + " is not set in property file " + LDAP_PROPERTIES_FILE);
+      env.put(Context.SECURITY_PROTOCOL, prop);
+      env.put(Context.SECURITY_AUTHENTICATION, authMethod);
+      if(authMethod != null && !authMethod.equals("none")){
+         env.put(Context.SECURITY_PRINCIPAL, principal);
+         env.put(Context.SECURITY_CREDENTIALS, credentials);
+      }
+      DirContext ctx = new InitialLdapContext(env, null);
+      log.info("Finished binding principal.");
+      return ctx;
+   }
+   /**
+    * Close the connection to the LDAP server
+    * 
+    * @param ctx
+    *           the context that was returned from the bind
+    * @throws NamingException
+    *            if there is a problem communicating to the LDAP server
+    */
+   private void close(Context ctx) throws NamingException {
+      ctx.close();
+   }
+   /**
+    * Read the properties
+    * 
+    * @throws IOException
+    *            if the properties cannot be found.
+    */
+   private void readProperties() throws IOException {
+      // create and load default properties
+      File propertiesFile = new File(getConfigurationDirectory(), LDAP_PROPERTIES_FILE);
+      if(defaultProperties == null){
+         defaultProperties = new Properties();
+         FileInputStream in = null;
+         try{
+            in = new FileInputStream(propertiesFile);
+            defaultProperties.load(in);
+         }finally{
+            if(in != null){
+               in.close();
             }
-        }
-
-        return authenticated;
-
-    }
-
-    /**
-     * @see org.apache.lenya.ac.Item#getName()
-     */
-    public String getName() {
-        return ldapName;
-    }
-
-    /**
-     * LDAP Users fetch their name information from the LDAP server, so we don't store it locally.
-     * Since we only have read access we basically can't set the name, i.e. any request to change
-     * the name is ignored.
-     * 
-     * @param string is ignored
-     */
-    public void setName(String string) {
-        // we do not have write access to LDAP, so we ignore
-        // change request to the name.
-    }
-
-    /**
-     * The LDAPUser doesn't store any passwords as they are handled by LDAP
-     * 
-     * @param plainTextPassword is ignored
-     */
-    public void setPassword(String plainTextPassword) {
-        setEncryptedPassword(null);
-    }
-
-    /**
-     * The LDAPUser doesn't store any passwords as they are handled by LDAP
-     * 
-     * @param encryptedPassword is ignored
-     */
-    protected void setEncryptedPassword(String encryptedPassword) {
-        encryptedPassword = null;
-    }
-
-    /**
-     * Connect to the LDAP server
-     * 
-     * @param principal the principal string for the LDAP connection
-     * @param credentials the credentials for the LDAP connection
-     * @param authMethod the authentication method
-     * @return a <code>DirContext</code>
-     * @throws NamingException if there are problems establishing the Ldap connection
-     */
-    private DirContext bind(String principal, String credentials,
-			    String authMethod) throws NamingException {
-
-        log.info("Binding principal: [" + principal + "]");
-
-        Hashtable env = new Hashtable();
-
-        System.setProperty("javax.net.ssl.trustStore", getConfigurationDirectory()
-                .getAbsolutePath()
-                + File.separator + defaultProperties.getProperty(KEY_STORE_PROP));
-
-        env.put(Context.INITIAL_CONTEXT_FACTORY, LdapCtxFactory.class.getName());
-
-        String prop = defaultProperties.getProperty(PROVIDER_URL_PROP);
-        if (prop == null)
-            throw new RuntimeException("LDAP configuration error: property " +
-                                       PROVIDER_URL_PROP + 
-                                       " is not set in property file " + 
-                                       LDAP_PROPERTIES_FILE);
-        env.put(Context.PROVIDER_URL, prop);
-
-        prop = defaultProperties.getProperty(SECURITY_PROTOCOL_PROP);
-        if (prop == null)
-            throw new RuntimeException("LDAP configuration error: property " +
-                                       SECURITY_PROTOCOL_PROP + 
-                                       " is not set in property file " + 
-                                       LDAP_PROPERTIES_FILE);
-        env.put(Context.SECURITY_PROTOCOL, prop);
-
-        env.put(Context.SECURITY_AUTHENTICATION, authMethod);
-	if (authMethod != null && ! authMethod.equals("none")) {
-	    env.put(Context.SECURITY_PRINCIPAL, principal);
-	    env.put(Context.SECURITY_CREDENTIALS, credentials);
-	}
-
-        DirContext ctx = new InitialLdapContext(env, null);
-
-        log.info("Finished binding principal.");
-
-        return ctx;
-    }
-
-    /**
-     * Close the connection to the LDAP server
-     * 
-     * @param ctx the context that was returned from the bind
-     * @throws NamingException if there is a problem communicating to the LDAP server
-     */
-    private void close(Context ctx) throws NamingException {
-        ctx.close();
-    }
-
-    /**
-     * Read the properties
-     * 
-     * @throws IOException if the properties cannot be found.
-     */
-    private void readProperties() throws IOException {
-        // create and load default properties
-        File propertiesFile = new File(getConfigurationDirectory(), LDAP_PROPERTIES_FILE);
-
-        if (defaultProperties == null) {
-            defaultProperties = new Properties();
-
-            FileInputStream in = null;
-            try {
-                in = new FileInputStream(propertiesFile);
-                defaultProperties.load(in);
-            } finally {
-                if (in != null) {
-                    in.close();
-                }
+         }
+      }
+   }
+   /**
+    * Wrapping of the decision whether a recursive search is wanted or not. Implementation: If the USR_BRANCH_PROP is present, this is the new style of configuration (starting Lenya 1.2.2); if it has a value, then a specific branch is wanted: no recursive search. If the property is present, but has no value, search recursively.
+    */
+   private boolean isSubtreeSearch() {
+      boolean recurse = false;
+      String usrBranchProp = defaultProperties.getProperty(USR_BRANCH_PROP);
+      if(usrBranchProp != null)
+         if(usrBranchProp.trim().length() == 0)
+            recurse = true;
+      return recurse;
+   }
+   private SearchResult getDirectoryEntry(String userId) throws NamingException, IOException {
+      DirContext context = null;
+      String searchFilter = "";
+      String objectName = "";
+      boolean recursiveSearch;
+      SearchResult result = null;
+      try{
+         readProperties();
+         context = bind(defaultProperties.getProperty(MGR_DN_PROP), defaultProperties.getProperty(MGR_PW_PROP), defaultProperties.getProperty(SECURITY_AUTHENTICATION_PROP));
+         // Get search information and user attribute from properties
+         // provide defaults if not present (backward compatibility)
+         String userAttribute = defaultProperties.getProperty(USR_ATTR_PROP, USR_ATTR_DEFAULT);
+         searchFilter = "(" + userAttribute + "=" + userId + ")";
+         SearchControls scope = new SearchControls();
+         NamingEnumeration results;
+         recursiveSearch = isSubtreeSearch();
+         if(recursiveSearch){
+            scope.setSearchScope(SearchControls.SUBTREE_SCOPE);
+            objectName = defaultProperties.getProperty(PROVIDER_URL_PROP);
+         }else{
+            scope.setSearchScope(SearchControls.ONELEVEL_SCOPE);
+            objectName = defaultProperties.getProperty(USR_BRANCH_PROP, USR_BRANCH_DEFAULT);
+         }
+         if(log.isDebugEnabled())
+            log.debug("searching object " + objectName + " filtering with " + searchFilter + ", recursive search ? " + recursiveSearch);
+         results = context.search(objectName, searchFilter, scope);
+         if(results != null && results.hasMore()){
+            result = (SearchResult) results.next();
+            // sanity check: if more than one entry is returned
+            // for a user-id, then the directory is probably flawed,
+            // so it would be nice to warn the administrator.
+            //
+            // This block is commented out for now, because of possible
+            // side-effects, such as unexpected exceptions.
+            // try {
+            // if (results.hasMore()) {
+            // log.warn("Found more than one entry in the directory for user " + userId + ". You probably should deactivate recursive searches. The first entry was used as a work-around.");
+            // }
+            // }
+            // catch (javax.naming.PartialResultException e) {
+            // if (log.isDebugEnabled())
+            // log.debug("Catching and ignoring PartialResultException, as this means LDAP server does not support our sanity check");
+            // }
+         }
+      }catch(NamingException e){
+         if(log.isDebugEnabled())
+            log.debug("NamingException caught when searching on objectName = " + objectName + " and searchFilter=" + searchFilter + ", this exception will be propagated: " + e);
+         throw e;
+      }finally{
+         try{
+            if(context != null){
+               close(context);
             }
-        }
-    }
-
-    /** 
-     * Wrapping of the decision whether a recursive search is wanted or not.
-     * Implementation: 
-     * If the USR_BRANCH_PROP is present, this is the new style of configuration
-     * (starting Lenya 1.2.2); if it has a value, then a specific branch is wanted:
-     * no recursive search. If the property is present, but has no value,
-     * search recursively.
-     */
-    private boolean isSubtreeSearch() {
-	boolean recurse = false;
-	String usrBranchProp = defaultProperties.getProperty(USR_BRANCH_PROP);
-	if (usrBranchProp != null)
-	    if (usrBranchProp.trim().length() == 0)
-		recurse = true;
-	
-	return recurse;
-    }
-
-
-    private SearchResult getDirectoryEntry(String userId) 
-	throws NamingException, IOException
-    {
-	DirContext context = null;
-	String searchFilter = "";
-	String objectName = "";
-	boolean recursiveSearch;
-	SearchResult result = null;
-	
-	try {
-            readProperties();
-	    
-            context = bind(defaultProperties.getProperty(MGR_DN_PROP), 
-			   defaultProperties.getProperty(MGR_PW_PROP),
-			   defaultProperties.getProperty(SECURITY_AUTHENTICATION_PROP));
-
-	    // Get search information and user attribute from properties
-	    // provide defaults if not present (backward compatibility)
-	    String userAttribute = 
-		defaultProperties.getProperty(USR_ATTR_PROP, USR_ATTR_DEFAULT);
-	    searchFilter = "(" + userAttribute + "=" + userId + ")";
-	    SearchControls scope = new SearchControls();
-	    NamingEnumeration results;
-
-	    recursiveSearch = isSubtreeSearch();
-	    if (recursiveSearch) {
-		scope.setSearchScope(SearchControls.SUBTREE_SCOPE);
-		objectName = defaultProperties.getProperty(PROVIDER_URL_PROP);
-	    }
-	    else {
-		scope.setSearchScope(SearchControls.ONELEVEL_SCOPE);
-		objectName =  
-		    defaultProperties.getProperty(USR_BRANCH_PROP, USR_BRANCH_DEFAULT);
-	    }
-	
-	    if (log.isDebugEnabled())
-		log.debug("searching object " + objectName + " filtering with " + searchFilter + ", recursive search ? " + recursiveSearch);
-
-	    results = context.search(objectName, searchFilter, scope);
-
-	    if (results != null && results.hasMore()) {
-		result = (SearchResult)results.next();
-
-		// sanity check: if more than one entry is returned
-		// for a user-id, then the directory is probably flawed,
-		// so it would be nice to warn the administrator.
-		//
-		// This block is commented out for now, because of possible
-		// side-effects, such as unexpected exceptions.
-// 		try {
-// 		    if (results.hasMore()) {
-// 			log.warn("Found more than one entry in the directory for user " + userId + ". You probably should deactivate recursive searches. The first entry was used as a work-around.");
-// 		    }
-// 		}
-// 		catch (javax.naming.PartialResultException e) {
-// 		    if (log.isDebugEnabled())
-// 			log.debug("Catching and ignoring PartialResultException, as this means LDAP server does not support our sanity check");
-// 		}
-		
-	    }
-	}
-        catch (NamingException e) {
-	    if (log.isDebugEnabled())
-		log.debug("NamingException caught when searching on objectName = " + objectName + " and searchFilter=" + searchFilter + ", this exception will be propagated: " + e);
-            throw e;
-        } 
-	finally {
-            try {
-                if (context != null) {
-                    close(context);
-                }
-            } catch (NamingException e) {
-		log.warn("this should not happen: exception closing context " + e);
+         }catch(NamingException e){
+            log.warn("this should not happen: exception closing context " + e);
+         }
+      }
+      return result;
+   }
+   /**
+    * Encapsulation of the creation of a principal: we need to distinguish three cases, in order to support different modes of using a directory. The first is the use of a domain-name (requirement of MS Active Directory): if this property is set, this is used to construct the principal. The second case is where a user-id is somewhere in a domain, but not in a specific branch: in this case, a subtree search is performed to retrieve the complete path. The third case is where a specific branch of the directory is to be used; this is the case where usr-branch is set to a value. In this case, this branch is used to construct the principal.
+    */
+   private String getPrincipal() throws IOException, NamingException {
+      String principal;
+      // 1. Check if domain-name is to be supported
+      String domainProp = defaultProperties.getProperty(DOMAIN_NAME_PROP);
+      if(domainProp != null && domainProp.trim().length() > 0){
+         principal = domainProp + "\\" + getLdapId();
+      }else{
+         if(isSubtreeSearch()){
+            // 2. Principal is constructed from directory entry
+            if(log.isDebugEnabled())
+               log.debug("getPrincipal() getting entry ...");
+            SearchResult entry = getDirectoryEntry(getLdapId());
+            principal = entry.getName();
+            if(entry.isRelative()){
+               if(principal.length() > 0){
+                  principal = principal + "," + defaultProperties.getProperty(BASE_DN_PROP);
+               }
             }
-        }
-	return result;
-    }
-
-    /**
-     * Encapsulation of the creation of a principal: we need to distinguish
-     * three cases, in order to support different modes of using a directory.
-     * The first is the use of a domain-name (requirement of MS Active Directory):
-     * if this property is set, this is used to construct the principal.
-     * The second case is where a user-id is somewhere in a domain, but not in a
-     * specific branch: in this case, a subtree search is performed to retrieve
-     * the complete path.
-     * The third case is where a specific branch of the directory is to be used;
-     * this is the case where usr-branch is set to a value. In this case, this branch
-     * is used to construct the principal.
-     */
-    private String getPrincipal() throws IOException, NamingException {
-
-	String principal;
-
-	// 1. Check if domain-name is to be supported
-	String domainProp = defaultProperties.getProperty(DOMAIN_NAME_PROP);
-	if (domainProp != null && domainProp.trim().length() > 0) {
-	    principal = domainProp + "\\" + getLdapId();
-	}
-	else {
-	    if (isSubtreeSearch()) {
-		// 2. Principal is constructed from directory entry
-		if (log.isDebugEnabled())
-		    log.debug("getPrincipal() getting entry ...");
-
-		SearchResult entry = getDirectoryEntry(getLdapId());
-		principal = entry.getName();
-		if (entry.isRelative()) {
-		    if (principal.length()>0){
-			principal = principal +","+ defaultProperties.getProperty(BASE_DN_PROP);
-		    }
-		}
-	    }
-	    else {
-		// 3. Principal is constructed from properties
-		principal = constructPrincipal(getLdapId());
-	    }
-	}
-
-	return principal;
-    }
-
-    /**
-     * Construct the principal for a user, by using the given userId along
-     * with the configured properties.
-     *
-     */
-    private String constructPrincipal(String userId) {
-	if (log.isDebugEnabled())
-	    log.debug("constructPrincipal() called with userId [" + userId + "]");
-	StringBuffer principal = new StringBuffer();
-	principal
-	    .append(defaultProperties.getProperty(USR_ATTR_PROP, USR_ATTR_DEFAULT))
-	    .append("=")
-	    .append(userId)
-	    .append(",");
-
-	String baseDn = defaultProperties.getProperty(BASE_DN_PROP);
-	if (baseDn != null && baseDn.length() > 0) {
-	    // USR_BRANCH_PROP may be empty, so only append when not-empty
-	    String usrBranch = defaultProperties.getProperty(USR_BRANCH_PROP);
-	    if (usrBranch != null) {
-		if (usrBranch.trim().length() > 0)
-		    principal.append(usrBranch).append(",");
-	    }
-	    else
-		principal.append(USR_BRANCH_DEFAULT).append(",");
-		
-	    principal.append(defaultProperties.getProperty(BASE_DN_PROP));
-	}
-	else {
-	    // try for backwards compatibility of ldap properties
-	    log.warn("constructPrincipal() read a deprecated format in ldap properties, please update");
-	    principal.append(defaultProperties.getProperty(PARTIAL_USER_DN_PROP));
-	}
-
-	if (log.isDebugEnabled())
-	    log.debug("constructPrincipal() returning " + principal.toString());
-
-	return principal.toString();
-    }
-
-
+         }else{
+            // 3. Principal is constructed from properties
+            principal = constructPrincipal(getLdapId());
+         }
+      }
+      return principal;
+   }
+   /**
+    * Construct the principal for a user, by using the given userId along with the configured properties.
+    * 
+    */
+   private String constructPrincipal(String userId) {
+      if(log.isDebugEnabled())
+         log.debug("constructPrincipal() called with userId [" + userId + "]");
+      StringBuffer principal = new StringBuffer();
+      principal.append(defaultProperties.getProperty(USR_ATTR_PROP, USR_ATTR_DEFAULT)).append("=").append(userId).append(",");
+      String baseDn = defaultProperties.getProperty(BASE_DN_PROP);
+      if(baseDn != null && baseDn.length() > 0){
+         // USR_BRANCH_PROP may be empty, so only append when not-empty
+         String usrBranch = defaultProperties.getProperty(USR_BRANCH_PROP);
+         if(usrBranch != null){
+            if(usrBranch.trim().length() > 0)
+               principal.append(usrBranch).append(",");
+         }else
+            principal.append(USR_BRANCH_DEFAULT).append(",");
+         principal.append(defaultProperties.getProperty(BASE_DN_PROP));
+      }else{
+         // try for backwards compatibility of ldap properties
+         log.warn("constructPrincipal() read a deprecated format in ldap properties, please update");
+         principal.append(defaultProperties.getProperty(PARTIAL_USER_DN_PROP));
+      }
+      if(log.isDebugEnabled())
+         log.debug("constructPrincipal() returning " + principal.toString());
+      return principal.toString();
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/DeleteNodeTask.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/DeleteNodeTask.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/DeleteNodeTask.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/DeleteNodeTask.java Wed Jan 30 23:44:03 2008
@@ -14,96 +14,90 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.cms.ant;
-
 import org.apache.lenya.cms.publication.SiteTree;
 import org.apache.lenya.cms.publication.SiteTreeException;
-import org.apache.lenya.cms.publication.SiteTreeNode;
 import org.apache.tools.ant.BuildException;
-
-
 /**
  * Ant task to delete a node of a tree.
  */
 public class DeleteNodeTask extends PublicationTask {
-    private String area;
-    private String documentid;
-
-    /**
-     * Creates a new instance of DeleteNodeTask
-     */
-    public DeleteNodeTask() {
-        super();
-    }
-
-    /**
-     * Get the area.
-     * 
-     * @return the area.
-     */
-    public String getArea() {
-        return area;
-    }
-
-    /**
-     * Set the area.
-     * 
-     * @param area the area
-     */
-    public void setArea(String area) {
-        this.area = area;
-    }
-
-    /**
-     * return the document-id corresponding to the node to delete
-     * @return string The document-id.
-     */
-    protected String getDocumentid() {
-        return documentid;
-    }
-
-    /**
-     * Set the value of the document-id corresponding to the node to delete
-     * 
-     * @param string The document-id.
-     */
-    public void setDocumentid(String string) {
-        documentid = string;
-    }
-
-    /**
-     * Delete a node of a tree.
-     * 
-     * @param documentid The id of the document corresponding to the node to delete.
-     * @param area the areaof the tree
-     * 
-     * @throws SiteTreeException if an error occurs
-     */
-    public void deleteNode(String documentid, String area)
-        throws SiteTreeException {
-		SiteTree tree = null;
-
-	  	try {
-			tree = getPublication().getTree(area);
-			tree.deleteNode(documentid);
-			tree.save();
-		} catch (Exception e) {
-			throw new SiteTreeException(e);
-		}
-    }   
-    /** (non-Javadoc)
-     * @see org.apache.tools.ant.Task#execute()
-     */
-    public void execute() throws BuildException {
-        try {
-            log("document-id corresponding to the node: " + getDocumentid());
-            log("area: " + getArea());
-			deleteNode(getDocumentid(), getArea());
-        } catch (Exception e) {
-            throw new BuildException(e);
-        }
-    }
+   private String area;
+   private String documentid;
+   /**
+    * Creates a new instance of DeleteNodeTask
+    */
+   public DeleteNodeTask() {
+      super();
+   }
+   /**
+    * Get the area.
+    * 
+    * @return the area.
+    */
+   public String getArea() {
+      return area;
+   }
+   /**
+    * Set the area.
+    * 
+    * @param area
+    *           the area
+    */
+   public void setArea(String area) {
+      this.area = area;
+   }
+   /**
+    * return the document-id corresponding to the node to delete
+    * 
+    * @return string The document-id.
+    */
+   protected String getDocumentid() {
+      return documentid;
+   }
+   /**
+    * Set the value of the document-id corresponding to the node to delete
+    * 
+    * @param string
+    *           The document-id.
+    */
+   public void setDocumentid(String string) {
+      documentid = string;
+   }
+   /**
+    * Delete a node of a tree.
+    * 
+    * @param documentid
+    *           The id of the document corresponding to the node to delete.
+    * @param area
+    *           the areaof the tree
+    * 
+    * @throws SiteTreeException
+    *            if an error occurs
+    */
+   public void deleteNode(String documentid, String area) throws SiteTreeException {
+      SiteTree tree = null;
+      try{
+         tree = getPublication().getTree(area);
+         tree.deleteNode(documentid);
+         tree.save();
+      }catch(Exception e){
+         throw new SiteTreeException(e);
+      }
+   }
+   /**
+    * (non-Javadoc)
+    * 
+    * @see org.apache.tools.ant.Task#execute()
+    */
+   public void execute() throws BuildException {
+      try{
+         log("document-id corresponding to the node: " + getDocumentid());
+         log("area: " + getArea());
+         deleteNode(getDocumentid(), getArea());
+      }catch(Exception e){
+         throw new BuildException(e);
+      }
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/DownloadFeeds.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/DownloadFeeds.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/DownloadFeeds.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/ant/DownloadFeeds.java Wed Jan 30 23:44:03 2008
@@ -14,185 +14,160 @@
  *  limitations under the License.
  *
  */
-
 package org.apache.lenya.cms.ant;
-
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.HttpURLConnection;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.util.NoSuchElementException;
 import java.util.StringTokenizer;
-
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
-
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Task;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
-
 /**
  * Download (via HTTP) feed (RSS, Atom, ...) and verify well-formedness of XML
  */
 public class DownloadFeeds extends Task {
-    private boolean verbose = false;
-    private boolean ignoreErrors = false;
-    
-    String rootDir;
-    String feeds;
-
-    /**
-     * Get feeds from build.xml
-     */
-    public void setFeeds(String str) {
-        feeds = str;
-    }
-
-    /**
-     * Get root directory from build.xml
-     */
-    public void setRootdir(String str) {
-        rootDir = str;
-    }
-    
-    /**
-     *
-     */
-    public void execute() {
-        if (rootDir == null) {
-            throw new BuildException("No rootdir specified");
-        } else {
-            log("Root directory: " + rootDir);
-        }
-
-        if (feeds == null) {
-            throw new BuildException("No feeds specified");
-        }
-        
-        StringTokenizer tok = new StringTokenizer(feeds, ",");
-        
-        if (tok.countTokens() == 0) {
-            throw new BuildException("Illegal feeds string");
-        }
-        
-        try {        
-            String url;
-            
-            while ((url = tok.nextToken()) != null) {
-                String fname = tok.nextToken();
-                
-                URL source = null;
-                try {
-                    source = new URL(url);
-                    log("Feed: " + url);
-                } catch (MalformedURLException e) {
-                    log("bad url");
-                    throw new BuildException(e, getLocation());
-                }
-                
-                File dest = null;
-                try {    
-                    //log("file: " + fname);
-                    dest = new File(fname);
-                    if (!dest.isAbsolute()) {
-                        //log("Is NOT absolute: " + dest);
-                        dest = new File(rootDir, fname);
-                    }
-                    log("Destination: " + dest);
-                } catch (NullPointerException e) {
-                    log(e.toString());
-                }
-
-                try {    
-                    URLConnection connection = source.openConnection();
-                    
-                    connection.connect();
-                    HttpURLConnection httpConnection = (HttpURLConnection) connection;
-                    
-                    InputStream is = null;
-                    for (int i = 0; i < 3; i++) {
-                        try {
-                            is = connection.getInputStream();
-                            break;
-                        } catch (IOException ex) {
-                            log("Error opening connection " + ex);
-                        }
-                    }
-                    if (is == null) {
-                        log("Can't get " + source + " to " + dest);
-                        if (ignoreErrors) {
-                            return;
-                        }
-                        throw new BuildException("Can't get " + source + " to " + dest,
-                                                 getLocation());
-                    }
-
-                    FileOutputStream fos = new FileOutputStream(dest);
-                    boolean finished = false;
-                    try {
-                        byte[] buffer = new byte[100 * 1024];
-                        int length;
-                        int dots = 0;
-
-                        while ((length = is.read(buffer)) >= 0) {
-                            fos.write(buffer, 0, length);
-                            if (verbose) {
-                                System.out.print(".");
-                                if (dots++ > 50) {
-                                    System.out.flush();
-                                    dots = 0;
-                                }
-                            }
-                        }
-                        if (verbose) {
-                            System.out.println();
-                        }
-                        finished = true;
-                    } finally {
-                        if (fos != null) {
-                            fos.close();
-                        }
-                        is.close();
-                        // we have started to (over)write dest, but failed.
-                        // Try to delete the garbage we'd otherwise leave
-                        // behind.
-                        if (!finished) {
-                            dest.delete();
-                        }
-                    }                        
-                } catch (IOException e) {
-                    log("IOException: " + e.toString());
-                    throw new BuildException(e, getLocation());
-                }
-                
-                SAXParserFactory factory = SAXParserFactory.newInstance();
-                try {
-                    SAXParser saxParser = factory.newSAXParser();
-                    saxParser.parse( dest, new DefaultHandler() );
-                } catch (IOException e) {
-                    e.toString();
-                    throw new BuildException(e, getLocation());
-                } catch (ParserConfigurationException e) {
-                    e.toString();
-                    throw new BuildException(e, getLocation());                
-                } catch (IllegalArgumentException e) {
-                    e.toString();
-                    throw new BuildException(e, getLocation());
-                } catch (SAXException e) {
-                    log("XML: " + dest + " is NOT well-formed!!!");
-                    throw new BuildException(e, getLocation());
-                }
-
-                log("XML file: " + dest + " seems to be well-formed :-)");
+   private boolean verbose = false;
+   private boolean ignoreErrors = false;
+   String rootDir;
+   String feeds;
+   /**
+    * Get feeds from build.xml
+    */
+   public void setFeeds(String str) {
+      feeds = str;
+   }
+   /**
+    * Get root directory from build.xml
+    */
+   public void setRootdir(String str) {
+      rootDir = str;
+   }
+   /**
+    * 
+    */
+   public void execute() {
+      if(rootDir == null){
+         throw new BuildException("No rootdir specified");
+      }else{
+         log("Root directory: " + rootDir);
+      }
+      if(feeds == null){
+         throw new BuildException("No feeds specified");
+      }
+      StringTokenizer tok = new StringTokenizer(feeds, ",");
+      if(tok.countTokens() == 0){
+         throw new BuildException("Illegal feeds string");
+      }
+      try{
+         String url;
+         while((url = tok.nextToken()) != null){
+            String fname = tok.nextToken();
+            URL source = null;
+            try{
+               source = new URL(url);
+               log("Feed: " + url);
+            }catch(MalformedURLException e){
+               log("bad url");
+               throw new BuildException(e, getLocation());
+            }
+            File dest = null;
+            try{
+               // log("file: " + fname);
+               dest = new File(fname);
+               if(!dest.isAbsolute()){
+                  // log("Is NOT absolute: " + dest);
+                  dest = new File(rootDir, fname);
+               }
+               log("Destination: " + dest);
+            }catch(NullPointerException e){
+               log(e.toString());
+            }
+            try{
+               URLConnection connection = source.openConnection();
+               connection.connect();
+               // HttpURLConnection httpConnection = (HttpURLConnection) connection;
+               InputStream is = null;
+               for(int i = 0; i < 3; i++){
+                  try{
+                     is = connection.getInputStream();
+                     break;
+                  }catch(IOException ex){
+                     log("Error opening connection " + ex);
+                  }
+               }
+               if(is == null){
+                  log("Can't get " + source + " to " + dest);
+                  if(ignoreErrors){
+                     return;
+                  }
+                  throw new BuildException("Can't get " + source + " to " + dest, getLocation());
+               }
+               FileOutputStream fos = new FileOutputStream(dest);
+               boolean finished = false;
+               try{
+                  byte[] buffer = new byte[100 * 1024];
+                  int length;
+                  int dots = 0;
+                  while((length = is.read(buffer)) >= 0){
+                     fos.write(buffer, 0, length);
+                     if(verbose){
+                        System.out.print(".");
+                        if(dots++ > 50){
+                           System.out.flush();
+                           dots = 0;
+                        }
+                     }
+                  }
+                  if(verbose){
+                     System.out.println();
+                  }
+                  finished = true;
+               }finally{
+                  if(fos != null){
+                     fos.close();
+                  }
+                  is.close();
+                  // we have started to (over)write dest, but failed.
+                  // Try to delete the garbage we'd otherwise leave
+                  // behind.
+                  if(!finished){
+                     dest.delete();
+                  }
+               }
+            }catch(IOException e){
+               log("IOException: " + e.toString());
+               throw new BuildException(e, getLocation());
+            }
+            SAXParserFactory factory = SAXParserFactory.newInstance();
+            try{
+               SAXParser saxParser = factory.newSAXParser();
+               saxParser.parse(dest, new DefaultHandler());
+            }catch(IOException e){
+               e.toString();
+               throw new BuildException(e, getLocation());
+            }catch(ParserConfigurationException e){
+               e.toString();
+               throw new BuildException(e, getLocation());
+            }catch(IllegalArgumentException e){
+               e.toString();
+               throw new BuildException(e, getLocation());
+            }catch(SAXException e){
+               log("XML: " + dest + " is NOT well-formed!!!");
+               throw new BuildException(e, getLocation());
             }
-        } catch (NoSuchElementException e) {
-            return;    
-        }                
-    }
+            log("XML file: " + dest + " seems to be well-formed :-)");
+         }
+      }catch(NoSuchElementException e){
+         return;
+      }
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/CreatorException.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/CreatorException.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/CreatorException.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/CreatorException.java Wed Jan 30 23:44:03 2008
@@ -14,44 +14,40 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.cms.authoring;
-
 public class CreatorException extends Exception {
-    /**
-     *
-     */
-    public CreatorException() {
-        super();
-    }
-
-    /**
-     * Create an instance of <code>CreatorException</code>
-     * 
-     * @param message the exception message
-     */
-    public CreatorException(String message) {
-        super(message);
-    }
-
-    /**
-     * Create an instance of <code>CreatorException</code>
-     * 
-     * @param cause the cause of the exception
-     */
-    public CreatorException(Throwable cause) {
-        super(cause);
-    }
-
-    /**
-     * Create an instance of <code>CreatorException</code>
-     * 
-     * @param message the exception message
-     * @param cause the cause of the exception
-     */
-    public CreatorException(String message, Throwable cause) {
-        super(message, cause);
-    }
+   private static final long serialVersionUID = 1L;
+   public CreatorException() {
+      super();
+   }
+   /**
+    * Create an instance of <code>CreatorException</code>
+    * 
+    * @param message
+    *           the exception message
+    */
+   public CreatorException(String message) {
+      super(message);
+   }
+   /**
+    * Create an instance of <code>CreatorException</code>
+    * 
+    * @param cause
+    *           the cause of the exception
+    */
+   public CreatorException(Throwable cause) {
+      super(cause);
+   }
+   /**
+    * Create an instance of <code>CreatorException</code>
+    * 
+    * @param message
+    *           the exception message
+    * @param cause
+    *           the cause of the exception
+    */
+   public CreatorException(String message, Throwable cause) {
+      super(message, cause);
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DefaultBranchCreator.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DefaultBranchCreator.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DefaultBranchCreator.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DefaultBranchCreator.java Wed Jan 30 23:44:03 2008
@@ -14,59 +14,40 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.cms.authoring;
-
-import org.apache.log4j.Category;
-
-import org.apache.lenya.cms.publication.Publication;
-
 import java.io.File;
-
+import org.apache.lenya.cms.publication.Publication;
 public class DefaultBranchCreator extends DefaultCreator {
-    private Category log = Category.getInstance(DefaultBranchCreator.class);
-
-    /**
-     * Return the child type.
-     *
-     * @param childType a <code>short</code> value
-     *
-     * @return a <code>short</code> value
-     *
-     * @exception Exception if an error occurs
-     */
-    public short getChildType(short childType) throws Exception {
-        return BRANCH_NODE;
-    }
-
-    /** (non-Javadoc)
-     * @depracted because it does not the DocumentIdToPathMapper
-     * @see org.apache.lenya.cms.authoring.DefaultCreator#getChildFileName(java.io.File, java.lang.String)
-     */
-    protected String getChildFileName(
-        Publication publication,
-        String area,
-        String parentId,
-        String childId,
-        String language) {
-	return publication.getPathMapper().getFile(publication, area, parentId + "/" + childId, language).getAbsolutePath();
-    }
-
-    /** (non-Javadoc)
-     * @see org.apache.lenya.cms.authoring.DefaultCreator#getChildMetaFileName(java.io.File, java.lang.String)
-     */
-    protected String getChildMetaFileName(
-        File parentDir,
-        String childId,
-        String language) {
-        return parentDir
-            + File.separator
-            + childId
-            + File.separator
-            + "indexmeta"
-            + getLanguageSuffix(language)
-            + ".xml";
-    }
+   /**
+    * Return the child type.
+    * 
+    * @param childType
+    *           a <code>short</code> value
+    * 
+    * @return a <code>short</code> value
+    * 
+    * @exception Exception
+    *               if an error occurs
+    */
+   public short getChildType(short childType) throws Exception {
+      return BRANCH_NODE;
+   }
+   /**
+    * (non-Javadoc)
+    * 
+    * @depracted because it does not the DocumentIdToPathMapper
+    * @see org.apache.lenya.cms.authoring.DefaultCreator#getChildFileName(java.io.File, java.lang.String)
+    */
+   protected String getChildFileName(Publication publication, String area, String parentId, String childId, String language) {
+      return publication.getPathMapper().getFile(publication, area, parentId + "/" + childId, language).getAbsolutePath();
+   }
+   /**
+    * (non-Javadoc)
+    * 
+    * @see org.apache.lenya.cms.authoring.DefaultCreator#getChildMetaFileName(java.io.File, java.lang.String)
+    */
+   protected String getChildMetaFileName(File parentDir, String childId, String language) {
+      return parentDir + File.separator + childId + File.separator + "indexmeta" + getLanguageSuffix(language) + ".xml";
+   }
 }

Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DefaultCreator.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DefaultCreator.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DefaultCreator.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/authoring/DefaultCreator.java Wed Jan 30 23:44:03 2008
@@ -14,304 +14,267 @@
  *  limitations under the License.
  *
  */
-
 /* $Id$  */
-
 package org.apache.lenya.cms.authoring;
-
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.util.Map;
-
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.lenya.cms.publication.Publication;
 import org.apache.lenya.xml.DocumentHelper;
-import org.apache.log4j.Category;
+import org.apache.log4j.Logger;
 import org.w3c.dom.Document;
-
 public abstract class DefaultCreator implements ParentChildCreatorInterface {
-    private static Category log = Category.getInstance(DefaultCreator.class);
-    public static final String RESOURCE_NAME = "resource-name";
-    public static final String RESOURCE_META_NAME = "resource-meta-name";
-    public static final String SAMPLE_NAME = "sample-name";
-    public static final String SAMPLE_META_NAME = "sample-meta-name";
-
-    private String resourceName = null;
-    private String resourceMetaName = null;
-    private String sampleResourceName = null;
-    private String sampleMetaName = null;
-
-    /**
-     * @see org.apache.lenya.cms.authoring.ParentChildCreatorInterface#init(Configuration)
-     *
-     * @param conf DOCUMENT ME!
-     */
-    public void init(Configuration conf) {
-        if (conf == null) {
-            return;
-        }
-
-        if (conf.getChild(RESOURCE_NAME, false) != null) {
-            resourceName = conf.getChild(RESOURCE_NAME).getValue("index.xml");
-        }
-
-        if (conf.getChild(RESOURCE_META_NAME, false) != null) {
-            resourceMetaName =
-                conf.getChild(RESOURCE_META_NAME).getValue("index-meta.xml");
-        }
-
-        if (conf.getChild(SAMPLE_NAME, false) != null) {
-            sampleResourceName =
-                conf.getChild(SAMPLE_NAME).getValue("sampleindex.xml");
-        }
-
-        if (conf.getChild(SAMPLE_META_NAME, false) != null) {
-            sampleMetaName =
-                conf.getChild(SAMPLE_META_NAME).getValue("samplemeta.xml");
-        }
-    }
-
-    /**
-     * Generate a tree id by returning the child ID.
-     *
-     * @param childId a <code>String</code> value
-     * @param childType a <code>short</code> value
-     *
-     * @return a <code>String</code> value
-     *
-     * @exception Exception if an error occurs
-     */
-    public String generateTreeId(String childId, short childType)
-        throws Exception {
-        return childId;
-    }
-
-    /**
-     * Return the child type by simply returning the child type.
-     *
-     * @param childType a <code>short</code> value
-     *
-     * @return a <code>short</code> value
-     *
-     * @exception Exception if an error occurs
-     */
-    public short getChildType(short childType) throws Exception {
-        return childType;
-    }
-
-    /**
-     * Create Child Name for tree entry
-     *
-     * @param childname a <code>String</code> value
-     *
-     * @return a <code>String</code> for Child Name for tree entry
-     *
-     * @exception Exception if an error occurs
-     */
-    public String getChildName(String childname) throws Exception {
-        if (childname.length() != 0) {
-            return childname;
-        } else {
-            return "abstract_default";
-        }
-    }
-
-    /**
-      * DOCUMENT ME!
-      *
-      * @param samplesDir DOCUMENT ME!
-      * @param parentDir DOCUMENT ME!
-      * @param childId DOCUMENT ME!
-      * @param childType DOCUMENT ME!
-      * @param childName the name of the child
-      * @param language for which the document is created
-      * @param parameters additional parameters that can be considered when 
-      *  creating the child
-      *
-      * @throws Exception DOCUMENT ME!
-      */
-    public void create(
-        Publication publication,
-        File samplesDir,
-        File parentDir,
-        String parentId,
-        String childId,
-        short childType,
-        String childName,
-        String language,
-        Map parameters)
-        throws Exception {
-        // Set filenames
-        String id = generateTreeId(childId, childType);
-        String filename = getChildFileName(publication, "authoring", parentId, childId, language);
-        log.debug("Filename: " + filename);
-        String filenameMeta = getChildMetaFileName(parentDir, id, language);
-
-        String doctypeSample = samplesDir + File.separator + sampleResourceName;
-        String doctypeMeta = samplesDir + File.separator + sampleMetaName;
-
-        File sampleFile = new File(doctypeSample);
-        if (!sampleFile.exists()) {
-            log.error("No such sample file: " + sampleFile + " Have you configured the sample within doctypes.xconf?");
-            throw new FileNotFoundException("" + sampleFile);
-        }
-
-        // Read sample file
-        log.debug("Read sample file: " + doctypeSample);
-
-        Document doc = DocumentHelper.readDocument(new File(doctypeSample));
-
-        log.debug("sample document: " + doc);
-
-        // transform the xml if needed
-        log.debug("transform sample file: ");
-        transformXML(doc, id, childType, childName, parameters);
-
-        // write the document (create the path, i.e. the parent
-        // directory first if needed)
-        File parent = new File(new File(filename).getParent());
-
-        if (!parent.exists()) {
+   private static Logger log = Logger.getLogger(DefaultCreator.class);
+   public static final String RESOURCE_NAME = "resource-name";
+   public static final String RESOURCE_META_NAME = "resource-meta-name";
+   public static final String SAMPLE_NAME = "sample-name";
+   public static final String SAMPLE_META_NAME = "sample-meta-name";
+   // private String resourceName = null;
+   // private String resourceMetaName = null;
+   private String sampleResourceName = null;
+   private String sampleMetaName = null;
+   /**
+    * @see org.apache.lenya.cms.authoring.ParentChildCreatorInterface#init(Configuration)
+    * 
+    * @param conf
+    *           DOCUMENT ME!
+    */
+   public void init(Configuration conf) {
+      if(conf == null){
+         return;
+      }
+      // if(conf.getChild(RESOURCE_NAME, false) != null){
+      // resourceName = conf.getChild(RESOURCE_NAME).getValue("index.xml");
+      // }
+      // if(conf.getChild(RESOURCE_META_NAME, false) != null){
+      // resourceMetaName = conf.getChild(RESOURCE_META_NAME).getValue("index-meta.xml");
+      // }
+      if(conf.getChild(SAMPLE_NAME, false) != null){
+         sampleResourceName = conf.getChild(SAMPLE_NAME).getValue("sampleindex.xml");
+      }
+      if(conf.getChild(SAMPLE_META_NAME, false) != null){
+         sampleMetaName = conf.getChild(SAMPLE_META_NAME).getValue("samplemeta.xml");
+      }
+   }
+   /**
+    * Generate a tree id by returning the child ID.
+    * 
+    * @param childId
+    *           a <code>String</code> value
+    * @param childType
+    *           a <code>short</code> value
+    * 
+    * @return a <code>String</code> value
+    * 
+    * @exception Exception
+    *               if an error occurs
+    */
+   public String generateTreeId(String childId, short childType) throws Exception {
+      return childId;
+   }
+   /**
+    * Return the child type by simply returning the child type.
+    * 
+    * @param childType
+    *           a <code>short</code> value
+    * 
+    * @return a <code>short</code> value
+    * 
+    * @exception Exception
+    *               if an error occurs
+    */
+   public short getChildType(short childType) throws Exception {
+      return childType;
+   }
+   /**
+    * Create Child Name for tree entry
+    * 
+    * @param childname
+    *           a <code>String</code> value
+    * 
+    * @return a <code>String</code> for Child Name for tree entry
+    * 
+    * @exception Exception
+    *               if an error occurs
+    */
+   public String getChildName(String childname) throws Exception {
+      if(childname.length() != 0){
+         return childname;
+      }else{
+         return "abstract_default";
+      }
+   }
+   /**
+    * DOCUMENT ME!
+    * 
+    * @param samplesDir
+    *           DOCUMENT ME!
+    * @param parentDir
+    *           DOCUMENT ME!
+    * @param childId
+    *           DOCUMENT ME!
+    * @param childType
+    *           DOCUMENT ME!
+    * @param childName
+    *           the name of the child
+    * @param language
+    *           for which the document is created
+    * @param parameters
+    *           additional parameters that can be considered when creating the child
+    * 
+    * @throws Exception
+    *            DOCUMENT ME!
+    */
+   public void create(Publication publication, File samplesDir, File parentDir, String parentId, String childId, short childType, String childName, String language, Map parameters) throws Exception {
+      // Set filenames
+      String id = generateTreeId(childId, childType);
+      String filename = getChildFileName(publication, "authoring", parentId, childId, language);
+      log.debug("Filename: " + filename);
+      String filenameMeta = getChildMetaFileName(parentDir, id, language);
+      String doctypeSample = samplesDir + File.separator + sampleResourceName;
+      String doctypeMeta = samplesDir + File.separator + sampleMetaName;
+      File sampleFile = new File(doctypeSample);
+      if(!sampleFile.exists()){
+         log.error("No such sample file: " + sampleFile + " Have you configured the sample within doctypes.xconf?");
+         throw new FileNotFoundException("" + sampleFile);
+      }
+      // Read sample file
+      log.debug("Read sample file: " + doctypeSample);
+      Document doc = DocumentHelper.readDocument(new File(doctypeSample));
+      log.debug("sample document: " + doc);
+      // transform the xml if needed
+      log.debug("transform sample file: ");
+      transformXML(doc, id, childType, childName, parameters);
+      // write the document (create the path, i.e. the parent
+      // directory first if needed)
+      File parent = new File(new File(filename).getParent());
+      if(!parent.exists()){
+         parent.mkdirs();
+         log.warn("Directory has been created: " + parent);
+      }
+      // Write file
+      log.debug("Write file: " + filename);
+      DocumentHelper.writeDocument(doc, new File(filename));
+      // now do the same thing for the meta document if the
+      // sampleMetaName is specified
+      if(sampleMetaName != null){
+         doc = DocumentHelper.readDocument(new File(doctypeMeta));
+         transformMetaXML(doc, id, childType, childName, parameters);
+         parent = new File(new File(filenameMeta).getParent());
+         if(!parent.exists()){
             parent.mkdirs();
-            log.warn("Directory has been created: " + parent);
-        }
-
-        // Write file
-        log.debug("Write file: " + filename);
-        DocumentHelper.writeDocument(doc, new File(filename));
-
-        // now do the same thing for the meta document if the
-        // sampleMetaName is specified
-        if (sampleMetaName != null) {
-            doc = DocumentHelper.readDocument(new File(doctypeMeta));
-
-            transformMetaXML(doc, id, childType, childName, parameters);
-
-            parent = new File(new File(filenameMeta).getParent());
-
-            if (!parent.exists()) {
-                parent.mkdirs();
-            }
-
-            DocumentHelper.writeDocument(doc, new File(filenameMeta));
-        }
-    }
-
-    /**
-      * @deprecated replaced by create method with access to publication context
-      *
-      * @param samplesDir DOCUMENT ME!
-      * @param parentDir DOCUMENT ME!
-      * @param childId DOCUMENT ME!
-      * @param childType DOCUMENT ME!
-      * @param childName the name of the child
-      * @param language for which the document is created
-      * @param parameters additional parameters that can be considered when 
-      *  creating the child
-      *
-      * @throws Exception DOCUMENT ME!
-      */
-    /*
-    public void create(
-        File samplesDir,
-        File parentDir,
-        String childId,
-        short childType,
-        String childName,
-        String language,
-        Map parameters)
-        throws Exception {
-
-        log.warn("Deprecated!");
-    }
-    */
-
-    /**
-     * Apply some transformation on the newly created child.
-     * 
-     * @param doc the xml document
-     * @param childId the id of the child
-     * @param childType the type of child
-     * @param childName the name of the child
-     * @param parameters additional parameters that can be used in the transformation
-     * 
-     * @throws Exception if the transformation fails
-     */
-    protected void transformXML(
-        Document doc,
-        String childId,
-        short childType,
-        String childName,
-        Map parameters)
-        throws Exception {}
-
-    /**
-     * Apply some transformation on the meta file of newly created child.
-     * 
-     * @param doc the xml document
-     * @param childId the id of the child
-     * @param childType the type of child
-     * @param childName the name of the child
-     * @param parameters additional parameters that can be used in the transformation
-     * 
-     * @throws Exception if the transformation fails
-     */
-    protected void transformMetaXML(
-        Document doc,
-        String childId,
-        short childType,
-        String childName,
-        Map parameters)
-        throws Exception {}
-
-    /**
-     * @deprecated because it implies not to use the DocumentIdToPathMapper
-     * Get the file name of the child
-     * 
-     * @param parentDir the parent directory
-     * @param childId the id of the child
-     * @param language for which the document is created
-     * 
-     * @return the file name of the child
-     */
-    protected abstract String getChildFileName(
-        Publication publication,
-        String area,
-        String parentId,
-        String childId,
-        String language);
-
-    /**
-     * Get the file name of the meta file
-     * 
-     * @param parentDir the parent directory
-     * @param childId the id of the child
-     * @param language for which the document is created
-     * 
-     * @return the name of the meta file
-     */
-    protected String getChildMetaFileName(
-        File parentDir,
-        String childId,
-        String language) {
-        return null;
-    }
-
-    /**
-     * Create the language suffix for a file name given a language string
-     * 
-     * @param language the language
-     * 
-     * @return the suffix for the language dependant file name
-     */
-    protected String getLanguageSuffix(String language) {
-        return (language != null) ? "_" + language : "";
-    }
-
-    /**
-     * Get filename of template/sample
-     */
-    public String getSampleResourceName() {
-        return sampleResourceName;
-    }
+         }
+         DocumentHelper.writeDocument(doc, new File(filenameMeta));
+      }
+   }
+   /**
+    * @deprecated replaced by create method with access to publication context
+    * 
+    * @param samplesDir
+    *           DOCUMENT ME!
+    * @param parentDir
+    *           DOCUMENT ME!
+    * @param childId
+    *           DOCUMENT ME!
+    * @param childType
+    *           DOCUMENT ME!
+    * @param childName
+    *           the name of the child
+    * @param language
+    *           for which the document is created
+    * @param parameters
+    *           additional parameters that can be considered when creating the child
+    * 
+    * @throws Exception
+    *            DOCUMENT ME!
+    */
+   /*
+    * public void create( File samplesDir, File parentDir, String childId, short childType, String childName, String language, Map parameters) throws Exception {
+    * 
+    * log.warn("Deprecated!"); }
+    */
+   /**
+    * Apply some transformation on the newly created child.
+    * 
+    * @param doc
+    *           the xml document
+    * @param childId
+    *           the id of the child
+    * @param childType
+    *           the type of child
+    * @param childName
+    *           the name of the child
+    * @param parameters
+    *           additional parameters that can be used in the transformation
+    * 
+    * @throws Exception
+    *            if the transformation fails
+    */
+   protected void transformXML(Document doc, String childId, short childType, String childName, Map parameters) throws Exception {
+   }
+   /**
+    * Apply some transformation on the meta file of newly created child.
+    * 
+    * @param doc
+    *           the xml document
+    * @param childId
+    *           the id of the child
+    * @param childType
+    *           the type of child
+    * @param childName
+    *           the name of the child
+    * @param parameters
+    *           additional parameters that can be used in the transformation
+    * 
+    * @throws Exception
+    *            if the transformation fails
+    */
+   protected void transformMetaXML(Document doc, String childId, short childType, String childName, Map parameters) throws Exception {
+   }
+   /**
+    * @deprecated because it implies not to use the DocumentIdToPathMapper Get the file name of the child
+    * 
+    * @param parentDir
+    *           the parent directory
+    * @param childId
+    *           the id of the child
+    * @param language
+    *           for which the document is created
+    * 
+    * @return the file name of the child
+    */
+   protected abstract String getChildFileName(Publication publication, String area, String parentId, String childId, String language);
+   /**
+    * Get the file name of the meta file
+    * 
+    * @param parentDir
+    *           the parent directory
+    * @param childId
+    *           the id of the child
+    * @param language
+    *           for which the document is created
+    * 
+    * @return the name of the meta file
+    */
+   protected String getChildMetaFileName(File parentDir, String childId, String language) {
+      return null;
+   }
+   /**
+    * Create the language suffix for a file name given a language string
+    * 
+    * @param language
+    *           the language
+    * 
+    * @return the suffix for the language dependant file name
+    */
+   protected String getLanguageSuffix(String language) {
+      return (language != null) ? "_" + language : "";
+   }
+   /**
+    * Get filename of template/sample
+    */
+   public String getSampleResourceName() {
+      return sampleResourceName;
+   }
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.