Example usage for org.apache.commons.chain Context put

List of usage examples for org.apache.commons.chain Context put

Introduction

In this page you can find the example usage for org.apache.commons.chain Context put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:bridge.toolkit.commands.S1000DConverter.java

/** 
 * The unit of processing work to be performed for the S1000DConverter module.
 * @see org.apache.commons.chain.Command#execute(org.apache.commons.chain.Context)
 *///from ww w  .  ja  v  a2 s  .c om
public boolean execute(Context ctx) {
    System.out.println("Executing S1000D Converter");
    if ((ctx.get(Keys.SCPM_FILE) != null) && (ctx.get(Keys.RESOURCE_PACKAGE) != null)) {
        /*
         * check the output directory in the context if it does not exist make it
         */
        if (!(ctx.containsKey(Keys.OUTPUT_DIRECTORY))) {
            ctx.put(Keys.OUTPUT_DIRECTORY, "");
        }

        resourcepack = ctx.get(Keys.RESOURCE_PACKAGE).toString();
        /*
         * if SCPM is 4.1 then Move the original file to the temp directory
         * in this file it will perform the downgrade to 4.0 version If
         * /scormContentPackage/content/scoEntry/scoEntryItem exists is a
         * 4.1 SCPM
         */
        org.w3c.dom.Document new40 = null;
        File tempSCPM = null;
        try {
            new40 = getDoc(new File(ctx.get(Keys.SCPM_FILE).toString()));
            if (processXPathSingleNode("/scormContentPackage/content/scoEntry/scoEntryItem", new40) == null) {
                System.out.println("S1000D Converter Complete");
                return CONTINUE_PROCESSING;
            }
            tempSCPM = File.createTempFile(new File(ctx.get(Keys.SCPM_FILE).toString()).getName(), ".xml");
            copy(ctx.get(Keys.SCPM_FILE).toString(), tempSCPM.toString());
            ctx.put(Keys.SCPM_FILE, tempSCPM.getAbsolutePath());
        } catch (Exception e) {
            e.printStackTrace();
            return PROCESSING_COMPLETE;
        }

        List<File> src_files = new ArrayList<File>();
        try {
            src_files = getSourceFiles((String) ctx.get(Keys.RESOURCE_PACKAGE));
        } catch (Exception npe) {
            System.out.println("The 'Resource Package' is empty.");
            return PROCESSING_COMPLETE;
        }

        /*
         * For each scoEntry adding sconEntryAddress and scoEntryStatus
         */
        try {
            // getting the modelic and issuer from status SCPM
            modelic = processXPathSingleNode(
                    "/scormContentPackage/identAndStatusSection/scormContentPackageAddress/scormContentPackageIdent/scormContentPackageCode/@modelIdentCode",
                    new40).getNodeValue();
            PackageIssuer = processXPathSingleNode(
                    "/scormContentPackage/identAndStatusSection/scormContentPackageAddress/scormContentPackageIdent/scormContentPackageCode/@scormContentPackageIssuer",
                    new40).getNodeValue();
            PackageNumber = processXPathSingleNode(
                    "/scormContentPackage/identAndStatusSection/scormContentPackageAddress/scormContentPackageIdent/scormContentPackageCode/@scormContentPackageNumber",
                    new40).getNodeValue();
            PackageVolume = processXPathSingleNode(
                    "/scormContentPackage/identAndStatusSection/scormContentPackageAddress/scormContentPackageIdent/scormContentPackageCode/@scormContentPackageVolume",
                    new40).getNodeValue();

            securityClassification = processXPathSingleNode(
                    "/scormContentPackage/identAndStatusSection/scormContentPackageStatus/security/@securityClassification",
                    new40).getNodeValue();
            ;
            qualityAssurance = processXPathSingleNode(
                    "/scormContentPackage/identAndStatusSection/scormContentPackageStatus/qualityAssurance",
                    new40);

            // getting the content node
            Node content = processXPathSingleNode("//content", new40);

            if (content != null) {
                // delete content..
                Node contentclone = content.cloneNode(true);
                removeNode(content);
                // add the content Node..
                org.w3c.dom.Element newcontent = new40.createElement("content");
                // navigate through the tree seeking for scoEntry
                for (int i = 0; i < contentclone.getChildNodes().getLength(); i++) {
                    Node node = contentclone.getChildNodes().item(i);
                    if (node.getNodeName().equals("scoEntry")) {
                        Node scoE = node.cloneNode(true);
                        walkingthrough(scoE, new40);
                        newcontent.appendChild(scoE);
                    }
                }

                // add the content modified
                Node pm = processXPathSingleNode("//scormContentPackage", new40);
                pm.appendChild(newcontent);

                // re write on temp file the new XML..
                writeOnDisk(tempSCPM, getXMLString(new40));
            }

        } catch (Exception npe) {
            Writer writer = new StringWriter();
            PrintWriter printWriter = new PrintWriter(writer);
            npe.printStackTrace(printWriter);
            writer.toString();
            System.out.println("Error " + npe + " " + writer.toString());
            return PROCESSING_COMPLETE;
        }

        System.out.println("Conversion of SCPM 4.1 to SCPM 4.0 was successful");
    } else {
        System.out.println("One of the required Context entries for the " + this.getClass().getSimpleName()
                + " command to be executed was null");
        return PROCESSING_COMPLETE;
    }
    return CONTINUE_PROCESSING;
}

