cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject cvs commit: cocoon-2.1/src/blocks/profiler/java/org/apache/cocoon/generation ProfilerGenerator.java
Date Fri, 21 Mar 2003 17:28:43 GMT
bruno       2003/03/21 09:28:43

  Modified:    src/blocks/profiler/java/org/apache/cocoon/generation
                        ProfilerGenerator.java
  Log:
  Allow to retrieve only the stored XML (without metadata from the profiler around it)
  by supporting a "fragmentonly" request parameter.
  
  Revision  Changes    Path
  1.3       +54 -21    cocoon-2.1/src/blocks/profiler/java/org/apache/cocoon/generation/ProfilerGenerator.java
  
  Index: ProfilerGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/profiler/java/org/apache/cocoon/generation/ProfilerGenerator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ProfilerGenerator.java	20 Mar 2003 15:04:16 -0000	1.2
  +++ ProfilerGenerator.java	21 Mar 2003 17:28:42 -0000	1.3
  @@ -111,6 +111,9 @@
       // Index of the componen of the latest results
       private int componentIndex = -1;
   
  +    // Indicates if the fragment only, and not the profiler metadata around it, should
be generated
  +    private boolean fragmentOnly;
  +
       /**
        * Composable
        */
  @@ -148,6 +151,12 @@
           } else {
               this.componentIndex = -1;
           }
  +
  +        if (request.getParameter("fragmentonly") != null && request.getParameter("fragmentonly").equals("true"))
{
  +            fragmentOnly = true;
  +        } else {
  +            fragmentOnly = false;
  +        }
       }
   
       /**
  @@ -167,16 +176,39 @@
        *         when there is a problem creating the output SAX events.
        */
       public void generate() throws SAXException {
  -
  -        // Start the document and set the PROFILER_NS.
  -        this.contentHandler.startDocument();
  -        this.contentHandler.startPrefixMapping("", PROFILER_NS);
  -
  -        generateProfilerInfo();
  -
  -        // End the document.
  -        this.contentHandler.endPrefixMapping("");
  -        this.contentHandler.endDocument();
  +        // check if only the stored XML data is requested
  +        if (fragmentOnly && key != null && resultIndex != -1 &&
componentIndex != -1) {
  +            // find the fragment
  +            Object fragment = null;
  +            try {
  +                ProfilerResult result = profiler.getResult(key);
  +                fragment = result.getSAXFragments()[resultIndex][componentIndex];
  +            } catch (Exception e) {
  +                // fragment will be null
  +            }
  +            if (fragment != null) {
  +                generateSAXFragment(fragment, false);
  +            } else {
  +                this.contentHandler.startDocument();
  +                this.contentHandler.startPrefixMapping("", PROFILER_NS);
  +                this.contentHandler.startElement(PROFILER_NS, "fragment-error", "fragment-error",
new AttributesImpl());
  +                char[] message = "Fragment is not available.".toCharArray();
  +                this.contentHandler.characters(message, 0, message.length);
  +                this.contentHandler.endElement(PROFILER_NS, "fragment-error", "fragment-error");
  +                this.contentHandler.endPrefixMapping("");
  +                this.contentHandler.endDocument();
  +            }
  +        } else {
  +            // Start the document and set the PROFILER_NS.
  +            this.contentHandler.startDocument();
  +            this.contentHandler.startPrefixMapping("", PROFILER_NS);
  +
  +            generateProfilerInfo();
  +
  +            // End the document.
  +            this.contentHandler.endPrefixMapping("");
  +            this.contentHandler.endDocument();
  +        }
       }
   
       /**
  @@ -368,7 +400,12 @@
           atts.clear();
   
           if (this.componentIndex==componentIndex) {
  -            generateSAXFragment(fragment);
  +            this.contentHandler.startElement(PROFILER_NS, FRAGMENT_ELEMENT,
  +                                             FRAGMENT_ELEMENT,
  +                                             new AttributesImpl());
  +            generateSAXFragment(fragment, true);
  +            this.contentHandler.endElement(PROFILER_NS, FRAGMENT_ELEMENT,
  +                                           FRAGMENT_ELEMENT);
           }
   
           this.contentHandler.endElement(PROFILER_NS, COMPONENT_ELEMENT,
  @@ -454,18 +491,17 @@
                                          ENVIROMENTINFO_ELEMENT);
       }
   
  -    public void generateSAXFragment(Object fragment) throws SAXException {
  +    public void generateSAXFragment(Object fragment, boolean embed) throws SAXException
{
   
           if (fragment!=null) {
  -            this.contentHandler.startElement(PROFILER_NS, FRAGMENT_ELEMENT,
  -                                             FRAGMENT_ELEMENT,
  -                                             new AttributesImpl());
  -
               XMLDeserializer deserializer = null;
   
               try {
                   deserializer = (XMLDeserializer) this.manager.lookup(XMLDeserializer.ROLE);
  -                deserializer.setConsumer(new IncludeXMLConsumer(this.xmlConsumer));
  +                if (embed)
  +                    deserializer.setConsumer(new IncludeXMLConsumer(this.xmlConsumer));
  +                else
  +                    deserializer.setConsumer(this.xmlConsumer);
                   deserializer.deserialize(fragment);
               } catch (ComponentException ce) {
                   getLogger().debug("Could not retrieve XMLDeserializer component",
  @@ -480,9 +516,6 @@
                       this.manager.release(deserializer);
                   }
               }
  -
  -            this.contentHandler.endElement(PROFILER_NS, FRAGMENT_ELEMENT,
  -                                           FRAGMENT_ELEMENT);
           }
       }
   }
  
  
  

Mime
View raw message