Re: svn commit: r566781 - in /ofbiz/trunk/framework/webapp: config/ script/ script/org/ script/org/ofbiz/ script/org/ofbiz/webapp/ script/org/ofbiz/webapp/event/ src/org/ofbiz/webapp/event/ src/org/ofbiz/webapp/view/

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r566781 - in /ofbiz/trunk/framework/webapp: config/ script/ script/org/ script/org/ofbiz/ script/org/ofbiz/webapp/ script/org/ofbiz/webapp/event/ src/org/ofbiz/webapp/event/ src/org/ofbiz/webapp/view/

Jacopo Cappellato
Hi Al,

could you please add the license header to all the new files in this commit?
You can find a collection of headers for each file type in
APACHE2_HEADER (in the ofbiz folder)

Jacopo

[hidden email] wrote:

> Author: byersa
> Date: Thu Aug 16 10:14:18 2007
> New Revision: 566781
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=566781
> Log:
> I am adding these GIS related files for safe keeping and to serve notice that a GIS component will be forthcoming.
> Actually, they work now, so it will be a matter of filling the out - especially translating ogc filter constraints to
> simple method entity expressions.
>
> WFS is a standard in the GIS world for querying and returning metadata (as opposed to the other two standards, WMS and WMC,
> which deal with returning images from vector info or images as the native format (coverages).
> By putting a WFS server interface in OFBiz, it can be used to add point-of-interest plotting to many business apps.
>
> Added:
>     ofbiz/trunk/framework/webapp/config/wfs.properties
>     ofbiz/trunk/framework/webapp/script/
>     ofbiz/trunk/framework/webapp/script/org/
>     ofbiz/trunk/framework/webapp/script/org/ofbiz/
>     ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/
>     ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/
>     ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl
>     ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl
>     ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java
>     ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java
>
> Added: ofbiz/trunk/framework/webapp/config/wfs.properties
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/config/wfs.properties?view=auto&rev=566781
> ==============================================================================
> --- ofbiz/trunk/framework/webapp/config/wfs.properties (added)
> +++ ofbiz/trunk/framework/webapp/config/wfs.properties Thu Aug 16 10:14:18 2007
> @@ -0,0 +1,2 @@
> +input.template.path=component://webapp/script/org/ofbiz/webapp/event/processWfs.ftl
> +format.template.path=component://webapp/script/org/ofbiz/webapp/event/formatWfs.ftl
> \ No newline at end of file
>
> Added: ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl?view=auto&rev=566781
> ==============================================================================
> --- ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl (added)
> +++ ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl Thu Aug 16 10:14:18 2007
> @@ -0,0 +1,36 @@
> +<?xml version="1.0" ?>
> +<wfs:FeatureCollection
> +    xmlns="http://www.hotwaxmedia.com/granite"
> +    xmlns:wfs="http://www.opengis.net/wfs"
> +    xmlns:gml="http://www.opengis.net/gml"
> +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> +    >
> +
> +<#list entityList as entity>
> +  <gml:featureMember>
> +      <#assign entityName=entity.getEntityName()/>
> +      <${entityName} fid="E${entity_index}">
> +      <#assign keyMap=entity.getAllFields()/>
> +      <#assign keys=keyMap.keySet()/>
> +      <#assign thisLongitude=""/>
> +      <#assign thisLatitude=""/>
> +      <#list keys as key>
> +        <#assign val = (entity.get(key))?default("")/>
> +        <#if key=="longitude"><#assign thisLongitude=val/></#if>
> +        <#if key == "latitude"><#assign thisLatitude=val/></#if>
> +        <#if key=="longitude" || key == "latitude">
> +            <#if thisLongitude?has_content && thisLatitude?has_content>
> + <geoTemp>
> + <gml:Point srsName="4326">
> + <gml:pos>${thisLongitude} ${thisLatitude}</gml:pos>
> + </gml:Point>
> + </geoTemp>
> +            </#if>
> +        <#else>
> +        <${key}>${val}</${key}>
> +        </#if>
> +      </#list>
> +      </${entityName}>
> +  </gml:featureMember>
> +</#list>
> +    </wfs:FeatureCollection>
> \ No newline at end of file
>
> Added: ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl?view=auto&rev=566781
> ==============================================================================
> --- ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl (added)
> +++ ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl Thu Aug 16 10:14:18 2007
> @@ -0,0 +1,31 @@
> +<#ftl ns_prefixes={"ogc":"http://ogc.org"}>
> +    <simple-method method-name="processWfs" short-description="Process a WFS request and return a simple method" login-required="false">
> +
> +<#if doc?node_name == "Filter">
> +  <#visit doc/>
> +<#else>
> +  <#recurse doc/>
> +</#if>
> +
> +</simple-method>
> +
> +
> +<#macro @element></#macro>
> +
> +
> +<#macro "ogc:Filter">
> +        <entity-condition list-name="entityList" entity-name="${entityName}" filter-by-date="false" use-cache="false">
> +  <#recurse .node>
> +                </entity-condition>
> +                <field-to-request field-name="entityList"/>
> +</#macro>
> +
> +<#macro "ogc:PropertyIsEqualTo"><#assign propName=.node["ogc:PropertyName"].@@text />
> +  <condition-expr field-name="${propName}" value="<@getLiteral nd=.node["ogc:Literal"] nm=propName/>"/>
> +
> +</#macro>
> +
> +<#macro "ogc:PropertyName"></#macro>
> +<#macro "ogc:Literal"></#macro>
> +<#macro getPropertyName nd>${nd.@@text}</#macro>
> +<#macro getLiteral nd nm>${(paramMap.nm)?default(nd.@@text)}</#macro>
>
> Added: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java?view=auto&rev=566781
> ==============================================================================
> --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java (added)
> +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java Thu Aug 16 10:14:18 2007
> @@ -0,0 +1,245 @@
> +/*******************************************************************************
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + *******************************************************************************/
> +package org.ofbiz.webapp.event ;
> +
> +import java.io.FileNotFoundException;
> +import java.io.File;
> +import java.io.FileReader;
> +import java.io.IOException;
> +import java.io.StringWriter;
> +import java.io.Writer;
> +import java.io.OutputStream;
> +import java.io.InputStream;
> +import java.util.HashMap;
> +import java.util.Iterator;
> +import java.util.List;
> +import java.util.Map;
> +import java.util.Set;
> +import java.net.URI;
> +import java.net.URL;
> +import java.net.URISyntaxException;
> +import javax.servlet.http.HttpServletRequest;
> +import javax.servlet.http.HttpServletResponse;
> +import javax.servlet.ServletContext;
> +import org.ofbiz.webapp.event.EventHandler;
> +import org.ofbiz.webapp.event.EventHandlerException;
> +
> +import javax.xml.parsers.DocumentBuilder;
> +import javax.xml.parsers.DocumentBuilderFactory;
> +import javax.xml.parsers.ParserConfigurationException;
> +
> +import javolution.util.FastList;
> +
> +import org.ofbiz.base.location.FlexibleLocation;
> +import org.ofbiz.base.util.Debug;
> +import org.ofbiz.base.util.UtilMisc;
> +import org.ofbiz.base.util.UtilXml;
> +import org.ofbiz.base.util.UtilFormatOut;
> +import org.ofbiz.base.util.UtilProperties;
> +import org.ofbiz.base.util.UtilValidate;
> +import org.ofbiz.entity.GenericDelegator;
> +import org.ofbiz.minilang.method.MethodContext;
> +import org.ofbiz.service.GenericServiceException;
> +import org.ofbiz.service.LocalDispatcher;
> +import org.ofbiz.service.ModelService;
> +import org.ofbiz.service.DispatchContext;
> +import org.ofbiz.service.ServiceUtil;
> +import org.ofbiz.webapp.control.RequestHandler;
> +import org.ofbiz.minilang.SimpleMethod;
> +
> +import org.apache.xml.serialize.OutputFormat;
> +import org.apache.xml.serialize.XMLSerializer;
> +import org.w3c.dom.Document;
> +import org.w3c.dom.DocumentFragment;
> +import org.w3c.dom.Element;
> +import org.w3c.dom.Node;
> +import org.xml.sax.EntityResolver;
> +import org.xml.sax.ErrorHandler;
> +import org.xml.sax.InputSource;
> +import org.xml.sax.SAXException;
> +import org.xml.sax.SAXParseException;
> +import org.xml.sax.helpers.DefaultHandler;
> +
> +import freemarker.ext.beans.BeansWrapper;
> +import freemarker.ext.dom.NodeModel;
> +import freemarker.template.Configuration;
> +import freemarker.template.SimpleSequence;
> +import freemarker.template.Template;
> +import freemarker.template.TemplateException;
> +
> +
> +/**
> + * WfsEventHandler - WFS Event Handler implementation
> + */
> +public class WfsEventHandler implements EventHandler {
> +
> +    public static final String module = WfsEventHandler.class.getName();
> +    
> +    public static final String InputTemplateUrl ="component://webapp/script/org/ofbiz/webapp/event/processWfs.ftl";
> +
> +    /**
> +     * @see org.ofbiz.webapp.event.EventHandler#init(javax.servlet.ServletContext)
> +     */
> +    public void init(ServletContext context) throws EventHandlerException {
> +    }
> +    
> +    /** Invoke the web event
> +     *@param eventPath The path or location of this event
> +     *@param eventMethod The method to invoke
> +     *@param request The servlet request object
> +     *@param response The servlet response object
> +     *@return String Result code
> +     *@throws EventHandlerException
> +     */
> +    public String invoke(String eventPath, String eventMethod, HttpServletRequest request, HttpServletResponse response) throws EventHandlerException {
> +        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
> +        String typeName = null;
> +        Element queryElem = null;
> +
> +        try {
> +            Map paramMap = request.getParameterMap();
> +            typeName = (String)request.getParameter("typename");
> +            //determine if "get" or "post" and get "filter" param accordingly
> +            if (UtilValidate.isNotEmpty(typeName)) {
> +                String queryFieldCoded = (String)request.getParameter("filter");
> +                String queryFieldDecoded = UtilFormatOut.decodeQueryValue(queryFieldCoded);
> +                Document doc = UtilXml.readXmlDocument(queryFieldDecoded);
> +                queryElem = doc.getDocumentElement();
> +            } else {
> +                Document doc = UtilXml.readXmlDocument(request.getInputStream(), "WFS Request");
> +                Element getFeatureElem = doc.getDocumentElement();
> +                queryElem = UtilXml.firstChildElement(getFeatureElem, "Query");
> +                typeName = queryElem.getAttribute("typeName");
> +            }
> +            // Take "ogc:filter" element and transform it to a Simple Method query script
> +            String inputTmplUrl = UtilProperties.getPropertyValue("wfs", "input.template.path", WfsEventHandler.InputTemplateUrl);
> +            String xmlScript = processWfsEntity(typeName, queryElem, inputTmplUrl);
> +            
> +            // run simple method script to get a list of entities
> +            Document simpleDoc = UtilXml.readXmlDocument(xmlScript);
> +            Element simpleElem = simpleDoc.getDocumentElement();
> +            SimpleMethod meth = new SimpleMethod(simpleElem, null, null);
> +            MethodContext methodContext = new MethodContext(request, response, null);
> +            String retStr = meth.exec(methodContext); //Need to check return string
> +            List entityList = (List)request.getAttribute("entityList");
> +            request.setAttribute("entityList", entityList);
> +            
> +        } catch (TemplateException ioe) {
> +            sendError(response, "Problem handling event");
> +            throw new EventHandlerException("Problem processing template", ioe);
> +        } catch (FileNotFoundException ioe) {
> +            sendError(response, "Problem handling event");
> +            throw new EventHandlerException("Cannot find file", ioe);
> +        } catch (URISyntaxException ioe) {
> +            sendError(response, "Problem handling event");
> +            throw new EventHandlerException("Cannot read the input stream", ioe);
> +        } catch (SAXException ioe) {
> +            sendError(response, "Problem handling event");
> +            throw new EventHandlerException("Cannot read the input stream", ioe);
> +        } catch (ParserConfigurationException ioe) {
> +            sendError(response, "Problem handling event");
> +            throw new EventHandlerException("Cannot read the input stream", ioe);
> +        } catch (IOException ioe) {
> +            sendError(response, "Problem handling event");
> +            throw new EventHandlerException("Cannot read the input stream", ioe);
> +        }
> +
> +
> +        return "success";
> +    }
> +
> +    private void sendError(HttpServletResponse res, Object obj) throws EventHandlerException {
> +//        Message msg = new Message(obj);
> +
> +        try {
> +//            res.setContentType(msg.getContentType(Constants.DEFAULT_WFS_VERSION));
> +//            res.setContentLength(Integer.parseInt(Long.toString(msg.getContentLength())));
> +//            msg.writeTo(res.getOutputStream());                        
> +//            res.flushBuffer();
> +        } catch (Exception e) {
> +            throw new EventHandlerException(e.getMessage(), e);
> +        }
> +    }
> +
> +    private String getLocationURI(HttpServletRequest request) {
> +        StringBuffer uri = new StringBuffer();
> +//        uri.append(request.getScheme());
> +//        uri.append("://");
> +//        uri.append(request.getServerName());
> +//        if (request.getServerPort() != 80 && request.getServerPort() != 443) {
> +//            uri.append(":");
> +//            uri.append(request.getServerPort());
> +//        }
> +//        uri.append(request.getContextPath());
> +//        uri.append(request.getServletPath());
> +//
> +//        String reqInfo = RequestHandler.getRequestUri(request.getPathInfo());
> +//        if (!reqInfo.startsWith("/")) {
> +//            reqInfo = "/" + reqInfo;
> +//        }
> +//
> +//        uri.append(reqInfo);
> +        return uri.toString();
> +    }
> +    
> +    public static String processWfsEntity(String entityName, Node domNode, String templatePath) throws TemplateException, FileNotFoundException, IOException, URISyntaxException {
> +        
> +        String result = null;
> +        
> +            NodeModel nodeModel = NodeModel.wrap(domNode);
> +    
> +            Map ctx = new HashMap();
> +            ctx.put("doc", nodeModel);
> +            ctx.put("entityName", entityName);
> +            StringWriter outWriter = new StringWriter();
> +            Template template = getDocTemplate(templatePath);
> +            template.process(ctx, outWriter);
> +            outWriter.close();
> +            result = outWriter.toString();
> +
> +        return result;
> +    }
> +    
> +    
> +    public static Template getDocTemplate(String fileUrl)  throws FileNotFoundException, IOException, TemplateException, URISyntaxException {
> +
> +        Template template = null;
> +                
> +                URL screenFileUrl = FlexibleLocation.resolveLocation(fileUrl, null);
> +                String urlStr = screenFileUrl.toString();
> +                URI uri = new URI(urlStr);
> +                File f = new File(uri);
> +                
> +            FileReader templateReader = new FileReader(f);
> +
> +            Configuration conf = makeDefaultOfbizConfig();
> +
> +            template = new Template("FMImportFilter", templateReader, conf);
> +
> +        return template;
> +    }
> +
> +    public static Configuration makeDefaultOfbizConfig() throws TemplateException, IOException {
> +        Configuration config = new Configuration();            
> +        config.setObjectWrapper(BeansWrapper.getDefaultInstance());
> +        config.setSetting("datetime_format", "yyyy-MM-dd HH:mm:ss.SSS");
> +        Configuration defaultOfbizConfig = config;
> +        return defaultOfbizConfig;
> +    }
> +}
>
> Added: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java?view=auto&rev=566781
> ==============================================================================
> --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java (added)
> +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java Thu Aug 16 10:14:18 2007
> @@ -0,0 +1,124 @@
> +/*******************************************************************************
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + *******************************************************************************/
> +package org.ofbiz.webapp.view;
> +
> +import java.io.File;
> +import java.io.FileNotFoundException;
> +import java.io.FileReader;
> +import java.io.IOException;
> +import java.io.StringWriter;
> +import java.net.URI;
> +import java.net.URISyntaxException;
> +import java.net.URL;
> +import java.util.HashMap;
> +import java.util.Map;
> +import java.util.List;
> +
> +import javax.servlet.ServletContext;
> +import javax.servlet.http.HttpServletRequest;
> +import javax.servlet.http.HttpServletResponse;
> +
> +import org.ofbiz.base.location.FlexibleLocation;
> +import org.ofbiz.base.util.Debug;
> +import org.ofbiz.base.util.HttpClient;
> +import org.ofbiz.base.util.HttpClientException;
> +import org.ofbiz.webapp.view.ViewHandler;
> +import org.ofbiz.webapp.view.ViewHandlerException;
> +
> +import freemarker.ext.beans.BeansWrapper;
> +import freemarker.template.Configuration;
> +import freemarker.template.SimpleSequence;
> +import freemarker.template.Template;
> +import freemarker.template.TemplateException;
> +
> +/**
> + * WfsViewHandler - View Handler
> + */
> +public class WfsViewHandler implements ViewHandler {
> +    
> +    public static final String module = WfsViewHandler.class.getName();
> +    public static final String FormatTemplateUrl ="component://webapp/script/org/ofbiz/webapp/event/formatWfs.ftl";
> +
> +    protected ServletContext context;
> +
> +    public void init(ServletContext context) throws ViewHandlerException {
> +        this.context = context;
> +    }
> +
> +    public void render(String name, String page, String info, String contentType, String encoding, HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException {
> +        // some containers call filters on EVERY request, even forwarded ones,
> +        // so let it know that it came from the control servlet
> +
> +        if (request == null)
> +            throw new ViewHandlerException("Null HttpServletRequest object");
> +        if (page == null || page.length() == 0)
> +            throw new ViewHandlerException("Null or empty source");
> +
> +        if (Debug.infoOn()) Debug.logInfo("Retreiving HTTP resource at: " + page, module);
> +        try {
> +           String result = null;
> +            
> +           List entityList = (List)request.getAttribute("entityList");
> +           SimpleSequence simpleList = new SimpleSequence(entityList);
> +           Map ctx = new HashMap();
> +           ctx.put("entityList", simpleList);
> +           StringWriter outWriter = new StringWriter();
> +           Template template = getDocTemplate(page);
> +           template.process(ctx, outWriter);
> +           outWriter.close();
> +           result = outWriter.toString();
> +           Debug.logInfo(result, result);
> +            response.getWriter().print(result);
> +        } catch (FileNotFoundException e) {
> +            throw new ViewHandlerException(e.getMessage(), e);
> +        } catch (IOException e) {
> +            throw new ViewHandlerException("IO Error in view", e);
> +        } catch (URISyntaxException e) {
> +            throw new ViewHandlerException(e.getMessage(), e);
> +        } catch (TemplateException e) {
> +            throw new ViewHandlerException(e.getMessage(), e);
> +        }
> +    }
> +    
> +    public static Template getDocTemplate(String fileUrl)  throws FileNotFoundException, IOException, TemplateException, URISyntaxException {
> +
> +        Template template = null;
> +                
> +        URL screenFileUrl = FlexibleLocation.resolveLocation(fileUrl, null);
> +        String urlStr = screenFileUrl.toString();
> +        URI uri = new URI(urlStr);
> +        File f = new File(uri);
> +                
> +        FileReader templateReader = new FileReader(f);
> +
> +        Configuration conf = makeDefaultOfbizConfig();
> +
> +        template = new Template("FMImportFilter", templateReader, conf);
> +
> +        return template;
> +    }
> +
> +    public static Configuration makeDefaultOfbizConfig() throws TemplateException, IOException {
> +        Configuration config = new Configuration();            
> +        config.setObjectWrapper(BeansWrapper.getDefaultInstance());
> +        config.setSetting("datetime_format", "yyyy-MM-dd HH:mm:ss.SSS");
> +        Configuration defaultOfbizConfig = config;
> +        return defaultOfbizConfig;
> +    }
> +}
>


Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r566781 - in /ofbiz/trunk/framework/webapp: config/ script/ script/org/ script/org/ofbiz/ script/org/ofbiz/webapp/ script/org/ofbiz/webapp/event/ src/org/ofbiz/webapp/event/ src/org/ofbiz/webapp/view/

Jacopo Cappellato
Also,

please convert all tabs to 4-spaces.

Thanks,

Jacopo

[hidden email] wrote:

> Author: byersa
> Date: Thu Aug 16 10:14:18 2007
> New Revision: 566781
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=566781
> Log:
> I am adding these GIS related files for safe keeping and to serve notice that a GIS component will be forthcoming.
> Actually, they work now, so it will be a matter of filling the out - especially translating ogc filter constraints to
> simple method entity expressions.
>
> WFS is a standard in the GIS world for querying and returning metadata (as opposed to the other two standards, WMS and WMC,
> which deal with returning images from vector info or images as the native format (coverages).
> By putting a WFS server interface in OFBiz, it can be used to add point-of-interest plotting to many business apps.
>
> Added:
>     ofbiz/trunk/framework/webapp/config/wfs.properties
>     ofbiz/trunk/framework/webapp/script/
>     ofbiz/trunk/framework/webapp/script/org/
>     ofbiz/trunk/framework/webapp/script/org/ofbiz/
>     ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/
>     ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/
>     ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl
>     ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl
>     ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java
>     ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java
>
> Added: ofbiz/trunk/framework/webapp/config/wfs.properties
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/config/wfs.properties?view=auto&rev=566781
> ==============================================================================
> --- ofbiz/trunk/framework/webapp/config/wfs.properties (added)
> +++ ofbiz/trunk/framework/webapp/config/wfs.properties Thu Aug 16 10:14:18 2007
> @@ -0,0 +1,2 @@
> +input.template.path=component://webapp/script/org/ofbiz/webapp/event/processWfs.ftl
> +format.template.path=component://webapp/script/org/ofbiz/webapp/event/formatWfs.ftl
> \ No newline at end of file
>
> Added: ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl?view=auto&rev=566781
> ==============================================================================
> --- ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl (added)
> +++ ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl Thu Aug 16 10:14:18 2007
> @@ -0,0 +1,36 @@
> +<?xml version="1.0" ?>
> +<wfs:FeatureCollection
> +    xmlns="http://www.hotwaxmedia.com/granite"
> +    xmlns:wfs="http://www.opengis.net/wfs"
> +    xmlns:gml="http://www.opengis.net/gml"
> +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> +    >
> +
> +<#list entityList as entity>
> +  <gml:featureMember>
> +      <#assign entityName=entity.getEntityName()/>
> +      <${entityName} fid="E${entity_index}">
> +      <#assign keyMap=entity.getAllFields()/>
> +      <#assign keys=keyMap.keySet()/>
> +      <#assign thisLongitude=""/>
> +      <#assign thisLatitude=""/>
> +      <#list keys as key>
> +        <#assign val = (entity.get(key))?default("")/>
> +        <#if key=="longitude"><#assign thisLongitude=val/></#if>
> +        <#if key == "latitude"><#assign thisLatitude=val/></#if>
> +        <#if key=="longitude" || key == "latitude">
> +            <#if thisLongitude?has_content && thisLatitude?has_content>
> + <geoTemp>
> + <gml:Point srsName="4326">
> + <gml:pos>${thisLongitude} ${thisLatitude}</gml:pos>
> + </gml:Point>
> + </geoTemp>
> +            </#if>
> +        <#else>
> +        <${key}>${val}</${key}>
> +        </#if>
> +      </#list>
> +      </${entityName}>
> +  </gml:featureMember>
> +</#list>
> +    </wfs:FeatureCollection>
> \ No newline at end of file
>
> Added: ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl?view=auto&rev=566781
> ==============================================================================
> --- ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl (added)
> +++ ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl Thu Aug 16 10:14:18 2007
> @@ -0,0 +1,31 @@
> +<#ftl ns_prefixes={"ogc":"http://ogc.org"}>
> +    <simple-method method-name="processWfs" short-description="Process a WFS request and return a simple method" login-required="false">
> +
> +<#if doc?node_name == "Filter">
> +  <#visit doc/>
> +<#else>
> +  <#recurse doc/>
> +</#if>
> +
> +</simple-method>
> +
> +
> +<#macro @element></#macro>
> +
> +
> +<#macro "ogc:Filter">
> +        <entity-condition list-name="entityList" entity-name="${entityName}" filter-by-date="false" use-cache="false">
> +  <#recurse .node>
> +                </entity-condition>
> +                <field-to-request field-name="entityList"/>
> +</#macro>
> +
> +<#macro "ogc:PropertyIsEqualTo"><#assign propName=.node["ogc:PropertyName"].@@text />
> +  <condition-expr field-name="${propName}" value="<@getLiteral nd=.node["ogc:Literal"] nm=propName/>"/>
> +
> +</#macro>
> +
> +<#macro "ogc:PropertyName"></#macro>
> +<#macro "ogc:Literal"></#macro>
> +<#macro getPropertyName nd>${nd.@@text}</#macro>
> +<#macro getLiteral nd nm>${(paramMap.nm)?default(nd.@@text)}</#macro>
>
> Added: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java?view=auto&rev=566781
> ==============================================================================
> --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java (added)
> +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java Thu Aug 16 10:14:18 2007
> @@ -0,0 +1,245 @@
> +/*******************************************************************************
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + *******************************************************************************/
> +package org.ofbiz.webapp.event ;
> +
> +import java.io.FileNotFoundException;
> +import java.io.File;
> +import java.io.FileReader;
> +import java.io.IOException;
> +import java.io.StringWriter;
> +import java.io.Writer;
> +import java.io.OutputStream;
> +import java.io.InputStream;
> +import java.util.HashMap;
> +import java.util.Iterator;
> +import java.util.List;
> +import java.util.Map;
> +import java.util.Set;
> +import java.net.URI;
> +import java.net.URL;
> +import java.net.URISyntaxException;
> +import javax.servlet.http.HttpServletRequest;
> +import javax.servlet.http.HttpServletResponse;
> +import javax.servlet.ServletContext;
> +import org.ofbiz.webapp.event.EventHandler;
> +import org.ofbiz.webapp.event.EventHandlerException;
> +
> +import javax.xml.parsers.DocumentBuilder;
> +import javax.xml.parsers.DocumentBuilderFactory;
> +import javax.xml.parsers.ParserConfigurationException;
> +
> +import javolution.util.FastList;
> +
> +import org.ofbiz.base.location.FlexibleLocation;
> +import org.ofbiz.base.util.Debug;
> +import org.ofbiz.base.util.UtilMisc;
> +import org.ofbiz.base.util.UtilXml;
> +import org.ofbiz.base.util.UtilFormatOut;
> +import org.ofbiz.base.util.UtilProperties;
> +import org.ofbiz.base.util.UtilValidate;
> +import org.ofbiz.entity.GenericDelegator;
> +import org.ofbiz.minilang.method.MethodContext;
> +import org.ofbiz.service.GenericServiceException;
> +import org.ofbiz.service.LocalDispatcher;
> +import org.ofbiz.service.ModelService;
> +import org.ofbiz.service.DispatchContext;
> +import org.ofbiz.service.ServiceUtil;
> +import org.ofbiz.webapp.control.RequestHandler;
> +import org.ofbiz.minilang.SimpleMethod;
> +
> +import org.apache.xml.serialize.OutputFormat;
> +import org.apache.xml.serialize.XMLSerializer;
> +import org.w3c.dom.Document;
> +import org.w3c.dom.DocumentFragment;
> +import org.w3c.dom.Element;
> +import org.w3c.dom.Node;
> +import org.xml.sax.EntityResolver;
> +import org.xml.sax.ErrorHandler;
> +import org.xml.sax.InputSource;
> +import org.xml.sax.SAXException;
> +import org.xml.sax.SAXParseException;
> +import org.xml.sax.helpers.DefaultHandler;
> +
> +import freemarker.ext.beans.BeansWrapper;
> +import freemarker.ext.dom.NodeModel;
> +import freemarker.template.Configuration;
> +import freemarker.template.SimpleSequence;
> +import freemarker.template.Template;
> +import freemarker.template.TemplateException;
> +
> +
> +/**
> + * WfsEventHandler - WFS Event Handler implementation
> + */
> +public class WfsEventHandler implements EventHandler {
> +
> +    public static final String module = WfsEventHandler.class.getName();
> +    
> +    public static final String InputTemplateUrl ="component://webapp/script/org/ofbiz/webapp/event/processWfs.ftl";
> +
> +    /**
> +     * @see org.ofbiz.webapp.event.EventHandler#init(javax.servlet.ServletContext)
> +     */
> +    public void init(ServletContext context) throws EventHandlerException {
> +    }
> +    
> +    /** Invoke the web event
> +     *@param eventPath The path or location of this event
> +     *@param eventMethod The method to invoke
> +     *@param request The servlet request object
> +     *@param response The servlet response object
> +     *@return String Result code
> +     *@throws EventHandlerException
> +     */
> +    public String invoke(String eventPath, String eventMethod, HttpServletRequest request, HttpServletResponse response) throws EventHandlerException {
> +        LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
> +        String typeName = null;
> +        Element queryElem = null;
> +
> +        try {
> +            Map paramMap = request.getParameterMap();
> +            typeName = (String)request.getParameter("typename");
> +            //determine if "get" or "post" and get "filter" param accordingly
> +            if (UtilValidate.isNotEmpty(typeName)) {
> +                String queryFieldCoded = (String)request.getParameter("filter");
> +                String queryFieldDecoded = UtilFormatOut.decodeQueryValue(queryFieldCoded);
> +                Document doc = UtilXml.readXmlDocument(queryFieldDecoded);
> +                queryElem = doc.getDocumentElement();
> +            } else {
> +                Document doc = UtilXml.readXmlDocument(request.getInputStream(), "WFS Request");
> +                Element getFeatureElem = doc.getDocumentElement();
> +                queryElem = UtilXml.firstChildElement(getFeatureElem, "Query");
> +                typeName = queryElem.getAttribute("typeName");
> +            }
> +            // Take "ogc:filter" element and transform it to a Simple Method query script
> +            String inputTmplUrl = UtilProperties.getPropertyValue("wfs", "input.template.path", WfsEventHandler.InputTemplateUrl);
> +            String xmlScript = processWfsEntity(typeName, queryElem, inputTmplUrl);
> +            
> +            // run simple method script to get a list of entities
> +            Document simpleDoc = UtilXml.readXmlDocument(xmlScript);
> +            Element simpleElem = simpleDoc.getDocumentElement();
> +            SimpleMethod meth = new SimpleMethod(simpleElem, null, null);
> +            MethodContext methodContext = new MethodContext(request, response, null);
> +            String retStr = meth.exec(methodContext); //Need to check return string
> +            List entityList = (List)request.getAttribute("entityList");
> +            request.setAttribute("entityList", entityList);
> +            
> +        } catch (TemplateException ioe) {
> +            sendError(response, "Problem handling event");
> +            throw new EventHandlerException("Problem processing template", ioe);
> +        } catch (FileNotFoundException ioe) {
> +            sendError(response, "Problem handling event");
> +            throw new EventHandlerException("Cannot find file", ioe);
> +        } catch (URISyntaxException ioe) {
> +            sendError(response, "Problem handling event");
> +            throw new EventHandlerException("Cannot read the input stream", ioe);
> +        } catch (SAXException ioe) {
> +            sendError(response, "Problem handling event");
> +            throw new EventHandlerException("Cannot read the input stream", ioe);
> +        } catch (ParserConfigurationException ioe) {
> +            sendError(response, "Problem handling event");
> +            throw new EventHandlerException("Cannot read the input stream", ioe);
> +        } catch (IOException ioe) {
> +            sendError(response, "Problem handling event");
> +            throw new EventHandlerException("Cannot read the input stream", ioe);
> +        }
> +
> +
> +        return "success";
> +    }
> +
> +    private void sendError(HttpServletResponse res, Object obj) throws EventHandlerException {
> +//        Message msg = new Message(obj);
> +
> +        try {
> +//            res.setContentType(msg.getContentType(Constants.DEFAULT_WFS_VERSION));
> +//            res.setContentLength(Integer.parseInt(Long.toString(msg.getContentLength())));
> +//            msg.writeTo(res.getOutputStream());                        
> +//            res.flushBuffer();
> +        } catch (Exception e) {
> +            throw new EventHandlerException(e.getMessage(), e);
> +        }
> +    }
> +
> +    private String getLocationURI(HttpServletRequest request) {
> +        StringBuffer uri = new StringBuffer();
> +//        uri.append(request.getScheme());
> +//        uri.append("://");
> +//        uri.append(request.getServerName());
> +//        if (request.getServerPort() != 80 && request.getServerPort() != 443) {
> +//            uri.append(":");
> +//            uri.append(request.getServerPort());
> +//        }
> +//        uri.append(request.getContextPath());
> +//        uri.append(request.getServletPath());
> +//
> +//        String reqInfo = RequestHandler.getRequestUri(request.getPathInfo());
> +//        if (!reqInfo.startsWith("/")) {
> +//            reqInfo = "/" + reqInfo;
> +//        }
> +//
> +//        uri.append(reqInfo);
> +        return uri.toString();
> +    }
> +    
> +    public static String processWfsEntity(String entityName, Node domNode, String templatePath) throws TemplateException, FileNotFoundException, IOException, URISyntaxException {
> +        
> +        String result = null;
> +        
> +            NodeModel nodeModel = NodeModel.wrap(domNode);
> +    
> +            Map ctx = new HashMap();
> +            ctx.put("doc", nodeModel);
> +            ctx.put("entityName", entityName);
> +            StringWriter outWriter = new StringWriter();
> +            Template template = getDocTemplate(templatePath);
> +            template.process(ctx, outWriter);
> +            outWriter.close();
> +            result = outWriter.toString();
> +
> +        return result;
> +    }
> +    
> +    
> +    public static Template getDocTemplate(String fileUrl)  throws FileNotFoundException, IOException, TemplateException, URISyntaxException {
> +
> +        Template template = null;
> +                
> +                URL screenFileUrl = FlexibleLocation.resolveLocation(fileUrl, null);
> +                String urlStr = screenFileUrl.toString();
> +                URI uri = new URI(urlStr);
> +                File f = new File(uri);
> +                
> +            FileReader templateReader = new FileReader(f);
> +
> +            Configuration conf = makeDefaultOfbizConfig();
> +
> +            template = new Template("FMImportFilter", templateReader, conf);
> +
> +        return template;
> +    }
> +
> +    public static Configuration makeDefaultOfbizConfig() throws TemplateException, IOException {
> +        Configuration config = new Configuration();            
> +        config.setObjectWrapper(BeansWrapper.getDefaultInstance());
> +        config.setSetting("datetime_format", "yyyy-MM-dd HH:mm:ss.SSS");
> +        Configuration defaultOfbizConfig = config;
> +        return defaultOfbizConfig;
> +    }
> +}
>
> Added: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java?view=auto&rev=566781
> ==============================================================================
> --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java (added)
> +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java Thu Aug 16 10:14:18 2007
> @@ -0,0 +1,124 @@
> +/*******************************************************************************
> + * Licensed to the Apache Software Foundation (ASF) under one
> + * or more contributor license agreements.  See the NOTICE file
> + * distributed with this work for additional information
> + * regarding copyright ownership.  The ASF licenses this file
> + * to you under the Apache License, Version 2.0 (the
> + * "License"); you may not use this file except in compliance
> + * with the License.  You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing,
> + * software distributed under the License is distributed on an
> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
> + * KIND, either express or implied.  See the License for the
> + * specific language governing permissions and limitations
> + * under the License.
> + *******************************************************************************/
> +package org.ofbiz.webapp.view;
> +
> +import java.io.File;
> +import java.io.FileNotFoundException;
> +import java.io.FileReader;
> +import java.io.IOException;
> +import java.io.StringWriter;
> +import java.net.URI;
> +import java.net.URISyntaxException;
> +import java.net.URL;
> +import java.util.HashMap;
> +import java.util.Map;
> +import java.util.List;
> +
> +import javax.servlet.ServletContext;
> +import javax.servlet.http.HttpServletRequest;
> +import javax.servlet.http.HttpServletResponse;
> +
> +import org.ofbiz.base.location.FlexibleLocation;
> +import org.ofbiz.base.util.Debug;
> +import org.ofbiz.base.util.HttpClient;
> +import org.ofbiz.base.util.HttpClientException;
> +import org.ofbiz.webapp.view.ViewHandler;
> +import org.ofbiz.webapp.view.ViewHandlerException;
> +
> +import freemarker.ext.beans.BeansWrapper;
> +import freemarker.template.Configuration;
> +import freemarker.template.SimpleSequence;
> +import freemarker.template.Template;
> +import freemarker.template.TemplateException;
> +
> +/**
> + * WfsViewHandler - View Handler
> + */
> +public class WfsViewHandler implements ViewHandler {
> +    
> +    public static final String module = WfsViewHandler.class.getName();
> +    public static final String FormatTemplateUrl ="component://webapp/script/org/ofbiz/webapp/event/formatWfs.ftl";
> +
> +    protected ServletContext context;
> +
> +    public void init(ServletContext context) throws ViewHandlerException {
> +        this.context = context;
> +    }
> +
> +    public void render(String name, String page, String info, String contentType, String encoding, HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException {
> +        // some containers call filters on EVERY request, even forwarded ones,
> +        // so let it know that it came from the control servlet
> +
> +        if (request == null)
> +            throw new ViewHandlerException("Null HttpServletRequest object");
> +        if (page == null || page.length() == 0)
> +            throw new ViewHandlerException("Null or empty source");
> +
> +        if (Debug.infoOn()) Debug.logInfo("Retreiving HTTP resource at: " + page, module);
> +        try {
> +           String result = null;
> +            
> +           List entityList = (List)request.getAttribute("entityList");
> +           SimpleSequence simpleList = new SimpleSequence(entityList);
> +           Map ctx = new HashMap();
> +           ctx.put("entityList", simpleList);
> +           StringWriter outWriter = new StringWriter();
> +           Template template = getDocTemplate(page);
> +           template.process(ctx, outWriter);
> +           outWriter.close();
> +           result = outWriter.toString();
> +           Debug.logInfo(result, result);
> +            response.getWriter().print(result);
> +        } catch (FileNotFoundException e) {
> +            throw new ViewHandlerException(e.getMessage(), e);
> +        } catch (IOException e) {
> +            throw new ViewHandlerException("IO Error in view", e);
> +        } catch (URISyntaxException e) {
> +            throw new ViewHandlerException(e.getMessage(), e);
> +        } catch (TemplateException e) {
> +            throw new ViewHandlerException(e.getMessage(), e);
> +        }
> +    }
> +    
> +    public static Template getDocTemplate(String fileUrl)  throws FileNotFoundException, IOException, TemplateException, URISyntaxException {
> +
> +        Template template = null;
> +                
> +        URL screenFileUrl = FlexibleLocation.resolveLocation(fileUrl, null);
> +        String urlStr = screenFileUrl.toString();
> +        URI uri = new URI(urlStr);
> +        File f = new File(uri);
> +                
> +        FileReader templateReader = new FileReader(f);
> +
> +        Configuration conf = makeDefaultOfbizConfig();
> +
> +        template = new Template("FMImportFilter", templateReader, conf);
> +
> +        return template;
> +    }
> +
> +    public static Configuration makeDefaultOfbizConfig() throws TemplateException, IOException {
> +        Configuration config = new Configuration();            
> +        config.setObjectWrapper(BeansWrapper.getDefaultInstance());
> +        config.setSetting("datetime_format", "yyyy-MM-dd HH:mm:ss.SSS");
> +        Configuration defaultOfbizConfig = config;
> +        return defaultOfbizConfig;
> +    }
> +}
>


Reply | Threaded
Open this post in threaded view
|

Re: svn commit: r566781 - in /ofbiz/trunk/framework/webapp: config/ script/ script/org/ script/org/ofbiz/ script/org/ofbiz/webapp/ script/org/ofbiz/webapp/event/ src/org/ofbiz/webapp/event/ src/org/ofbiz/webapp/view/

Jacopo Cappellato
In reply to this post by Jacopo Cappellato
Hi Al,

it's me again :-)

I've noticed that in the java classes the formatting can be cleaned up a it.
For example:
1) use
if (condition) {
     instruction;
}
instead of
if (condition) instruction;

2) the name of the 'constant' FormatTemplateUrl should be
FORMAT_TEMPLATE_URL; however it doesn't seem to be used, so maybe you
can remove it...

All our official formatting rules are here:

http://docs.ofbiz.org/x/mg

Thanks!!!

Jacopo

Jacopo Cappellato wrote:

> Hi Al,
>
> could you please add the license header to all the new files in this
> commit?
> You can find a collection of headers for each file type in
> APACHE2_HEADER (in the ofbiz folder)
>
> Jacopo
>
> [hidden email] wrote:
>> Author: byersa
>> Date: Thu Aug 16 10:14:18 2007
>> New Revision: 566781
>>
>> URL: http://svn.apache.org/viewvc?view=rev&rev=566781
>> Log:
>> I am adding these GIS related files for safe keeping and to serve
>> notice that a GIS component will be forthcoming.
>> Actually, they work now, so it will be a matter of filling the out -
>> especially translating ogc filter constraints to simple method entity
>> expressions.
>>
>> WFS is a standard in the GIS world for querying and returning metadata
>> (as opposed to the other two standards, WMS and WMC,
>> which deal with returning images from vector info or images as the
>> native format (coverages).
>> By putting a WFS server interface in OFBiz, it can be used to add
>> point-of-interest plotting to many business apps.
>>
>> Added:
>>     ofbiz/trunk/framework/webapp/config/wfs.properties
>>     ofbiz/trunk/framework/webapp/script/
>>     ofbiz/trunk/framework/webapp/script/org/
>>     ofbiz/trunk/framework/webapp/script/org/ofbiz/
>>     ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/
>>     ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/
>>    
>> ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl
>>    
>> ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl
>>    
>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java
>>
>>    
>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java
>>
>>
>> Added: ofbiz/trunk/framework/webapp/config/wfs.properties
>> URL:
>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/config/wfs.properties?view=auto&rev=566781 
>>
>> ==============================================================================
>>
>> --- ofbiz/trunk/framework/webapp/config/wfs.properties (added)
>> +++ ofbiz/trunk/framework/webapp/config/wfs.properties Thu Aug 16
>> 10:14:18 2007
>> @@ -0,0 +1,2 @@
>> +input.template.path=component://webapp/script/org/ofbiz/webapp/event/processWfs.ftl
>>
>> +format.template.path=component://webapp/script/org/ofbiz/webapp/event/formatWfs.ftl
>>
>> \ No newline at end of file
>>
>> Added:
>> ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl
>> URL:
>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl?view=auto&rev=566781 
>>
>> ==============================================================================
>>
>> ---
>> ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl
>> (added)
>> +++
>> ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/formatWfs.ftl
>> Thu Aug 16 10:14:18 2007
>> @@ -0,0 +1,36 @@
>> +<?xml version="1.0" ?>
>> +<wfs:FeatureCollection
>> +    xmlns="http://www.hotwaxmedia.com/granite"
>> +    xmlns:wfs="http://www.opengis.net/wfs"
>> +    xmlns:gml="http://www.opengis.net/gml"
>> +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> +    >
>> +
>> +<#list entityList as entity>
>> +  <gml:featureMember>
>> +      <#assign entityName=entity.getEntityName()/>
>> +      <${entityName} fid="E${entity_index}">
>> +      <#assign keyMap=entity.getAllFields()/>
>> +      <#assign keys=keyMap.keySet()/>
>> +      <#assign thisLongitude=""/>
>> +      <#assign thisLatitude=""/>
>> +      <#list keys as key>
>> +        <#assign val = (entity.get(key))?default("")/>
>> +        <#if key=="longitude"><#assign thisLongitude=val/></#if>
>> +        <#if key == "latitude"><#assign thisLatitude=val/></#if>
>> +        <#if key=="longitude" || key == "latitude">
>> +            <#if thisLongitude?has_content && thisLatitude?has_content>
>> +                <geoTemp>
>> +                    <gml:Point srsName="4326">
>> +                    <gml:pos>${thisLongitude} ${thisLatitude}</gml:pos>
>> +                    </gml:Point>
>> +                </geoTemp>
>> +            </#if>
>> +        <#else>
>> +        <${key}>${val}</${key}>
>> +        </#if>
>> +      </#list>
>> +      </${entityName}>
>> +  </gml:featureMember>
>> +</#list>
>> +    </wfs:FeatureCollection>
>> \ No newline at end of file
>>
>> Added:
>> ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl
>> URL:
>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl?view=auto&rev=566781 
>>
>> ==============================================================================
>>
>> ---
>> ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl
>> (added)
>> +++
>> ofbiz/trunk/framework/webapp/script/org/ofbiz/webapp/event/processWfs.ftl
>> Thu Aug 16 10:14:18 2007
>> @@ -0,0 +1,31 @@
>> +<#ftl ns_prefixes={"ogc":"http://ogc.org"}>
>> +    <simple-method method-name="processWfs"
>> short-description="Process a WFS request and return a simple method"
>> login-required="false">
>> +
>> +<#if doc?node_name == "Filter">
>> +  <#visit doc/>
>> +<#else>
>> +  <#recurse doc/>
>> +</#if>
>> +
>> +</simple-method>
>> +
>> +
>> +<#macro @element></#macro>
>> +
>> +
>> +<#macro "ogc:Filter">
>> +                <entity-condition list-name="entityList"
>> entity-name="${entityName}" filter-by-date="false" use-cache="false">
>> +  <#recurse .node>
>> +                </entity-condition>
>> +                <field-to-request field-name="entityList"/>
>> +</#macro>
>> +
>> +<#macro "ogc:PropertyIsEqualTo"><#assign
>> propName=.node["ogc:PropertyName"].@@text />
>> +  <condition-expr field-name="${propName}" value="<@getLiteral
>> nd=.node["ogc:Literal"] nm=propName/>"/>
>> +
>> +</#macro>
>> +
>> +<#macro "ogc:PropertyName"></#macro>
>> +<#macro "ogc:Literal"></#macro>
>> +<#macro getPropertyName nd>${nd.@@text}</#macro>
>> +<#macro getLiteral nd nm>${(paramMap.nm)?default(nd.@@text)}</#macro>
>>
>> Added:
>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java
>>
>> URL:
>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java?view=auto&rev=566781 
>>
>> ==============================================================================
>>
>> ---
>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java
>> (added)
>> +++
>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/WfsEventHandler.java
>> Thu Aug 16 10:14:18 2007
>> @@ -0,0 +1,245 @@
>> +/*******************************************************************************
>>
>> + * Licensed to the Apache Software Foundation (ASF) under one
>> + * or more contributor license agreements.  See the NOTICE file
>> + * distributed with this work for additional information
>> + * regarding copyright ownership.  The ASF licenses this file
>> + * to you under the Apache License, Version 2.0 (the
>> + * "License"); you may not use this file except in compliance
>> + * with the License.  You may obtain a copy of the License at
>> + * + * http://www.apache.org/licenses/LICENSE-2.0
>> + * + * Unless required by applicable law or agreed to in writing,
>> + * software distributed under the License is distributed on an
>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> + * KIND, either express or implied.  See the License for the
>> + * specific language governing permissions and limitations
>> + * under the License.
>> +
>> *******************************************************************************/
>>
>> +package org.ofbiz.webapp.event ;
>> +
>> +import java.io.FileNotFoundException;
>> +import java.io.File;
>> +import java.io.FileReader;
>> +import java.io.IOException;
>> +import java.io.StringWriter;
>> +import java.io.Writer;
>> +import java.io.OutputStream;
>> +import java.io.InputStream;
>> +import java.util.HashMap;
>> +import java.util.Iterator;
>> +import java.util.List;
>> +import java.util.Map;
>> +import java.util.Set;
>> +import java.net.URI;
>> +import java.net.URL;
>> +import java.net.URISyntaxException;
>> +import javax.servlet.http.HttpServletRequest;
>> +import javax.servlet.http.HttpServletResponse;
>> +import javax.servlet.ServletContext;
>> +import org.ofbiz.webapp.event.EventHandler;
>> +import org.ofbiz.webapp.event.EventHandlerException;
>> +
>> +import javax.xml.parsers.DocumentBuilder;
>> +import javax.xml.parsers.DocumentBuilderFactory;
>> +import javax.xml.parsers.ParserConfigurationException;
>> +
>> +import javolution.util.FastList;
>> +
>> +import org.ofbiz.base.location.FlexibleLocation;
>> +import org.ofbiz.base.util.Debug;
>> +import org.ofbiz.base.util.UtilMisc;
>> +import org.ofbiz.base.util.UtilXml;
>> +import org.ofbiz.base.util.UtilFormatOut;
>> +import org.ofbiz.base.util.UtilProperties;
>> +import org.ofbiz.base.util.UtilValidate;
>> +import org.ofbiz.entity.GenericDelegator;
>> +import org.ofbiz.minilang.method.MethodContext;
>> +import org.ofbiz.service.GenericServiceException;
>> +import org.ofbiz.service.LocalDispatcher;
>> +import org.ofbiz.service.ModelService;
>> +import org.ofbiz.service.DispatchContext;
>> +import org.ofbiz.service.ServiceUtil;
>> +import org.ofbiz.webapp.control.RequestHandler;
>> +import org.ofbiz.minilang.SimpleMethod;
>> +
>> +import org.apache.xml.serialize.OutputFormat;
>> +import org.apache.xml.serialize.XMLSerializer;
>> +import org.w3c.dom.Document;
>> +import org.w3c.dom.DocumentFragment;
>> +import org.w3c.dom.Element;
>> +import org.w3c.dom.Node;
>> +import org.xml.sax.EntityResolver;
>> +import org.xml.sax.ErrorHandler;
>> +import org.xml.sax.InputSource;
>> +import org.xml.sax.SAXException;
>> +import org.xml.sax.SAXParseException;
>> +import org.xml.sax.helpers.DefaultHandler;
>> +
>> +import freemarker.ext.beans.BeansWrapper;
>> +import freemarker.ext.dom.NodeModel;
>> +import freemarker.template.Configuration;
>> +import freemarker.template.SimpleSequence;
>> +import freemarker.template.Template;
>> +import freemarker.template.TemplateException;
>> +
>> +
>> +/**
>> + * WfsEventHandler - WFS Event Handler implementation
>> + */
>> +public class WfsEventHandler implements EventHandler {
>> +
>> +    public static final String module = WfsEventHandler.class.getName();
>> +    +    public static final String InputTemplateUrl
>> ="component://webapp/script/org/ofbiz/webapp/event/processWfs.ftl";
>> +
>> +    /**
>> +     * @see
>> org.ofbiz.webapp.event.EventHandler#init(javax.servlet.ServletContext)
>> +     */
>> +    public void init(ServletContext context) throws
>> EventHandlerException {
>> +    }
>> +    +    /** Invoke the web event
>> +     *@param eventPath The path or location of this event
>> +     *@param eventMethod The method to invoke
>> +     *@param request The servlet request object
>> +     *@param response The servlet response object
>> +     *@return String Result code
>> +     *@throws EventHandlerException
>> +     */
>> +    public String invoke(String eventPath, String eventMethod,
>> HttpServletRequest request, HttpServletResponse response) throws
>> EventHandlerException {
>> +        LocalDispatcher dispatcher = (LocalDispatcher)
>> request.getAttribute("dispatcher");
>> +        String typeName = null;
>> +        Element queryElem = null;
>> +
>> +        try {
>> +            Map paramMap = request.getParameterMap();
>> +            typeName = (String)request.getParameter("typename");
>> +            //determine if "get" or "post" and get "filter" param
>> accordingly
>> +            if (UtilValidate.isNotEmpty(typeName)) {
>> +                String queryFieldCoded =
>> (String)request.getParameter("filter");
>> +                String queryFieldDecoded =
>> UtilFormatOut.decodeQueryValue(queryFieldCoded);
>> +                Document doc =
>> UtilXml.readXmlDocument(queryFieldDecoded);
>> +                queryElem = doc.getDocumentElement();
>> +            } else {
>> +                Document doc =
>> UtilXml.readXmlDocument(request.getInputStream(), "WFS Request");
>> +                Element getFeatureElem = doc.getDocumentElement();
>> +                queryElem = UtilXml.firstChildElement(getFeatureElem,
>> "Query");
>> +                typeName = queryElem.getAttribute("typeName");
>> +            }
>> +            // Take "ogc:filter" element and transform it to a Simple
>> Method query script
>> +            String inputTmplUrl =
>> UtilProperties.getPropertyValue("wfs", "input.template.path",
>> WfsEventHandler.InputTemplateUrl);
>> +            String xmlScript = processWfsEntity(typeName, queryElem,
>> inputTmplUrl);
>> +            +            // run simple method script to get a list of
>> entities
>> +            Document simpleDoc = UtilXml.readXmlDocument(xmlScript);
>> +            Element simpleElem = simpleDoc.getDocumentElement();
>> +            SimpleMethod meth = new SimpleMethod(simpleElem, null,
>> null);
>> +            MethodContext methodContext = new MethodContext(request,
>> response, null);
>> +            String retStr = meth.exec(methodContext); //Need to check
>> return string
>> +            List entityList = (List)request.getAttribute("entityList");
>> +            request.setAttribute("entityList", entityList);
>> +            +        } catch (TemplateException ioe) {
>> +            sendError(response, "Problem handling event");
>> +            throw new EventHandlerException("Problem processing
>> template", ioe);
>> +        } catch (FileNotFoundException ioe) {
>> +            sendError(response, "Problem handling event");
>> +            throw new EventHandlerException("Cannot find file", ioe);
>> +        } catch (URISyntaxException ioe) {
>> +            sendError(response, "Problem handling event");
>> +            throw new EventHandlerException("Cannot read the input
>> stream", ioe);
>> +        } catch (SAXException ioe) {
>> +            sendError(response, "Problem handling event");
>> +            throw new EventHandlerException("Cannot read the input
>> stream", ioe);
>> +        } catch (ParserConfigurationException ioe) {
>> +            sendError(response, "Problem handling event");
>> +            throw new EventHandlerException("Cannot read the input
>> stream", ioe);
>> +        } catch (IOException ioe) {
>> +            sendError(response, "Problem handling event");
>> +            throw new EventHandlerException("Cannot read the input
>> stream", ioe);
>> +        }
>> +
>> +
>> +        return "success";
>> +    }
>> +
>> +    private void sendError(HttpServletResponse res, Object obj)
>> throws EventHandlerException {
>> +//        Message msg = new Message(obj);
>> +
>> +        try {
>> +//            
>> res.setContentType(msg.getContentType(Constants.DEFAULT_WFS_VERSION));
>> +//            
>> res.setContentLength(Integer.parseInt(Long.toString(msg.getContentLength())));
>>
>> +//            
>> msg.writeTo(res.getOutputStream());                        
>> +//            res.flushBuffer();
>> +        } catch (Exception e) {
>> +            throw new EventHandlerException(e.getMessage(), e);
>> +        }
>> +    }
>> +
>> +    private String getLocationURI(HttpServletRequest request) {
>> +        StringBuffer uri = new StringBuffer();
>> +//        uri.append(request.getScheme());
>> +//        uri.append("://");
>> +//        uri.append(request.getServerName());
>> +//        if (request.getServerPort() != 80 &&
>> request.getServerPort() != 443) {
>> +//            uri.append(":");
>> +//            uri.append(request.getServerPort());
>> +//        }
>> +//        uri.append(request.getContextPath());
>> +//        uri.append(request.getServletPath());
>> +//
>> +//        String reqInfo =
>> RequestHandler.getRequestUri(request.getPathInfo());
>> +//        if (!reqInfo.startsWith("/")) {
>> +//            reqInfo = "/" + reqInfo;
>> +//        }
>> +//
>> +//        uri.append(reqInfo);
>> +        return uri.toString();
>> +    }
>> +    +    public static String processWfsEntity(String entityName,
>> Node domNode, String templatePath) throws TemplateException,
>> FileNotFoundException, IOException, URISyntaxException {
>> +        +        String result = null;
>> +        +            NodeModel nodeModel = NodeModel.wrap(domNode);
>> +    +            Map ctx = new HashMap();
>> +            ctx.put("doc", nodeModel);
>> +            ctx.put("entityName", entityName);
>> +            StringWriter outWriter = new StringWriter();
>> +            Template template = getDocTemplate(templatePath);
>> +            template.process(ctx, outWriter);
>> +            outWriter.close();
>> +            result = outWriter.toString();
>> +
>> +        return result;
>> +    }
>> +    +    +    public static Template getDocTemplate(String fileUrl)  
>> throws FileNotFoundException, IOException, TemplateException,
>> URISyntaxException { +
>> +        Template template = null;
>> +                +                URL screenFileUrl =
>> FlexibleLocation.resolveLocation(fileUrl, null);
>> +                String urlStr = screenFileUrl.toString();
>> +                URI uri = new URI(urlStr);
>> +                File f = new File(uri);
>> +                +            FileReader templateReader = new
>> FileReader(f);
>> +
>> +            Configuration conf = makeDefaultOfbizConfig();
>> +
>> +            template = new Template("FMImportFilter", templateReader,
>> conf);
>> +
>> +        return template;
>> +    }
>> +
>> +    public static Configuration makeDefaultOfbizConfig() throws
>> TemplateException, IOException {
>> +        Configuration config = new Configuration();            
>> +        config.setObjectWrapper(BeansWrapper.getDefaultInstance());
>> +        config.setSetting("datetime_format", "yyyy-MM-dd HH:mm:ss.SSS");
>> +        Configuration defaultOfbizConfig = config;
>> +        return defaultOfbizConfig;
>> +    }
>> +}
>>
>> Added:
>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java
>>
>> URL:
>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java?view=auto&rev=566781 
>>
>> ==============================================================================
>>
>> ---
>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java
>> (added)
>> +++
>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/view/WfsViewHandler.java
>> Thu Aug 16 10:14:18 2007
>> @@ -0,0 +1,124 @@
>> +/*******************************************************************************
>>
>> + * Licensed to the Apache Software Foundation (ASF) under one
>> + * or more contributor license agreements.  See the NOTICE file
>> + * distributed with this work for additional information
>> + * regarding copyright ownership.  The ASF licenses this file
>> + * to you under the Apache License, Version 2.0 (the
>> + * "License"); you may not use this file except in compliance
>> + * with the License.  You may obtain a copy of the License at
>> + * + * http://www.apache.org/licenses/LICENSE-2.0
>> + * + * Unless required by applicable law or agreed to in writing,
>> + * software distributed under the License is distributed on an
>> + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
>> + * KIND, either express or implied.  See the License for the
>> + * specific language governing permissions and limitations
>> + * under the License.
>> +
>> *******************************************************************************/
>>
>> +package org.ofbiz.webapp.view;
>> +
>> +import java.io.File;
>> +import java.io.FileNotFoundException;
>> +import java.io.FileReader;
>> +import java.io.IOException;
>> +import java.io.StringWriter;
>> +import java.net.URI;
>> +import java.net.URISyntaxException;
>> +import java.net.URL;
>> +import java.util.HashMap;
>> +import java.util.Map;
>> +import java.util.List;
>> +
>> +import javax.servlet.ServletContext;
>> +import javax.servlet.http.HttpServletRequest;
>> +import javax.servlet.http.HttpServletResponse;
>> +
>> +import org.ofbiz.base.location.FlexibleLocation;
>> +import org.ofbiz.base.util.Debug;
>> +import org.ofbiz.base.util.HttpClient;
>> +import org.ofbiz.base.util.HttpClientException;
>> +import org.ofbiz.webapp.view.ViewHandler;
>> +import org.ofbiz.webapp.view.ViewHandlerException;
>> +
>> +import freemarker.ext.beans.BeansWrapper;
>> +import freemarker.template.Configuration;
>> +import freemarker.template.SimpleSequence;
>> +import freemarker.template.Template;
>> +import freemarker.template.TemplateException;
>> +
>> +/**
>> + * WfsViewHandler - View Handler + */
>> +public class WfsViewHandler implements ViewHandler {
>> +    +    public static final String module =
>> WfsViewHandler.class.getName();
>> +    public static final String FormatTemplateUrl
>> ="component://webapp/script/org/ofbiz/webapp/event/formatWfs.ftl";
>> +
>> +    protected ServletContext context;
>> +
>> +    public void init(ServletContext context) throws
>> ViewHandlerException {
>> +        this.context = context;
>> +    }
>> +
>> +    public void render(String name, String page, String info, String
>> contentType, String encoding, HttpServletRequest request,
>> HttpServletResponse response) throws ViewHandlerException {
>> +        // some containers call filters on EVERY request, even
>> forwarded ones,
>> +        // so let it know that it came from the control servlet
>> +
>> +        if (request == null)
>> +            throw new ViewHandlerException("Null HttpServletRequest
>> object");
>> +        if (page == null || page.length() == 0)
>> +            throw new ViewHandlerException("Null or empty source");
>> +
>> +        if (Debug.infoOn()) Debug.logInfo("Retreiving HTTP resource
>> at: " + page, module);
>> +        try {
>> +           String result = null;
>> +            +           List entityList =
>> (List)request.getAttribute("entityList");
>> +           SimpleSequence simpleList = new SimpleSequence(entityList);
>> +           Map ctx = new HashMap();
>> +           ctx.put("entityList", simpleList);
>> +           StringWriter outWriter = new StringWriter();
>> +           Template template = getDocTemplate(page);
>> +           template.process(ctx, outWriter);
>> +           outWriter.close();
>> +           result = outWriter.toString();
>> +           Debug.logInfo(result, result);
>> +            response.getWriter().print(result);
>> +        } catch (FileNotFoundException e) {
>> +            throw new ViewHandlerException(e.getMessage(), e);
>> +        } catch (IOException e) {
>> +            throw new ViewHandlerException("IO Error in view", e);
>> +        } catch (URISyntaxException e) {
>> +            throw new ViewHandlerException(e.getMessage(), e);
>> +        } catch (TemplateException e) {
>> +            throw new ViewHandlerException(e.getMessage(), e);
>> +        }
>> +    }
>> +    +    public static Template getDocTemplate(String fileUrl)  
>> throws FileNotFoundException, IOException, TemplateException,
>> URISyntaxException { +
>> +        Template template = null;
>> +                +        URL screenFileUrl =
>> FlexibleLocation.resolveLocation(fileUrl, null);
>> +        String urlStr = screenFileUrl.toString();
>> +        URI uri = new URI(urlStr);
>> +        File f = new File(uri);
>> +                +        FileReader templateReader = new FileReader(f);
>> +
>> +        Configuration conf = makeDefaultOfbizConfig();
>> +
>> +        template = new Template("FMImportFilter", templateReader, conf);
>> +
>> +        return template;
>> +    }
>> +
>> +    public static Configuration makeDefaultOfbizConfig() throws
>> TemplateException, IOException {
>> +        Configuration config = new Configuration();            
>> +        config.setObjectWrapper(BeansWrapper.getDefaultInstance());
>> +        config.setSetting("datetime_format", "yyyy-MM-dd HH:mm:ss.SSS");
>> +        Configuration defaultOfbizConfig = config;
>> +        return defaultOfbizConfig;
>> +    }
>> +}
>>
>