Index: plugin/packaging/DocumentInfoAPI.java
===================================================================
--- plugin/packaging/DocumentInfoAPI.java	(revision 9631)
+++ plugin/packaging/DocumentInfoAPI.java	(working copy)
@@ -23,6 +23,8 @@
 
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.api.Api;
+import com.xpn.xwiki.plugin.packaging.DocumentInfo.DocumentInstallationAction;
+import com.xpn.xwiki.plugin.packaging.DocumentInfo.DocumentInstallationStatus;
 
 public class DocumentInfoAPI extends Api
 {
@@ -62,43 +64,28 @@
         return (doc.getFullName());
     }
 
-    public int isInstallable()
+    public DocumentInstallationStatus isInstallable()
     {
         return doc.isInstallable();
     }
 
-    public int getAction()
+    public DocumentInstallationAction getAction()
     {
         return doc.getAction();
     }
 
-    public void setAction(int action)
+    public void setAction(DocumentInstallationAction action)
     {
         doc.setAction(action);
     }
 
-    public int testInstall(XWikiContext context)
+    public DocumentInstallationStatus testInstall(XWikiContext context)
     {
         return doc.testInstall(false, context);
     }
 
-    public int testInstall(boolean isAdmin, XWikiContext context)
+    public DocumentInstallationStatus testInstall(boolean isAdmin, XWikiContext context)
     {
         return doc.testInstall(isAdmin, context);
     }
-
-    public static String installStatusToString(int status)
-    {
-        return DocumentInfo.installStatusToString(status);
-    }
-
-    public static String actionToString(int status)
-    {
-        return DocumentInfo.actionToString(status);
-    }
-
-    public static int actionToInt(String status)
-    {
-        return DocumentInfo.actionToInt(status);
-    }
 }
Index: plugin/packaging/PackageAPI.java
===================================================================
--- plugin/packaging/PackageAPI.java	(revision 9631)
+++ plugin/packaging/PackageAPI.java	(working copy)
@@ -23,12 +23,13 @@
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
 import com.xpn.xwiki.api.Api;
+import com.xpn.xwiki.plugin.packaging.DocumentInfo.DocumentInstallationAction;
+import com.xpn.xwiki.plugin.packaging.DocumentInfo.DocumentInstallationStatus;
 import com.xpn.xwiki.util.Util;
 
 public class PackageAPI extends Api
@@ -50,6 +51,14 @@
         this.plugin = plugin;
     }
 
+    public Package getPackage()
+    {
+        if (hasProgrammingRights()) {
+            return plugin;
+        }
+        return null;
+    }
+
     public String getName()
     {
         return plugin.getName();
@@ -60,14 +69,6 @@
         plugin.setName(name);
     }
 
-    public Package getPackage()
-    {
-        if (hasProgrammingRights()) {
-            return plugin;
-        }
-        return null;
-    }
-
     public String getDescription()
     {
         return plugin.getDescription();
@@ -143,43 +144,41 @@
         plugin.addDocumentFilter(filter);
     }
 