From source file:com.netsteadfast.greenstep.bsc.action.KpiReportContentQueryAction.java

@SuppressWarnings("unchecked")
private void setContextForSingleObject(Context context) throws Exception {
    String nextType = this.getFields().get("nextType");
    String nextId = this.getFields().get("nextId");
    if (StringUtils.isBlank(nextType) || StringUtils.isBlank(nextId)) {
        return;//from   w w  w. ja  va 2 s  .  c o m
    }
    if (!(BscConstants.HEAD_FOR_PER_ID.equals(nextType) || BscConstants.HEAD_FOR_OBJ_ID.equals(nextType)
            || BscConstants.HEAD_FOR_KPI_ID.equals(nextType))) {
        return;
    }
    context.put("nextType", nextType);
    context.put("nextId", nextId);
}

From source file:bridge.toolkit.commands.SCOBuilder.java

/**
 * The unit of processing work to be performed for the SCOBuilder module.
 * /*ww w.j a v  a  2  s. c  om*/
 * @see org.apache.commons.chain.Command#execute(org.apache.commons.chain.Context)
 */
@Override
public boolean execute(Context ctx) {
    System.out.println("Executing SCOBuilder");
    commonFiles = new ArrayList<String>();
    //System.out.println("Executing SCOBuilder");
    //System.out.flush();
    if ((ctx.get(Keys.XML_SOURCE) != null) && (ctx.get(Keys.RESOURCE_PACKAGE) != null)
            && (ctx.get(Keys.SCPM_FILE) != null)) {
        //check to see if a cp_package directory exist yet
        if (ctx.get(Keys.CP_PACKAGE) == null) {

            ContentPackageCreator cpc = new ContentPackageCreator((String) ctx.get(Keys.RESOURCE_PACKAGE));
            try {
                cpPackage = cpc.createPackage();
            } catch (IOException e) {
                System.out.println(SCOBUILDER_FAILED);
                e.printStackTrace();
                return PROCESSING_COMPLETE;
            } catch (JDOMException e) {
                System.out.println(SCOBUILDER_FAILED);
                e.printStackTrace();
                return PROCESSING_COMPLETE;
            }
            ctx.put(Keys.CP_PACKAGE, cpPackage);
        } else {
            cpPackage = (File) ctx.get(Keys.CP_PACKAGE);
        }

        try {
            //copy necessary files over to CP folder
            copyViewerAppFiles();

            //apply the SCORM CP XSLT StyleSheet to the data modules
            StylesheetApplier sa = new StylesheetApplier();
            if (ctx.get(Keys.OUTPUT_TYPE) == "SCORMHTML") {
                sa.applyStylesheetToDMCs(cpPackage, CPHTMLSTYLESHEET);
            } else {
                sa.applyStylesheetToDMCs(cpPackage, CPSTYLESHEET);
            }

            //create list.js, add to CP
            dmp = new DMParser();
            manifest = (Document) ctx.get(Keys.XML_SOURCE);
            File scpmFile = new File((String) ctx.get(Keys.SCPM_FILE));
            scpm = dmp.getDoc(scpmFile);

            generateListFile();

            //write urn map to cp app location
            Document urn_map = (Document) ctx.get(Keys.URN_MAP);
            File js = new File(cpPackage + File.separator + "resources/s1000d/app/urn_resource_map.xml");

            XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
            FileWriter writer = new FileWriter(js);
            outputter.output(urn_map, writer);
            writer.flush();
            writer.close();
            //System.out.println("A " + js.getAbsolutePath());
            commonFiles.add(js.getAbsolutePath());

            //add as a common resource element
            generateCommonResource();

            //build launchable htm files and add to manifest
            generateLaunchableFile();
        } catch (JDOMException e) {
            System.out.println(SCOBUILDER_FAILED);
            e.printStackTrace();
            return PROCESSING_COMPLETE;
        } catch (IOException ioe) {
            System.out.println(SCOBUILDER_FAILED);
            ioe.printStackTrace();
            return PROCESSING_COMPLETE;
        }

        ctx.put(Keys.XML_SOURCE, manifest);
        System.out.println("SCOBuilder processing was successful");
    } else {
        System.out.println(SCOBUILDER_FAILED);
        System.out.println("One of the required Context entries for the " + this.getClass().getSimpleName()
                + " command to be executed was null");
        return PROCESSING_COMPLETE;
    }

    return CONTINUE_PROCESSING;
}

