[Schmitzm-commits] r456 - branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sun Oct 11 23:43:40 CEST 2009
Author: alfonx
Date: 2009-10-11 23:43:40 +0200 (Sun, 11 Oct 2009)
New Revision: 456
Modified:
branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/LabelSearch.java
Log:
* Feature iterator has to be closed!
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/LabelSearch.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/LabelSearch.java 2009-10-11 21:41:53 UTC (rev 455)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/LabelSearch.java 2009-10-11 21:43:40 UTC (rev 456)
@@ -64,14 +64,11 @@
*/
public class LabelSearch {
final static private Logger LOGGER = Logger.getLogger(LabelSearch.class);
-
+
public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil
- .extendPackagePath(LabelSearch.class,
- "labelsearch"), Locale.ENGLISH);
-
-
-
-
+ .extendPackagePath(LabelSearch.class, "labelsearch"),
+ Locale.ENGLISH);
+
public static String R(String key, Object... values) {
return RESOURCE.getString(key, values);
}
@@ -83,7 +80,7 @@
}
/**
- * The Attribute that provides the labels for this text symbolizer.
+ * The Attribute that provides the labels for this text symbolizer.
*/
private AttributeDescriptor getLabelAttribute(final TextSymbolizer ts,
final SimpleFeatureType schema) {
@@ -91,7 +88,7 @@
// This layer has no labels
return null;
}
-
+
final Expression labelExp = ts.getLabel();
if (labelExp instanceof PropertyName) {
final PropertyName pn = (PropertyName) labelExp;
@@ -99,7 +96,8 @@
return schema.getDescriptor(propertyName);
} else {
// When does this happen
- throw new RuntimeException("labelExp "+labelExp+" IS NOT instanceof PropertyName!");
+ throw new RuntimeException("labelExp " + labelExp
+ + " IS NOT instanceof PropertyName!");
}
}
@@ -118,19 +116,20 @@
if (!ml.isVisible())
continue;
- final List<TextSymbolizer> allTS = StylingUtil.getVisibleTextSymbolizers(ml
- .getStyle());
+ final List<TextSymbolizer> allTS = StylingUtil
+ .getVisibleTextSymbolizers(ml.getStyle());
if (allTS.size() == 0) {
// A layer without any TextSymbolizer doesn't have to be
// searched any more.
continue;
}
-
- final FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = (FeatureSource<SimpleFeatureType, SimpleFeature>) ml.getFeatureSource();
-
- final String typeName = featureSource.getSchema()
- .getName().getLocalPart();
+ final FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = (FeatureSource<SimpleFeatureType, SimpleFeature>) ml
+ .getFeatureSource();
+
+ final String typeName = featureSource.getSchema().getName()
+ .getLocalPart();
+
// Expression labelExp = ts.getLabel();
// ff.like(labelExp, "*"+searchMe+"*");
// FeatureCollection features =
@@ -138,8 +137,8 @@
// new DefaultQuery(typeName, ff.like(labelExp,
// "*"+searchMe+"*"), properties));
- final FeatureCollection<SimpleFeatureType, SimpleFeature> features = featureSource.getFeatures(
- new DefaultQuery(typeName, Filter.INCLUDE));
+ final FeatureCollection<SimpleFeatureType, SimpleFeature> features = featureSource
+ .getFeatures(new DefaultQuery(typeName, Filter.INCLUDE));
// new MemoryDataStore().getFeatureSource(typeName)
@@ -149,60 +148,72 @@
* function.
*/
final Iterator<SimpleFeature> fi = features.iterator();
- while (fi.hasNext()) {
- final SimpleFeature f = fi.next();
+ try {
- final TextSymbolizer ts = StylingUtil.getTextSymbolizer(ml
- .getStyle(), f);
- if (ts == null)
- continue;
+ while (fi.hasNext()) {
+ final SimpleFeature f = fi.next();
- // TODO Evaluate the Rule that belongs to the TextSymbolizer against the feature...
- final AttributeDescriptor labelAttribute = getLabelAttribute(ts, featureSource.getSchema());
+ final TextSymbolizer ts = StylingUtil
+ .getTextSymbolizer(ml.getStyle(), f);
+ if (ts == null)
+ continue;
- if (labelAttribute == null) {
- continue;
- }
+ // TODO Evaluate the Rule that belongs to the
+ // TextSymbolizer against the feature...
+ final AttributeDescriptor labelAttribute = getLabelAttribute(
+ ts, featureSource.getSchema());
- // System.out.println("labelAttrib local name" +
- // labelAttribute.getLocalName());
+ if (labelAttribute == null) {
+ continue;
+ }
- final Object value = f
- .getAttribute(labelAttribute.getLocalName());
+ // System.out.println("labelAttrib local name" +
+ // labelAttribute.getLocalName());
- // System.out.println("labelAttrib value " + value);
+ final Object value = f.getAttribute(labelAttribute
+ .getLocalName());
- if (value == null) {
- LOGGER.info("Skipping f: getLocalName() is null for feature="+f);
- continue;
- }
+ // System.out.println("labelAttrib value " + value);
- /**
- * LabelString ist z.B. "IMPETUS pluviograph". Suchwort
- * "plu" soll treffen. Also wird nach spaces zerlegt und
- * dann gesucht
- */
- final String labelString = value.toString().toLowerCase();
- if (labelString.startsWith(searchMe)) {
- hits.add(createSearchResult(f, value.toString(), ml
- .getTitle(),ml));
- } else {
- final String[] parts = labelString.trim().split(" ");
- for (final String part : parts) {
- if (part.startsWith(searchMe)) {
- hits.add(createSearchResult(f, value.toString(), ml
- .getTitle(), ml));
- break;
+ if (value == null) {
+ LOGGER
+ .info("Skipping f: getLocalName() is null for feature="
+ + f);
+ continue;
+ }
+
+ /**
+ * LabelString ist z.B. "IMPETUS pluviograph". Suchwort
+ * "plu" soll treffen. Also wird nach spaces zerlegt und
+ * dann gesucht
+ */
+ final String labelString = value.toString()
+ .toLowerCase();
+ if (labelString.startsWith(searchMe)) {
+ hits.add(createSearchResult(f, value.toString(), ml
+ .getTitle(), ml));
+ } else {
+ final String[] parts = labelString.trim()
+ .split(" ");
+ for (final String part : parts) {
+ if (part.startsWith(searchMe)) {
+ hits.add(createSearchResult(f, value
+ .toString(), ml.getTitle(), ml));
+ break;
+ }
}
}
+
}
-
+ } finally {
+ features.close(fi);
}
} catch (final IOException e) {
// Searching this layer failed
LOGGER.error(e);
}
+
} // next layer
// Hits from the top-most layer should appear first.
@@ -211,8 +222,8 @@
return hits;
}
- protected SearchResult createSearchResult(final SimpleFeature f, final String title,
- final String inTitle, MapLayer ml) {
+ protected SearchResult createSearchResult(final SimpleFeature f,
+ final String title, final String inTitle, MapLayer ml) {
return new SearchResultFeature(f, title, inTitle, mapPane, ml);
}
More information about the Schmitzm-commits
mailing list