public static IWebXml getWebXml(string pathToWebXmlFile)
        {

            // hack to handle prob with XSD schema (which doesn't load when ...)
            var fileContents = Files.getFileContents(pathToWebXmlFile);
            if (fileContents.IndexOf("<web-app>") > -1)
            {
                fileContents = fileContents.Replace("<web-app>",
                                                    "<web-app version=\"2.4\" xmlns=\"http://java.sun.com/xml/ns/j2ee\">");
                pathToWebXmlFile = PublicDI.config.getTempFileInTempDirectory("web.xml");
                Files.WriteFileContent(pathToWebXmlFile, fileContents);            
            }
            var webXml = new KWebXml();
            var webAppType = ((webappType)Serialize.getDeSerializedObjectFromXmlFile(pathToWebXmlFile, typeof(webappType)));
            if (webAppType != null)
            {
                foreach (var item in webAppType.Items)
                {
                    switch (item.GetType().Name)
                    {
                        case "displaynameType":
                            var displayName = (displaynameType) item;
                            webXml.displayName = displayName.Value;
                            break;
                        case "descriptionType":
                            var description = (descriptionType) item;
                            webXml.description = description.Value;
                            break;
                        case "paramvalueType":
                            var paramvalue = (paramvalueType)item;
                            PublicDI.log.debug("paramvalueType:  {0} = {1}", paramvalue.paramname.Value, paramvalue.paramvalue.Value);
                            //webXml.displayName = displayName.Value;
                            break;
                        case "filterType":
                            var filter = (filterType) item;
                            webXml.filters.Add(
                                new KWebXml_Filter
                                    {
                                        filterClass =
                                            (filter.filterclass != null ? filter.filterclass.Value : ""),
                                        filterName =
                                            filter.filtername != null ? filter.filtername.Value : ""
                                    });
                            break;
                        case "filtermappingType":
                            var filterMapping = (filtermappingType) item;
                            var newFilterMapping =
                                new kWebXml_Filter_Mapping()
                                    {
                                        filterName =
                                            filterMapping.filtername != null
                                                ? filterMapping.filtername.Value
                                                : "",
                                        dispatcher =
                                            filterMapping.filtername != null
                                                ? filterMapping.filtername.Value
                                                : ""
                                    };
                            if (filterMapping.Item != null)
                                if (filterMapping.Item is urlpatternType)
                                    newFilterMapping.urlPattern = ((urlpatternType) filterMapping.Item).Value;
                            webXml.filterMappings.Add(newFilterMapping);
                            break;

                        case "listenerType":
                            var listenerType = (listenerType)item;
                            webXml.listenerClass = listenerType.listenerclass.Value;
                            break;
                        case "servletType":
                            var servletType = (servletType)item;
                            var newServlet = new KWebXml_Servlet
                                              {
                                                  servletName = (servletType.servletname != null)  ? servletType.servletname.Value : "",
                                                  loadOnStartUp = (servletType.loadonstartup != null) ? servletType.loadonstartup.Value : ""
                                              };
                            if (servletType.Item is fullyqualifiedclassType)
                                newServlet.servletClass = servletType.Item.Value;
                            if (servletType.initparam != null)
                                foreach (var _initParam in servletType.initparam)                                
                                    newServlet.initParam.Add(_initParam.paramname.Value, _initParam.paramvalue.Value);                                    

                            webXml.servlets.Add(newServlet);
                            break;
                        case "servletmappingType":
                            var servletMapping = (servletmappingType)item;
                            var newServletMapping =
                                new KWebXml_Servlet_Mapping()
                                    {
                                        servletName = servletMapping.servletname.Value,
                                        urlPattern = servletMapping.urlpattern.Value
                                    };
                            webXml.servletMappings.Add(newServletMapping);
                            break;
                        default:
                            PublicDI.log.info("no mapping for :" + item.GetType().Name);
                            break;
                    }
                }
            }
            return webXml;
        }
