/* 
    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.apache.wiki.parser;

import java.lang.ref.WeakReference;

import org.jdom2.Document;

import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiPage;

/**
 *  Stores the DOM tree of a rendered WikiPage.  This class
 *  extends the org.jdom.Document to provide some extra metadata
 *  specific to JSPWiki.
 *  <p>
 *  The document is not stored as metadata in the WikiPage because
 *  otherwise it could not be cached separately.
 *  
 *  @since  2.4
 */
public class WikiDocument extends Document
{
    private static final long serialVersionUID = 1L;
    
    private WikiPage                   m_page;
    private String                     m_wikiText;

    private WeakReference<WikiContext> m_context;
    
    /**
     *  Creates a new WikiDocument for a specific page.
     * 
     *  @param page The page to which this document refers to.
     */
    public WikiDocument( WikiPage page )
    {
        m_page     = page;
    }
    
    /**
     *  Set the WikiMarkup for this document.
     *  
     *  @param data The WikiMarkup
     */
    public void setPageData( String data )
    {
        m_wikiText = data;
    }
    
    /**
     *  Returns the wikimarkup used to render this document.
     *  
     *  @return The WikiMarkup
     */
    public String getPageData()
    {
        return m_wikiText;
    }
    
    /**
     *  Return the WikiPage for whom this WikiDocument exists.
     *  
     *  @return The WikiPage
     */
    public WikiPage getPage()
    {
        return m_page;
    }

    /**
     *  Set the WikiContext in which the WikiDocument is rendered. The
     *  WikiContext is stored in a WeakReference, which means that it 
     *  can be garbagecollected away.  This is to allow for caching of
     *  the WikiDocument without having to carry the WikiContext around
     *  for a long time.
     *  
     *  @param ctx A WikiContext.
     */
    public void setContext( WikiContext ctx )
    {
        m_context = new WeakReference<WikiContext>( ctx );
    }
    
    /**
     * Returns the wiki context for this document. This method
     * may return <code>null</code> if the associated wiki session
     * had previously been garbage-collected.
     * @return the wiki context
     */
    public WikiContext getContext()
    {
        return m_context.get();
    }
}

@@ -858,66 +858,37 @@
 ort 
-java.lang.ref.WeakReference;%0A%0Aimport org.jdom2.Documen
+org.apache.wiki.WikiContex
 t;%0A
-%0A
 impo
@@ -902,39 +902,36 @@
 apache.wiki.Wiki
-Context
+Page
 ;%0Aimport org.apa
@@ -927,35 +927,66 @@
 ort org.
-apache.wiki.WikiPag
+jdom2.Document;%0A%0Aimport java.lang.ref.WeakReferenc
 e;%0A%0A/**%0A
@@ -1032,17 +1032,16 @@
 ikiPage.
- 
  This cl
@@ -1043,20 +1043,16 @@
 is class
-%0A * 
  extends
@@ -1204,20 +1204,16 @@
  because
-%0A * 
  otherwi
@@ -1321,10 +1321,11 @@
 ment
+ %7B
 %0A
-%7B
 %0A   
@@ -1400,34 +1400,16 @@
 ikiPage 
-                  
 m_page;%0A
@@ -1427,36 +1427,16 @@
  String 
-                    
 m_wikiTe
@@ -1439,17 +1439,16 @@
 kiText;%0A
-%0A
     priv
@@ -1457,32 +1457,33 @@
 e WeakReference%3C
+ 
 WikiContext%3E m_c
@@ -1477,16 +1477,17 @@
 iContext
+ 
 %3E m_cont
@@ -1663,16 +1663,22 @@
 ocument(
+ final
  WikiPag
@@ -1707,20 +1707,16 @@
  m_page 
-    
 = page;%0A
@@ -1860,16 +1860,22 @@
 ageData(
+ final
  String 
@@ -2379,24 +2379,16 @@
 red. The
-%0A     * 
  WikiCon
@@ -2441,17 +2441,16 @@
  that it
- 
 %0A     * 
@@ -2512,24 +2512,16 @@
 ching of
-%0A     * 
  the Wik
@@ -2680,16 +2680,22 @@
 Context(
+ final
  WikiCon
@@ -2749,27 +2749,16 @@
 ference%3C
-WikiContext
 %3E( ctx )
@@ -3074,10 +3074,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

format code