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