Solved

xml browser detection

Posted on 2002-03-19
4
318 Views
Last Modified: 2008-02-01
hi,

as a total newbie to xml, I'm wondering how to detect a browser type in an xml file. The varianble called treeview.xsl should change according to the browser type (ie.xsl / ns.xsl) The script looks like this;

***********
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
  <display-name>hmg</display-name>
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>application</param-name>
      <param-value>ApplicationFormResources</param-value>
    </init-param>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>validate</param-name>
      <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
   
  </servlet>
  <servlet>
    <servlet-name>content</servlet-name>
    <servlet-class>no.cellnetwork.hmg.contentmanagement.servlets.ShowContentServlet</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>initservlet</servlet-name>
    <servlet-class>no.cellnetwork.hmg.init.servlets.InitServlet</servlet-class>
        <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet>
    <servlet-name>treeview</servlet-name>
    <servlet-class>no.cellnetwork.hmg.tree.servlets.TreeViewServlet</servlet-class>
    <init-param>
      <param-name>xslurl</param-name>
      <param-value>http://localhost/eportal/hmg/xsl/treeview.xsl</param-value>
    </init-param>
    <init-param>
      <param-name>xslurlmyprofile</param-name>
      <param-value>http://localhost/eportal/hmg/xsl/myprofile.xsl</param-value>
    </init-param>
    <init-param>
      <param-name>defaultrepository</param-name>
      <param-value>public</param-value>
    </init-param>
  </servlet>
  <servlet>
    <servlet-name>iconservlet</servlet-name>
    <servlet-class>no.cellnetwork.hmg.icon.servlets.IconServlet</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>imageservlet</servlet-name>
    <servlet-class>no.cellnetwork.hmg.image.servlets.ImageServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>content</servlet-name>
    <url-pattern>/jsp/content/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>treeview</servlet-name>
    <url-pattern>/jsp/treeview/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>imageservlet</servlet-name>
    <url-pattern>/jsp/imageservlet/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>initservlet</servlet-name>
    <url-pattern>/init</url-pattern>
  </servlet-mapping>  
  <servlet-mapping>
    <servlet-name>iconservlet</servlet-name>
    <url-pattern>/jsp/iconservlet/*</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>
  <taglib>
    <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
  </taglib>
  <taglib>
    <taglib-uri>/struts</taglib-uri>
    <taglib-location>/WEB-INF/lib/struts.jar</taglib-location>
  </taglib>
</web-app>
***************

Any ideas greatly appreciated!

Regards,

Erik
0
Comment
Question by:gooroo
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 100 total points
ID: 6879786
Look at the user agent in the servlet or jsp:

<%!
public final static int IE = 0;
public final static int NETSCAPE = 1;
public final static int WML = 2;

public int getBrowser(HttpServletRequest request) {
   String accept = request.getHeader("ACCEPT");
   if (null != accept && -1 !=
accept.indexOf("wml")) {
     return WML;
   }
   String agent = request.getHeader("USER-AGENT");
   if (null != agent && -1 !=
agent.indexOf("MSIE")) {
     return IE;
   }
   return NETSCAPE;
}
%>

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 8647674
Please finalize this?
Thanks
Michel
PS: Please do not respond with a "C" Grade to get rid of the question
0
 
LVL 9

Expert Comment

by:sparkplug
ID: 8730672
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
[Accept mplungjan's comment as answer.]
Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

>S'Plug<
EE Cleanup Volunteer
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now