home *** CD-ROM | disk | FTP | other *** search
- package com.kav.xsl;
-
- import com.kav.util.List;
- import java.util.Hashtable;
- import org.mitre.tjt.xsl.XslNumberFormat;
- import org.w3c.dom.Element;
- import org.w3c.dom.Node;
-
- public class XSLNumber extends XSLObject {
- public static final int SINGLE_LEVEL = 0;
- public static final int MULTI_LEVEL = 1;
- public static final int ANY_LEVEL = 2;
- private MatchExpr countExpr;
- private MatchExpr fromExpr;
- private int level = 0;
-
- public XSLNumber(XSLStylesheet var1) {
- super(var1, (short)24);
- }
-
- public static int countSiblings(Element var0, boolean var1) {
- int var2 = 0;
- String var3 = var0.getNodeName();
- Object var5 = var0;
- if (var1) {
- while((var5 = ((Node)var5).getPreviousSibling()) != null) {
- if (((Node)var5).getNodeType() == 1) {
- String var7 = ((Element)var5).getNodeName();
- if (var3.equals(var7)) {
- ++var2;
- }
- }
- }
- } else {
- while((var5 = ((Node)var5).getNextSibling()) != null) {
- if (((Node)var5).getNodeType() == 1) {
- String var4 = ((Element)var5).getNodeName();
- if (var3.equals(var4)) {
- ++var2;
- }
- }
- }
- }
-
- ++var2;
- return var2;
- }
-
- public int[] doNumbering(Element var1) {
- Object var2 = null;
- int var5 = 0;
- int[] var7;
- switch (this.level) {
- case 1:
- List var10 = this.getAncestors(var1);
- var7 = new int[var10.size()];
- var5 = 0;
-
- for(int var13 = var10.size() - 1; var13 >= 0; --var13) {
- Element var8 = (Element)var10.get(var13);
- var7[var5++] = countSiblings(var8, true);
- }
- break;
- case 2:
- List var4 = this.getAnyPreviousNodes(var1);
- var7 = new int[var4.size()];
- var5 = 0;
-
- for(int var6 = var4.size() - 1; var6 >= 0; --var6) {
- Element var3 = (Element)var4.get(var6);
- var7[var5++] = countSiblings(var3, true);
- }
- break;
- default:
- var7 = new int[1];
- Element var9 = this.getNearestAncestor(var1);
- if (var9 != null) {
- var7[0] = countSiblings(var9, true);
- }
- }
-
- return var7;
- }
-
- public String getFormattedNumber(Element var1) {
- int[] var2 = this.doNumbering(var1);
- return XslNumberFormat.format(var2, this.getFormat());
- }
-
- public MatchExpr getCountExpr() {
- return this.countExpr;
- }
-
- public String getFormat() {
- return ((XSLObject)this).getAttribute("format");
- }
-
- public MatchExpr getFromExpr() {
- return this.fromExpr;
- }
-
- public String getLevel() {
- return ((XSLObject)this).getAttribute("level");
- }
-
- public boolean hasCountExpr() {
- return this.countExpr != null;
- }
-
- public void setAttribute(String var1, String var2) throws XSLException {
- if ("count".equals(var1)) {
- if (var2 == null) {
- this.countExpr = null;
- } else {
- try {
- this.countExpr = ExpressionParser.createMatchExpr(var2);
- } catch (InvalidExprException var5) {
- throw new XSLException("invalid 'count' attribute of xsl:number - " + ((Throwable)var5).getMessage());
- }
- }
- } else if ("from".equals(var1)) {
- if (var2 == null) {
- this.fromExpr = null;
- } else {
- try {
- this.fromExpr = ExpressionParser.createMatchExpr(var2);
- } catch (InvalidExprException var4) {
- throw new XSLException("invalid 'from' attribute of xsl:number - " + ((Throwable)var4).getMessage());
- }
- }
- } else if ("level".equals(var1)) {
- if ("multi".equals(var2)) {
- this.level = 1;
- } else if (var2.equals("any")) {
- this.level = 2;
- } else {
- this.level = 0;
- var2 = "single";
- }
- }
-
- super.setAttribute(var1, var2);
- }
-
- public void setCountExpr(MatchExpr var1) {
- this.countExpr = var1;
- if (var1 != null) {
- try {
- super.setAttribute("count", var1.toString());
- } catch (XSLException var2) {
- }
- }
- }
-
- public void setFormat(String var1) {
- try {
- this.setAttribute("format", var1);
- } catch (XSLException var2) {
- }
- }
-
- public void setFromExpr(MatchExpr var1) {
- this.fromExpr = var1;
- if (var1 != null) {
- try {
- super.setAttribute("from", var1.toString());
- } catch (XSLException var2) {
- }
- }
- }
-
- public void setLevel(String var1) {
- try {
- this.setAttribute("level", var1);
- } catch (XSLException var2) {
- }
- }
-
- protected List getAncestors(Element var1) {
- List var2 = new List();
-
- for(Object var3 = var1; var3 != null && ((Node)var3).getNodeType() == 1 && (this.fromExpr == null || !this.fromExpr.matches((Element)var3, (Hashtable)null)); var3 = ((Node)var3).getParentNode()) {
- if (this.matches((Element)var3, var1)) {
- var2.add(var3);
- }
- }
-
- return var2;
- }
-
- protected List getAnyPreviousNodes(Element var1) {
- List var2 = new List();
-
- for(Object var3 = var1; var3 != null && ((Node)var3).getNodeType() == 1; var3 = ((Node)var3).getParentNode()) {
- if (this.fromExpr != null && this.fromExpr.matches((Element)var3, (Hashtable)null)) {
- return var2;
- }
-
- if (this.matches((Element)var3, var1)) {
- var2.add(var3);
- }
-
- Object var4 = var3;
-
- while((var4 = ((Node)var4).getPreviousSibling()) != null) {
- if (((Node)var4).getNodeType() == 1) {
- if (this.fromExpr != null && this.fromExpr.matches((Element)var4, (Hashtable)null)) {
- return var2;
- }
-
- if (this.matches((Element)var4, var1)) {
- var2.add(var4);
- }
- }
- }
- }
-
- return var2;
- }
-
- protected Element getNearestAncestor(Element var1) {
- for(Object var2 = var1; var2 != null && ((Node)var2).getNodeType() == 1 && (this.fromExpr == null || !this.fromExpr.matches((Element)var2, (Hashtable)null)); var2 = ((Node)var2).getParentNode()) {
- if (this.matches((Element)var2, var1)) {
- return (Element)var2;
- }
- }
-
- return null;
- }
-
- private boolean matches(Element var1, Element var2) {
- String var3 = var1.getNodeName();
- return this.countExpr != null ? this.countExpr.matches(var1, (Hashtable)null) : var3.equals(var2.getNodeName());
- }
- }
-