From source file:com.netsteadfast.greenstep.bsc.command.LoadPdcaDataCommand.java

@SuppressWarnings("unchecked")
@Override/*from  w w  w .j a  va2s.  c  om*/
public boolean execute(Context context) throws Exception {
    pdcaService = (IPdcaService<PdcaVO, BbPdca, String>) AppContext.getBean("bsc.service.PdcaService");
    pdcaDocService = (IPdcaDocService<PdcaDocVO, BbPdcaDoc, String>) AppContext
            .getBean("bsc.service.PdcaDocService");
    pdcaItemService = (IPdcaItemService<PdcaItemVO, BbPdcaItem, String>) AppContext
            .getBean("bsc.service.PdcaItemService");
    pdcaItemDocService = (IPdcaItemDocService<PdcaItemDocVO, BbPdcaItemDoc, String>) AppContext
            .getBean("bsc.service.PdcaItemDocService");
    pdcaAuditService = (IPdcaAuditService<PdcaAuditVO, BbPdcaAudit, String>) AppContext
            .getBean("bsc.service.PdcaAuditService");
    employeeService = (IEmployeeService<EmployeeVO, BbEmployee, String>) AppContext
            .getBean("bsc.service.EmployeeService");
    organizationService = (IOrganizationService<OrganizationVO, BbOrganization, String>) AppContext
            .getBean("bsc.service.OrganizationService");
    kpiService = (IKpiService<KpiVO, BbKpi, String>) AppContext.getBean("bsc.service.KpiService");
    String pdcaOid = (String) context.get("pdcaOid");
    PdcaVO pdca = new PdcaVO();
    pdca.setOid(pdcaOid);
    DefaultResult<PdcaVO> result = pdcaService.findObjectByOid(pdca);
    if (result.getValue() == null) {
        this.setMessage(context, result.getSystemMessage().getValue());
    } else {
        pdca = result.getValue();
        this.loadDetail(pdca);
        this.loadPdcaItems(pdca);
        this.loadAudit(pdca);
        this.setResult(context, pdca);
        context.put("pdca", pdca); // Action ??
    }
    return false;
}

From source file:bridge.toolkit.commands.PreProcess.java

/** 
 * The unit of processing work to be performed for the PreProcess module.
 * @see org.apache.commons.chain.Command#execute(org.apache.commons.chain.Context)
 *//*  w w w  . j  a va  2  s. c  o m*/
