Example usage for org.apache.commons.chain Catalog getCommand

List of usage examples for org.apache.commons.chain Catalog getCommand

Introduction

In this page you can find the example usage for org.apache.commons.chain Catalog getCommand.

Prototype

Command getCommand(String name);

Source Link

Document

Return the Command or Chain associated with the specified name, if any; otherwise, return null.

Usage

From source file:bridge.toolkit.Controller.java

/**
 * @param args//from www. j a  v  a 2s.c o  m
 */
public static void main(String[] args) {
    Controller loader = new Controller();
    Catalog sampleCatalog = loader.createCatalog();
    Command toolkit = sampleCatalog.getCommand("SCORM");
    Context ctx = new ContextBase();

    ctx.put(Keys.SCPM_FILE, args[0]);
    ctx.put(Keys.RESOURCE_PACKAGE, args[1]);
    try {

        if (args.length > 2) {
            if (args[2] != null && args[2].equalsIgnoreCase("-scormflash")) {
                toolkit = sampleCatalog.getCommand("SCORM");
                ctx.put(Keys.OUTPUT_TYPE, null);
            } else if (args[2] != null && args[2].equalsIgnoreCase("-scormhtml")) {
                toolkit = sampleCatalog.getCommand("SCORM");
                ctx.put(Keys.OUTPUT_TYPE, "SCORMHTML");
            } else if (args.length > 2 && args[2] != null && (args[2].equalsIgnoreCase("-mobileCourse"))) {
                toolkit = sampleCatalog.getCommand("Mobile");
                ctx.put(Keys.OUTPUT_TYPE, "mobileCourse");
            } else if (args.length > 2 && args[2] != null
                    && (args[2].equalsIgnoreCase("-mobilePerformanceSupport"))) {
                toolkit = sampleCatalog.getCommand("Mobile");
            } else if (args[2] != null && args[2].equalsIgnoreCase("-pdfinstructor")) {
                toolkit = sampleCatalog.getCommand("PDF");
                ctx.put(Keys.PDF_OUTPUT_OPTION, "-instructor");
            } else if (args[2] != null && args[2].equalsIgnoreCase("-pdfstudent")) {
                toolkit = sampleCatalog.getCommand("PDF");
                ctx.put(Keys.PDF_OUTPUT_OPTION, "-student");
            }

            if (args.length > 3 && args[3] != null) {
                ctx.put(Keys.OUTPUT_DIRECTORY, args[3]);
            }
        }

        toolkit.execute(ctx);
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(e.getCause().toString());
    }
}

From source file:net.jradius.handler.RunChainHandler.java

public boolean handle(JRadiusEvent event) throws Exception {
    Catalog catalog = getCatalog();
    if (catalog != null && chainName != null) {
        JRCommand c = (JRCommand) catalog.getCommand(chainName);
        if (c == null) {
            RadiusLog.error("There is no command '" + chainName + "' in catalog " + getCatalogName());
            return false;
        }/*from  w w w . j a v a 2 s  .com*/
        return execute(c, event);
    }
    return false;
}

From source file:com.netsteadfast.greenstep.base.chain.SimpleChain.java

public ChainResultObj getResultFromResource(String commandName, Context context) throws Exception {
    Catalog catalog = this.getCatalog(ChainConstants.CHAIN_RESOURCE_CONFIG, ChainConstants.CHAIN_CATALOG);
    this.addCommand(catalog.getCommand(commandName));
    this.execute(context);
    return this.getResult(context);
}

From source file:info.magnolia.commands.CommandsManager.java

/**
 * Get the command//from   w w  w.  ja  v a 2  s. c o m
 * @param catalogName the catalog containing the command
 * @param commandName the name of the command
 * @return the command to execute
 */
public Command getCommand(String catalogName, String commandName) {
    Catalog catalog = CatalogFactory.getInstance().getCatalog(catalogName);
    if (catalog != null) {
        return catalog.getCommand(commandName);
    } else {
        return null;
    }
}

From source file:net.jradius.handler.tlstunnel.AuthorizeHandler.java

