1*a1b4a26bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*a1b4a26bSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*a1b4a26bSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*a1b4a26bSAndrew Rist  * distributed with this work for additional information
6*a1b4a26bSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*a1b4a26bSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*a1b4a26bSAndrew Rist  * "License"); you may not use this file except in compliance
9*a1b4a26bSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*a1b4a26bSAndrew Rist  *
11*a1b4a26bSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*a1b4a26bSAndrew Rist  *
13*a1b4a26bSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*a1b4a26bSAndrew Rist  * software distributed under the License is distributed on an
15*a1b4a26bSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*a1b4a26bSAndrew Rist  * KIND, either express or implied.  See the License for the
17*a1b4a26bSAndrew Rist  * specific language governing permissions and limitations
18*a1b4a26bSAndrew Rist  * under the License.
19*a1b4a26bSAndrew Rist  *
20*a1b4a26bSAndrew Rist  *************************************************************/
21*a1b4a26bSAndrew Rist 
22*a1b4a26bSAndrew Rist 
23cdf0e10cSrcweir package com.sun.star.wizards.web;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.awt.XWindowPeer;
26cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
27cdf0e10cSrcweir import com.sun.star.wizards.common.JavaTools;
28cdf0e10cSrcweir import com.sun.star.wizards.web.data.CGDocument;
29cdf0e10cSrcweir import com.sun.star.wizards.web.data.CGPublish;
30cdf0e10cSrcweir 
31cdf0e10cSrcweir /**
32cdf0e10cSrcweir  * @author rpiterman
33cdf0e10cSrcweir  * used to interact error accuring when generating the
34cdf0e10cSrcweir  * web-site to the user.
35cdf0e10cSrcweir  * This class renders the different errors,
36cdf0e10cSrcweir  * replaceing some strings from the resources with
37cdf0e10cSrcweir  * content of the given arguments, depending on the error
38cdf0e10cSrcweir  * that accured.
39cdf0e10cSrcweir  */
40cdf0e10cSrcweir public class ProcessErrorHandler extends AbstractErrorHandler
41cdf0e10cSrcweir         implements WebWizardConst,
42cdf0e10cSrcweir         ProcessErrors
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 
45cdf0e10cSrcweir     private static final String FILENAME = "%FILENAME";
46cdf0e10cSrcweir     private static final String URL = "%URL";
47cdf0e10cSrcweir     private static final String ERROR = "%ERROR";
48cdf0e10cSrcweir     WebWizardDialogResources resources;
49cdf0e10cSrcweir 
ProcessErrorHandler(XMultiServiceFactory xmsf, XWindowPeer peer, WebWizardDialogResources res)50cdf0e10cSrcweir     public ProcessErrorHandler(XMultiServiceFactory xmsf, XWindowPeer peer, WebWizardDialogResources res)
51cdf0e10cSrcweir     {
52cdf0e10cSrcweir         super(xmsf, peer);
53cdf0e10cSrcweir         resources = res;
54cdf0e10cSrcweir     }
55cdf0e10cSrcweir 
getMessageFor(Exception ex, Object obj, int ix, int errType)56cdf0e10cSrcweir     protected String getMessageFor(Exception ex, Object obj, int ix, int errType)
57cdf0e10cSrcweir     {
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         switch (ix)
60cdf0e10cSrcweir         {
61cdf0e10cSrcweir 
62cdf0e10cSrcweir             case ERROR_MKDIR:
63cdf0e10cSrcweir                 return JavaTools.replaceSubString(resources.resErrDocExport, ((CGDocument) obj).localFilename, FILENAME);
64cdf0e10cSrcweir             case ERROR_EXPORT_MKDIR:
65cdf0e10cSrcweir                 return JavaTools.replaceSubString(resources.resErrMkDir, ((CGDocument) obj).localFilename, FILENAME);
66cdf0e10cSrcweir             case ERROR_DOC_VALIDATE:
67cdf0e10cSrcweir                 return JavaTools.replaceSubString(resources.resErrDocInfo, ((CGDocument) obj).localFilename, FILENAME);
68cdf0e10cSrcweir             case ERROR_EXPORT_IO:
69cdf0e10cSrcweir                 return JavaTools.replaceSubString(resources.resErrExportIO, ((CGDocument) obj).localFilename, FILENAME);
70cdf0e10cSrcweir             case ERROR_EXPORT_SECURITY:
71cdf0e10cSrcweir                 return JavaTools.replaceSubString(resources.resErrSecurity, ((CGDocument) obj).localFilename, FILENAME);
72cdf0e10cSrcweir             case ERROR_GENERATE_XSLT:
73cdf0e10cSrcweir                 return resources.resErrTOC;
74cdf0e10cSrcweir             case ERROR_GENERATE_COPY:
75cdf0e10cSrcweir                 return resources.resErrTOCMedia;
76cdf0e10cSrcweir             case ERROR_PUBLISH:
77cdf0e10cSrcweir                 return JavaTools.replaceSubString(resources.resErrPublish, ((CGPublish) obj).cp_URL, URL);
78cdf0e10cSrcweir             case ERROR_EXPORT:
79cdf0e10cSrcweir             case ERROR_PUBLISH_MEDIA:
80cdf0e10cSrcweir                 return resources.resErrPublishMedia;
81cdf0e10cSrcweir             case ERROR_CLEANUP:
82cdf0e10cSrcweir                 return resources.resErrUnexpected;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir             default:
85cdf0e10cSrcweir                 return JavaTools.replaceSubString(resources.resErrUnknown, ex.getClass().getName() + "/" + obj.getClass().getName() + "/" + ix, ERROR);
86cdf0e10cSrcweir         }
87cdf0e10cSrcweir     }
88cdf0e10cSrcweir }
89