@SuppressWarnings("unchecked")
public boolean execute(Context ctx) {
    System.out.println("Executing PreProcess");
    if ((ctx.get(Keys.SCPM_FILE) != null) && (ctx.get(Keys.RESOURCE_PACKAGE) != null)) {

        src_dir = (String) ctx.get(Keys.RESOURCE_PACKAGE);

        List<File> src_files = new ArrayList<File>();
        try {
            src_files = URNMapper.getSourceFiles(src_dir);
        } catch (NullPointerException npe) {
            System.out.println(CONVERSION_FAILED);
            System.out.println("The 'Resource Package' is empty.");
            return PROCESSING_COMPLETE;
        } catch (JDOMException e) {
            System.out.println(CONVERSION_FAILED);
            e.printStackTrace();
            return PROCESSING_COMPLETE;
        } catch (IOException e) {
            System.out.println(CONVERSION_FAILED);
            e.printStackTrace();
            return PROCESSING_COMPLETE;
        }

        urn_map = URNMapper.writeURNMap(src_files, "");

        transform = this.getClass().getResourceAsStream(TRANSFORM_FILE);

        try {
            doTransform((String) ctx.get(Keys.SCPM_FILE));

            addResources(urn_map);

            processDeps(mapDependencies());
        } catch (ResourceMapException e) {
            System.out.println(CONVERSION_FAILED);
            e.printTrace();
            return PROCESSING_COMPLETE;
        } catch (JDOMException jde) {
            System.out.println(CONVERSION_FAILED);
            jde.printStackTrace();
            return PROCESSING_COMPLETE;
        } catch (TransformerException te) {
            System.out.println(CONVERSION_FAILED);
            te.printStackTrace();
            return PROCESSING_COMPLETE;
        } catch (IOException e1) {
            System.out.println(CONVERSION_FAILED);
            e1.printStackTrace();
            return PROCESSING_COMPLETE;
        }

        ctx.put(Keys.URN_MAP, urn_map);
        ctx.put(Keys.XML_SOURCE, manifest);

        System.out.println("Conversion of SCPM to IMS Manifest was successful");
    } else {
        System.out.println(CONVERSION_FAILED);
        System.out.println("One of the required Context entries for the " + this.getClass().getSimpleName()
                + " command to be executed was null");
        return PROCESSING_COMPLETE;
    }
    return CONTINUE_PROCESSING;
}

From source file:bridge.toolkit.commands.MobileBuilder.java

/** 
 * The unit of processing work to be performed for the MobileBuilder module.
 * // ww  w  . j  a  v  a2 s.  com
 * @see org.apache.commons.chain.Command#execute(org.apache.commons.chain.Context)
 */
