/*********************************************************************************
* The contents of this file are subject to the OpenI Public License Version 1.0
* ("License"); You may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.openi.org/docs/LICENSE.txt
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is: OpenI Open Source
*
* The Initial Developer of the Original Code is Loyalty Matrix, Inc.
* Portions created by Loyalty Matrix, Inc. are
* Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
********************************************************************************/
package org.openi.xmla;
import com.tonbeller.jpivot.core.Model;
import com.tonbeller.jpivot.core.ModelFactory;
import com.tonbeller.jpivot.olap.model.OlapException;
import com.tonbeller.jpivot.olap.model.OlapModel;
import com.tonbeller.jpivot.olap.navi.ClickableExtension;
import com.tonbeller.jpivot.olap.navi.ClickableExtensionImpl;
import com.tonbeller.jpivot.table.ClickableMember;
import com.tonbeller.jpivot.tags.OlapModelProxy;
import com.tonbeller.jpivot.xmla.XMLA_Model;
import com.tonbeller.jpivot.xmla.XMLA_OlapModelTag;
import com.tonbeller.wcf.controller.RequestContext;
import org.apache.log4j.Logger;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
/**
* JSP tag for XMLA Olap Model
*/
public class XMLAQueryTag extends XMLA_OlapModelTag {
private static Logger logger = Logger.getLogger(XMLAQueryTag.class);
private List clickables;
private String user = null;
private String password = null;
private String mdxQuery = null;
private String queryName;
private boolean stackMode;
public void addClickable(ClickableMember clickable) {
clickables.add(clickable);
}
protected OlapModel getOlapModel(RequestContext context)
throws SAXException, IOException, OlapException {
URL url;
if (getConfig() == null) {
url = getClass().getResource("config.xml");
} else {
url = pageContext.getServletContext().getResource(getConfig());
}
// let Digester create a model from config input
// the config input stream MUST refer to the XMLA_Model class
// <model class="com.tonbeller.bii.xmla.XMLA_Model"> is required
Model model = ModelFactory.instance(url);
if (!(model instanceof XMLA_Model)) {
throw new com.tonbeller.jpivot.olap.model.OlapException(
"invalid class attribute for model tag, resource="
+ getConfig());
}
XMLA_Model xm = (XMLA_Model) model;
xm.setUri(getUri());
xm.setDataSource(getDataSource());
xm.setCatalog(getCatalog());
// xm.setMdxQuery(getBodyContent().getString());
xm.setUser(URLEncoder.encode(user, "UTF-8"));
xm.setPassword(URLEncoder.encode(password, "UTF-8"));
xm.setMdxQuery(mdxQuery);
return xm;
}
public void init(RequestContext context) throws Exception {
long start = System.currentTimeMillis();
// logger.debug("init'ing XMLAQueryTag using context params: " + context.getParameters());
clickables = new ArrayList();
OlapModel om = getOlapModel(context);
om = (OlapModel) om.getTopDecorator();
om.setLocale(context.getLocale());
om.setID(id);
ClickableExtension ext = (ClickableExtension) om.getExtension(ClickableExtension.ID);
if (ext == null) {
ext = new ClickableExtensionImpl();
om.addExtension(ext);
}
ext.setClickables(clickables);
OlapModelProxy omp = OlapModelProxy.instance(id, context.getSession(),
stackMode);
if (queryName != null) {
omp.initializeAndShow(queryName, om);
} else {
omp.initializeAndShow(om);
}
logger.info("init completed in: "
+ (System.currentTimeMillis() - start) + " ms");
}
public String getMdxQuery() {
return mdxQuery;
}
public void setMdxQuery(String mdxquery) {
mdxQuery = mdxquery;
}
public String getUser() {
return user;
}
public String getPassword() {
return password;
}
public void setUser(String user) {
this.user = user;
}
public void setPassword(String password) {
this.password = password;
}
public void setQueryName(String queryName) {
this.queryName = queryName;
}
public void setStackMode(boolean stackMode) {
this.stackMode = stackMode;
}
}
|