1 package net.sf.saxon.style; 2 import net.sf.saxon.Configuration; 3 import net.sf.saxon.PreparedStylesheet; 4 import net.sf.saxon.expr.Expression; 5 import net.sf.saxon.instruct.Executable; 6 import net.sf.saxon.om.AttributeCollection; 7 import net.sf.saxon.trans.StaticError; 8 import net.sf.saxon.trans.XPathException; 9 import net.sf.saxon.tree.DocumentImpl; 10 import net.sf.saxon.tree.ElementImpl; 11 12 import javax.xml.transform.Source ; 13 import javax.xml.transform.TransformerException ; 14 15 16 20 21 public abstract class XSLGeneralIncorporate extends StyleElement { 22 23 String href; 24 DocumentImpl includedDoc; 25 26 29 30 public abstract boolean isImport(); 31 32 public void prepareAttributes() throws XPathException { 33 34 AttributeCollection atts = getAttributeList(); 35 36 for (int a=0; a<atts.getLength(); a++) { 37 int nc = atts.getNameCode(a); 38 String f = getNamePool().getClarkName(nc); 39 if (f==StandardNames.HREF) { 40 href = atts.getValue(a).trim(); 41 } else { 42 checkUnknownAttribute(nc); 43 } 44 } 45 46 if (href==null) { 47 reportAbsence("href"); 48 } 49 } 50 51 public void validate() throws XPathException { 52 checkEmpty(); 55 checkTopLevel(null); 56 } 57 58 public XSLStylesheet getIncludedStylesheet(XSLStylesheet importer, int precedence) 59 throws XPathException { 60 61 if (href==null) { 62 return null; 64 } 65 66 checkEmpty(); 67 checkTopLevel((this instanceof XSLInclude ? "XTSE0170" : "XTSE0190")); 68 69 try { 70 XSLStylesheet thisSheet = (XSLStylesheet)getParent(); 71 PreparedStylesheet pss = getPreparedStylesheet(); 72 Configuration config = pss.getConfiguration(); 73 74 Source source; 76 try { 77 source = config.getURIResolver().resolve(href, getBaseURI()); 78 } catch (TransformerException e) { 79 throw StaticError.makeStaticError(e); 80 } 81 82 if (source==null) { 85 source = config.getSystemURIResolver().resolve(href, getBaseURI()); 86 } 87 88 90 XSLStylesheet anc = thisSheet; 91 92 if (source.getSystemId() != null) { 93 while(anc!=null) { 94 if (source.getSystemId().equals(anc.getSystemId())) { 95 compileError("A stylesheet cannot " + getLocalPart() + " itself", 96 (this instanceof XSLInclude ? "XTSE0180" : "XTSE0210")); 97 return null; 98 } 99 anc = anc.getImporter(); 100 } 101 } 102 103 StyleNodeFactory snFactory = new StyleNodeFactory(config); 104 includedDoc = PreparedStylesheet.loadStylesheetModule(source, config, getNamePool(), snFactory); 105 106 108 ElementImpl outermost = includedDoc.getDocumentElement(); 109 110 if (outermost instanceof LiteralResultElement) { 111 includedDoc = ((LiteralResultElement)outermost) 112 .makeStylesheet(getPreparedStylesheet(), snFactory); 113 outermost = includedDoc.getDocumentElement(); 114 } 115 116 if (!(outermost instanceof XSLStylesheet)) { 117 compileError("Included document " + href + " is not a stylesheet", "XTSE0165"); 118 return null; 119 } 120 XSLStylesheet incSheet = (XSLStylesheet)outermost; 121 122 if (incSheet.validationError!=null) { 123 if (reportingCircumstances == REPORT_ALWAYS) { 124 incSheet.compileError(incSheet.validationError); 125 } else if (incSheet.reportingCircumstances == REPORT_UNLESS_FORWARDS_COMPATIBLE 126 && !incSheet.forwardsCompatibleModeIsEnabled()) { 127 incSheet.compileError(incSheet.validationError); 128 } 129 } 130 131 incSheet.setPrecedence(precedence); 132 incSheet.setImporter(importer); 133 incSheet.spliceIncludes(); 135 thisSheet.setInputTypeAnnotations(incSheet.getInputTypeAnnotationsAttribute() | 137 incSheet.getInputTypeAnnotations()); 138 139 return incSheet; 140 141 } catch (XPathException err) { 142 err.setErrorCode("XTSE0165"); 143 compileError(err); 144 return null; 145 } 146 } 147 148 public Expression compile(Executable exec) throws XPathException { 149 return null; 150 } 153 } 154 155 | Popular Tags |