001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005: package org.vfny.geoserver.action.data;
006:
007: import java.io.IOException;
008: import java.util.ArrayList;
009: import java.util.Collections;
010: import java.util.HashSet;
011: import java.util.List;
012: import java.util.Locale;
013: import java.util.Map;
014: import java.util.Set;
015: import java.util.logging.Level;
016:
017: import javax.servlet.ServletException;
018: import javax.servlet.http.HttpServletRequest;
019: import javax.servlet.http.HttpServletResponse;
020:
021: import org.apache.struts.action.ActionError;
022: import org.apache.struts.action.ActionErrors;
023: import org.apache.struts.action.ActionForm;
024: import org.apache.struts.action.ActionForward;
025: import org.apache.struts.action.ActionMapping;
026: import org.apache.struts.util.MessageResources;
027: import org.geotools.data.DataStore;
028: import org.geotools.data.DataStoreFinder;
029: import org.geotools.data.FeatureSource;
030: import org.geotools.feature.AttributeType;
031: import org.geotools.feature.FeatureType;
032: import org.geotools.geometry.jts.JTS;
033: import org.geotools.referencing.CRS;
034: import org.opengis.referencing.FactoryException;
035: import org.opengis.referencing.NoSuchAuthorityCodeException;
036: import org.opengis.referencing.crs.CoordinateReferenceSystem;
037: import org.opengis.referencing.operation.MathTransform;
038: import org.opengis.referencing.operation.TransformException;
039: import org.vfny.geoserver.action.ConfigAction;
040: import org.vfny.geoserver.action.HTMLEncoder;
041: import org.vfny.geoserver.config.AttributeTypeInfoConfig;
042: import org.vfny.geoserver.config.ConfigRequests;
043: import org.vfny.geoserver.config.DataConfig;
044: import org.vfny.geoserver.config.DataStoreConfig;
045: import org.vfny.geoserver.config.FeatureTypeConfig;
046: import org.vfny.geoserver.form.data.AttributeForm;
047: import org.vfny.geoserver.form.data.TypesEditorForm;
048: import org.vfny.geoserver.global.MetaDataLink;
049: import org.vfny.geoserver.global.UserContainer;
050: import org.vfny.geoserver.util.DataStoreUtils;
051:
052: import com.vividsolutions.jts.geom.Envelope;
053:
054: /**
055: * These Action handles all the buttons for the FeatureType Editor.
056: *
057: * <p>
058: * This one is more complicated then usual since not all the actions require
059: * the form bean to be validated! I am going to have to hack a little bit to
060: * make that happen, I may end up making the form bean validation differ
061: * depending on the selected action.
062: * </p>
063: *
064: * <p>
065: * Buttons that make this action go:
066: *
067: * <ul>
068: * <li>
069: * Submit: update the FeatureTypeConfig held by the user, punt it back into
070: * DataConfig and return to the FeatureTypeSelect screen.
071: * </li>
072: * <li>
073: * Up and Down (for each attribute): not quite sure how to make these work yet
074: * - I hope I dont have to give them different names.
075: * </li>
076: * </ul>
077: *
078: * As usual we will have to uninternationlize the action name provided to us.
079: * </p>
080: *
081: * @author Richard Gould
082: * @author Jody Garnett
083: */
084: public class TypesEditorAction extends ConfigAction {
085: public ActionForward execute(ActionMapping mapping,
086: ActionForm form, UserContainer user,
087: HttpServletRequest request, HttpServletResponse response)
088: throws IOException, ServletException {
089: if (LOGGER.isLoggable(Level.FINER)) {
090: LOGGER.finer(new StringBuffer("form bean:").append(
091: form.getClass().getName()).toString());
092: }
093:
094: TypesEditorForm typeForm = (TypesEditorForm) form;
095:
096: String action = typeForm.getAction();
097:
098: if (LOGGER.isLoggable(Level.FINER)) {
099: LOGGER.finer(new StringBuffer("TypesEditorAction is ")
100: .append(action).toString());
101: }
102:
103: Locale locale = (Locale) request.getLocale();
104: MessageResources messages = getResources(request);
105: final String SUBMIT = HTMLEncoder.decode(messages.getMessage(
106: locale, "label.submit"));
107: final String ADD = HTMLEncoder.decode(messages.getMessage(
108: locale, "label.add"));
109: final String BBOX = HTMLEncoder.decode(messages.getMessage(
110: locale, "config.data.calculateBoundingBox.label"));
111: final String LOOKUP_SRS = HTMLEncoder.decode(messages
112: .getMessage(locale, "config.data.lookupSRS.label"));
113:
114: if (LOGGER.isLoggable(Level.FINER)) {
115: LOGGER.finer(new StringBuffer("BBOX: ").append(BBOX)
116: .toString());
117: }
118:
119: final String NEWSLD = HTMLEncoder.decode(messages.getMessage(
120: locale, "config.data.sldWizard.label"));
121:
122: if (typeForm.getAutoGenerateExtent().equals("true")) {
123: if ((typeForm.getSRS() == null)
124: || typeForm.getSRS().trim().equals("0")) {
125: executeLookupSRS(mapping, typeForm, user, request);
126: }
127:
128: executeBBox(mapping, typeForm, user, request);
129:
130: return executeSubmit(mapping, typeForm, user, request);
131: }
132:
133: if (SUBMIT.equals(action)) {
134: return executeSubmit(mapping, typeForm, user, request);
135: }
136:
137: if (action.equals(BBOX)) {
138: return executeBBox(mapping, typeForm, user, request);
139: }
140:
141: if (action.equals(LOOKUP_SRS)) {
142: return executeLookupSRS(mapping, typeForm, user, request);
143: }
144:
145: if (action.equals(NEWSLD)) { // if the SLDWizard button was hit
146:
147: return mapping.findForward("SLDWizard");
148: }
149:
150: List attributes = typeForm.getAttributes();
151:
152: if (action.startsWith("up_")) {
153: int index = Integer.parseInt(action.substring(3));
154: Object attribute = attributes.remove(index);
155: attributes.add(index - 1, attribute);
156: } else if (action.startsWith("down_")) {
157: int index = Integer.parseInt(action.substring(5));
158: Object attribute = attributes.remove(index);
159: attributes.add(index + 1, attribute);
160: } else if (action.startsWith("delete_")) {
161: int index = Integer.parseInt(action.substring(7));
162: attributes.remove(index);
163: } else if (action.equals(ADD)) {
164: executeAdd(mapping, typeForm, user, request);
165: }
166:
167: // Update, Up, Down, Add, Remove need to resync
168: sync(typeForm, user.getFeatureTypeConfig(), request);
169: form.reset(mapping, request);
170:
171: return mapping.findForward("config.data.type.editor");
172: }
173:
174: private ActionForward executeLookupSRS(ActionMapping mapping,
175: TypesEditorForm typeForm, UserContainer user,
176: HttpServletRequest request) throws IOException,
177: ServletException {
178: DataConfig dataConfig = getDataConfig();
179: DataStoreConfig dsConfig = dataConfig.getDataStore(typeForm
180: .getDataStoreId());
181: DataStore dataStore = null;
182: try {
183: dataStore = dsConfig.findDataStore(request.getSession()
184: .getServletContext());
185: FeatureType featureType = dataStore.getSchema(typeForm
186: .getTypeName());
187: FeatureSource fs = dataStore.getFeatureSource(featureType
188: .getTypeName());
189:
190: CoordinateReferenceSystem crs = fs.getSchema()
191: .getDefaultGeometry().getCoordinateSystem();
192: String s = CRS.lookupIdentifier(crs, true);
193:
194: if (s == null) {
195: typeForm.setSRS("UNKNOWN");
196: } else if (s.indexOf(':') != -1) {
197: typeForm.setSRS(s.substring(s.indexOf(':') + 1));
198: } else {
199: typeForm.setSRS(s);
200: }
201: } catch (Exception e) {
202: LOGGER.log(Level.FINE,
203: "Error occurred trying to lookup the SRS", e);
204: typeForm.setSRS("UNKNOWN");
205: } finally {
206: if (dataStore != null)
207: dataStore.dispose();
208: }
209:
210: return mapping.findForward("config.data.type.editor");
211: }
212:
213: /**
214: * Populate the bounding box fields from the source and pass control back
215: * to the UI
216: *
217: * @param mapping DOCUMENT ME!
218: * @param typeForm DOCUMENT ME!
219: * @param user DOCUMENT ME!
220: * @param request DOCUMENT ME!
221: *
222: * @return DOCUMENT ME!
223: *
224: * @throws IOException DOCUMENT ME!
225: * @throws ServletException DOCUMENT ME!
226: */
227: private ActionForward executeBBox(ActionMapping mapping,
228: TypesEditorForm typeForm, UserContainer user,
229: HttpServletRequest request) throws IOException,
230: ServletException {
231: DataConfig dataConfig = getDataConfig();
232: DataStoreConfig dsConfig = dataConfig.getDataStore(typeForm
233: .getDataStoreId());
234: DataStore dataStore = null;
235: try {
236: dataStore = dsConfig.findDataStore(request.getSession()
237: .getServletContext());
238: FeatureType featureType = dataStore.getSchema(typeForm
239: .getTypeName());
240: FeatureSource fs = dataStore.getFeatureSource(featureType
241: .getTypeName());
242:
243: if (LOGGER.isLoggable(Level.FINE)) {
244: LOGGER.fine(new StringBuffer(
245: "calculating bbox for their dataset")
246: .toString());
247: }
248:
249: Envelope envelope = DataStoreUtils
250: .getBoundingBoxEnvelope(fs);
251:
252: if (envelope.isNull()) // there's no data in the featuretype!!
253: {
254: if (LOGGER.isLoggable(Level.FINE)) {
255: LOGGER.fine(new StringBuffer("FeatureType '")
256: .append(featureType.getTypeName()).append(
257: "' has a null bounding box")
258: .toString());
259: }
260:
261: ActionErrors errors = new ActionErrors();
262: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
263: "error.data.nullBBOX", featureType
264: .getTypeName()));
265: saveErrors(request, errors);
266:
267: return mapping.findForward("config.data.type.editor");
268: }
269:
270: // do a translation from the data's coordinate system to lat/long
271:
272: //TODO: DJB: NOTE: 1/2 of the config stuff has the srs as an int, 1/2 as string!! We should be more consistent!
273: String srs = typeForm.getSRS(); // what the user typed in for the srs in the form
274:
275: if (srs.indexOf(':') == -1) { // check to see if its of the form "EPSG:#" (or some such thing)
276: srs = "EPSG:" + srs; //assume they wanted to use an EPSG number
277: }
278:
279: CoordinateReferenceSystem crsDeclared = CRS.decode(srs);
280: CoordinateReferenceSystem original = null;
281:
282: if (featureType.getDefaultGeometry() != null) {
283: original = featureType.getDefaultGeometry()
284: .getCoordinateSystem();
285: }
286:
287: if (original == null) {
288: original = crsDeclared;
289: }
290:
291: CoordinateReferenceSystem crsLatLong = CRS
292: .decode("EPSG:4326"); // latlong
293:
294: // let's show coordinates in the declared crs, not in the native one, to
295: // avoid confusion (since on screen we do have the declared one, the native is
296: // not visible)
297: Envelope declaredEnvelope = envelope;
298:
299: if (!CRS.equalsIgnoreMetadata(original, crsDeclared)) {
300: MathTransform xform = CRS.findMathTransform(original,
301: crsDeclared, true);
302: declaredEnvelope = JTS.transform(envelope, null, xform,
303: 10); //convert data bbox to lat/long
304: }
305:
306: LOGGER.finer("Seeting form's data envelope: "
307: + declaredEnvelope);
308: typeForm.setDataMinX(Double.toString(declaredEnvelope
309: .getMinX()));
310: typeForm.setDataMaxX(Double.toString(declaredEnvelope
311: .getMaxX()));
312: typeForm.setDataMinY(Double.toString(declaredEnvelope
313: .getMinY()));
314: typeForm.setDataMaxY(Double.toString(declaredEnvelope
315: .getMaxY()));
316:
317: MathTransform xform = CRS.findMathTransform(original,
318: crsLatLong, true);
319: Envelope xformed_envelope = JTS.transform(envelope, xform); //convert data bbox to lat/long
320:
321: typeForm.setMinX(Double
322: .toString(xformed_envelope.getMinX()));
323: typeForm.setMaxX(Double
324: .toString(xformed_envelope.getMaxX()));
325: typeForm.setMinY(Double
326: .toString(xformed_envelope.getMinY()));
327: typeForm.setMaxY(Double
328: .toString(xformed_envelope.getMaxY()));
329: } catch (NoSuchAuthorityCodeException e) {
330: if (LOGGER.isLoggable(Level.FINE)) {
331: LOGGER.fine(e.getLocalizedMessage());
332: LOGGER.fine(e.getStackTrace().toString());
333: }
334:
335: ActionErrors errors = new ActionErrors();
336: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
337: "error.data.couldNotFindSRSAuthority", e
338: .getLocalizedMessage(), e
339: .getAuthorityCode()));
340: saveErrors(request, errors);
341:
342: return mapping.findForward("config.data.type.editor");
343: } catch (FactoryException fe) {
344: if (LOGGER.isLoggable(Level.FINE)) {
345: LOGGER.fine(fe.getLocalizedMessage());
346: LOGGER.fine(fe.getStackTrace().toString());
347: }
348:
349: ActionErrors errors = new ActionErrors();
350: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
351: "error.data.factoryException", fe
352: .getLocalizedMessage()));
353: saveErrors(request, errors);
354:
355: return mapping.findForward("config.data.type.editor");
356: } catch (TransformException te) {
357: if (LOGGER.isLoggable(Level.FINE)) {
358: LOGGER.fine(te.getLocalizedMessage());
359: LOGGER.fine(te.getStackTrace().toString());
360: }
361:
362: ActionErrors errors = new ActionErrors();
363: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
364: "error.data.transformException"));
365: saveErrors(request, errors);
366:
367: return mapping.findForward("config.data.type.editor");
368: } finally {
369: if (dataStore != null)
370: dataStore.dispose();
371: }
372:
373: return mapping.findForward("config.data.type.editor");
374: }
375:
376: /**
377: * Sync generated attributes with schemaBase.
378: *
379: * @param form
380: * @param config
381: */
382: private void sync(TypesEditorForm form, FeatureTypeConfig config,
383: HttpServletRequest request) {
384: config.setName(form.getTypeName());
385: if (form.getAlias() != null
386: && "".equals(form.getAlias().trim()))
387: config.setAlias(null);
388: else
389: config.setAlias(form.getAlias());
390: config.setAbstract(form.getAbstract());
391: config.setDefaultStyle(form.getStyleId());
392:
393: config.getStyles().clear();
394: if (form.getOtherSelectedStyles() != null) {
395:
396: for (int i = 0; i < form.getOtherSelectedStyles().length; i++) {
397: config.addStyle(form.getOtherSelectedStyles()[i]);
398: }
399: }
400:
401: config.setSRS(Integer.parseInt(form.getSRS()));
402: config.setTitle(form.getTitle());
403: Envelope latLonBbox = getBoundingBox(form);
404: // if the lat/lon bbox did not change, don't try to update stuff, since we don't have
405: // the native bbox calculated
406: if (!(config.getLatLongBBox().equals(latLonBbox) && config
407: .getSRS() == (Integer.parseInt(form.getSRS())))) {
408: config.setLatLongBBox(latLonBbox);
409: try {
410: Envelope nativeBBox = convertBBoxFromLatLon(latLonBbox,
411: "EPSG: " + config.getSRS());
412: config.setNativeBBox(nativeBBox);
413: } catch (Exception e) {
414: LOGGER
415: .severe("Couldn't convert new BBox to native coordinate system! Error was"
416: + e);
417: }
418: }
419: // may the native bbox have been changed due to a change
420: // in the CRS code by the user
421: // if(config.getNativeBBox() != null || (nativeBbox != null && !config.getNativeBBox().equals(nativeBbox))){
422: // config.setNativeBBox(nativeBbox);
423: // }
424: config.setKeywords(keyWords(form));
425: config.setMetadataLinks(metadataLinks(form));
426: config.setWmsPath(form.getWmsPath());
427: config.setCacheMaxAge(form.getCacheMaxAge());
428: config.setCachingEnabled(form.isCachingEnabled());
429: config.setMaxFeatures(Integer.parseInt(form.getMaxFeatures()));
430: config.setSRSHandling(form.getSrsHandlingCode());
431:
432: if (!form.isCachingEnabledChecked()) {
433: config.setCachingEnabled(false);
434: }
435:
436: String schemaBase = form.getSchemaBase();
437:
438: if ((schemaBase == null) || schemaBase.equals("")
439: || schemaBase.equals("--")) {
440: config.setSchemaBase(null);
441: config.setSchemaName(null);
442: config.setSchemaAttributes(null);
443: } else {
444: config.setSchemaBase(schemaBase);
445:
446: String schemaName = config.getSchemaName();
447: List schemaAttributes = config.getSchemaAttributes();
448: System.out.println("in non null sb, sname: " + schemaName
449: + ", satts: " + schemaAttributes);
450:
451: if ((schemaName == null)
452: || (schemaName.trim().length() == 0)) {
453: schemaName = form.getTypeName() + "_Type";
454: //HACK: For some reason only when editing an already exisitng
455: //featureType, on the first time of switching to the editor
456: //it gets a full schemaAttribute list, and I can't find where
457: //so for now we are just relying on schemaName being null or
458: schemaAttributes = null;
459: //System.out.println("testing on schemaAtts: " + schemaAttributes);
460: config.setSchemaName(schemaName);
461: } else {
462: config.setSchemaName(form.getSchemaName());
463: }
464:
465: if ((schemaAttributes == null)
466: || schemaAttributes.isEmpty()) {
467: schemaAttributes = new ArrayList();
468:
469: List createList = form.getCreateableAttributes();
470: System.out.println("schemaAtts null, createList: "
471: + createList);
472:
473: FeatureType fType = getFeatureType(form, request);
474:
475: for (int i = 0; i < fType.getAttributeCount(); i++) {
476: AttributeType attType = fType.getAttributeType(i);
477: AttributeTypeInfoConfig attributeConfig = new AttributeTypeInfoConfig(
478: attType);
479: schemaAttributes.add(attributeConfig);
480:
481: //new ArrayList();
482: //DataStoreConfig dsConfig = config.
483: //FeatureType featureType = config.get
484: }
485:
486: config.setSchemaAttributes(schemaAttributes);
487: } else {
488: config.setSchemaAttributes(form.toSchemaAttributes());
489: }
490: }
491:
492: // config.setSchemaAttributes(form.toSchemaAttributes());
493: LOGGER.fine("config schema atts is "
494: + config.getSchemaAttributes());
495:
496: //config.setSchemaAttributes(form.toSchemaAttributes());
497: }
498:
499: /**
500: * Convert a boudning box in latintute/longitude coordinates to another CRS, specified by name.
501: * @param latLonBbox the latitude/longitude boudning box
502: * @param crsName the name of the CRS to which it should be converted
503: * @return the converted bounding box
504: * @throws Exception if anything goes wrong
505: */
506: private Envelope convertBBoxFromLatLon(Envelope latLonBbox,
507: String crsName) throws Exception {
508: CoordinateReferenceSystem latLon = CRS.decode("EPSG:4326");
509: CoordinateReferenceSystem nativeCRS = CRS.decode(crsName);
510:
511: Envelope env = null;
512: if (!CRS.equalsIgnoreMetadata(latLon, nativeCRS)) {
513: MathTransform xform = CRS.findMathTransform(latLon,
514: nativeCRS, true);
515: env = JTS.transform(latLonBbox, null, xform, 10); // convert databbox to native CRS
516: } else {
517: env = latLonBbox;
518: }
519:
520: return env;
521: }
522:
523: private void executeAdd(ActionMapping mapping,
524: TypesEditorForm form, UserContainer user,
525: HttpServletRequest request) {
526: String attributeName = form.getNewAttribute();
527:
528: FeatureType fType = getFeatureType(form, request);
529: AttributeForm newAttribute = newAttributeForm(attributeName,
530: fType);
531: form.getAttributes().add(newAttribute);
532: }
533:
534: private AttributeForm newAttributeForm(String attributeName,
535: FeatureType featureType) {
536: AttributeType attributeType = featureType
537: .getAttributeType(attributeName);
538: AttributeTypeInfoConfig attributeConfig = new AttributeTypeInfoConfig(
539: attributeType);
540: AttributeForm newAttribute = new AttributeForm(attributeConfig,
541: attributeType);
542:
543: return newAttribute;
544: }
545:
546: private FeatureType getFeatureType(TypesEditorForm form,
547: HttpServletRequest request) {
548: FeatureType featureType = null;
549:
550: DataStore dataStore = null;
551: try {
552: DataConfig config = ConfigRequests.getDataConfig(request);
553: DataStoreConfig dataStoreConfig = config.getDataStore(form
554: .getDataStoreId());
555: dataStore = dataStoreConfig.findDataStore(getServlet()
556: .getServletContext());
557: featureType = dataStore.getSchema(form.getTypeName());
558: } catch (IOException e) {
559: // DataStore unavailable!
560: } finally {
561: if (dataStore != null)
562: dataStore.dispose();
563: }
564:
565: return featureType;
566: }
567:
568: /**
569: * Execute Submit Action.
570: *
571: * @param mapping
572: * @param form
573: * @param user
574: * @param request
575: *
576: * @return
577: */
578: private ActionForward executeSubmit(ActionMapping mapping,
579: TypesEditorForm form, UserContainer user,
580: HttpServletRequest request) {
581: FeatureTypeConfig config = user.getFeatureTypeConfig();
582:
583: // clean up old names
584: DataConfig dataConfig = (DataConfig) getDataConfig();
585: dataConfig.removeFeatureType(config.getDataStoreId() + ":"
586: + config.getName());
587: if (config.getAlias() != null)
588: dataConfig.removeFeatureType(config.getDataStoreId() + ":"
589: + config.getAlias());
590:
591: sync(form, config, request);
592: if (config.getAlias() != null && !"".equals(config.getAlias()))
593: dataConfig.addFeatureType(config.getDataStoreId() + ":"
594: + config.getAlias(), config);
595: else
596: dataConfig.addFeatureType(config.getDataStoreId() + ":"
597: + config.getName(), config);
598:
599: // Don't think reset is needed (as me have moved on to new page)
600: // form.reset(mapping, request);
601: getApplicationState().notifyConfigChanged();
602:
603: // Feature no longer selected
604: user.setFeatureTypeConfig(null);
605:
606: return mapping.findForward("config.data.type");
607: }
608:
609: /**
610: * DOCUMENT ME!
611: *
612: * @param typeForm
613: *
614: * @return Bounding box in lat long
615: */
616: private Envelope getBoundingBox(TypesEditorForm typeForm) {
617: return new Envelope(Double.parseDouble(typeForm.getMinX()),
618: Double.parseDouble(typeForm.getMaxX()), Double
619: .parseDouble(typeForm.getMinY()), Double
620: .parseDouble(typeForm.getMaxY()));
621: }
622:
623: /**
624: * DOCUMENT ME!
625: *
626: * @param typeForm
627: *
628: * @return Bounding box in lat long
629: */
630: private Envelope getNativeBBox(TypesEditorForm typeForm) {
631: // here, we try to use the native bbox computed during "generate", but if the
632: // user specified the bbox by hand, we have to resort to back-project the lat/lon one
633: try {
634: return new Envelope(Double.parseDouble(typeForm
635: .getDataMinX()), Double.parseDouble(typeForm
636: .getDataMaxX()), Double.parseDouble(typeForm
637: .getDataMinY()), Double.parseDouble(typeForm
638: .getDataMaxY()));
639: } catch (NumberFormatException e) {
640: return null;
641: }
642: }
643:
644: /**
645: * DOCUMENT ME!
646: *
647: * @param typeForm
648: *
649: * @return Set of keywords
650: */
651: private Set keyWords(TypesEditorForm typeForm) {
652: HashSet keywords = new HashSet();
653: String[] array = (typeForm.getKeywords() != null) ? typeForm
654: .getKeywords().split(",") : new String[0];
655:
656: for (int i = 0; i < array.length; i++) {
657: keywords.add(array[i].trim());
658: }
659:
660: return keywords;
661: }
662:
663: private Set metadataLinks(TypesEditorForm typeForm) {
664: HashSet links = new HashSet();
665:
666: MetaDataLink link = getLink(typeForm, 0);
667:
668: if (link != null) {
669: links.add(link);
670: }
671:
672: link = getLink(typeForm, 1);
673:
674: if (link != null) {
675: links.add(link);
676: }
677:
678: return links;
679: }
680:
681: private MetaDataLink getLink(TypesEditorForm typeForm, int index) {
682: MetaDataLink link = typeForm.getMetadataLink(index);
683:
684: if ((link.getContent() == null)
685: || link.getContent().trim().equals("")) {
686: return null;
687: }
688:
689: return link;
690: }
691:
692: DataStore aquireDataStore(String dataStoreID) throws IOException {
693: DataConfig dataConfig = getDataConfig();
694: DataStoreConfig dataStoreConfig = dataConfig
695: .getDataStore(dataStoreID);
696:
697: Map params = dataStoreConfig.getConnectionParams();
698:
699: return DataStoreUtils.getDataStore(params);
700: }
701:
702: FeatureType getSchema(String dataStoreID, String typeName)
703: throws IOException {
704: DataStore dataStore = null;
705: try {
706: dataStore = aquireDataStore(dataStoreID);
707: return dataStore.getSchema(typeName);
708: } finally {
709: if (dataStore != null)
710: dataStore.dispose();
711: }
712: }
713: }
|