List of usage examples for org.apache.commons.chain Context containsKey
boolean containsKey(Object key);
From source file:com.azaptree.services.command.impl.CommandContextValidatorSupport.java
protected void checkRequiredInputKeys(final Command command, final Context ctx) { final Optional<TypeReferenceKey<?>[]> keys = command.getInputKeys(); if (!keys.isPresent()) { return;//from w w w. ja v a 2s .com } for (final TypeReferenceKey<?> key : keys.get()) { if (key.isRequired()) { if (!ctx.containsKey(key)) { throw new ValidationException( String.format("%s : TypeReferenceKey is required: %s", command.getName(), key)); } } } }
From source file:com.azaptree.services.command.impl.CommandContextValidatorSupport.java
protected void checkRequiredOutputKeys(final Command command, final Context ctx) { final Optional<TypeReferenceKey<?>[]> keys = command.getOutputKeys(); if (!keys.isPresent()) { return;// w ww . j av a2 s . c o m } for (final TypeReferenceKey<?> key : keys.get()) { if (key.isRequired()) { if (!ctx.containsKey(key)) { throw new ValidationException( String.format("%s : TypeReferenceKey is required: %s", command.getName(), key)); } } } }
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) *//*ww w .j av a2s . com*/ 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:org.exoplatform.frameworks.jcr.command.core.AddNodeCommand.java
public boolean execute(Context context) throws Exception { Session session = ((JCRAppContext) context).getSession(); Node parentNode = (Node) session.getItem((String) context.get(currentNodeKey)); String relPath = (String) context.get(pathKey); if (context.containsKey(nodeTypeKey)) context.put(resultKey, parentNode.addNode(relPath, (String) context.get(nodeTypeKey))); else// w ww .ja v a 2 s . c o m context.put(resultKey, parentNode.addNode(relPath)); return true; }