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   * 
20   *   David Masclet <davidmasclet@gisgraphy.com>
21   ******************************************************************************/
22  package com.gisgraphy.fulltext;
23  
24  import com.gisgraphy.domain.valueobject.Output;
25  import com.gisgraphy.domain.valueobject.Output.OutputStyle;
26  
27  public class OutputStyleHelper {
28      
29      public String getFulltextFieldList(OutputStyle outputStyle,String languageCode){
30  	if (outputStyle == Output.OutputStyle.SHORT){
31  	    return new StringBuffer("score,").append(
32  			FullTextFields.FEATUREID.getValue()).append(",")
33  			.append(FullTextFields.NAME.getValue()).append(",")
34  			.append(FullTextFields.FULLY_QUALIFIED_NAME.getValue())
35  			.append(",").append(FullTextFields.ZIPCODE.getValue())
36  			.append(",")
37  			.append(FullTextFields.PLACETYPE.getValue())
38  			.append(",").append(
39  				FullTextFields.COUNTRYCODE.getValue())
40  			.append(",").append(
41  				FullTextFields.COUNTRYNAME.getValue())
42  			.toString();
43  	    
44  	} else if (outputStyle == Output.OutputStyle.MEDIUM){
45  	    return new StringBuffer(getFulltextFieldList(OutputStyle.SHORT,languageCode))
46  		.append(",").append(FullTextFields.ONE_WAY.getValue())
47  		.append(",").append(FullTextFields.LENGTH.getValue())
48  		.append(",").append(FullTextFields.STREET_TYPE.getValue())
49  		.append(",").append(FullTextFields.OPENSTREETMAP_ID.getValue())
50  		.append(",").append(FullTextFields.LAT.getValue())
51  		.append(",").append(FullTextFields.LONG.getValue())
52  		.append(",").append(
53  			FullTextFields.FEATURECLASS.getValue()).append(
54  			",").append(
55  			FullTextFields.FEATURECODE.getValue()).append(
56  			",").append(
57  			FullTextFields.POPULATION.getValue()).append(
58  			",")
59  		.append(FullTextFields.NAMEASCII.getValue())
60  		.append(",").append(FullTextFields.TIMEZONE.getValue())
61  		.append(",").append(FullTextFields.ELEVATION.getValue())
62  		
63  		//country fields only
64  		.append(",").append(FullTextFields.CONTINENT.getValue())
65  		.append(",").append(FullTextFields.CURRENCY_CODE.getValue())
66  		.append(",").append(FullTextFields.CURRENCY_NAME.getValue())
67  		.append(",").append(FullTextFields.FIPS_CODE.getValue())
68  		.append(",").append(FullTextFields.ISOALPHA2_COUNTRY_CODE.getValue())
69  		.append(",").append(FullTextFields.ISOALPHA3_COUNTRY_CODE.getValue())
70  		.append(",").append(FullTextFields.POSTAL_CODE_MASK.getValue())
71  		.append(",").append(FullTextFields.POSTAL_CODE_REGEX.getValue())
72  		.append(",").append(FullTextFields.PHONE_PREFIX.getValue())
73  		.append(",").append(FullTextFields.SPOKEN_LANGUAGES.getValue())
74  		.append(",").append(FullTextFields.TLD.getValue())
75  		.append(",").append(FullTextFields.CAPITAL_NAME.getValue())
76  		.append(",").append(FullTextFields.AREA.getValue())
77  		.append(",").append(FullTextFields.IS_IN.getValue())
78  		.append(",").append(FullTextFields.IS_IN_PLACE.getValue())
79  		.append(",").append(FullTextFields.IS_IN_ADM.getValue())
80  		.append(",").append(FullTextFields.IS_IN_ZIP.getValue())
81  		.append(",").append(FullTextFields.FULLY_QUALIFIED_ADDRESS.getValue())
82  		.append(",").append(FullTextFields.HOUSE_NUMBERS.getValue())
83  		.append(",").append(FullTextFields.AMENITY.getValue())
84  		.append(",").append(FullTextFields.MUNICIPALITY.getValue())
85  		
86  		//adm only
87  		.append(",").append(FullTextFields.LEVEL.getValue())
88  		
89  		.append(",").append(FullTextFields.GTOPO30.getValue())
90  		.append(",").append(
91  			FullTextFields.COUNTRY_FLAG_URL.getValue())
92  		.append(",").append(
93  			FullTextFields.GOOGLE_MAP_URL.getValue())
94  		.append(",").append(
95  			FullTextFields.YAHOO_MAP_URL.getValue())
96  			.append(",").append(
97  			FullTextFields.OPENSTREETMAP_MAP_URL.getValue())
98  		.toString();
99  	} else if (outputStyle == Output.OutputStyle.LONG){
100 	    StringBuffer sb = new StringBuffer(getFulltextFieldList(OutputStyle.MEDIUM,languageCode)).append(",").append(
101 			FullTextFields.ADM1NAME.getValue()).append(",").append(
102 			FullTextFields.ADM2NAME.getValue()).append(",").append(
103 			FullTextFields.ADM3NAME.getValue()).append(",").append(
104 			FullTextFields.ADM4NAME.getValue()).append(",").append(
105 			FullTextFields.ADM1CODE.getValue()).append(",").append(
106 			FullTextFields.ADM2CODE.getValue()).append(",").append(
107 			FullTextFields.ADM3CODE.getValue()).append(",").append(
108 			FullTextFields.ADM4CODE.getValue());
109 		return sb.toString();
110 	}else if (outputStyle == Output.OutputStyle.FULL){
111 	    if (languageCode != null) {
112 		    StringBuffer sb = new StringBuffer(getFulltextFieldList(OutputStyle.LONG,languageCode)).append(",").append(
113 			    FullTextFields.COUNTRYNAME.getValue()).append(
114 			    FullTextFields.ALTERNATE_NAME_SUFFIX.getValue())
115 			    .append(",").append(
116 				    FullTextFields.ADM1NAME.getValue()).append(
117 				    FullTextFields.ALTERNATE_NAME_SUFFIX
118 					    .getValue()).append(",").append(
119 				    FullTextFields.ADM2NAME.getValue()).append(
120 				    FullTextFields.ALTERNATE_NAME_SUFFIX
121 					    .getValue()).append(",").append(
122 				    FullTextFields.NAME.getValue()).append(
123 				    FullTextFields.ALTERNATE_NAME_DYNA_SUFFIX
124 					    .getValue()).append(languageCode)
125 			    .append(",").append(FullTextFields.NAME.getValue())
126 			    .append(
127 				    FullTextFields.ALTERNATE_NAME_SUFFIX
128 					    .getValue()).append(",").append(
129 				    FullTextFields.COUNTRYNAME.getValue())
130 			    .append(
131 				    FullTextFields.ALTERNATE_NAME_DYNA_SUFFIX
132 					    .getValue()).append(languageCode)
133 			    .append(",").append(
134 				    FullTextFields.ADM1NAME.getValue()).append(
135 				    FullTextFields.ALTERNATE_NAME_DYNA_SUFFIX
136 					    .getValue()).append(languageCode)
137 			    .append(",").append(
138 				    FullTextFields.ADM2NAME.getValue()).append(
139 				    FullTextFields.ALTERNATE_NAME_DYNA_SUFFIX
140 					    .getValue()).append(languageCode);
141 
142 		    return sb.toString();
143 		} else {
144 		    return "*,score";
145 		}
146 	} else { 
147 	    throw new RuntimeException(outputStyle+" is not implemented");
148 	}
149     }
150     
151     public String getFulltextFieldList(Output output){
152 	return getFulltextFieldList(output.getStyle(),output.getLanguageCode());
153 	
154     }
155 
156 }