001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.forms.formmodel;
018:
019: import java.util.ArrayList;
020:
021: import org.apache.cocoon.forms.FormsConstants;
022: import org.apache.cocoon.forms.util.DomHelper;
023: import org.apache.excalibur.xml.sax.XMLizable;
024: import org.w3c.dom.Element;
025:
026: /**
027: * Builds {@link GoogleMapDefinition}s.
028: */
029: public final class GoogleMapDefinitionBuilder extends
030: AbstractWidgetDefinitionBuilder {
031: public WidgetDefinition buildWidgetDefinition(Element widgetElement)
032: throws Exception {
033:
034: GoogleMapDefinition definition = new GoogleMapDefinition();
035:
036: setupDefinition(widgetElement, definition);
037: setDisplayData(widgetElement, definition);
038:
039: // Initial value
040: Element initialValueElement = DomHelper.getChildElement(
041: widgetElement, FormsConstants.DEFINITION_NS,
042: "initial-value", false);
043: if (initialValueElement != null) {
044: GoogleMapValue googleMapValue = new GoogleMapValue();
045: googleMapValue.setLng(Float.valueOf(
046: initialValueElement.getAttribute("lng"))
047: .floatValue());
048: googleMapValue.setLat(Float.valueOf(
049: initialValueElement.getAttribute("lat"))
050: .floatValue());
051: googleMapValue.setZoom(Integer.valueOf(
052: initialValueElement.getAttribute("zoom"))
053: .intValue());
054:
055: // usermarker
056: Element userMarkerElement = DomHelper.getChildElement(
057: initialValueElement, FormsConstants.DEFINITION_NS,
058: "usermarker", false);
059: if (userMarkerElement != null) {
060: GoogleMapMarker usermarker = new GoogleMapMarker();
061: usermarker.setLng(Float.valueOf(
062: userMarkerElement.getAttribute("lng"))
063: .floatValue());
064: usermarker.setLat(Float.valueOf(
065: userMarkerElement.getAttribute("lat"))
066: .floatValue());
067: googleMapValue.setUsermarker(usermarker);
068: }
069:
070: Element markersElement = DomHelper.getChildElement(
071: initialValueElement, FormsConstants.DEFINITION_NS,
072: "markers", false);
073: if (markersElement != null) {
074: ArrayList markers = new ArrayList();
075: Element[] markerElements = DomHelper.getChildElements(
076: markersElement, FormsConstants.DEFINITION_NS,
077: "marker");
078: for (int i = 0; i < markerElements.length; i++) {
079: Element markerElement = markerElements[i];
080: GoogleMapMarker googleMapMarker = new GoogleMapMarker();
081: googleMapMarker.setLng(Float.valueOf(
082: markerElement.getAttribute("lng"))
083: .floatValue());
084: googleMapMarker.setLat(Float.valueOf(
085: markerElement.getAttribute("lat"))
086: .floatValue());
087: XMLizable data = null;
088: Element dataElement = DomHelper.getChildElement(
089: markerElement,
090: FormsConstants.DEFINITION_NS, "text");
091: if (dataElement != null) {
092: data = DomHelper
093: .compileElementContent(dataElement);
094: }
095: googleMapMarker.setText(data);
096: markers.add(googleMapMarker);
097: }
098: googleMapValue.setMarkers(markers);
099: }
100: googleMapValue.setCurrentMarker(-1);
101:
102: definition.setInitialValue(googleMapValue);
103: }
104:
105: definition.makeImmutable();
106: return definition;
107: }
108: }
|