net.sf.saxon.trans.StylesheetCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Saxon-HE Show documentation
Show all versions of Saxon-HE Show documentation
The XSLT and XQuery Processor
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2018-2022 Saxonica Limited
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package net.sf.saxon.trans;
import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.transpile.CSharpModifiers;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* A cache of the stylesheets (as XsltExecutables) used in calls to the fn:transform function, in a stylesheet or query.
*/
@CSharpModifiers(code = {"internal"})
public class StylesheetCache {
private final Map cacheByText = new ConcurrentHashMap();
private final Map cacheByLocation = new ConcurrentHashMap();
private final Map cacheByNode = new ConcurrentHashMap();
/**
* Get the stylesheet (XsltExecutable) in the cache associated with the supplied stylesheet text string.
* @param style the stylesheet text as a string (as supplied in the stylesheet-text option of fn:transform())
* @return the XsltExecutable corresponding to this stylesheet-text, if already cached.
*/
public XsltExecutable getStylesheetByText(String style) {
return cacheByText.get(style);
}
/**
* Get the stylesheet (XsltExecutable) in the cache associated with the supplied stylesheet location string.
* @param style the URI for the stylesheet location (as supplied in the stylesheet-location option of fn:transform())
* @return the XsltExecutable corresponding to this stylesheet-location, if already cached.
*/
public XsltExecutable getStylesheetByLocation(String style) {
return cacheByLocation.get(style);
}
/**
* Get the stylesheet (XsltExecutable) in the cache associated with the supplied stylesheet node.
* @param style the root node of the stylesheet (as supplied in the stylesheet-node option of fn:transform())
* @return the XsltExecutable corresponding to this stylesheet-node, if already cached.
*/
public XsltExecutable getStylesheetByNode(NodeInfo style) {
return cacheByNode.get(style);
}
/**
* Set a key-value pair in the cache for stylesheets referenced by stylesheet text.
* @param style the stylesheet text as a string (as supplied in the stylesheet-text option of fn:transform())
* @param xsltExecutable the compiled stylesheet
*/
public void setStylesheetByText(String style, XsltExecutable xsltExecutable) {
cacheByText.put(style, xsltExecutable);
}
/**
* Set a key-value pair in the cache for stylesheets referenced by stylesheet location.
* @param style the URI for the stylesheet location (as supplied in the stylesheet-location option of fn:transform())
* @param xsltExecutable the compiled stylesheet
*/
public void setStylesheetByLocation(String style, XsltExecutable xsltExecutable) {
cacheByLocation.put(style, xsltExecutable);
}
/**
* Set a key-value pair in the cache for stylesheets referenced by stylesheet root node.
* @param style the root node of the stylesheet (as supplied in the stylesheet-node option of fn:transform())
* @param xsltExecutable the compiled stylesheet
*/
public void setStylesheetByNode(NodeInfo style, XsltExecutable xsltExecutable) {
cacheByNode.put(style, xsltExecutable);
}
}