01: /*
02: * ====================================================================
03: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
04: *
05: * This software is licensed as described in the file COPYING, which
06: * you should have received as part of this distribution. The terms
07: * are also available at http://svnkit.com/license.html
08: * If newer versions of this license are posted there, you may use a
09: * newer version instead, at your option.
10: * ====================================================================
11: */
12:
13: package org.tmatesoft.svn.core.internal.io.dav.handlers;
14:
15: import org.tmatesoft.svn.core.SVNErrorCode;
16: import org.tmatesoft.svn.core.SVNErrorMessage;
17: import org.tmatesoft.svn.core.SVNException;
18: import org.tmatesoft.svn.core.internal.io.dav.DAVElement;
19: import org.xml.sax.Attributes;
20:
21: /**
22: * @version 1.1.1
23: * @author TMate Software Ltd.
24: */
25: public class DAVErrorHandler extends BasicDAVHandler {
26:
27: private static final DAVElement SVN_ERROR = DAVElement.getElement(
28: DAVElement.SVN_NAMESPACE, "error");
29: private static final DAVElement ERROR_DATA = DAVElement.getElement(
30: DAVElement.SVN_APACHE_PROPERTY_NAMESPACE, "human-readable");
31:
32: private SVNErrorMessage myError;
33: private SVNErrorCode myErrorCode;
34: private String myErrorMessage;
35:
36: public DAVErrorHandler() {
37: init();
38: myErrorCode = SVNErrorCode.RA_DAV_REQUEST_FAILED;
39: myErrorMessage = "General svn error from server";
40: }
41:
42: public SVNErrorMessage getErrorMessage() {
43: return myError;
44: }
45:
46: protected void startElement(DAVElement parent, DAVElement element,
47: Attributes attrs) throws SVNException {
48: if (element == SVN_ERROR) {
49: myErrorMessage = "General svn error from server";
50: myError = SVNErrorMessage.create(myErrorCode,
51: myErrorMessage);
52: } else if (element == ERROR_DATA) {
53: String errCode = attrs.getValue("errcode");
54: if (errCode != null) {
55: try {
56: myErrorCode = SVNErrorCode.getErrorCode(Integer
57: .parseInt(errCode));
58: myError = SVNErrorMessage.create(myErrorCode,
59: myErrorMessage);
60: } catch (NumberFormatException nfe) {
61: }
62: }
63: }
64: }
65:
66: protected void endElement(DAVElement parent, DAVElement element,
67: StringBuffer cdata) throws SVNException {
68: if (element == ERROR_DATA && cdata != null) {
69: String errorMessage = cdata.toString();
70: while (errorMessage.endsWith("\n")) {
71: errorMessage = errorMessage.substring(0, errorMessage
72: .length() - 1);
73: }
74: while (errorMessage.startsWith("\n")) {
75: errorMessage = errorMessage.substring(1);
76: }
77: myErrorMessage = errorMessage;
78: myError = SVNErrorMessage.create(myErrorCode,
79: myErrorMessage);
80: }
81: }
82: }
|