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

  1. package com.kav.xsl;
  2.  
  3. import java.util.Hashtable;
  4. import org.w3c.dom.Node;
  5.  
  6. public class TemplateRule extends XSLObject {
  7.    private MatchExpr matchExpr;
  8.    float priority;
  9.    private boolean mIsRoot = false;
  10.  
  11.    public TemplateRule(XSLStylesheet var1) {
  12.       super(var1, (short)31);
  13.    }
  14.  
  15.    public XSLObject copy() {
  16.       Object var1 = null;
  17.       TemplateRule var2 = new TemplateRule(((XSLObject)this).getParentStylesheet());
  18.       var2.setPriority(this.priority);
  19.       var2.setMatchExpr(this.matchExpr);
  20.       ((XSLObject)var2).copyActions(this);
  21.       ((XSLObject)var2).copyAttributes(this);
  22.       return var2;
  23.    }
  24.  
  25.    public int compareTo(TemplateRule var1, Node var2, Hashtable var3) {
  26.       PathExpr var4 = this.matchExpr.getMatchingExpr(var2, var3);
  27.       PathExpr var5 = var1.getMatchingExpr(var2, var3);
  28.       if (var5 == null && var4 == null) {
  29.          return 0;
  30.       } else if (var5 == null) {
  31.          return 1;
  32.       } else if (var4 == null) {
  33.          return -1;
  34.       } else {
  35.          int var6 = var4.compareTo(var5);
  36.          if (var6 != 0) {
  37.             return var6;
  38.          } else if (var1.getPriority() > this.priority) {
  39.             return -1;
  40.          } else {
  41.             return var1.getPriority() < this.priority ? 1 : 0;
  42.          }
  43.       }
  44.    }
  45.  
  46.    public PathExpr getMatchingExpr(Node var1, Hashtable var2) {
  47.       return this.matchExpr.getMatchingExpr(var1, var2);
  48.    }
  49.  
  50.    public MatchExpr getMatchExpr() {
  51.       return this.matchExpr;
  52.    }
  53.  
  54.    public String getMode() {
  55.       return ((XSLObject)this).getAttribute("mode");
  56.    }
  57.  
  58.    public float getPriority() {
  59.       if (this.priority == 0.0F) {
  60.          String var1 = ((XSLObject)this).getAttribute("priority");
  61.          if (var1 != null && var1.length() > 0) {
  62.             try {
  63.                this.priority = Float.valueOf(var1);
  64.             } catch (NumberFormatException var2) {
  65.                this.priority = 0.0F;
  66.             }
  67.          }
  68.       }
  69.  
  70.       return this.priority;
  71.    }
  72.  
  73.    public boolean matchesRoot() {
  74.       return this.mIsRoot;
  75.    }
  76.  
  77.    public boolean matches(Node var1, Hashtable var2) {
  78.       return this.matchExpr.matches(var1, var2);
  79.    }
  80.  
  81.    public void setIsRoot(boolean var1) {
  82.       this.mIsRoot = var1;
  83.    }
  84.  
  85.    public void setMatchExpr(String var1) throws InvalidExprException {
  86.       if (var1 == null) {
  87.          var1 = "";
  88.       }
  89.  
  90.       this.matchExpr = ExpressionParser.createMatchExpr(var1);
  91.  
  92.       try {
  93.          this.setAttribute("match", var1);
  94.       } catch (XSLException var2) {
  95.       }
  96.  
  97.       if (this.matchExpr != null && this.matchExpr.matchesRoot()) {
  98.          this.mIsRoot = true;
  99.       }
  100.  
  101.    }
  102.  
  103.    public void setMatchExpr(MatchExpr var1) {
  104.       this.matchExpr = var1;
  105.       if (var1 != null && var1.matchesRoot()) {
  106.          this.mIsRoot = true;
  107.       }
  108.  
  109.    }
  110.  
  111.    public void setMode(String var1) {
  112.       try {
  113.          this.setAttribute("mode", var1);
  114.       } catch (XSLException var2) {
  115.       }
  116.    }
  117.  
  118.    public void setPriority(float var1) {
  119.       this.priority = var1;
  120.  
  121.       try {
  122.          this.setAttribute("priority", String.valueOf(var1));
  123.       } catch (XSLException var2) {
  124.       }
  125.    }
  126.  
  127.    public void setAttribute(String var1, String var2) throws XSLException {
  128.       if ("priority".equals(var1)) {
  129.          try {
  130.             this.priority = Float.valueOf(var2);
  131.          } catch (NumberFormatException var3) {
  132.             this.priority = 0.0F;
  133.          }
  134.       }
  135.  
  136.       super.setAttribute(var1, var2);
  137.    }
  138. }
  139.