1 /*******************************************************************************
2 * Gisgraphy Project
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17 *
18 * Copyright 2008 Gisgraphy project
19 * David Masclet <davidmasclet@gisgraphy.com>
20 *
21 *
22 *******************************************************************************/
23 /**
24 *
25 */
26 package com.gisgraphy.domain.geoloc.service.geoloc;
27
28 import com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor;
29 import com.gisgraphy.domain.valueobject.Output.OutputFormat;
30
31 /**
32 * Visitor (visitor pattern) to return error message according to the format for
33 * the geoloc service
34 *
35 * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
36 *
37 */
38 public class StreetSearchErrorVisitor implements IoutputFormatVisitor {
39
40
41
42 private String errorMessage = IoutputFormatVisitor.DEFAULT_ERROR_MESSAGE;
43
44 public StreetSearchErrorVisitor() {
45 super();
46 }
47
48 /**
49 * @param errorMessage
50 * The error Message
51 */
52 public StreetSearchErrorVisitor(String errorMessage) {
53 super();
54 this.errorMessage = errorMessage;
55 }
56
57 /*
58 * (non-Javadoc)
59 *
60 * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitXML(com.gisgraphy.domain.valueobject.Output.OutputFormat)
61 */
62 public String visitXML(OutputFormat format) {
63 return String
64 .format(
65 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><results xmlns=\"http://gisgraphy.com\"><error>%s</error><numFound>0</numFound></results>",
66 errorMessage);
67 }
68
69 /*
70 * (non-Javadoc)
71 *
72 * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitJSON(com.gisgraphy.domain.valueobject.Output.OutputFormat)
73 */
74 public String visitJSON(OutputFormat format) {
75 return String.format("{\"numFound\":0,\"error\":\"%s\",\"result\":[]}",
76 errorMessage);
77 }
78
79 /*
80 * (non-Javadoc)
81 *
82 * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitPYTHON(com.gisgraphy.domain.valueobject.Output.OutputFormat)
83 */
84 public String visitPYTHON(OutputFormat format) {
85 return visitXML(format);
86 }
87
88 /*
89 * (non-Javadoc)
90 *
91 * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitRUBY(com.gisgraphy.domain.valueobject.Output.OutputFormat)
92 */
93 public String visitRUBY(OutputFormat format) {
94 return visitXML(format);
95 }
96
97 /*
98 * (non-Javadoc)
99 *
100 * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitPHP(com.gisgraphy.domain.valueobject.Output.OutputFormat)
101 */
102 public String visitPHP(OutputFormat format) {
103 return visitXML(format);
104 }
105
106 /*
107 * (non-Javadoc)
108 *
109 * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitATOM(com.gisgraphy.domain.valueobject.Output.OutputFormat)
110 */
111 public String visitATOM(OutputFormat outputFormat) {
112 return visitXML(outputFormat);
113 }
114
115 /*
116 * (non-Javadoc)
117 *
118 * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitGEORSS(com.gisgraphy.domain.valueobject.Output.OutputFormat)
119 */
120 public String visitGEORSS(OutputFormat outputFormat) {
121 return visitXML(outputFormat);
122 }
123
124
125 /* (non-Javadoc)
126 * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#getErrorMessage()
127 */
128 public String getErrorMessage() {
129 return errorMessage;
130 }
131
132 }