public boolean handle(JRadiusRequest request) throws Exception {
    RadiusPacket req = request.getRequestPacket();
    AttributeList ci = request.getConfigItems();

    JRadiusSession session = request.getSession();

    String username = (String) req.getAttributeValue(Attr_UserName.TYPE);
    String realm = session.getRealm();

    Attr_EAPType eap = (Attr_EAPType) req.findAttribute(Attr_EAPType.TYPE);

    if (eap != null) {
        NamedValue eapv = (NamedValue) eap.getValue();
        String eapType = eapv.getValueString();

        if (session.isSecured()) {
            Catalog catalog = getCatalog();
            if (catalog != null && chainName != null) {
                JRCommand c = (JRCommand) catalog.getCommand(chainName);
                if (c == null) {
                    RadiusLog.error("There is no command '" + chainName + "' in catalog " + getCatalogName());
                    return false;
                }//w  w  w  .java  2s.  c  o  m
                return execute(c, request);
            }
        } else if ((Attr_EAPType.Identity.equals(eapType) || Attr_EAPType.NAK.equals(eapType)
                || Attr_EAPType.EAPTTLS.equals(eapType) || Attr_EAPType.PEAP.equals(eapType))
                && ((anonUserName != null && anonUserName.equals(username))
                        || terminatedRealms.containsKey(realm))) {
            // Here we are returning NOOP so that TTLS or PEAP tunnels
            // can terminate at this radius server and we can proxy the tunneled credentials.
            RadiusSessionKeyProvider skp = (RadiusSessionKeyProvider) JRadiusSessionManager
                    .getManager(request.getSender()).getSessionKeyProvider(request.getSender());

            // Rewrite the log type (not an authorization, but a tunnel
            // termination)
            session.getLogEntry(request).setType("tls-tunnel");

            // Force the local handling of the tunnel (do not proxy)
            ci.remove(Attr_ProxyToRealm.TYPE);

            // Record the session as a tls tunnel
            tlsTunnels.put(new Element(skp.getTunneledRequestKey(request), session.getSessionKey()));

            RadiusLog.info(
                    "EAP-TTLS Termination: username = " + username + ", session = " + session.getSessionKey());

            return true;
        }
    }

    return false;
}

From source file:com.liulangf.pattern.gof.behavioral.chain.jakarta.simple.ExampleServlet.java

/**
 * <p>Configure a {@link ServletWebContext} for the current request, and
 * pass it to the <code>execute()</code> method of the specified
 * {@link Command}, loaded from our configured {@link Catalog}.</p>
 *
 * @param request The request we are processing
 * @param response The response we are creating
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet exception occurs
 *//*from ww  w . j a  v  a 2 s.co m*/
public void service(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    CatalogFactory factory = CatalogFactory.getInstance();
    Catalog catalog = factory.getCatalog(servletName);
    if (catalog == null) {
        catalog = factory.getCatalog();
    }

    ServletWebContext context = new ServletWebContext(getServletContext(), request, response);
    Command command = catalog.getCommand("COMMAND_MAPPER");
    try {
        command.execute(context);
    } catch (Exception e) {
        throw new ServletException(e);
    }

}

From source file:net.jradius.server.config.Configuration.java

public static Command getCommand(String commandID) throws IllegalArgumentException {
    // XXX: This function taken from CVS version of CatalogFactory
    String DELIMITER = ":";
    String commandName = commandID;
    String catalogName = null;// www  .java2s  . c o  m
    Catalog catalog = null;

    if (commandID != null) {
        int splitPos = commandID.indexOf(DELIMITER);
        if (splitPos != -1) {
            catalogName = commandID.substring(0, splitPos);
            commandName = commandID.substring(splitPos + DELIMITER.length());
            if (commandName.indexOf(DELIMITER) != -1) {
                throw new IllegalArgumentException(
                        "commandID [" + commandID + "] has too many delimiters (reserved for future use)");
            }
        }
    }

    if (catalogName != null) {
        catalog = factory.getCatalog(catalogName);
        if (catalog == null) {
            RadiusLog.warn("No catalog found for name: " + catalogName + ".");
            return null;
        }
    } else {
        catalog = factory.getCatalog();
        if (catalog == null) {
            RadiusLog.warn("No default catalog found.");
            return null;
        }
    }

    return catalog.getCommand(commandName);
}

