home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 November / PCONLINE_11_99.ISO / filesbbs / OS2 / APCHSSL2.ZIP / OS2HTTPD / jserv / com / kav / xsl / XSLObject.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-05-16  |  6.8 KB  |  331 lines

  1. package com.kav.xsl;
  2.  
  3. import com.kav.util.List;
  4. import java.util.Enumeration;
  5. import java.util.Hashtable;
  6. import org.w3c.dom.Attr;
  7. import org.w3c.dom.Comment;
  8. import org.w3c.dom.Element;
  9. import org.w3c.dom.NamedNodeMap;
  10. import org.w3c.dom.Node;
  11. import org.w3c.dom.NodeList;
  12. import org.w3c.dom.ProcessingInstruction;
  13. import org.w3c.dom.Text;
  14.  
  15. public class XSLObject {
  16.    public static final short APPLY_IMPORTS = 0;
  17.    public static final short APPLY_TEMPLATES = 1;
  18.    public static final short ATTRIBUTE = 2;
  19.    public static final short ATTRIBUTE_SET = 3;
  20.    public static final short CHOOSE = 4;
  21.    public static final short COMMENT = 5;
  22.    public static final short CONSTANT = 6;
  23.    public static final short CONTENTS = 7;
  24.    public static final short COPY = 8;
  25.    public static final short COUNTER = 9;
  26.    public static final short COUNTERS = 10;
  27.    public static final short COUNTER_INCREMENT = 11;
  28.    public static final short COUNTER_RESET = 12;
  29.    public static final short COUNTER_SCOPE = 13;
  30.    public static final short ELEMENT = 14;
  31.    // $FF: renamed from: ID short
  32.    public static final short field_0 = 15;
  33.    // $FF: renamed from: IF short
  34.    public static final short field_1 = 16;
  35.    public static final short IMPORT = 17;
  36.    public static final short INCLUDE = 18;
  37.    public static final short INVOKE = 19;
  38.    public static final short FOR_EACH = 20;
  39.    public static final short LITERAL = 21;
  40.    public static final short MACRO = 22;
  41.    public static final short MACRO_ARG = 23;
  42.    public static final short NUMBER = 24;
  43.    public static final short OTHERWISE = 25;
  44.    // $FF: renamed from: PI short
  45.    public static final short field_2 = 26;
  46.    public static final short PRESERVE_SPACE = 27;
  47.    public static final short SORT = 28;
  48.    public static final short STRIP_SPACE = 29;
  49.    public static final short STYLESHEET = 30;
  50.    public static final short TEMPLATE = 31;
  51.    public static final short TEXT = 32;
  52.    public static final short USE = 33;
  53.    public static final short VALUE_OF = 34;
  54.    public static final short WHEN = 35;
  55.    public static final short CDATA = 36;
  56.    public static final short ARG = 37;
  57.    public static final short ENTITY_REF = 38;
  58.    public static final short SCRIPT = 39;
  59.    private static final short MAX_TYPE = 40;
  60.    private short type = 21;
  61.    private Hashtable avtCache;
  62.    private List children;
  63.    private Hashtable attributes;
  64.    private List readOnlyAttrs;
  65.    private boolean allowActions = true;
  66.    private XSLStylesheet parentStylesheet;
  67.    private String typeName = "XSLObject";
  68.    private XSLObject parent;
  69.    static String[] typeNames = null;
  70.  
  71.    public XSLObject(XSLStylesheet var1, short var2) {
  72.       this.type = var2;
  73.       this.typeName = typeNames[var2];
  74.       this.parentStylesheet = var1;
  75.       this.attributes = new Hashtable();
  76.       this.children = new List();
  77.       this.readOnlyAttrs = new List();
  78.       this.avtCache = new Hashtable();
  79.    }
  80.  
  81.    public boolean appendAction(XSLObject var1) {
  82.       if (!this.allowActions) {
  83.          return false;
  84.       } else {
  85.          if (var1.type == 32) {
  86.             XSLText var2 = (XSLText)var1;
  87.             if (this.children.size() > 0) {
  88.                XSLObject var3 = (XSLObject)this.children.get(this.children.size() - 1);
  89.                if (var3.type == 32) {
  90.                   ((XSLText)var3).appendData(var2.getData());
  91.                   return true;
  92.                }
  93.             }
  94.          }
  95.  
  96.          this.children.add(var1);
  97.          var1.setParentStylesheet(this.parentStylesheet);
  98.          var1.setParent(this);
  99.          return true;
  100.       }
  101.    }
  102.  
  103.    public List getActions() {
  104.       return (List)this.children.clone();
  105.    }
  106.  
  107.    public String getAttribute(String var1) {
  108.       return var1 != null ? (String)this.attributes.get(var1) : null;
  109.    }
  110.  
  111.    public AttributeValueTemplate getAttributeAsAVT(String var1) throws XSLException {
  112.       if (var1 == null) {
  113.          return null;
  114.       } else {
  115.          String var2 = this.getAttribute(var1);
  116.          AttributeValueTemplate var3 = null;
  117.          if (var2 != null && var2.length() > 0) {
  118.             var3 = (AttributeValueTemplate)this.avtCache.get(var2);
  119.             if (var3 == null) {
  120.                try {
  121.                   var3 = new AttributeValueTemplate(var2);
  122.                   this.avtCache.put(var2, var3);
  123.                } catch (InvalidExprException var5) {
  124.                   throw new XSLException(5, ((Throwable)var5).getMessage());
  125.                }
  126.             }
  127.          }
  128.  
  129.          return var3;
  130.       }
  131.    }
  132.  
  133.    public Enumeration getAttributeNames() {
  134.       return this.attributes.keys();
  135.    }
  136.  
  137.    public XSLObject getNearestAncestor(short var1) {
  138.       if (this.parent == null) {
  139.          return null;
  140.       } else {
  141.          XSLObject var2 = this.parent;
  142.          return var2.type == var1 ? this.parent : this.parent.getNearestAncestor(var1);
  143.       }
  144.    }
  145.  
  146.    public static String getNodeValue(Node var0) {
  147.       if (var0 == null) {
  148.          return "";
  149.       } else {
  150.          switch (var0.getNodeType()) {
  151.             case 1:
  152.                return getText((Element)var0);
  153.             case 2:
  154.                return ((Attr)var0).getValue();
  155.             case 3:
  156.             case 4:
  157.                return ((Text)var0).getData();
  158.             case 5:
  159.             case 6:
  160.             default:
  161.                return "";
  162.             case 7:
  163.                return ((ProcessingInstruction)var0).getData();
  164.             case 8:
  165.                return ((Comment)var0).getData();
  166.          }
  167.       }
  168.    }
  169.  
  170.    public XSLStylesheet getParentStylesheet() {
  171.       return this.parentStylesheet;
  172.    }
  173.  
  174.    public final short getType() {
  175.       return this.type;
  176.    }
  177.  
  178.    public static String getText(Element var0) {
  179.       if (var0 == null) {
  180.          return null;
  181.       } else {
  182.          NodeList var1 = var0.getChildNodes();
  183.          int var3 = var1.getLength();
  184.          StringBuffer var4 = new StringBuffer();
  185.  
  186.          for(int var5 = 0; var5 < var3; ++var5) {
  187.             Node var2 = var1.item(var5);
  188.             switch (var2.getNodeType()) {
  189.                case 1:
  190.                   if (var3 == 1) {
  191.                      return getText((Element)var2);
  192.                   }
  193.  
  194.                   var4.append(getText((Element)var2));
  195.                case 2:
  196.                default:
  197.                   break;
  198.                case 3:
  199.                case 4:
  200.                   if (var3 == 1) {
  201.                      return ((Text)var2).getData();
  202.                   }
  203.  
  204.                   var4.append(((Text)var2).getData());
  205.             }
  206.          }
  207.  
  208.          return var4.toString();
  209.       }
  210.    }
  211.  
  212.    public String getTypeName() {
  213.       return this.typeName;
  214.    }
  215.  
  216.    public void setAllowActions(boolean var1) {
  217.       this.allowActions = var1;
  218.    }
  219.  
  220.    public void setTypeName(String var1) {
  221.       this.typeName = var1;
  222.    }
  223.  
  224.    public void setAttribute(String var1, String var2) throws XSLException {
  225.       if (var1 != null && var2 != null) {
  226.          if (this.readOnlyAttrs.contains(var1)) {
  227.             StringBuffer var3 = new StringBuffer("The attribute '");
  228.             var3.append(var1);
  229.             var3.append("' has been set to read only for this ");
  230.             var3.append(this.getTypeName());
  231.             var3.append(" and cannot be changed.");
  232.             throw new XSLException(var3.toString());
  233.          }
  234.  
  235.          this.attributes.put(var1, var2);
  236.       }
  237.  
  238.    }
  239.  
  240.    protected void copyAttributes(Element var1) throws XSLException {
  241.       NamedNodeMap var2 = var1.getAttributes();
  242.       if (var2 != null) {
  243.          for(int var4 = 0; var4 < var2.getLength(); ++var4) {
  244.             Attr var3 = (Attr)var2.item(var4);
  245.             this.setAttribute(var3.getName(), var3.getValue());
  246.          }
  247.  
  248.       }
  249.    }
  250.  
  251.    protected void copyAttributes(XSLObject var1) {
  252.       var1.copyAttributesInto(this.attributes);
  253.    }
  254.  
  255.    protected void copyActions(XSLObject var1) {
  256.       List var2 = var1.getActions();
  257.  
  258.       for(int var3 = 0; var3 < var2.size(); ++var3) {
  259.          XSLObject var4 = (XSLObject)var2.get(var3);
  260.          this.appendAction(var4);
  261.       }
  262.  
  263.    }
  264.  
  265.    protected void makeAttrReadOnly(String var1) {
  266.       this.readOnlyAttrs.add(var1);
  267.    }
  268.  
  269.    protected void setParent(XSLObject var1) {
  270.       this.parent = var1;
  271.    }
  272.  
  273.    protected void setParentStylesheet(XSLStylesheet var1) {
  274.       this.parentStylesheet = var1;
  275.    }
  276.  
  277.    protected void copyAttributesInto(Hashtable var1) {
  278.       Enumeration var2 = this.attributes.keys();
  279.  
  280.       while(var2.hasMoreElements()) {
  281.          Object var3 = var2.nextElement();
  282.          var1.put(var3, this.attributes.get(var3));
  283.       }
  284.  
  285.    }
  286.  
  287.    static {
  288.       typeNames = new String[40];
  289.       typeNames[0] = "xsl:apply-imports";
  290.       typeNames[1] = "xsl:apply-templates";
  291.       typeNames[37] = "xsl:arg";
  292.       typeNames[3] = "xsl:attribute-set";
  293.       typeNames[2] = "xsl:attribute";
  294.       typeNames[4] = "xsl:choose";
  295.       typeNames[5] = "xsl:comment";
  296.       typeNames[6] = "xsl:constant";
  297.       typeNames[7] = "xsl:contents";
  298.       typeNames[8] = "xsl:copy";
  299.       typeNames[9] = "xsl:counter";
  300.       typeNames[10] = "xsl:counters";
  301.       typeNames[11] = "xsl:counter-increment";
  302.       typeNames[12] = "xsl:counter-reset";
  303.       typeNames[13] = "xsl:counter-scope";
  304.       typeNames[14] = "xsl:element";
  305.       typeNames[15] = "xsl:id";
  306.       typeNames[16] = "xsl:if";
  307.       typeNames[17] = "xsl:import";
  308.       typeNames[18] = "xsl:include";
  309.       typeNames[19] = "xsl:invoke";
  310.       typeNames[20] = "xsl:for-each";
  311.       typeNames[21] = "xsl:element";
  312.       typeNames[22] = "xsl:macro";
  313.       typeNames[23] = "xsl:macro-arg";
  314.       typeNames[24] = "xsl:number";
  315.       typeNames[25] = "xsl:otherwise";
  316.       typeNames[26] = "xsl:pi";
  317.       typeNames[27] = "xsl:preserve-space";
  318.       typeNames[28] = "xsl:sort";
  319.       typeNames[29] = "xsl:strip-space";
  320.       typeNames[30] = "xsl:stylesheet";
  321.       typeNames[31] = "xsl:template";
  322.       typeNames[32] = "xsl:text";
  323.       typeNames[33] = "xsl:use";
  324.       typeNames[34] = "xsl:value-of";
  325.       typeNames[35] = "xsl:when";
  326.       typeNames[36] = "xsl:cdata";
  327.       typeNames[38] = "xsl:entity-ref";
  328.       typeNames[39] = "xsl:script";
  329.    }
  330. }
  331.