dleslie     00/04/19 11:16:22

  Modified:    samples/Servlet DefaultApplyXSL.java ApplyXSL.java
  Log:
  Servlet now reads xml-stylesheet PI from xml source document.
  Updated procedure for navigating through xml source, and
  "reset" xml source prior to performing operation. Evidently
  navigating into xml source to get PI put XSLTInput in a state
  where root could not be found during transformation.
  Scott/Myriam should take a look!
  
  Revision  Changes    Path
  1.2       +33 -22    xml-xalan/samples/Servlet/DefaultApplyXSL.java
  
  Index: DefaultApplyXSL.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/samples/Servlet/DefaultApplyXSL.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultApplyXSL.java      2000/02/12 00:00:13     1.1
  +++ DefaultApplyXSL.java      2000/04/19 18:16:22     1.2
  @@ -1,5 +1,5 @@
   
/*****************************************************************************************************
  - * $Id: DefaultApplyXSL.java,v 1.1 2000/02/12 00:00:13 dleslie Exp $
  + * $Id: DefaultApplyXSL.java,v 1.2 2000/04/19 18:16:22 dleslie Exp $
    *
    * Copyright (c) 1998-1999 Lotus Corporation, Inc. All Rights Reserved.
    *                           This software is provided without a warranty of 
any kind.
  @@ -443,32 +443,39 @@
      * @return The preferred XSL stylesheet URL, or null if no XSL stylesheet 
association is found
      * @see #getStylesheet
      */
  -  public static String getXSLURLfromDoc(XSLTInputSource xmlSource, String 
attributeName, String attributeValue)
  +  public static String getXSLURLfromDoc(XSLTInputSource xmlSource,
  +                                        String attributeName,
  +                                        String attributeValue,
  +                                        XSLTProcessor processor)
     {
       String tempURL = null, returnURL = null;
  -    NodeList children = xmlSource.getNode().getChildNodes();
  -    int nNodes = children.getLength(), i;
  -    for(i = 0; i < nNodes; i++)
  +    try
       {
  -      Node child = children.item(i);
  -      if(Node.PROCESSING_INSTRUCTION_NODE == child.getNodeType())
  +      Node sourceTree = processor.getSourceTreeFromInput(xmlSource); 
//replaced xmlSource.getNode()
  +      for(Node child=sourceTree.getFirstChild(); null != child; 
child=child.getNextSibling())
         {
  -        ProcessingInstruction pi = (ProcessingInstruction)child;
  -        if(pi.getNodeName().equals("xml-stylesheet"))
  +        if(Node.PROCESSING_INSTRUCTION_NODE == child.getNodeType())
           {
  -          PIA pia = new PIA(pi);
  -          if("text/xsl".equals(pia.getAttribute("type")))
  +          ProcessingInstruction pi = (ProcessingInstruction)child;
  +          if(pi.getNodeName().equals("xml-stylesheet"))
             {
  -            tempURL = pia.getAttribute("href");
  -            String attribute = pia.getAttribute(attributeName);
  -            if ((attribute != null) && (attribute.indexOf(attributeValue) > 
-1))
  -              return tempURL;
  -            if (!"yes".equals(pia.getAttribute("alternate")))
  -              returnURL = tempURL;
  +            PIA pia = new PIA(pi);
  +            if("text/xsl".equals(pia.getAttribute("type")))
  +            {
  +              tempURL = pia.getAttribute("href");
  +              String attribute = pia.getAttribute(attributeName);
  +              if ((attribute != null) && (attribute.indexOf(attributeValue) 
> -1))
  +                return tempURL;
  +              if (!"yes".equals(pia.getAttribute("alternate")))
  +                returnURL = tempURL;
  +            }
             }
           }
         }
       }
  +    catch(Exception saxExc)
  +    {
  +    }
       return returnURL;
     }
   
  @@ -499,21 +506,25 @@
      */
     protected XSLTInputSource getStylesheet(HttpServletRequest request,
                                             XSLTInputSource xmlSource,
  -                                          ApplyXSLListener listener)
  +                                          ApplyXSLListener listener, 
XSLTProcessor processor)
       throws ApplyXSLException
     {
  +
       try
       {
         //stylesheet URL from request
         String xslURL = ((DefaultApplyXSLProperties) 
ourDefaultParameters).getXSLRequestURL(request);
  +
         if (xslURL != null)
           listener.out.println("Parsing XSL Stylesheet Document from request 
parameter: "
                                + xslURL);
         else
         {
           // find stylesheet from XML Document, Media tag preference
  -        if (xmlSource != null)
  -          xslURL = getXSLURLfromDoc(xmlSource, STYLESHEET_ATTRIBUTE, 
getMedia(request));
  +        if (xmlSource != null){
  +          listener.out.println("calling getXSLURLfromDoc and getMedia " + 
getMedia(request) );
  +          xslURL = getXSLURLfromDoc(xmlSource, STYLESHEET_ATTRIBUTE, 
getMedia(request), processor);
  +        }
           if (xslURL != null)
             listener.out.println("Parsing XSL Stylesheet Document from XML 
Document tag: " + xslURL);
           else
  @@ -521,8 +532,9 @@
             if ((xslURL = ourDefaultParameters.getXSLurl(null)) != null)
               listener.out.println("Parsing XSL Stylesheet Document from 
configuration: " + xslURL);
         }
  -      return new XSLTInputSource(toAcceptLanguageConnection(new URL(xslURL),
  -                                                            
request).getURL().toString());
  +        return new XSLTInputSource(xslURL);  // replacement for following 
statement 05-19-00
  +//      return new XSLTInputSource(toAcceptLanguageConnection(new 
URL(xslURL),
  +//                                                            
request).getURL().toString());
       }
       catch (IOException ioe)
       {
  @@ -695,5 +707,4 @@
     {
       return (String) piAttributes.get(name);
     }
  -
   }
  
  
  
  1.2       +4 -2      xml-xalan/samples/Servlet/ApplyXSL.java
  
  Index: ApplyXSL.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/samples/Servlet/ApplyXSL.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ApplyXSL.java     2000/02/12 00:00:12     1.1
  +++ ApplyXSL.java     2000/04/19 18:16:22     1.2
  @@ -1,5 +1,5 @@
   
/*****************************************************************************************************
  - * $Id: ApplyXSL.java,v 1.1 2000/02/12 00:00:12 dleslie Exp $
  + * $Id: ApplyXSL.java,v 1.2 2000/04/19 18:16:22 dleslie Exp $
    *
    * Copyright (c) 1998-1999 Lotus Corporation, Inc. All Rights Reserved.
    *                           This software is provided without a warranty of 
any kind.
  @@ -112,7 +112,7 @@
      */
     protected abstract XSLTInputSource getStylesheet(HttpServletRequest 
request,
                                                      XSLTInputSource xmlSource,
  -                                                   ApplyXSLListener listener)
  +                                                   ApplyXSLListener 
listener, XSLTProcessor processor)
       throws ApplyXSLException;
   
     /**
  @@ -302,10 +302,12 @@
       {
         try
         {
  -        if ((xslSource = getStylesheet(request, xmlSource, listener)) == 
null)
  +        if ((xslSource = getStylesheet(request, xmlSource, listener, 
processor)) == null){
             throw new ApplyXSLException("getStylesheet() returned null",
               new NullPointerException(),
               response.SC_NOT_FOUND);
  +        }
  +        xmlSource = getDocument(processor, request, listener); // must 
"reset" xmlSource -- 05-19-00
         }
         catch (ApplyXSLException axe)
         {
  
  
  

Reply via email to