package org.tizzit.plugins.server.transformer;
import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.tizzit.util.xml.SAXHelper;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import de.juwimm.cms.beans.WebServiceSpring;
import de.juwimm.cms.plugins.server.Request;
import de.juwimm.cms.plugins.server.Response;
import de.juwimm.cms.vo.UnitValue;
import de.juwimm.cms.vo.ViewComponentValue;
/**
* <p>
* <b>Namespace: <code>http://plugins.tizzit.org/UnitInformationTransformerPlugin</code></b>
* </p>
*
* @author <a href="mailto:rene.hertzfeldt@juwimm.com">Rene Hertzfeldt</a>
* company Juwi MacMillan Group GmbH, Walsrode, Germany
* @version $Id: UnitInformationTransformerPlugin.java 759 2010-05-05 13:34:28Z rene.hertzfeldt $
*/
public class UnitInformationTransformerPlugin implements ManagedTizzitPlugin {
private static final Log log = LogFactory.getLog(UnitInformationTransformerPlugin.class);
private ContentHandler parent;
private final String UNITINFORMATION = "unitInformation";
private Integer viewComponentId = null;
private WebServiceSpring webSpringBean = null;
private ContentHandler manager;
private String nameSpace;
public void setup(ContentHandler pluginManager, String nameSpace, WebServiceSpring wss, ViewComponentValue viewComponent, boolean liveServer) {
this.manager = pluginManager;
this.nameSpace = nameSpace;
this.webSpringBean = wss;
}
/* (non-Javadoc)
* @see de.juwimm.cms.plugins.server.ConquestPlugin#configurePlugin(de.juwimm.cms.plugins.server.Request, de.juwimm.cms.plugins.server.Response, org.xml.sax.ContentHandler, java.lang.Integer)
*/
public void configurePlugin(Request req, Response resp, ContentHandler ch, Integer uniquePageId) {
if (log.isDebugEnabled()) log.debug("configurePlugin() -> begin");
this.parent = ch;
this.viewComponentId = uniquePageId;
//webSpringBean = (WebServiceSpring) PluginSpringHelper.getBean(objectModel, PluginSpringHelper.WEB_SERVICE_SPRING);
if (log.isDebugEnabled()) log.debug("configurePlugin() -> end");
}
/* (non-Javadoc)
* @see de.juwimm.cms.plugins.server.ConquestPlugin#getLastModifiedDate()
*/
public Date getLastModifiedDate() {
return new Date();
}
/* (non-Javadoc)
* @see de.juwimm.cms.plugins.server.ConquestPlugin#isCacheable()
*/
public boolean isCacheable() {
return false;
}
/* (non-Javadoc)
* @see de.juwimm.cms.plugins.server.ConquestPlugin#processContent()
*/
public void processContent() {
if (log.isDebugEnabled()) log.debug("processContent() -> begin");
if (log.isDebugEnabled()) log.debug("processContent() -> end");
}
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
*/
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException {
if (log.isDebugEnabled()) log.debug("startElement: " + localName + " in nameSpace: " + uri + " found " + attrs.getLength() + " attributes");
if (localName.compareTo(UNITINFORMATION) == 0) {
startUnitInformationElement(uri, localName, qName, attrs);
} else {
parent.startElement(uri, localName, qName, attrs);
}
}
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#characters(char[], int, int)
*/
public void characters(char[] ch, int start, int length) throws SAXException {
if (log.isDebugEnabled()) log.debug("characters: " + length + " long");
parent.characters(ch, start, length);
}
// FIXME: debug strings only
// needs to be called for start element
private void startUnitInformationElement(String uri, String localName, String qName, Attributes attrs) {
try {
String strUn = attrs.getValue("unitId");
UnitValue uv = null;
AttributesImpl newAttrs = new AttributesImpl();
if (strUn != null && !strUn.equals("")) {
SAXHelper.setSAXAttr(newAttrs, "unitId", strUn);
//uv = webSpringBean.getUnit(Integer.decode(strUn));
} else {
//uv = webSpringBean.getUnit4ViewComponent(viewComponentId);
//SAXHelper.setSAXAttr(newAttrs, "unitId", uv.getUnitId().toString());
SAXHelper.setSAXAttr(newAttrs, "unitId", "123");
}
//if (uv != null) {
//Integer viewDocumentId = webSpringBean.getViewDocument4ViewComponentId(viewComponentId).getViewDocumentId();
try {
//String unitPath = webSpringBean.getPath4Unit(uv.getUnitId(), viewDocumentId);
String unitPath = "1, 12, 124, 33";
SAXHelper.setSAXAttr(newAttrs, "url", unitPath);
} catch (Exception exe) {
}
//SAXHelper.setSAXAttr(newAttrs, "unitName", uv.getName());
SAXHelper.setSAXAttr(newAttrs, "unitName", "debug");
//}
parent.startElement(uri, localName, qName, newAttrs);
} catch (Exception e) {
if (log.isDebugEnabled()) log.debug("error while transforming unitInformationTag ", e);
}
}
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
*/
public void endElement(String uri, String localName, String qName) throws SAXException {
if (log.isDebugEnabled()) log.debug("endElement: " + localName + " in nameSpace: " + uri);
parent.endElement(uri, localName, qName);
}
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#endDocument()
*/
public void endDocument() throws SAXException {
// do nothing
}
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#endPrefixMapping(java.lang.String)
*/
public void endPrefixMapping(String prefix) throws SAXException {
// do nothing
}
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#ignorableWhitespace(char[], int, int)
*/
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
// do nothing
}
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#processingInstruction(java.lang.String, java.lang.String)
*/
public void processingInstruction(String target, String data) throws SAXException {
// do nothing
}
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#setDocumentLocator(org.xml.sax.Locator)
*/
public void setDocumentLocator(Locator locator) {
// do nothing
}
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#skippedEntity(java.lang.String)
*/
public void skippedEntity(String name) throws SAXException {
// do nothing
}
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#startDocument()
*/
public void startDocument() throws SAXException {
// do nothing
}
/* (non-Javadoc)
* @see org.xml.sax.ContentHandler#startPrefixMapping(java.lang.String, java.lang.String)
*/
public void startPrefixMapping(String prefix, String uri) throws SAXException {
// do nothing
}
}