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