com.twinsoft.convertigo.beans.steps.SessionGetStep.java Source code

Java tutorial

Introduction

Here is the source code for com.twinsoft.convertigo.beans.steps.SessionGetStep.java

Source

/*
 * Copyright (c) 2001-2011 Convertigo SA.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see<http://www.gnu.org/licenses/>.
 *
 * $URL: http://sourceus/svn/convertigo/CEMS_opensource/trunk/Studio/src/com/twinsoft/convertigo/beans/steps/SetAuthenticatedUserStep.java $
 * $Author: julienda $
 * $Revision: 34210 $
 * $Date: 2013-12-09 16:37:15 +0200 (lun., 09 dec 2013) $
 */

package com.twinsoft.convertigo.beans.steps;

import org.apache.commons.lang3.StringUtils;
import org.apache.ws.commons.schema.XmlSchema;
import org.apache.ws.commons.schema.XmlSchemaCollection;
import org.apache.ws.commons.schema.XmlSchemaComplexType;
import org.apache.ws.commons.schema.XmlSchemaElement;
import org.apache.ws.commons.schema.XmlSchemaSequence;
import org.apache.ws.commons.schema.constants.Constants;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import com.twinsoft.convertigo.beans.core.IComplexTypeAffectation;
import com.twinsoft.convertigo.beans.core.Step;
import com.twinsoft.convertigo.engine.EngineException;
import com.twinsoft.convertigo.engine.enums.SchemaMeta;
import com.twinsoft.convertigo.engine.util.XmlSchemaUtils;

public class SessionGetStep extends Step implements IComplexTypeAffectation {

    private static final long serialVersionUID = -1894558458026853410L;

    private String key = "";

    public SessionGetStep() {
        super();
        setOutput(true);
        this.xml = true;
    }

    @Override
    public SessionGetStep clone() throws CloneNotSupportedException {
        SessionGetStep clonedObject = (SessionGetStep) super.clone();
        return clonedObject;
    }

    @Override
    public SessionGetStep copy() throws CloneNotSupportedException {
        SessionGetStep copiedObject = (SessionGetStep) super.copy();
        return copiedObject;
    }

    @Override
    public String getStepNodeName() {
        return "session";
    }

    @Override
    protected void createStepNodeValue(Document doc, Element stepNode) throws EngineException {
        if (StringUtils.isNotEmpty(key)) {
            Element keyElement = doc.createElement("key");
            keyElement.setTextContent(key);
            stepNode.appendChild(keyElement);

            Object value = getSequence().context.httpSession.getAttribute(key);
            if (value != null) {
                Element expressionElement = doc.createElement("expression");
                expressionElement.setTextContent(value.toString());
                stepNode.appendChild(expressionElement);
            }
        }
    }

    @Override
    public XmlSchemaElement getXmlSchemaObject(XmlSchemaCollection collection, XmlSchema schema) {
        XmlSchemaElement element = (XmlSchemaElement) super.getXmlSchemaObject(collection, schema);

        XmlSchemaComplexType cType = XmlSchemaUtils.makeDynamic(this, new XmlSchemaComplexType(schema));
        element.setType(cType);

        XmlSchemaSequence sequence = XmlSchemaUtils.makeDynamic(this, new XmlSchemaSequence());
        cType.setParticle(sequence);
        SchemaMeta.setContainerXmlSchemaGroupBase(element, sequence);

        XmlSchemaElement elt = XmlSchemaUtils.makeDynamic(this, new XmlSchemaElement());
        sequence.getItems().add(elt);
        elt.setName("key");
        elt.setMinOccurs(0);
        elt.setMaxOccurs(1);
        elt.setSchemaTypeName(Constants.XSD_STRING);

        elt = XmlSchemaUtils.makeDynamic(this, new XmlSchemaElement());
        sequence.getItems().add(elt);
        elt.setName("expression");
        elt.setMinOccurs(0);
        elt.setMaxOccurs(1);
        elt.setSchemaTypeName(Constants.XSD_STRING);

        return element;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    @Override
    public String toJsString() {
        String string = (String) getSequence().context.httpSession.getAttribute(key);
        if (string != null && string.length() > 0) {
            return string;
        }
        return "";
    }
}