1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package com.sun.star.wizards.web;
28 
29 import com.sun.star.awt.XWindowPeer;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.wizards.common.JavaTools;
32 import com.sun.star.wizards.web.data.CGDocument;
33 import com.sun.star.wizards.web.data.CGPublish;
34 
35 /**
36  * @author rpiterman
37  * used to interact error accuring when generating the
38  * web-site to the user.
39  * This class renders the different errors,
40  * replaceing some strings from the resources with
41  * content of the given arguments, depending on the error
42  * that accured.
43  */
44 public class ProcessErrorHandler extends AbstractErrorHandler
45         implements WebWizardConst,
46         ProcessErrors
47 {
48 
49     private static final String FILENAME = "%FILENAME";
50     private static final String URL = "%URL";
51     private static final String ERROR = "%ERROR";
52     WebWizardDialogResources resources;
53 
54     public ProcessErrorHandler(XMultiServiceFactory xmsf, XWindowPeer peer, WebWizardDialogResources res)
55     {
56         super(xmsf, peer);
57         resources = res;
58     }
59 
60     protected String getMessageFor(Exception ex, Object obj, int ix, int errType)
61     {
62 
63         switch (ix)
64         {
65 
66             case ERROR_MKDIR:
67                 return JavaTools.replaceSubString(resources.resErrDocExport, ((CGDocument) obj).localFilename, FILENAME);
68             case ERROR_EXPORT_MKDIR:
69                 return JavaTools.replaceSubString(resources.resErrMkDir, ((CGDocument) obj).localFilename, FILENAME);
70             case ERROR_DOC_VALIDATE:
71                 return JavaTools.replaceSubString(resources.resErrDocInfo, ((CGDocument) obj).localFilename, FILENAME);
72             case ERROR_EXPORT_IO:
73                 return JavaTools.replaceSubString(resources.resErrExportIO, ((CGDocument) obj).localFilename, FILENAME);
74             case ERROR_EXPORT_SECURITY:
75                 return JavaTools.replaceSubString(resources.resErrSecurity, ((CGDocument) obj).localFilename, FILENAME);
76             case ERROR_GENERATE_XSLT:
77                 return resources.resErrTOC;
78             case ERROR_GENERATE_COPY:
79                 return resources.resErrTOCMedia;
80             case ERROR_PUBLISH:
81                 return JavaTools.replaceSubString(resources.resErrPublish, ((CGPublish) obj).cp_URL, URL);
82             case ERROR_EXPORT:
83             case ERROR_PUBLISH_MEDIA:
84                 return resources.resErrPublishMedia;
85             case ERROR_CLEANUP:
86                 return resources.resErrUnexpected;
87 
88             default:
89                 return JavaTools.replaceSubString(resources.resErrUnknown, ex.getClass().getName() + "/" + obj.getClass().getName() + "/" + ix, ERROR);
90         }
91     }
92 }
93