<commit_before>/*
 * Copyright 2006, XpertNet SARL, and individual contributors as indicated
 * by the contributors.txt.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 *
 * @author ludovic
 * @author wr0ngway
 * @author sdumitriu
 */

package com.xpn.xwiki;

import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.objects.classes.BaseClass;
import com.xpn.xwiki.user.api.XWikiUser;
import com.xpn.xwiki.util.Util;
import com.xpn.xwiki.web.*;
import com.xpn.xwiki.validation.XWikiValidationStatus;
import org.apache.xmlrpc.server.XmlRpcServer;

import java.net.URL;
import java.util.*;

public class XWikiContext extends Hashtable {

   public static final int MODE_SERVLET = 0;
   public static final int MODE_PORTLET = 1;
   public static final int MODE_XMLRPC = 2;
   public static final int MODE_ATOM = 3;
   public static final int MODE_PDF = 4;
   public static final int MODE_GWT = 5;
   public static final int MODE_GWT_DEBUG = 6;

   private boolean finished = false;
   private XWiki wiki;
   private XWikiEngineContext engine_context;
   private XWikiRequest request;
   private XWikiResponse response;
   private XWikiForm form;
   private String action;
   private String orig_database;
   private String database;
   private boolean virtual;
   private XWikiUser user;
   private String language;
   private String interfaceLanguage;
   private int mode;
   private URL url;
   private XWikiURLFactory URLFactory;
   private XmlRpcServer xmlRpcServer;
   private String wikiOwner;
   private XWikiDocument wikiServer;
   private int cacheDuration = 0;

   // Used to avoid recursive loading of documents if there are recursives usage of classes
   private Map classCache = new HashMap();
   // Used to avoir reloading archives in the same request
   private Map archiveCache = new HashMap();

   private List displayedFields = new ArrayList();

   public XWikiContext() {
   }

   public XWiki getWiki() {
       return wiki;
   }

   public Util getUtil() {
       Util util = (Util) this.get("util");
       if (util==null) {
           util = new Util();
           this.put("util", util);
       }
       return util;
    }
<commit_msg>XWIKI-1101: XWikiContext caches become too big when playing with a big number of documents in a single request Fixed. Applyed patch from <NAME>, with minor changes.<commit_after>/*
 * Copyright 2006, XpertNet SARL, and individual contributors as indicated
 * by the contributors.txt.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 *
 * @author ludovic
 * @author wr0ngway
 * @author sdumitriu
 */

package com.xpn.xwiki;

import java.net.URL;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.map.LRUMap;
import org.apache.xmlrpc.server.XmlRpcServer;

import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.objects.classes.BaseClass;
import com.xpn.xwiki.user.api.XWikiUser;
import com.xpn.xwiki.util.Util;
import com.xpn.xwiki.validation.XWikiValidationStatus;
import com.xpn.xwiki.web.XWikiEngineContext;
import com.xpn.xwiki.web.XWikiForm;
import com.xpn.xwiki.web.XWikiMessageTool;
import com.xpn.xwiki.web.XWikiRequest;
import com.xpn.xwiki.web.XWikiResponse;
import com.xpn.xwiki.web.XWikiURLFactory;

public class XWikiContext extends Hashtable {

   public static final int MODE_SERVLET = 0;
   public static final int MODE_PORTLET = 1;
   public static final int MODE_XMLRPC = 2;
   public static final int MODE_ATOM = 3;
   public static final int MODE_PDF = 4;
   public static final int MODE_GWT = 5;
   public static final int MODE_GWT_DEBUG = 6;

   private boolean finished = false;
   private XWiki wiki;
   private XWikiEngineContext engine_context;
   private XWikiRequest request;
   private XWikiResponse response;
   private XWikiForm form;
   private String action;
   private String orig_database;
   private String database;
   private boolean virtual;
   private XWikiUser user;
   private String language;
   private String interfaceLanguage;
   private int mode;
   private URL url;
   private XWikiURLFactory URLFactory;
   private XmlRpcServer xmlRpcServer;
   private String wikiOwner;
   private XWikiDocument wikiServer;
   private int cacheDuration = 0;
   private int classCacheSize = 20;
   private int archiveCacheSize = 20;

   // Used to avoid recursive loading of documents if there are recursives usage of classes
   private Map classCache = new LRUMap(classCacheSize);
   // Used to avoid reloading archives in the same request
   private Map archiveCache = new LRUMap(archiveCacheSize);

   private List displayedFields = new ArrayList();

   public XWikiContext() {
   }

   public XWiki getWiki() {
       return wiki;
   }

   public Util getUtil() {
       Util util = (Util) this.get("util");
       if (util==null) {
           util = new Util();
           this.put("util", util);
       }
       return util;
    }

{'fraction_non_alphanumeric': 0.0719435736677116, 'fraction_numerical': 0.009404388714733543, 'mean_word_length': 3.640727272727273, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5822228', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1838, 'n_words': 711}