001: /*********************************************************************************
002: * The contents of this file are subject to the OpenI Public License Version 1.0
003: * ("License"); You may not use this file except in compliance with the
004: * License. You may obtain a copy of the License at
005: * http://www.openi.org/docs/LICENSE.txt
006: *
007: * Software distributed under the License is distributed on an "AS IS" basis,
008: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009: * the specific language governing rights and limitations under the License.
010: *
011: * The Original Code is: OpenI Open Source
012: *
013: * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
014: * Portions created by Loyalty Matrix, Inc. are
015: * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
016: *
017: * Contributor(s): ______________________________________.
018: *
019: ********************************************************************************/package org.openi.xmla;
020:
021: import com.tonbeller.jpivot.core.Model;
022: import com.tonbeller.jpivot.core.ModelFactory;
023: import com.tonbeller.jpivot.olap.model.OlapException;
024: import com.tonbeller.jpivot.olap.model.OlapModel;
025: import com.tonbeller.jpivot.olap.navi.ClickableExtension;
026: import com.tonbeller.jpivot.olap.navi.ClickableExtensionImpl;
027: import com.tonbeller.jpivot.table.ClickableMember;
028: import com.tonbeller.jpivot.tags.OlapModelProxy;
029: import com.tonbeller.jpivot.xmla.XMLA_Model;
030: import com.tonbeller.jpivot.xmla.XMLA_OlapModelTag;
031: import com.tonbeller.wcf.controller.RequestContext;
032: import org.apache.log4j.Logger;
033: import org.xml.sax.SAXException;
034: import java.io.IOException;
035: import java.net.URL;
036: import java.net.URLEncoder;
037: import java.util.ArrayList;
038: import java.util.List;
039:
040: /**
041: * JSP tag for XMLA Olap Model
042: */
043: public class XMLAQueryTag extends XMLA_OlapModelTag {
044: private static Logger logger = Logger.getLogger(XMLAQueryTag.class);
045: private List clickables;
046: private String user = null;
047: private String password = null;
048: private String mdxQuery = null;
049: private String queryName;
050: private boolean stackMode;
051:
052: public void addClickable(ClickableMember clickable) {
053: clickables.add(clickable);
054: }
055:
056: protected OlapModel getOlapModel(RequestContext context)
057: throws SAXException, IOException, OlapException {
058: URL url;
059:
060: if (getConfig() == null) {
061: url = getClass().getResource("config.xml");
062: } else {
063: url = pageContext.getServletContext().getResource(
064: getConfig());
065: }
066:
067: // let Digester create a model from config input
068: // the config input stream MUST refer to the XMLA_Model class
069: // <model class="com.tonbeller.bii.xmla.XMLA_Model"> is required
070: Model model = ModelFactory.instance(url);
071:
072: if (!(model instanceof XMLA_Model)) {
073: throw new com.tonbeller.jpivot.olap.model.OlapException(
074: "invalid class attribute for model tag, resource="
075: + getConfig());
076: }
077:
078: XMLA_Model xm = (XMLA_Model) model;
079: xm.setUri(getUri());
080: xm.setDataSource(getDataSource());
081: xm.setCatalog(getCatalog());
082: // xm.setMdxQuery(getBodyContent().getString());
083: xm.setUser(URLEncoder.encode(user, "UTF-8"));
084: xm.setPassword(URLEncoder.encode(password, "UTF-8"));
085: xm.setMdxQuery(mdxQuery);
086:
087: return xm;
088: }
089:
090: public void init(RequestContext context) throws Exception {
091: long start = System.currentTimeMillis();
092: // logger.debug("init'ing XMLAQueryTag using context params: " + context.getParameters());
093: clickables = new ArrayList();
094:
095: OlapModel om = getOlapModel(context);
096: om = (OlapModel) om.getTopDecorator();
097: om.setLocale(context.getLocale());
098: om.setID(id);
099:
100: ClickableExtension ext = (ClickableExtension) om
101: .getExtension(ClickableExtension.ID);
102:
103: if (ext == null) {
104: ext = new ClickableExtensionImpl();
105: om.addExtension(ext);
106: }
107:
108: ext.setClickables(clickables);
109:
110: OlapModelProxy omp = OlapModelProxy.instance(id, context
111: .getSession(), stackMode);
112:
113: if (queryName != null) {
114: omp.initializeAndShow(queryName, om);
115: } else {
116: omp.initializeAndShow(om);
117: }
118:
119: logger.info("init completed in: "
120: + (System.currentTimeMillis() - start) + " ms");
121: }
122:
123: public String getMdxQuery() {
124: return mdxQuery;
125: }
126:
127: public void setMdxQuery(String mdxquery) {
128: mdxQuery = mdxquery;
129: }
130:
131: public String getUser() {
132: return user;
133: }
134:
135: public String getPassword() {
136: return password;
137: }
138:
139: public void setUser(String user) {
140: this .user = user;
141: }
142:
143: public void setPassword(String password) {
144: this .password = password;
145: }
146:
147: public void setQueryName(String queryName) {
148: this .queryName = queryName;
149: }
150:
151: public void setStackMode(boolean stackMode) {
152: this.stackMode = stackMode;
153: }
154: }
|