1 package com.icl.saxon.style; 2 import com.icl.saxon.tree.AttributeCollection; 3 import com.icl.saxon.*; 4 import com.icl.saxon.om.*; 5 import com.icl.saxon.handlers.*; 6 import com.icl.saxon.expr.*; 7 import com.icl.saxon.output.*; 8 9 import javax.xml.transform.*; 10 import java.util.*; 11 12 15 16 public class XSLCopy extends StyleElement { 17 18 private String use; 20 24 25 public boolean isInstruction() { 26 return true; 27 } 28 29 33 34 public boolean mayContainTemplateBody() { 35 return true; 36 } 37 38 public void prepareAttributes() throws TransformerConfigurationException { 39 40 StandardNames sn = getStandardNames(); 41 AttributeCollection atts = getAttributeList(); 42 43 for (int a=0; a<atts.getLength(); a++) { 44 int nc = atts.getNameCode(a); 45 int f = nc & 0xfffff; 46 if (f==sn.USE_ATTRIBUTE_SETS) { 47 use = atts.getValue(a); 48 } else { 49 checkUnknownAttribute(nc); 50 } 51 } 52 } 53 54 public void validate() throws TransformerConfigurationException { 55 checkWithinTemplate(); 56 if (use!=null) { 57 findAttributeSets(use); } 59 } 60 61 public void process(Context context) throws TransformerException 62 { 63 NodeInfo source = context.getCurrentNodeInfo(); 64 Outputter out = context.getOutputter(); 65 66 68 switch(source.getNodeType()) { 69 70 case NodeInfo.ELEMENT: 71 out.writeStartTag(source.getNameCode()); 72 73 source.outputNamespaceNodes(out, true); 74 75 processAttributeSets(context); 76 processChildren(context); 77 out.writeEndTag(source.getNameCode()); 78 break; 79 80 case NodeInfo.ATTRIBUTE: 81 int nameCode = source.getNameCode(); 82 if (((nameCode>>20)&0xff) != 0) { nameCode = out.checkAttributePrefix(nameCode); 84 } 85 out.writeAttribute(nameCode, source.getStringValue()); 86 break; 87 88 case NodeInfo.TEXT: 89 out.writeContent(source.getStringValue()); 90 break; 91 92 case NodeInfo.PI: 93 out.writePI(source.getDisplayName(), source.getStringValue()); 94 break; 95 96 case NodeInfo.COMMENT: 97 out.writeComment(source.getStringValue()); 98 break; 99 100 case NodeInfo.NAMESPACE: 101 source.copy(out); 102 break; 103 104 case NodeInfo.ROOT: 105 processChildren(context); 106 break; 107 108 default: 109 throw new IllegalArgumentException ("Unknown node type " + source.getNodeType()); 110 111 } 112 } 113 114 115 } 116 117 | Popular Tags |