Search in sources :

Example 1 with XmlBuilder

use of org.activityinfo.server.util.xml.XmlBuilder in project activityinfo by bedatadriven.

the class KmlDataServlet method writeDocument.

protected void writeDocument(User user, PrintWriter out, int actvityId) throws TransformerConfigurationException, SAXException, CommandException {
    // TODO: rewrite using FreeMarker
    DomainFilters.applyUserFilter(user, entityManager.get());
    XmlBuilder xml = new XmlBuilder(new StreamResult(out));
    SchemaDTO schema = dispatcher.execute(new GetSchema());
    List<SiteDTO> sites = querySites(user, schema, actvityId);
    xml.startDocument();
    KMLNamespace kml = new KMLNamespace(xml);
    kml.startKml();
    ActivityDTO activity = schema.getActivityById(actvityId);
    kml.startDocument();
    kml.startStyle().at("id", "noDirectionsStyle");
    kml.startBalloonStyle();
    kml.text("$[description]");
    xml.close();
    xml.close();
    for (SiteDTO pm : sites) {
        if (pm.hasLatLong()) {
            kml.startPlaceMark();
            kml.styleUrl("#noDirectionsStyle");
            kml.name(pm.getLocationName());
            kml.startSnippet();
            xml.cdata(renderSnippet(activity, pm));
            // Snippet
            xml.close();
            kml.startDescription();
            xml.cdata(renderDescription(activity, pm));
            // Description
            xml.close();
            kml.startTimeSpan();
            if (pm.getDate1() != null) {
                kml.begin(pm.getDate1().atMidnightInMyTimezone());
                kml.end(pm.getDate2().atMidnightInMyTimezone());
                // Timespan
                xml.close();
            }
            kml.startPoint();
            kml.coordinates(pm.getLongitude(), pm.getLatitude());
            // Point
            xml.close();
            // Placemark
            xml.close();
        }
    }
    // Document
    xml.close();
    // kml
    xml.close();
    xml.endDocument();
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) XmlBuilder(org.activityinfo.server.util.xml.XmlBuilder) SiteDTO(org.activityinfo.shared.dto.SiteDTO) ActivityDTO(org.activityinfo.shared.dto.ActivityDTO) SchemaDTO(org.activityinfo.shared.dto.SchemaDTO) GetSchema(org.activityinfo.shared.command.GetSchema)

Aggregations

StreamResult (javax.xml.transform.stream.StreamResult)1 XmlBuilder (org.activityinfo.server.util.xml.XmlBuilder)1 GetSchema (org.activityinfo.shared.command.GetSchema)1 ActivityDTO (org.activityinfo.shared.dto.ActivityDTO)1 SchemaDTO (org.activityinfo.shared.dto.SchemaDTO)1 SiteDTO (org.activityinfo.shared.dto.SiteDTO)1