From source file:net.jradius.handler.PacketHandlerChain.java

public boolean handle(JRadiusRequest request) throws Exception {
    Catalog catalog = getCatalog();
    if (catalog != null) {
        JRCommand command;/*from  ww w.  ja v  a  2s  .c  o  m*/

        if (request.getType() == JRadiusServer.JRADIUS_accounting) {
            RadiusPacket req = request.getRequestPacket();
            Long i = (Long) req.getAttributeValue(AttributeDictionary.ACCT_STATUS_TYPE);
            if (i != null) {
                String com = "other_accounting";
                switch (i.intValue()) {
                case AccountingRequest.ACCT_STATUS_START:
                    com = "start_accounting";
                    break;
                case AccountingRequest.ACCT_STATUS_STOP:
                    com = "stop_accounting";
                    break;
                case AccountingRequest.ACCT_STATUS_INTERIM:
                    com = "interim_accounting";
                    break;
                case AccountingRequest.ACCT_STATUS_ACCOUNTING_ON:
                    com = "accounting_on";
                    break;
                case AccountingRequest.ACCT_STATUS_ACCOUNTING_OFF:
                    com = "accounting_off";
                    break;
                }
                command = (JRCommand) catalog.getCommand(com);
                if (command != null)
                    return execute(command, request);
            }
        }

        command = (JRCommand) catalog.getCommand(request.getTypeString());
        return execute(command, request);
    }
    return true;
}

From source file:org.apache.struts.chain.commands.ExceptionCatcher.java

/**
 * <p> Return the command to be executed if an exception occurs. </p>
 *
 * @return The command to be executed if an exception occurs
 * @throws IllegalArgumentException If catalog cannot be found
 * @throws IllegalStateException    If command property is not specified
 *///w w  w.ja v a  2  s.c o m
protected Command lookupExceptionCommand() {
    String catalogName = getCatalogName();
    Catalog catalog;

    if (catalogName == null) {
        catalog = CatalogFactory.getInstance().getCatalog();

        if (catalog == null) {
            LOG.error("Cannot find default catalog");
            throw new IllegalArgumentException("Cannot find default catalog");
        }
    } else {
        catalog = CatalogFactory.getInstance().getCatalog(catalogName);

        if (catalog == null) {
            LOG.error("Cannot find catalog '" + catalogName + "'");
            throw new IllegalArgumentException("Cannot find catalog '" + catalogName + "'");
        }
    }

    String exceptionCommand = getExceptionCommand();

    if (exceptionCommand == null) {
        LOG.error("No exceptionCommand property specified");
        throw new IllegalStateException("No exceptionCommand property specfied");
    }

    return catalog.getCommand(exceptionCommand);
}

From source file:org.apache.struts.chain.commands.ExecuteCommand.java

/**
 * <p> Retrieve the specified Command from the specified Catalog. </p>
 *
 * @param commandName The Command to retrieve.
 * @param catalogName The Catalog to search.
 * @return Instantiated Command, or null
 *///from   w  w  w.  j  av a 2  s  .  c  o  m
protected Command getCommand(String commandName, String catalogName) {
    if (commandName == null) {
        return null;
    }

    Catalog catalog;

    if (catalogName != null) {
        catalog = CatalogFactory.getInstance().getCatalog(catalogName);

        if (catalog == null) {
            LOG.warn("When looking up " + commandName + "," + " no catalog found under " + catalogName);

            return null;
        }
    } else {
        catalogName = "the default catalog";
        catalog = CatalogFactory.getInstance().getCatalog();

        if (catalog == null) {
            LOG.warn("When looking up " + commandName + "," + " no default catalog found.");

            return null;
        }
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("looking up command " + commandName + " in " + catalogName);
    }

    return catalog.getCommand(commandName);
}