@Override
public boolean execute(Context ctx) {
    System.out.println("Executing Mobile Builder");
    if ((ctx.get(Keys.SCPM_FILE) != null) && (ctx.get(Keys.RESOURCE_PACKAGE) != null)) {
        CopyDirectory cd = new CopyDirectory();
        src_dir = (String) ctx.get(Keys.RESOURCE_PACKAGE);
        scpm_file = (String) ctx.get(Keys.SCPM_FILE);

        List<File> src_files = new ArrayList<File>();
        try {
            src_files = URNMapper.getSourceFiles(src_dir);
        } catch (NullPointerException npe) {
            System.out.println(MOBILEBUILDER_FAILED);
            System.out.println("The 'Resource Package' is empty.");
            return PROCESSING_COMPLETE;
        } catch (JDOMException e) {
            System.out.println(MOBILEBUILDER_FAILED);
            e.printStackTrace();
            return PROCESSING_COMPLETE;
        } catch (IOException e) {
            System.out.println(MOBILEBUILDER_FAILED);
            e.printStackTrace();
            return PROCESSING_COMPLETE;
        }

        urn_map = URNMapper.writeURNMap(src_files, "../media/");

        //write urn map file out to the ViewerApplication directory temporarily.  
        File js = null;
        File jsviewer = null;
        File xsldir = null;
        try {

            jsviewer = new File(System.getProperty("user.dir") + File.separator + "ViewerApplication");
            js = new File(System.getProperty("user.dir") + File.separator
                    + "ViewerApplication/app/urn_resource_map.xml");
            //check if the directory exists if it does use it and set the file object to null so it will not be deleted
            // else copy it from the jar and delete it when finished processing.
            if (!(jsviewer.exists())) {
                //System.out.println("Path directory creation " + jsapp.getAbsolutePath());
                jsviewer.mkdirs();
                cd.CopyJarFiles(this.getClass(), "ViewerApplication", jsviewer.getAbsolutePath());
            } else {
                jsviewer = null;
            }

            //check if the directory exists if it does use it and set the file object to null so it will not be deleted
            // else copy it from the jar and delete it when finished processing.
            xsldir = new File(System.getProperty("user.dir") + File.separator + "xsl");
            if (!(xsldir.exists())) {
                //System.out.println("jsviewer directory creation " + jsviewer.getAbsolutePath());
                xsldir.mkdirs();
                cd.CopyJarFiles(this.getClass(), "xsl", xsldir.getAbsolutePath());
            } else {
                xsldir = null;
            }

            XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
            FileWriter writer;
            writer = new FileWriter(js);
            outputter.output(urn_map, writer);
            writer.flush();
            writer.close();

        } catch (IOException e) {
            System.out.println(MOBILEBUILDER_FAILED);
            e.printStackTrace();
            return PROCESSING_COMPLETE;
        }

        String outputPath = "";
        if (ctx.get(Keys.OUTPUT_DIRECTORY) != null) {
            outputPath = (String) ctx.get(Keys.OUTPUT_DIRECTORY);
            if (outputPath.length() > 0) {
                outputPath = outputPath + File.separator;
            }
        }

        //create new directory and folder for mobile_output
        File newMobApp = createOutputLocation(outputPath);

        //transform SCPM to main index.htm file
        try {
            transformSCPM(newMobApp, ctx.get(Keys.OUTPUT_TYPE));
        } catch (FileNotFoundException e) {
            System.out.println(MOBILEBUILDER_FAILED);
            e.printStackTrace();
            return PROCESSING_COMPLETE;
        } catch (TransformerConfigurationException e1) {
            System.out.println(MOBILEBUILDER_FAILED);
            e1.printStackTrace();
            return PROCESSING_COMPLETE;
        } catch (TransformerException e) {
            System.out.println(MOBILEBUILDER_FAILED);
            e.printStackTrace();
            return PROCESSING_COMPLETE;
        }

        //parse SCPM for list of files in each scoEntry to create the individual mobile app pages
        try {
            generateMobilePages(newMobApp, (String) ctx.get(Keys.OUTPUT_TYPE));

        } catch (TransformerConfigurationException e2) {
            System.out.println(MOBILEBUILDER_FAILED);
            e2.printStackTrace();
            return PROCESSING_COMPLETE;
        } catch (FileNotFoundException e2) {
            System.out.println(MOBILEBUILDER_FAILED);
            e2.printStackTrace();
            return PROCESSING_COMPLETE;
        } catch (JDOMException e2) {
            System.out.println(MOBILEBUILDER_FAILED);
            e2.printStackTrace();
            return PROCESSING_COMPLETE;
        } catch (IOException e2) {
            System.out.println(MOBILEBUILDER_FAILED);
            e2.printStackTrace();
            return PROCESSING_COMPLETE;
        } catch (TransformerFactoryConfigurationError e2) {
            System.out.println(MOBILEBUILDER_FAILED);
            e2.printStackTrace();
            return PROCESSING_COMPLETE;
        } catch (TransformerException e2) {
            System.out.println(MOBILEBUILDER_FAILED);
            e2.printStackTrace();
            return PROCESSING_COMPLETE;
        }

        //create list.js file
        try {
            generateListFile(newMobApp);
        } catch (IOException e1) {
            System.out.println(MOBILEBUILDER_FAILED);
            e1.printStackTrace();
            return PROCESSING_COMPLETE;
        } catch (JDOMException e1) {
            System.out.println(MOBILEBUILDER_FAILED);
            e1.printStackTrace();
            return PROCESSING_COMPLETE;
        }

        try {
            //copy over css and jquery mobile files              
            File mobiApp_loc = new File(System.getProperty("user.dir") + File.separator + "mobiApp");
            //check if the directory exists if it does use it else copy it from the jar
            if (mobiApp_loc.exists()) {
                cd.copyDirectory(mobiApp_loc, newMobApp);
            } else {
                cd.CopyJarFiles(this.getClass(), "mobiApp", newMobApp.getAbsolutePath());
            }

            //copy commonmobile.js
            File commonmobile_js = new File(System.getProperty("user.dir") + File.separator + "xsl"
                    + File.separator + "bridge" + File.separator + "toolkit" + File.separator + "commands"
                    + File.separator + "commonmobile.js");
            //check if the directory exists if it does use it else copy it from the jar
            if (commonmobile_js.exists()) {
                cd.copyDirectory(commonmobile_js, newMobApp);
            }

            //copy over media files           
            File new_media_loc = new File(newMobApp.getAbsolutePath() + File.separator + "media");
            new_media_loc.mkdir();
            Iterator<File> srcIterator = src_files.iterator();
            while (srcIterator.hasNext()) {
                File src = srcIterator.next();
                if (!src.getName().endsWith(".xml") && !src.getName().endsWith(".XML")) {
                    cd.copyDirectory(src, new_media_loc);
                }
            }
        } catch (IOException e) {
            System.out.println(MOBILEBUILDER_FAILED);
            e.printStackTrace();
            return PROCESSING_COMPLETE;
        }

        //delete the urn map from the ViewerApplication location
        ArrayList<String> files_to_delete = new ArrayList<String>();
        if (jsviewer != null) {
            DeleteDirectoryOnExit(jsviewer, files_to_delete);
        }
        if (js != null) {
            files_to_delete.add(js.getAbsolutePath());
        }
        if (xsldir != null) {
            DeleteDirectoryOnExit(xsldir, files_to_delete);
        }
        ctx.put(Keys.MOBLIE_FILES_TO_DELETE, files_to_delete);
        System.out.println("MobileBuilder processing was successful");

    }
    return CONTINUE_PROCESSING;

}

