KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > xmla > XMLA_MemberProp


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.jpivot.xmla;
14
15 import com.tonbeller.jpivot.olap.model.Dimension;
16 import com.tonbeller.jpivot.olap.model.Level;
17
18 /**
19  * a member property in xmla
20  */

21 public class XMLA_MemberProp {
22
23   private String JavaDoc caption;
24   private Level level;
25   private Dimension dimension;
26   private String JavaDoc name;
27   private String JavaDoc xmlTag;
28
29   private boolean sap = false;
30
31   /**
32    * C'tor NOT SAP
33    */

34   public XMLA_MemberProp(String JavaDoc name, String JavaDoc caption, Level level) {
35     this.name = name;
36     this.caption = caption;
37     this.level = level;
38     this.sap = false;
39     this.dimension = level.getHierarchy().getDimension();
40     // replace special characters
41
xmlTag = escapeSpecialChars(name);
42
43   }
44
45   /**
46    * C'tor SAP
47    */

48   public XMLA_MemberProp(String JavaDoc name, String JavaDoc caption, Dimension dimension) {
49     this.name = name;
50     this.caption = caption;
51     this.level = null;
52     this.sap = true;
53     this.dimension = dimension;
54     // replace special characters (Microsoft)
55
xmlTag = escapeSpecialChars(name);
56
57     // SAP: replace enclosing brackets
58
int len = xmlTag.length();
59     if (xmlTag.charAt(0) == '[' && xmlTag.charAt(len - 1) == ']')
60       xmlTag = xmlTag.substring(1, len - 1); // remove brackets
61
// SAP XML tag always starts with "_"
62
if (xmlTag.charAt(0) != '_')
63       xmlTag = "_" + xmlTag;
64   }
65
66   /**
67    * @return
68    */

69   public Level getLevel() {
70     return level;
71   }
72
73   /**
74    * @return
75    */

76   public String JavaDoc getName() {
77     return name;
78   }
79
80   /**
81    * @return
82    */

83   public String JavaDoc getXmlTag() {
84     return xmlTag;
85   }
86
87   /**
88    * escape special characters
89    */

90   static final char[] special = { ' ', '<', '>' };
91   private String JavaDoc escapeSpecialChars(String JavaDoc str) {
92
93     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
94     Outer : for (int i = 0; i < str.length(); i++) {
95       char c = str.charAt(i);
96       for (int j = 0; j < special.length; j++) {
97         if (c == special[j]) {
98           sb.append("_x");
99           String JavaDoc x = Integer.toHexString(c);
100           int k = 4 - x.length();
101           /*
102           if (k > 0)
103             sb.append("0000".substring(0, k));
104           */

105           for (int m = 0; m < k; m++)
106             sb.append('0');
107           sb.append(x);
108           sb.append("_");
109           continue Outer;
110         }
111       }
112       sb.append(c);
113     }
114     return sb.toString();
115   }
116
117   /**
118    * @return
119    */

120   public String JavaDoc getCaption() {
121     return caption;
122   }
123
124   /**
125    * @return
126    */

127   public Dimension getDimension() {
128     return dimension;
129   }
130
131 } // XMLA_MemberProp
132
Popular Tags