/** * Factory method to make a PreparedStylesheet * @param source the source of this principal stylesheet module * @param config the Saxon configuration * @param info compile-time options for this stylesheet compilation * @return the prepared stylesheet */ public static PreparedStylesheet compile(Source source, Configuration config, CompilerInfo info) throws TransformerConfigurationException { PreparedStylesheet pss = new PreparedStylesheet(config, info); pss.prepare(source); return pss; }
/** * Load a PreparedStylesheet from a compiled stylesheet stored in a file. * @param config The Configuration. <b>This method changes the NamePool used by this configuration * to be the NamePool that was stored with the compiled stylesheet. The method must therefore not * be used in a multi-threaded environment where the Configuration (and NamePool) are shared between * multiple concurrent transformations.</b> * @param ois The ObjectInputStream containing the compiled stylesheet (which is just the Java serialization * of a PreparedStylesheet object). * @return the PreparedStylesheet, which can be used in JAXP interfaces as the Templates object */ public static PreparedStylesheet loadCompiledStylesheet(Configuration config, ObjectInputStream ois) throws IOException, ClassNotFoundException { PreparedStylesheet sheet = (PreparedStylesheet)ois.readObject(); ois.close(); NamePool compiledNamePool = sheet.getTargetNamePool(); sheet.setConfiguration(config); sheet.getExecutable().setConfiguration(config); config.setNamePool(compiledNamePool); NamePool.setDefaultNamePool(compiledNamePool); return sheet; }
pss.setTopLevelPackage(this); if (isSchemaAware() || !schemaIndex.isEmpty()) { pss.setSchemaAware(true); pss.setHostLanguage(Configuration.XSLT); pss.setFunctionLibrary(libraryList); pss.setKeyManager(keyManager); if (!pss.createsSecondaryResult()) { pss.setCreatesSecondaryResult(mayCreateSecondaryResultDocuments()); pss.setDefaultOutputProperties(defaultOutputProperties); for (Map.Entry<StructuredQName, Properties> entry : namedOutputProperties.entrySet()) { pss.setOutputProperties(entry.getKey(), entry.getValue()); pss.getCharacterMapIndex().putCharacterMap(cm.getName(), cm); pss.setRuleManager(ruleManager); if (comp.getActor() instanceof NamedTemplate) { NamedTemplate t = (NamedTemplate) comp.getActor(); pss.putNamedTemplate(t.getTemplateName(), t); pss.setComponentIndex(componentIndex); if (comp.getActor() instanceof GlobalParam) { GlobalParam gv = (GlobalParam) comp.getActor();
presenter.namespace("fn", NamespaceConstant.FN); presenter.namespace("xs", NamespaceConstant.SCHEMA); getKeyManager().exportKeys(presenter, null); explainGlobalVariables(presenter); ruleManager.explainTemplateRules(presenter); explainNamedTemplates(presenter); presenter.startElement("accumulators"); for (Accumulator acc : getTopLevelPackage().getAccumulatorRegistry().getAllAccumulators()) { acc.export(presenter); FunctionLibraryList libList = getFunctionLibrary(); List<FunctionLibrary> libraryList = libList.getLibraryList(); presenter.startElement("functions");
XSLStylesheet thisSheet = (XSLStylesheet)getParent(); PreparedStylesheet pss = getPreparedStylesheet(); URIResolver resolver = pss.getURIResolver(); Configuration config = pss.getConfiguration(); StyleNodeFactory snFactory = new StyleNodeFactory(config, pss.getErrorListener()); includedDoc = pss.loadStylesheetModule(source, snFactory);
/** * Make a Controller from this stylesheet object. * * @return the new Controller * @see net.sf.saxon.Controller */ public XsltController newController() { Configuration config = getConfiguration(); XsltController c = new XsltController(config, this); c.setMessageReceiverClassName(messageReceiverClassName); c.setOutputURIResolver(outputURIResolver); c.setRecoveryPolicy(recoveryPolicy); if (defaultInitialMode != null) { try { c.setInitialMode(defaultInitialMode); } catch (XPathException e) { // ignore the error if the default initial mode is not defined } } return c; }
String msg = ((PreparedStylesheet)sheet).getExecutable().getReasonUnableToCompile(); if (msg != null) { System.err.println(msg); ((PreparedStylesheet)sheet).setTargetNamePool( ((PreparedStylesheet)sheet).getConfiguration().getNamePool()); OutputStream fos = new FileOutputStream(outputFileName); if (debug) {
/** * Link this package with the packages it uses, to form an executable stylesheet. This process fixes * up any cross-package references to files, templates, and other components, and checks to ensure * that all such references are consistent. * * @return the resulting XsltExecutable * @throws SaxonApiException if any error is found during the linking process, for example * if the constituent packages containing duplicate component names, or if abstract components * are not resolved. */ public XsltExecutable link() throws SaxonApiException { try { Configuration config = processor.getUnderlyingConfiguration(); CompilerInfo info = config.makeCompilerInfo(); Compilation compilation = new Compilation(config, info); stylesheetPackage.checkForAbstractComponents(); PreparedStylesheet pss = new PreparedStylesheet(compilation); stylesheetPackage.updatePreparedStylesheet(pss); pss.addPackage(stylesheetPackage); return new XsltExecutable(processor, pss); } catch (XPathException e) { throw new SaxonApiException(e); } }
/** * Constructor - deliberately protected * * @param compilation Compilation options */ public PreparedStylesheet(Compilation compilation) { super(compilation.getConfiguration()); CompilerInfo compilerInfo = compilation.getCompilerInfo(); setHostLanguage(Configuration.XSLT); if (compilerInfo.isSchemaAware()) { int localLic = compilation.getPackageData().getLocalLicenseId(); getConfiguration().checkLicensedFeature(Configuration.LicenseFeature.ENTERPRISE_XSLT, "schema-aware XSLT", localLic); schemaAware = true; } //setSchemaAware(compilerInfo.isSchemaAware()); if (compilerInfo.getErrorListener() == null) { compilerInfo.setErrorListener(getConfiguration().getErrorListener()); } defaultInitialMode = compilerInfo.getDefaultInitialMode(); defaultInitialTemplate = compilerInfo.getDefaultInitialTemplate(); recoveryPolicy = compilerInfo.getRecoveryPolicy(); messageReceiverClassName = compilerInfo.getMessageReceiverClassName(); outputURIResolver = compilerInfo.getOutputURIResolver(); compileTimeParams = compilation.getParameters(); }
Configuration config = preparedStylesheet.getConfiguration(); if (!config.isSchemaAware(Configuration.XSLT)) { compileError("To use xsl:import-schema, you need the schema-aware " + namespace = config.readInlineSchema(inlineSchema, namespace, preparedStylesheet.getErrorListener()); getPrincipalStylesheet().addImportedSchema(namespace);
pss.reportError(err); } catch (TransformerException err2) { pss.reportError(err); } catch (TransformerException err2) { builder.setPipelineConfiguration(pss.getConfiguration().makePipelineConfiguration()); builder.setNodeFactory(nodeFactory); builder.setSystemId(this.getSystemId());
/** * Get the Templates object to used for a transformation */ public Templates getTemplates() { if (templates==null) { DocumentImpl doc = (DocumentImpl)builder.getCurrentRoot(); if (doc==null) { return null; } final Configuration config = getConfiguration(); CompilerInfo info = new CompilerInfo(); info.setURIResolver(config.getURIResolver()); info.setErrorListener(config.getErrorListener()); info.setCompileWithTracing(config.isCompileWithTracing()); PreparedStylesheet sheet = new PreparedStylesheet(config, info); try { sheet.setStylesheetDocument(doc, nodeFactory); templates = sheet; } catch (XPathException tce) { // don't know why we aren't allowed to just throw it! throw new UnsupportedOperationException(tce.getMessage()); } } return templates; }
sheet = PreparedStylesheet.loadCompiledStylesheet(config, styleFileName); if (showTime) { long endTime = (new Date()).getTime(); props); ExpressionPresenter expressionPresenter = new ExpressionPresenter(config, diag); sheet.explain(expressionPresenter); expressionPresenter.close();
/** * Associate this Controller with a compiled stylesheet. * <p> * This method is intended for internal use only. * * @param sheet the compiled stylesheet */ public void setPreparedStylesheet(PreparedStylesheet sheet) { preparedStylesheet = sheet; executable = sheet.getExecutable(); //setOutputProperties(sheet.getOutputProperties()); // above line deleted for bug 490964 - may have side-effects }
/** * Produce a diagnostic representation of the compiled stylesheet, in XML form. * <p><i>The detailed form of this representation is not stable (or even documented).</i></p> * * @param destination the destination for the XML document containing the diagnostic representation * of the compiled stylesheet * @since 9.1 */ public void explain(Destination destination) throws SaxonApiException { Configuration config = processor.getUnderlyingConfiguration(); try { Receiver out = destination.getReceiver(config.makePipelineConfiguration(), config.obtainDefaultSerializationProperties()); preparedStylesheet.explain(new ExpressionPresenter(config, out)); } catch (XPathException e) { throw new SaxonApiException(e); } }
XsltExecutable exec = compiler.compile(stylesheet); PreparedStylesheet ps = exec.getUnderlyingCompiledStylesheet(); fl = ps.getFunctionLibrary(); } else { XQueryCompiler xqcomp = processor.newXQueryCompiler();
if (getPreparedStylesheet().getErrorCount() > 0) {
presenter.namespace("fn", NamespaceConstant.FN); presenter.namespace("xs", NamespaceConstant.SCHEMA); getKeyManager().exportKeys(presenter, null); explainGlobalVariables(presenter); ruleManager.explainTemplateRules(presenter); explainNamedTemplates(presenter); presenter.startElement("accumulators"); for (Accumulator acc : getTopLevelPackage().getAccumulatorRegistry().getAllAccumulators()) { acc.export(presenter); FunctionLibraryList libList = getFunctionLibrary(); List<FunctionLibrary> libraryList = libList.getLibraryList(); presenter.startElement("functions");
XSLStylesheet thisSheet = (XSLStylesheet)getParent(); PreparedStylesheet pss = getPreparedStylesheet(); URIResolver resolver = pss.getURIResolver(); Configuration config = pss.getConfiguration(); StyleNodeFactory snFactory = new StyleNodeFactory(config, getPreparedStylesheet().getErrorListener()); includedDoc = PreparedStylesheet.loadStylesheetModule(source, config, getNamePool(), snFactory);
/** * Make a Controller from this stylesheet object. * * @return the new Controller * @see net.sf.saxon.Controller */ public XsltController newController() { Configuration config = getConfiguration(); XsltController c = new XsltController(config, this); c.setMessageReceiverClassName(messageReceiverClassName); c.setOutputURIResolver(outputURIResolver); c.setRecoveryPolicy(recoveryPolicy); if (defaultInitialMode != null) { try { c.setInitialMode(defaultInitialMode); } catch (XPathException e) { // ignore the error if the default initial mode is not defined } } return c; }