-    public List getFiles()
+    public List<DocumentInfoAPI> getFiles()
     {
-        List files = plugin.getFiles();
-        ArrayList APIfiles = new ArrayList(files.size());
+        ArrayList<DocumentInfoAPI> apiFiles =
+            new ArrayList<DocumentInfoAPI>(plugin.getFiles().size());
 
-        for (int i = 0; i < files.size(); i++) {
-            APIfiles.add(new DocumentInfoAPI((DocumentInfo) files.get(i), getXWikiContext()));
+        for (DocumentInfo file : plugin.getFiles()) {
+            apiFiles.add(new DocumentInfoAPI(file, getXWikiContext()));
         }
-        return APIfiles;
+        return apiFiles;
     }
 
-    public boolean add(String docFullName, int DefaultAction) throws XWikiException
+    public boolean add(String docFullName) throws XWikiException
     {
-        return plugin.add(docFullName, DefaultAction, getXWikiContext());
+        return plugin.add(docFullName, getXWikiContext());
     }
 
-    public boolean add(String docFullName) throws XWikiException
+    public boolean add(String docFullName, DocumentInstallationAction defaultAction)
+        throws XWikiException
     {
-        return plugin.add(docFullName, getXWikiContext());
+        return plugin.add(docFullName, defaultAction, getXWikiContext());
     }
 
-    public void setDocumentAction(String docFullName, int action)
+    public void setDocumentAction(String docFullName, DocumentInstallationAction action)
     {
-        Iterator it = plugin.getFiles().iterator();
-        while (it.hasNext()) {
-            DocumentInfo docInfos = (DocumentInfo) it.next();
+        for (DocumentInfo docInfos : plugin.getFiles()) {
             if (docInfos.getFullName().compareTo(docFullName) == 0) {
                 docInfos.setAction(action);
             }
         }
     }
 
-    public void setDocumentAction(String docFullName, String language, int action)
+    public void setDocumentAction(String docFullName, String language,
+        DocumentInstallationAction action)
     {
-        Iterator it = plugin.getFiles().iterator();
-        while (it.hasNext()) {
-            DocumentInfo docInfos = (DocumentInfo) it.next();
+        for (DocumentInfo docInfos : plugin.getFiles()) {
             if ((docInfos.getFullName().compareTo(docFullName) == 0)
                 && (language.equals(docInfos.getLanguage()))) {
                 docInfos.setAction(action);
@@ -202,12 +201,12 @@
         return plugin.Import(file, getXWikiContext());
     }
 
-    public int testInstall()
+    public DocumentInstallationStatus testInstall()
     {
         return plugin.testInstall(false, getXWikiContext());
     }
 
-    public int testInstall(boolean isAdmin)
+    public DocumentInstallationStatus testInstall(boolean isAdmin)
     {
         return plugin.testInstall(isAdmin, getXWikiContext());
     }
@@ -223,27 +222,27 @@
         return plugin.toXml(getXWikiContext());
     }
 
-    public int install() throws XWikiException
+    public DocumentInstallationStatus install() throws XWikiException
     {
         return plugin.install(getXWikiContext());
     }
 
-    public List getErrors()
+    public List<String> getErrors()
     {
         return plugin.getErrors(getXWikiContext());
     }
 
-    public List getSkipped()
+    public List<String> getSkipped()
     {
         return plugin.getSkipped(getXWikiContext());
     }
 
-    public List getInstalled()
+    public List<String> getInstalled()
     {
         return plugin.getInstalled(getXWikiContext());
     }
 
-    public int getStatus()
+    public DocumentInstallationStatus getStatus()
     {
         return plugin.getStatus(getXWikiContext());
     }
Index: plugin/packaging/DocumentInfo.java
===================================================================
--- plugin/packaging/DocumentInfo.java	(revision 9631)
+++ plugin/packaging/DocumentInfo.java	(working copy)
@@ -21,6 +21,7 @@
 
 package com.xpn.xwiki.plugin.packaging;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -30,36 +31,52 @@
 
 public class DocumentInfo
 {
-    private static final Log log = LogFactory.getLog(DocumentInfo.class);
+    public enum DocumentInstallationStatus
+    {
+        IMPOSSIBLE, ALREADY_EXIST, OK, ERROR;
+    }
 
-    private XWikiDocument doc;
+    public enum DocumentInstallationAction
+    {
+        UNDEFINED, OVERWRITE, SKIP, MERGE;
+        public static DocumentInstallationAction fromInt(int value)
+        {
+            for (DocumentInstallationAction action : DocumentInstallationAction.values()) {
+                // We add +1 as UNDEFINED should actually be -1, instead of 0 (for backwards
+                // compatibility).
+                if (action.ordinal() == value + 1) {
+                    return action;
+                }
+            }
+            return UNDEFINED;
+        }
 
-    private int installable = INSTALL_IMPOSSIBLE;
+        public static DocumentInstallationAction fromString(String value)
+        {
+            DocumentInstallationAction result = null;
+            try {
+                result = DocumentInstallationAction.valueOf(StringUtils.upperCase(value));
+            } catch (Exception ex) {
+                try {
+                    result = DocumentInstallationAction.fromInt(Integer.parseInt(value));
+                } catch (Exception ex2) {
+                    result = UNDEFINED;
+                }
+            }
+            return result;
+        }
+    }
 
-    private int action = ACTION_NOT_DEFINED;
+    private static final Log LOG = LogFactory.getLog(DocumentInfo.class);
 
-    private int fileType;
+    private XWikiDocument doc;
 
-    public final static int TYPE_SAMPLE = 0;
+    private DocumentInstallationStatus installable = DocumentInstallationStatus.IMPOSSIBLE;
 
-    public final static int TYPE_NORMAL = 1;
+    private DocumentInstallationAction action = DocumentInstallationAction.UNDEFINED;
 
-    public final static int ACTION_NOT_DEFINED = -1;
+    private int fileType;
 
-    public final static int ACTION_OVERWRITE = 0;
-
-    public final static int ACTION_SKIP = 1;
-
-    public final static int ACTION_MERGE = 2;
-
-    public final static int INSTALL_IMPOSSIBLE = 0;
-
-    public final static int INSTALL_ALREADY_EXIST = 1;
-
-    public final static int INSTALL_OK = 2;
-
-    public final static int INSTALL_ERROR = 4;
-
     public DocumentInfo(XWikiDocument doc)
     {
         this.doc = doc;
@@ -81,7 +98,7 @@
             return;
         }
         doc.setSpace(Space);
-        installable = INSTALL_IMPOSSIBLE;
+        installable = DocumentInstallationStatus.IMPOSSIBLE;
     }
 
     public int getFileType()
@@ -104,24 +121,21 @@
         return (doc.getLanguage());
     }
 
-    public int isInstallable()
+    public DocumentInstallationStatus isInstallable()
     {
         return installable;
     }
 
-    public int testInstall(boolean isAdmin, XWikiContext context)
+    public DocumentInstallationStatus testInstall(boolean isAdmin, XWikiContext context)
     {
-        if (log.isDebugEnabled()) {
-            log.debug("Package test install document " + ((doc == null) ? "" : getFullName())
-                + " " + ((doc == null) ? "" : getLanguage()));
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(String.format("Package test install document [%s] (%s)", ((doc == null)
+                ? "" : getFullName()), ((doc == null) ? "" : getLanguage())));
         }
 
-        installable = INSTALL_IMPOSSIBLE;
+        installable = DocumentInstallationStatus.IMPOSSIBLE;
 
-        try {
-            if (this.doc == null) {
-                return installable;
-            }
+        if (this.doc != null) {
             try {
                 if ((!isAdmin) && (!context.getWiki().checkAccess("edit", this.doc, context))) {
                     return installable;
@@ -129,73 +143,34 @@
                 XWikiDocument doc1 = context.getWiki().getDocument(doc.getFullName(), context);
                 boolean isNew = doc1.isNew();
                 if (!isNew) {
-                    if ((doc.getLanguage() != null) && (!doc.getLanguage().equals(""))) {
+                    if (!StringUtils.isBlank(doc.getLanguage())) {
                         isNew = !doc1.getTranslationList(context).contains(doc.getLanguage());
                     }
                 }
 
                 if (!isNew) {
-                    installable = INSTALL_ALREADY_EXIST;
-                    return installable;
+                    installable = DocumentInstallationStatus.ALREADY_EXIST;
+                } else {
+                    installable = DocumentInstallationStatus.OK;
                 }
             } catch (XWikiException e) {
-                installable = INSTALL_IMPOSSIBLE;
-                return installable;
+                installable = DocumentInstallationStatus.IMPOSSIBLE;
             }
-            installable = INSTALL_OK;
-            return installable;
-        } finally {
-            if (log.isDebugEnabled()) {
-                log.debug("Package test install document " + ((doc == null) ? "" : getFullName())
-                    + " " + ((doc == null) ? "" : getLanguage()) + " result " + installable);
-            }
         }
-    }
-
-    public static String installStatusToString(int status)
-    {
-        if (status == INSTALL_IMPOSSIBLE) {
-            return "Impossible";
-        } else if (status == INSTALL_ERROR) {
-            return "Error";
-        } else if (status == INSTALL_OK) {
-            return "Ok";
-        } else if (status == INSTALL_ALREADY_EXIST) {
-            return "Already exist";
+        if (LOG.isDebugEnabled()) {
+            LOG.debug(String.format("Package test install document [%s] (%s) result %s",
+                ((doc == null) ? "" : getFullName()), ((doc == null) ? "" : getLanguage()),
+                installable));
         }
-        return "Unknown Status";
+        return installable;
     }
 
-    public static String actionToString(int status)
+    public DocumentInstallationAction getAction()
     {
-        if (status == ACTION_MERGE) {
-            return "merge";
-        } else if (status == ACTION_OVERWRITE) {
-            return "overwrite";
-        } else if (status == ACTION_SKIP) {
-            return "skip";
-        }
-        return "Not defined";
-    }
-
-    public static int actionToInt(String status)
-    {
-        if (status.compareTo("merge") == 0) {
-            return ACTION_MERGE;
-        } else if (status.compareTo("overwrite") == 0) {
-            return ACTION_OVERWRITE;
-        } else if (status.compareTo("skip") == 0) {
-            return ACTION_SKIP;
-        }
-        return ACTION_NOT_DEFINED;
-    }
-
-    public int getAction()
-    {
         return action;
     }
 
-    public void setAction(int action)
+    public void setAction(DocumentInstallationAction action)
     {
         this.action = action;
     }
Index: plugin/packaging/Package.java
===================================================================
--- plugin/packaging/Package.java	(revision 9631)
+++ plugin/packaging/Package.java	(working copy)
@@ -30,12 +30,12 @@
 import java.io.OutputStream;
 import java.io.StringWriter;
 import java.util.ArrayList;
-import java.util.Iterator;
 import java.util.List;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 import java.util.zip.ZipOutputStream;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.dom4j.Document;
@@ -52,6 +52,8 @@
 import com.xpn.xwiki.XWikiException;
 import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.objects.classes.BaseClass;
+import com.xpn.xwiki.plugin.packaging.DocumentInfo.DocumentInstallationAction;
+import com.xpn.xwiki.plugin.packaging.DocumentInfo.DocumentInstallationStatus;
 
 public class Package
 {
@@ -67,11 +69,11 @@
 
     private String authorName = "XWiki";
 
-    private List files = null;
+    private List<DocumentInfo> files = null;
 
-    private List customMappingFiles = null;
+    private List<DocumentInfo> customMappingFiles = null;
 
-    private List classFiles = null;
+    private List<DocumentInfo> classFiles = null;
 
     private boolean backupPack = false;
 
@@ -79,12 +81,8 @@
 
     private boolean withVersions = true;
 
-    private List documentFilters = new ArrayList();
+    private List<DocumentFilter> documentFilters = new ArrayList<DocumentFilter>();
 
-    public static final int OK = 0;
-
-    public static final int Right = 1;
-
     public static final String DefaultPackageFileName = "package.xml";
 
     public static final String DefaultPluginName = "package";
@@ -173,12 +171,12 @@
         this.preserveVersion = preserveVersion;
     }
 
-    public List getFiles()
+    public List<DocumentInfo> getFiles()
     {
         return files;
     }
 
-    public List getCustomMappingFiles()
+    public List<DocumentInfo> getCustomMappingFiles()
     {
         return customMappingFiles;
     }
@@ -205,7 +203,7 @@
     public void addDocumentFilter(Object filter) throws PackageException
     {
         if (filter instanceof DocumentFilter) {
-            this.documentFilters.add(filter);
+            this.documentFilters.add((DocumentFilter) filter);
         } else {
             throw new PackageException(PackageException.ERROR_PACKAGE_INVALID_FILTER,
                 "Invalid Document Filter");
@@ -214,22 +212,21 @@
 
     public Package()
     {
-        files = new ArrayList();
-        customMappingFiles = new ArrayList();
-        classFiles = new ArrayList();
+        files = new ArrayList<DocumentInfo>();
+        customMappingFiles = new ArrayList<DocumentInfo>();
+        classFiles = new ArrayList<DocumentInfo>();
     }
 
-    public boolean add(XWikiDocument doc, int defaultAction, XWikiContext context)
-        throws XWikiException
+    public boolean add(XWikiDocument doc, DocumentInstallationAction defaultAction,
+        XWikiContext context) throws XWikiException
     {
         if (!context.getWiki().checkAccess("edit", doc, context)) {
             return false;
         }
-        for (int i = 0; i < files.size(); i++) {
-            DocumentInfo di = (DocumentInfo) files.get(i);
+        for (DocumentInfo di : files) {
             if (di.getFullName().equals(doc.getFullName())
                 && (di.getLanguage().equals(doc.getLanguage()))) {
-                if (defaultAction != DocumentInfo.ACTION_NOT_DEFINED) {
+                if (defaultAction != DocumentInstallationAction.UNDEFINED) {
                     di.setAction(defaultAction);
                 }
                 if (!doc.isNew()) {
@@ -256,67 +253,64 @@
             }
             return true;
         } catch (ExcludeDocumentException e) {
-            log.info("Skip the document " + doc.getFullName());
+            log.info(String.format("Skip the document [%s]", doc.getFullName()));
             return false;
         }
     }
 
     public boolean add(XWikiDocument doc, XWikiContext context) throws XWikiException
     {
-        return add(doc, DocumentInfo.ACTION_NOT_DEFINED, context);
+        return add(doc, DocumentInstallationAction.UNDEFINED, context);
     }
 
-    public boolean updateDoc(String docFullName, int action, XWikiContext context)
-        throws XWikiException
+    public boolean updateDoc(String docFullName, DocumentInstallationAction action,
+        XWikiContext context) throws XWikiException
     {
         XWikiDocument doc = new XWikiDocument();
         doc.setFullName(docFullName, context);
         return add(doc, action, context);
     }
 
-    public boolean add(String docFullName, int DefaultAction, XWikiContext context)
-        throws XWikiException
+    public boolean add(String docFullName, DocumentInstallationAction defaultAction,
+        XWikiContext context) throws XWikiException
     {
         XWikiDocument doc = context.getWiki().getDocument(docFullName, context);
-        add(doc, DefaultAction, context);
-        List languages = doc.getTranslationList(context);
-        for (int i = 0; i < languages.size(); i++) {
-            String language = (String) languages.get(i);
-            if (!((language == null) || (language.equals("")) || (language.equals(doc
-                .getDefaultLanguage())))) {
-                add(doc.getTranslatedDocument(language, context), DefaultAction, context);
+        add(doc, defaultAction, context);
+        for (String language : doc.getTranslationList(context)) {
+            if (!(StringUtils.isBlank(language) || (language.equals(doc.getDefaultLanguage())))) {
+                add(doc.getTranslatedDocument(language, context), defaultAction, context);
             }
         }
         return true;
     }
 
-    public boolean add(String docFullName, String language, int DefaultAction,
-        XWikiContext context) throws XWikiException
+    public boolean add(String docFullName, String language,
+        DocumentInstallationAction defaultAction, XWikiContext context) throws XWikiException
     {
         XWikiDocument doc = context.getWiki().getDocument(docFullName, context);
-        if ((language == null) || (language.equals(""))) {
-            add(doc, DefaultAction, context);
+        if (StringUtils.isBlank(language)) {
+            add(doc, defaultAction, context);
         } else {
-            add(doc.getTranslatedDocument(language, context), DefaultAction, context);
+            add(doc.getTranslatedDocument(language, context), defaultAction, context);
         }
         return true;
     }
 
     public boolean add(String docFullName, XWikiContext context) throws XWikiException
     {
-        return add(docFullName, DocumentInfo.ACTION_NOT_DEFINED, context);
+        return add(docFullName, DocumentInstallationAction.UNDEFINED, context);
     }
 
     public boolean add(String docFullName, String language, XWikiContext context)
         throws XWikiException
     {
-        return add(docFullName, language, DocumentInfo.ACTION_NOT_DEFINED, context);
+        return add(docFullName, language, DocumentInstallationAction.UNDEFINED, context);
     }
 
     public void filter(XWikiDocument doc, XWikiContext context) throws ExcludeDocumentException
     {
-        for (int i = 0; i < documentFilters.size(); i++) {
-            ((DocumentFilter) documentFilters.get(i)).filter(doc, context);
+        for (DocumentFilter filter : documentFilters) {
+            filter.filter(doc, context);
         }
     }
 
@@ -328,8 +322,7 @@
         }
 
         ZipOutputStream zos = new ZipOutputStream(os);
-        for (int i = 0; i < files.size(); i++) {
-            DocumentInfo docinfo = (DocumentInfo) files.get(i);
+        for (DocumentInfo docinfo : files) {
             XWikiDocument doc = docinfo.getDoc();
             addToZip(doc, zos, withVersions, context);
         }
@@ -353,8 +346,7 @@
             }
         }
 
-        for (int i = 0; i < files.size(); i++) {
-            DocumentInfo docinfo = (DocumentInfo) files.get(i);
+        for (DocumentInfo docinfo : files) {
             XWikiDocument doc = docinfo.getDoc();
             addToDir(doc, dir, withVersions, context);
         }
@@ -423,15 +415,14 @@
         return "";
     }
 
+    @SuppressWarnings("unchecked")
     private boolean documentExistInPackageFile(String docName, String language, Document xml)
     {
         Element docFiles = xml.getRootElement();
         Element infosFiles = docFiles.element("files");
 
-        List ListFile = infosFiles.elements("file");
-        Iterator it = ListFile.iterator();
-        while (it.hasNext()) {
-            Element el = (Element) it.next();
+        List<Element> ListFile = infosFiles.elements("file");
+        for (Element el : ListFile) {
             String tmpDocName = el.getStringValue();
             if (tmpDocName.compareTo(docName) != 0) {
                 continue;
@@ -447,25 +438,27 @@
         return false;
     }
 
+    @SuppressWarnings("unchecked")
     private void updateFileInfos(Document xml)
     {
         Element docFiles = xml.getRootElement();
         Element infosFiles = docFiles.element("files");
 
-        List ListFile = infosFiles.elements("file");
-        for (int i = 0; i < ListFile.size(); i++) {
-            Element el = (Element) ListFile.get(i);
+        List<Element> ListFile = infosFiles.elements("file");
+        for (Element el : ListFile) {
             String defaultAction = el.attributeValue("defaultAction");
             String language = el.attributeValue("language");
             if (language == null) {
                 language = "";
             }
             String docName = el.getStringValue();
-            setDocumentDefaultAction(docName, language, Integer.parseInt(defaultAction));
+            setDocumentDefaultAction(docName, language, DocumentInstallationAction
+                .fromString(defaultAction));
         }
     }
 
-    private void setDocumentDefaultAction(String docName, String language, int defaultAction)
+    private void setDocumentDefaultAction(String docName, String language,
+        DocumentInstallationAction defaultAction)
     {
         if (files == null) {
             return;
@@ -479,23 +472,22 @@
         }
     }
 
-    public int testInstall(boolean isAdmin, XWikiContext context)
+    public DocumentInstallationStatus testInstall(boolean isAdmin, XWikiContext context)
     {
         if (log.isDebugEnabled()) {
             log.debug("Package test install");
         }
 
-        int result = DocumentInfo.INSTALL_IMPOSSIBLE;
+        DocumentInstallationStatus result = DocumentInstallationStatus.IMPOSSIBLE;
         try {
             if (files.size() == 0) {
                 return result;
             }
 
-            result = ((DocumentInfo) files.get(0)).testInstall(isAdmin, context);
-            for (int i = 1; i < files.size(); i++) {
-                DocumentInfo docInfo = ((DocumentInfo) files.get(i));
-                int res = docInfo.testInstall(isAdmin, context);
-                if (res < result) {
+            result = files.get(0).testInstall(isAdmin, context);
+            for (DocumentInfo docInfo : files) {
+                DocumentInstallationStatus res = docInfo.testInstall(isAdmin, context);
+                if (res.compareTo(result) < 0) {
                     result = res;
                 }
             }
@@ -507,18 +499,18 @@
         }
     }
 
-    public int install(XWikiContext context) throws XWikiException
+    public DocumentInstallationStatus install(XWikiContext context) throws XWikiException
     {
         boolean isAdmin = context.getWiki().getRightService().hasAdminRights(context);
 
-        if (testInstall(isAdmin, context) == DocumentInfo.INSTALL_IMPOSSIBLE) {
-            setStatus(DocumentInfo.INSTALL_IMPOSSIBLE, context);
-            return DocumentInfo.INSTALL_IMPOSSIBLE;
+        if (testInstall(isAdmin, context) == DocumentInstallationStatus.IMPOSSIBLE) {
+            setStatus(DocumentInstallationStatus.IMPOSSIBLE, context);
+            return DocumentInstallationStatus.IMPOSSIBLE;
         }
 
         boolean hasCustomMappings = false;
         for (int j = 0; j < customMappingFiles.size(); j++) {
-            DocumentInfo docinfo = (DocumentInfo) files.get(j);
+            DocumentInfo docinfo = files.get(j);
             BaseClass bclass = docinfo.getDoc().getxWikiClass();
             hasCustomMappings |=
                 context.getWiki().getStore().injectCustomMapping(bclass, context);
@@ -528,22 +520,21 @@
             context.getWiki().getStore().injectUpdatedCustomMappings(context);
         }
 
-        int status = DocumentInfo.INSTALL_OK;
+        DocumentInstallationStatus status = DocumentInstallationStatus.OK;
 
-        // Start by installing all documents having a class definition so that their
-        // definitions are available when installing documents using them.
-        for (int i = 0; i < classFiles.size(); i++) {
-            if (installDocument(((DocumentInfo) classFiles.get(i)), isAdmin, context) == DocumentInfo.INSTALL_ERROR) {
-                status = DocumentInfo.INSTALL_ERROR;
+        // Start by installing all documents having a class definition so that their definitions are
+        // available when installing documents using them.
+        for (DocumentInfo di : classFiles) {
+            if (installDocument(di, isAdmin, context) == DocumentInstallationStatus.ERROR) {
+                status = DocumentInstallationStatus.ERROR;
             }
         }
 
         // Install the remaining documents (without class definitions).
-        for (int i = 0; i < files.size(); i++) {
-            DocumentInfo di = (DocumentInfo) files.get(i);
+        for (DocumentInfo di : files) {
             if (!classFiles.contains(di)) {
-                if (installDocument(di, isAdmin, context) == DocumentInfo.INSTALL_ERROR) {
-                    status = DocumentInfo.INSTALL_ERROR;
+                if (installDocument(di, isAdmin, context) == DocumentInstallationStatus.ERROR) {
+                    status = DocumentInstallationStatus.ERROR;
                 }
             }
         }
@@ -551,31 +542,33 @@
         return status;
     }
 
-    private int installDocument(DocumentInfo doc, boolean isAdmin, XWikiContext context)
-        throws XWikiException
+    private DocumentInstallationStatus installDocument(DocumentInfo doc, boolean isAdmin,
+        XWikiContext context) throws XWikiException
     {
-        int result = DocumentInfo.INSTALL_OK;
+        DocumentInstallationStatus result = DocumentInstallationStatus.OK;
 
         if (log.isDebugEnabled()) {
             log.debug("Package installing document " + doc.getFullName() + " "
                 + doc.getLanguage());
         }
 
-        if (doc.getAction() == DocumentInfo.ACTION_SKIP) {
+        if (doc.getAction() == DocumentInstallationAction.SKIP) {
             addToSkipped(doc.getFullName() + ":" + doc.getLanguage(), context);
-            return DocumentInfo.INSTALL_OK;
+            return result;
         }
 
-        int status = doc.testInstall(isAdmin, context);
-        if (status == DocumentInfo.INSTALL_IMPOSSIBLE) {
+        DocumentInstallationStatus status = doc.testInstall(isAdmin, context);
+        if (status == DocumentInstallationStatus.IMPOSSIBLE) {
             addToErrors(doc.getFullName() + ":" + doc.getLanguage(), context);
-            return DocumentInfo.INSTALL_IMPOSSIBLE;
+            return DocumentInstallationStatus.IMPOSSIBLE;
         }
-        if (status == DocumentInfo.INSTALL_OK || status == DocumentInfo.INSTALL_ALREADY_EXIST
-            && doc.getAction() == DocumentInfo.ACTION_OVERWRITE) {
-            if (status == DocumentInfo.INSTALL_ALREADY_EXIST) {
-            	XWikiDocument deleteddoc = context.getWiki().getDocument(doc.getFullName(), context);
-        		//if this document is a translation: we should only delete the translation
+        if (status == DocumentInstallationStatus.OK
+            || status == DocumentInstallationStatus.ALREADY_EXIST
+            && doc.getAction() == DocumentInstallationAction.OVERWRITE) {
+            if (status == DocumentInstallationStatus.ALREADY_EXIST) {
+                XWikiDocument deleteddoc =
+                    context.getWiki().getDocument(doc.getFullName(), context);
+                // if this document is a translation: we should only delete the translation
                 if (doc.getDoc().getTranslation() != 0) {
                     deleteddoc = deleteddoc.getTranslatedDocument(doc.getLanguage(), context);
                 }
@@ -583,15 +576,18 @@
                     context.getWiki().deleteDocument(deleteddoc, context);
                 } catch (Exception e) {
                     // let's log the error but not stop
-                    result = DocumentInfo.INSTALL_ERROR;
+                    result = DocumentInstallationStatus.ERROR;
                     addToErrors(doc.getFullName() + ":" + doc.getLanguage(), context);
                     if (log.isErrorEnabled()) {
-                        log.error("Failed to delete document " + deleteddoc.getFullName());
+                        log.error("Failed to delete document " + deleteddoc.getFullName(), e);
                     }
                     if (log.isDebugEnabled()) {
                         log.debug("Failed to delete document " + deleteddoc.getFullName(), e);
                     }
                 }
+                if (log.isDebugEnabled()) {
+                    throw new Error("Stopping now");
+                }
             }
             try {
                 if (!backupPack) {
@@ -633,17 +629,18 @@
                 if (log.isDebugEnabled()) {
                     log.debug("Failed to save document " + doc.getFullName(), e);
                 }
-                result = DocumentInfo.INSTALL_ERROR;
+                result = DocumentInstallationStatus.ERROR;
             }
         }
         return result;
     }
 
-    private List getList(String name, XWikiContext context)
+    @SuppressWarnings("unchecked")
+    private List<String> getList(String name, XWikiContext context)
     {
-        List list = (List) context.get(name);
+        List<String> list = (List<String>) context.get(name);
         if (list == null) {
-            list = new ArrayList();
+            list = new ArrayList<String>();
             context.put(name, list);
         }
         return list;
@@ -673,33 +670,33 @@
         getList("install_installed", context).add(fullName);
     }
 
-    private void setStatus(int status, XWikiContext context)
+    private void setStatus(DocumentInstallationStatus status, XWikiContext context)
     {
-        context.put("install_status", new Integer((status)));
+        context.put("install_status", status);
     }
 
-    public List getErrors(XWikiContext context)
+    public List<String> getErrors(XWikiContext context)
     {
         return getList("install_errors", context);
     }
 
-    public List getSkipped(XWikiContext context)
+    public List<String> getSkipped(XWikiContext context)
     {
         return getList("install_skipped", context);
     }
 
-    public List getInstalled(XWikiContext context)
+    public List<String> getInstalled(XWikiContext context)
     {
         return getList("install_installed", context);
     }
 
-    public int getStatus(XWikiContext context)
+    public DocumentInstallationStatus getStatus(XWikiContext context)
     {
-        Integer status = (Integer) context.get("install_status");
+        DocumentInstallationStatus status = (DocumentInstallationStatus) context.get("install_status");
         if (status == null) {
-            return -1;
+            return DocumentInstallationStatus.IMPOSSIBLE;
         } else {
-            return status.intValue();
+            return status;
         }
     }
 
@@ -967,12 +964,12 @@
     public void addAllWikiDocuments(XWikiContext context) throws XWikiException
     {
         XWiki wiki = context.getWiki();
-        List spaces = wiki.getSpaces(context);
+        List<String> spaces = wiki.getSpaces(context);
         for (int i = 0; i < spaces.size(); i++) {
-            List DocsName = wiki.getSpaceDocsName((String) spaces.get(i), context);
+            List<String> DocsName = wiki.getSpaceDocsName(spaces.get(i), context);
             for (int j = 0; j < DocsName.size(); j++) {
-                this.add(spaces.get(i) + "." + DocsName.get(j), DocumentInfo.ACTION_OVERWRITE,
-                    context);
+                this.add(spaces.get(i) + "." + DocsName.get(j),
+                    DocumentInstallationAction.OVERWRITE, context);
             }
         }
     }
@@ -980,9 +977,9 @@
     public void deleteAllWikiDocuments(XWikiContext context) throws XWikiException
     {
         XWiki wiki = context.getWiki();
-        List spaces = wiki.getSpaces(context);
+        List<String> spaces = wiki.getSpaces(context);
         for (int i = 0; i < spaces.size(); i++) {
-            List DocsName = wiki.getSpaceDocsName((String) spaces.get(i), context);
+            List<String> DocsName = wiki.getSpaceDocsName(spaces.get(i), context);
             for (int j = 0; j < DocsName.size(); j++) {
                 String docName = spaces.get(i) + "." + DocsName.get(j);
                 XWikiDocument doc = wiki.getDocument(docName, context);
Index: web/ExportAction.java
===================================================================
--- web/ExportAction.java	(revision 9631)
+++ web/ExportAction.java	(working copy)
@@ -19,20 +19,20 @@
  */
 package com.xpn.xwiki.web;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
 import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.export.html.HtmlPackager;
 import com.xpn.xwiki.pdf.impl.PdfExportImpl;
 import com.xpn.xwiki.plugin.packaging.PackageAPI;
+import com.xpn.xwiki.plugin.packaging.DocumentInfo.DocumentInstallationAction;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 /**
  * Exports in XAR, PDF, RTF or HTML formats.
  * 
@@ -60,6 +60,8 @@
             } else {
                 defaultPage = exportPDFOrRTF(format, context);
             }
+        } catch (XWikiException ex) {
+            throw ex;
         } catch (Exception e) {
             throw new XWikiException(XWikiException.MODULE_XWIKI_APP,
                 XWikiException.ERROR_XWIKI_APP_EXPORT,
@@ -87,7 +89,7 @@
         String name = request.get("name");
         String[] pages = request.getParameterValues("pages");
 
-        List pageList = new ArrayList();
+        List<String> pageList = new ArrayList<String>();
         if (pages == null || pages.length == 0) {
             pageList.add(context.getDoc().getFullName());
 
@@ -95,10 +97,10 @@
                 name = context.getDoc().getFullName();
             }
         } else {
-            Map wikiQueries = new HashMap();
+            Map<String, Object[]> wikiQueries = new HashMap<String, Object[]>();
             for (int i = 0; i < pages.length; ++i) {
                 String pattern = pages[i];
-                
+
                 String wikiName;
                 if (pattern.contains(":")) {
                     int index = pattern.indexOf(':');
@@ -107,42 +109,41 @@
                 } else {
                     wikiName = context.getDatabase();
                 }
-                
+
                 StringBuffer where;
-                List params;
-                
+                List<String> params;
+
                 if (!wikiQueries.containsKey(wikiName)) {
                     Object[] query = new Object[2];
                     query[0] = where = new StringBuffer("where ");
-                    query[1] = params = new ArrayList();
+                    query[1] = params = new ArrayList<String>();
                     wikiQueries.put(wikiName, query);
                 } else {
-                    Object[] query = (Object[])wikiQueries.get(wikiName);
-                    where = (StringBuffer)query[0];
-                    params = (List)query[1];
+                    Object[] query = (Object[]) wikiQueries.get(wikiName);
+                    where = (StringBuffer) query[0];
+                    params = (List<String>) query[1];
                 }
-                
+
                 if (i > 0) {
                     where.append(" or ");
                 }
-                
+
                 where.append("doc.fullName like ?");
                 params.add(pattern);
             }
-            
+
             String database = context.getDatabase();
             try {
-                for (Iterator it = wikiQueries.entrySet().iterator(); it.hasNext();) {
-                    Map.Entry entry = (Map.Entry)it.next();
-                    String wikiName = (String)entry.getKey();
-                    Object[] query = (Object[])entry.getValue();
-                    String where = ((StringBuffer)query[0]).toString();
-                    List params = (List)query[1];
-                    
+                for (Map.Entry<String, Object[]> entry : wikiQueries.entrySet()) {
+                    String wikiName = entry.getKey();
+                    Object[] query = entry.getValue();
+                    String where = ((StringBuffer) query[0]).toString();
+                    List<String> params = (List<String>) query[1];
+
                     context.setDatabase(wikiName);
-                    List docsNames = context.getWiki().getStore().searchDocumentsNames(where, params, context);
-                    for (Iterator itDocName = docsNames.iterator(); itDocName.hasNext();) {
-                        String docName = (String)itDocName.next();
+                    List<String> docsNames =
+                        context.getWiki().getStore().searchDocumentsNames(where, params, context);
+                    for (String docName : docsNames) {
                         pageList.add(wikiName + XWikiDocument.DB_SPACE_SEP + docName);
                     }
                 }
@@ -150,7 +151,7 @@
                 context.setDatabase(database);
             }
         }
-        
+
         if (pageList.size() == 0) {
             return null;
         }
@@ -164,11 +165,11 @@
         if (description != null) {
             packager.setDescription(description);
         }
-        
+
         packager.addPages(pageList);
-        
+
         packager.export(context);
-        
+
         return null;
     }
 
@@ -267,13 +268,7 @@
                 for (int i = 0; i < pages.length; i++) {
                     String pageName = pages[i];
                     String defaultAction = request.get("action_" + pageName);
-                    int iAction;
-                    try {
-                        iAction = Integer.parseInt(defaultAction);
-                    } catch (Exception e) {
-                        iAction = 0;
-                    }
-                    export.add(pageName, iAction);
+                    export.add(pageName, DocumentInstallationAction.fromString(defaultAction));
                 }
             }
             export.export();
Index: web/ImportAction.java
===================================================================
--- web/ImportAction.java	(revision 9631)
+++ web/ImportAction.java	(working copy)
@@ -2,14 +2,12 @@
 
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
-import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.doc.XWikiAttachment;
-import com.xpn.xwiki.plugin.packaging.PackageAPI;
-import com.xpn.xwiki.plugin.packaging.DocumentInfo;
+import com.xpn.xwiki.doc.XWikiDocument;
 import com.xpn.xwiki.plugin.packaging.DocumentInfoAPI;
+import com.xpn.xwiki.plugin.packaging.PackageAPI;
+import com.xpn.xwiki.plugin.packaging.DocumentInfo.DocumentInstallationAction;
 
-import java.util.List;
-
 public class ImportAction extends XWikiAction
 {
 
@@ -50,10 +48,8 @@
                 String all = request.get("all");
                 if (!"1".equals(all)) {
                     if (pages != null) {
-                        List filelist = importer.getFiles();
-                        for (int i = 0; i < filelist.size(); i++) {
-                            DocumentInfoAPI dia = (DocumentInfoAPI) filelist.get(i);
-                            dia.setAction(DocumentInfo.ACTION_SKIP);
+                        for (DocumentInfoAPI dia : importer.getFiles()) {
+                            dia.setAction(DocumentInstallationAction.SKIP);
                         }
 
                         for (int i = 0; i < pages.length; i++) {
@@ -64,14 +60,15 @@
                                 actionName = "_" + language;
                             }
                             String defaultAction = request.get(actionName);
-                            int iAction;
+                            DocumentInstallationAction iAction;
                             if ((defaultAction == null) || (defaultAction.equals(""))) {
-                                iAction = DocumentInfo.ACTION_OVERWRITE;
+                                iAction = DocumentInstallationAction.OVERWRITE;
                             } else {
                                 try {
-                                    iAction = Integer.parseInt(defaultAction);
+                                    iAction =
+                                        DocumentInstallationAction.fromString(defaultAction);
                                 } catch (Exception e) {
-                                    iAction = DocumentInfo.ACTION_SKIP;
+                                    iAction = DocumentInstallationAction.SKIP;
                                 }
                             }
 
