View Javadoc
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.fulltext;
27  
28  import com.gisgraphy.serializer.common.IoutputFormatVisitor;
29  import com.gisgraphy.serializer.common.OutputFormat;
30  
31  /**
32   * Visitor (visitor pattern) to return error message according to the format for
33   * the fulltext service
34   * 
35   * @author <a href="mailto:david.masclet@gisgraphy.com">David Masclet</a>
36   * 
37   */
38  public class FulltextErrorVisitor implements IoutputFormatVisitor {
39  
40      private String errorMessage = IoutputFormatVisitor.DEFAULT_ERROR_MESSAGE;
41  
42      public FulltextErrorVisitor() {
43  	super();
44      }
45  
46      /**
47       * @param errorMessage
48       *                The error Message
49       */
50      public FulltextErrorVisitor(String errorMessage) {
51  	super();
52  	this.errorMessage = errorMessage;
53      }
54  
55      /*
56       * (non-Javadoc)
57       * 
58       * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitXML(com.gisgraphy.domain.valueobject.Output.OutputFormat)
59       */
60      public String visitXML(OutputFormat format) {
61  	return String
62  		.format(
63  			"<?xml version=\"1.0\" encoding=\"UTF-8\"?><response><lst name=\"responseHeader\"><int name=\"status\">-1</int><str name=\"error\">%s</str><int name=\"QTime\">1</int></lst><result name=\"response\" numFound=\"0\" start=\"0\" maxScore=\"0.0\"/></response>",
64  			errorMessage);
65      }
66  
67      /*
68       * (non-Javadoc)
69       * 
70       * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitJSON(com.gisgraphy.domain.valueobject.Output.OutputFormat)
71       */
72      public String visitJSON(OutputFormat format) {
73  	return String
74  		.format(
75  			"{\"responseHeader\":{\"status\":-1,\"error\":\"%s\",\"QTime\":2},\"response\":{\"numFound\":0,\"start\":0,\"maxScore\":0.0,\"docs\":[]}}",
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 String
86  		.format(
87  			"{'responseHeader':{'status':-1,'error':'%s','QTime':4},'response':{'numFound':0,'start':0,'maxScore':0.0,'docs':[]}}",
88  			errorMessage);
89      }
90  
91      /*
92       * (non-Javadoc)
93       * 
94       * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitRUBY(com.gisgraphy.domain.valueobject.Output.OutputFormat)
95       */
96      public String visitRUBY(OutputFormat format) {
97  	return String
98  		.format(
99  			"{'responseHeader'=>{'status'=>0,'error'=>'%s','QTime'=>1},'response'=>{'numFound'=>0,'start'=>0,'maxScore'=>0.0,'docs'=>[]}}",
100 			errorMessage);
101     }
102 
103     /*
104      * (non-Javadoc)
105      * 
106      * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitPHP(com.gisgraphy.domain.valueobject.Output.OutputFormat)
107      */
108     public String visitPHP(OutputFormat format) {
109 	return String
110 		.format(
111 			"array('responseHeader'=>array('status'=>0,'error'=>'%s','QTime'=>12),'response'=>array('numFound'=>0,'start'=>0,'maxScore'=>0.0,'docs'=>array() ))",
112 			errorMessage);
113     }
114 
115     /*
116      * (non-Javadoc)
117      * 
118      * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitATOM(com.gisgraphy.domain.valueobject.Output.OutputFormat)
119      */
120     public String visitATOM(OutputFormat outputFormat) {
121 	return visitXML(outputFormat);
122     }
123 
124     /*
125      * (non-Javadoc)
126      * 
127      * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitGEORSS(com.gisgraphy.domain.valueobject.Output.OutputFormat)
128      */
129     public String visitGEORSS(OutputFormat outputFormat) {
130 	return visitXML(outputFormat);
131     }
132     
133     /* (non-Javadoc)
134      * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitUNSUPPORTED(com.gisgraphy.domain.valueobject.Output.OutputFormat)
135      */
136     public String visitUNSUPPORTED(OutputFormat format) {
137 		return "";
138 	}
139     
140     /* (non-Javadoc)
141      * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#visitUNSUPPORTED(com.gisgraphy.domain.valueobject.Output.OutputFormat)
142      */
143     public String visitYAML(OutputFormat format) {
144 		return errorMessage;
145 	}
146     
147 
148     /* (non-Javadoc)
149      * @see com.gisgraphy.domain.geoloc.service.errors.IoutputFormatVisitor#getErrorMessage()
150      */
151     public String getErrorMessage() {
152         return errorMessage;
153     }
154 
155 	
156 
157 }