예제 #2
0
        public static IWebXml getWebXml(string pathToWebXmlFile)
        {
            // hack to handle prob with XSD schema (which doesn't load when ...)
            var fileContents = Files.getFileContents(pathToWebXmlFile);

            if (fileContents.IndexOf("<web-app>") > -1)
            {
                fileContents = fileContents.Replace("<web-app>",
                                                    "<web-app version=\"2.4\" xmlns=\"http://java.sun.com/xml/ns/j2ee\">");
                pathToWebXmlFile = DI.config.getTempFileInTempDirectory("web.xml");
                Files.WriteFileContent(pathToWebXmlFile, fileContents);
            }
            var webXml     = new KWebXml();
            var webAppType = ((webappType)Serialize.getDeSerializedObjectFromXmlFile(pathToWebXmlFile, typeof(webappType)));

            if (webAppType != null)
            {
                foreach (var item in webAppType.Items)
                {
                    switch (item.GetType().Name)
                    {
                    case "displaynameType":
                        var displayName = (displaynameType)item;
                        webXml.displayName = displayName.Value;
                        break;

                    case "descriptionType":
                        var description = (descriptionType)item;
                        webXml.description = description.Value;
                        break;

                    case "paramvalueType":
                        var paramvalue = (paramvalueType)item;
                        DI.log.debug("paramvalueType:  {0} = {1}", paramvalue.paramname.Value, paramvalue.paramvalue.Value);
                        //webXml.displayName = displayName.Value;
                        break;

                    case "filterType":
                        var filter = (filterType)item;
                        webXml.filters.Add(
                            new KWebXml_Filter
                        {
                            filterClass =
                                (filter.filterclass != null ? filter.filterclass.Value : ""),
                            filterName =
                                filter.filtername != null ? filter.filtername.Value : ""
                        });
                        break;

                    case "filtermappingType":
                        var filterMapping    = (filtermappingType)item;
                        var newFilterMapping =
                            new kWebXml_Filter_Mapping()
                        {
                            filterName =
                                filterMapping.filtername != null
                                                ? filterMapping.filtername.Value
                                                : "",
                            dispatcher =
                                filterMapping.filtername != null
                                                ? filterMapping.filtername.Value
                                                : ""
                        };
                        if (filterMapping.Item != null)
                        {
                            if (filterMapping.Item is urlpatternType)
                            {
                                newFilterMapping.urlPattern = ((urlpatternType)filterMapping.Item).Value;
                            }
                        }
                        webXml.filterMappings.Add(newFilterMapping);
                        break;

                    case "listenerType":
                        var listenerType = (listenerType)item;
                        webXml.listenerClass = listenerType.listenerclass.Value;
                        break;

                    case "servletType":
                        var servletType = (servletType)item;
                        var newServlet  = new KWebXml_Servlet
                        {
                            servletName   = (servletType.servletname != null)  ? servletType.servletname.Value : "",
                            loadOnStartUp = (servletType.loadonstartup != null) ? servletType.loadonstartup.Value : ""
                        };
                        if (servletType.Item is fullyqualifiedclassType)
                        {
                            newServlet.servletClass = servletType.Item.Value;
                        }
                        if (servletType.initparam != null)
                        {
                            foreach (var _initParam in servletType.initparam)
                            {
                                newServlet.initParam.Add(_initParam.paramname.Value, _initParam.paramvalue.Value);
                            }
                        }

                        webXml.servlets.Add(newServlet);
                        break;

                    case "servletmappingType":
                        var servletMapping    = (servletmappingType)item;
                        var newServletMapping =
                            new KWebXml_Servlet_Mapping()
                        {
                            servletName = servletMapping.servletname.Value,
                            urlPattern  = servletMapping.urlpattern.Value
                        };
                        webXml.servletMappings.Add(newServletMapping);
                        break;

                    default:
                        DI.log.info("no mapping for :" + item.GetType().Name);
                        break;
                    }
                }
            }
            return(webXml);
        }