Skip to content

Commit

Permalink
Linking to the actual EPSG database version, fix a bug introduced whi…
Browse files Browse the repository at this point in the history
…le trying to make unparsable wkt searchable anyways

git-svn-id: http://svn.opengeo.org/prj2epsg/trunk@31 2b570a05-cf41-4656-bcd1-a58c8d0808ed
  • Loading branch information
aaime committed Jun 3, 2010
1 parent 9e5b7a4 commit 33dc5c1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/main/java/org/opengeo/prj2epsg/BaseResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Logger;

import org.geotools.referencing.factory.epsg.ThreadedHsqlEpsgFactory;
import org.geotools.util.logging.Logging;
import org.json.JSONException;
import org.json.JSONObject;
import org.restlet.Context;
Expand Down Expand Up @@ -36,6 +39,8 @@
*
*/
public class BaseResource extends Resource {
protected static final Logger LOGGER = Logging.getLogger("prj2epsg");

protected Map<String, Object> dataModel = new LinkedHashMap<String, Object>();

protected String type;
Expand All @@ -48,8 +53,9 @@ public BaseResource(Context context, Request request, Response response) {
// grab the type if possible
type = (String) request.getAttributes().get("type");

// set the root
// set the root and the epsg version
dataModel.put("html_webroot", request.getRootRef().toString());
dataModel.put("html_epsg_version", ThreadedHsqlEpsgFactory.VERSION.toString());
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/opengeo/prj2epsg/Prj2EPSG.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.geotools.referencing.ReferencingFactoryFinder;
import org.geotools.referencing.factory.AbstractAuthorityFactory;
import org.geotools.referencing.factory.DeferredAuthorityFactory;
import org.geotools.referencing.factory.epsg.ThreadedHsqlEpsgFactory;
import org.geotools.util.WeakCollectionCleaner;
import org.geotools.util.logging.Logging;
import org.opengis.referencing.AuthorityFactory;
Expand Down Expand Up @@ -102,7 +103,7 @@ public synchronized void start() throws Exception {
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);
File directory = new File(System.getProperty("java.io.tmpdir", "."), "Geotools");
if (directory.isDirectory() || directory.mkdir()) {
directory = new File(directory, "LuceneIndex-" + 123);
directory = new File(directory, "LuceneIndex-" + ThreadedHsqlEpsgFactory.VERSION);
directory.mkdir();
}
if (directory.exists() && directory.isDirectory()) {
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/org/opengeo/prj2epsg/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
Expand Down Expand Up @@ -114,11 +115,13 @@ private void lookupAuto(String terms) throws ResourceException {
// some parameters GT2 cannot parse. If it is, Lucene won't be happy either with it,
// so let's check and cleanup a bit the search string.

String start = terms.trim().substring(0, 10).toUpperCase();
if(start.startsWith("PROJCS") || start.startsWith("GEOGCS") || start.startsWith("COMPD_CS")) {
// remove parenthesis and common terms
String cleaned = terms.replaceAll("(COMPD_CS|PROJCS|GEOGCS|DATUM|SPHEROID|TOWGS84|AUTHORITY|PRIMEM|UNIT|AXIS|AUTHORITY|PARAMETER|PROJECTION|VERT_CS|[\\[\\],\\n\\r]+)", " ");
terms = cleaned;
if(terms.length() > 7) {
String start = terms.trim().substring(0, 7).toUpperCase();
if(start.startsWith("PROJCS") || start.startsWith("GEOGCS") || start.startsWith("COMPD_CS")) {
// remove parenthesis and common terms
String cleaned = terms.replaceAll("(COMPD_CS|PROJCS|GEOGCS|DATUM|SPHEROID|TOWGS84|AUTHORITY|PRIMEM|UNIT|AXIS|AUTHORITY|PARAMETER|PROJECTION|VERT_CS|[\\[\\],\\n\\r]+)", " ");
terms = cleaned;
}
}

lookupFromLucene(terms);
Expand Down Expand Up @@ -267,6 +270,7 @@ public Representation represent(Variant variant) throws ResourceException {
}
}
} catch(Throwable t) {
LOGGER.log(Level.SEVERE, "Search failure: " + t.getMessage(), t);
if(t instanceof ResourceException) {
throw (ResourceException) t;
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/org/opengeo/prj2epsg/epsgcode.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ul>

<strong>WKT representation:</strong>
<textarea>
<textarea readonly="true">
${wkt}
</textarea>

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/org/opengeo/prj2epsg/tail.ftl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
</div>
<div class="footer">
<h2>About</h2>
<p>This service was built by <a href="http://www.opengeo.org">OpenGeo</a> using Geotools, Restlet, Freemarker, Lucene and version 7.4.0 of the official <a href="http://www.epsg.org/">ESPG</a> database. Hosting is generously provided by <a href="http://www.skygoneinc.com/">SkyGone</a>. This site is also available as a set of web services, see the <a href="${html_webroot}/apidocs.html">API documentation</a> for details.</p>
<p>This service was built by <a href="http://www.opengeo.org">OpenGeo</a> using Geotools, Restlet, Freemarker, Lucene and version ${html_epsg_version} of the official <a href="http://www.epsg.org/">ESPG</a> database. Hosting is generously provided by <a href="http://www.skygoneinc.com/">SkyGone</a>. This site is also available as a set of web services, see the <a href="${html_webroot}/apidocs.html">API documentation</a> for details.</p>
</div><!-- End .footer -->
</div> <!-- End .content -->
</body>
Expand Down

0 comments on commit 33dc5c1

Please sign in to comment.