1 16 19 20 package org.apache.xalan.xsltc.compiler; 21 22 import java.io.File ; 23 import java.io.FileNotFoundException ; 24 import java.net.MalformedURLException ; 25 import java.net.URL ; 26 import java.util.Enumeration ; 27 28 import org.apache.xml.utils.SystemIDResolver; 29 import org.apache.xalan.xsltc.compiler.util.ClassGenerator; 30 import org.apache.xalan.xsltc.compiler.util.ErrorMsg; 31 import org.apache.xalan.xsltc.compiler.util.MethodGenerator; 32 import org.apache.xalan.xsltc.compiler.util.Type; 33 import org.apache.xalan.xsltc.compiler.util.TypeCheckError; 34 35 import org.xml.sax.InputSource ; 36 import org.xml.sax.XMLReader ; 37 38 44 final class Include extends TopLevelElement { 45 46 private Stylesheet _included = null; 47 48 public Stylesheet getIncludedStylesheet() { 49 return _included; 50 } 51 52 public void parseContents(final Parser parser) { 53 XSLTC xsltc = parser.getXSLTC(); 54 Stylesheet context = parser.getCurrentStylesheet(); 55 56 String docToLoad = getAttribute("href"); 57 try { 58 if (context.checkForLoop(docToLoad)) { 59 final ErrorMsg msg = new ErrorMsg(ErrorMsg.CIRCULAR_INCLUDE_ERR, 60 docToLoad, this); 61 parser.reportError(Constants.FATAL, msg); 62 return; 63 } 64 65 InputSource input = null; 66 XMLReader reader = null; 67 String currLoadedDoc = context.getSystemId(); 68 SourceLoader loader = context.getSourceLoader(); 69 70 if (loader != null) { 72 input = loader.loadSource(docToLoad, currLoadedDoc, xsltc); 73 if (input != null) { 74 docToLoad = input.getSystemId(); 75 reader = xsltc.getXMLReader(); 76 } 77 } 78 79 if (input == null) { 81 docToLoad = SystemIDResolver.getAbsoluteURI(docToLoad, currLoadedDoc); 82 input = new InputSource (docToLoad); 83 } 84 85 if (input == null) { 87 final ErrorMsg msg = 88 new ErrorMsg(ErrorMsg.FILE_NOT_FOUND_ERR, docToLoad, this); 89 parser.reportError(Constants.FATAL, msg); 90 return; 91 } 92 93 final SyntaxTreeNode root; 94 if (reader != null) { 95 root = parser.parse(reader,input); 96 } 97 else { 98 root = parser.parse(input); 99 } 100 101 if (root == null) return; 102 _included = parser.makeStylesheet(root); 103 if (_included == null) return; 104 105 _included.setSourceLoader(loader); 106 _included.setSystemId(docToLoad); 107 _included.setParentStylesheet(context); 108 _included.setIncludingStylesheet(context); 109 _included.setTemplateInlining(context.getTemplateInlining()); 110 111 final int precedence = context.getImportPrecedence(); 114 _included.setImportPrecedence(precedence); 115 parser.setCurrentStylesheet(_included); 116 _included.parseContents(parser); 117 118 final Enumeration elements = _included.elements(); 119 final Stylesheet topStylesheet = parser.getTopLevelStylesheet(); 120 while (elements.hasMoreElements()) { 121 final Object element = elements.nextElement(); 122 if (element instanceof TopLevelElement) { 123 if (element instanceof Variable) { 124 topStylesheet.addVariable((Variable) element); 125 } 126 else if (element instanceof Param) { 127 topStylesheet.addParam((Param) element); 128 } 129 else { 130 topStylesheet.addElement((TopLevelElement) element); 131 } 132 } 133 } 134 } 135 catch (Exception e) { 136 e.printStackTrace(); 137 } 138 finally { 139 parser.setCurrentStylesheet(context); 140 } 141 } 142 143 public Type typeCheck(SymbolTable stable) throws TypeCheckError { 144 return Type.Void; 145 } 146 147 public void translate(ClassGenerator classGen, MethodGenerator methodGen) { 148 } 150 } 151 | Popular Tags |