From source file:org.ambiance.chain.FalseCommand.java

@SuppressWarnings("unchecked")
public boolean execute(Context ctx) throws Exception {
    ctx.put("FalseCommand", "no");
    return false;
}

From source file:org.ambiance.chain.TrueCommand.java

@SuppressWarnings("unchecked")
public boolean execute(Context ctx) throws Exception {
    ctx.put("TrueCommand", "yes");
    return true;//from   w ww  . jav a  2  s  .  co  m
}

From source file:org.apache.jackrabbit.standalone.cli.collect.AbstractCollect.java

/**
 * {@inheritDoc}/*from   ww w  . j  a v  a  2 s  .  c  o m*/
 */
public final boolean execute(Context ctx) throws Exception {
    if (this.destKey == null || this.destKey.length() == 0) {
        throw new IllegalStateException("target variable is not set");
    }
    String relPath = (String) ctx.get(this.srcPathKey);
    if (relPath == null) {
        relPath = ".";
    }
    String namePattern = (String) ctx.get(this.namePatternKey);
    if (namePattern == null || namePattern.length() == 0) {
        namePattern = "*";
    }

    int depth = Integer.parseInt((String) ctx.get(this.depthKey));

    Node node = CommandHelper.getNode(ctx, relPath);
    if (log.isDebugEnabled()) {
        log.debug("collecting nodes from " + node.getPath() + " depth=" + depth + " pattern=" + namePattern
                + " into target variable " + this.destKey);
    }

    Collection items = new ArrayList();
    ChildrenCollectorFilter collector = new ChildrenCollectorFilter(namePattern, items, isCollectNodes(),
            isCollectProperties(), depth);
    collector.visit(node);
    ctx.put(this.destKey, items.iterator());

    return false;
}

From source file:org.apache.jackrabbit.standalone.cli.CommandHelper.java

/**
 * Sets the current <code>PrintWriter</code>.
 * @param ctx//w w  w. j av a2  s  .  c  o m
 *        the <code>Context</code>
 * @param out
 *        the <code>PrintWriter</code>
 */
public static void setOutput(Context ctx, PrintWriter out) {
    if (out == null) {
        ctx.remove(OUTPUT_KEY);
    } else {
        ctx.put(OUTPUT_KEY, out);
    }
}