Example usage for org.apache.commons.lang StringUtils endsWithIgnoreCase

List of usage examples for org.apache.commons.lang StringUtils endsWithIgnoreCase

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils endsWithIgnoreCase.

Prototype

public static boolean endsWithIgnoreCase(String str, String suffix) 

Source Link

Document

Case insensitive check if a String ends with a specified suffix.

Usage

From source file:nl.nn.adapterframework.webcontrol.pipes.TestPipeLine.java

private String doPost(IPipeLineSession session) throws PipeRunException {
    Object form_file = session.get("file");
    String form_message = null;/*  w  w  w.  jav a2 s .com*/
    form_message = (String) session.get("message");
    if (form_file == null && (StringUtils.isEmpty(form_message))) {
        throw new PipeRunException(this, getLogPrefix(session) + "Nothing to send or test");
    }

    String form_adapterName = (String) session.get("adapterName");
    if (StringUtils.isEmpty(form_adapterName)) {
        throw new PipeRunException(this, getLogPrefix(session) + "No adapter selected");
    }
    IAdapter adapter = RestListenerUtils.retrieveIbisManager(session).getRegisteredAdapter(form_adapterName);
    if (adapter == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "Adapter with specified name ["
                + form_adapterName + "] could not be retrieved");
    }

    boolean writeSecLogMessage = false;
    if (secLogEnabled && secLogMessage) {
        writeSecLogMessage = (Boolean) session.get("writeSecLogMessage");
    }

    if (form_file != null) {
        if (form_file instanceof InputStream) {
            InputStream inputStream = (InputStream) form_file;
            String form_fileName = (String) session.get("fileName");
            String form_fileEncoding = (String) session.get("fileEncoding");
            try {
                if (inputStream.available() > 0) {
                    String fileEncoding;
                    if (StringUtils.isNotEmpty(form_fileEncoding)) {
                        fileEncoding = form_fileEncoding;
                    } else {
                        fileEncoding = Misc.DEFAULT_INPUT_STREAM_ENCODING;
                    }
                    if (StringUtils.endsWithIgnoreCase(form_fileName, ".zip")) {
                        try {
                            form_message = processZipFile(session, inputStream, fileEncoding, adapter,
                                    writeSecLogMessage);
                        } catch (Exception e) {
                            throw new PipeRunException(this,
                                    getLogPrefix(session) + "exception on processing zip file", e);
                        }
                    } else {
                        form_message = Misc.streamToString(inputStream, "\n", fileEncoding, false);
                    }
                }
            } catch (IOException e) {
                throw new PipeRunException(this,
                        getLogPrefix(session) + "exception on converting stream to string", e);
            }
        } else {
            form_message = form_file.toString();
        }
        session.put("message", form_message);
    }
    if (StringUtils.isNotEmpty(form_message)) {
        try {
            PipeLineResult plr = processMessage(adapter, form_message, writeSecLogMessage);
            session.put("state", plr.getState());
            session.put("result", plr.getResult());
        } catch (Exception e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception on sending message", e);
        }
    }
    return "<dummy/>";
}

From source file:org.agnitas.cms.web.CMTemplateAction.java

public int readArchivedCMTemplate(CMTemplateForm aForm, InputStream stream, HttpServletRequest request) {
    ZipInputStream zipInputStream = new ZipInputStream(stream);
    ZipEntry entry;// w  w  w  .ja v a2  s  . c  o  m
    String templateBody = null;
    // binds image name in zip to image id in CCR (Central Content Repository)
    Map<String, Integer> imageBindMap = new HashMap<String, Integer>();
    int newTemplateId = createEmptyCMTemplate(request);
    if (newTemplateId == -1) {
        return -1;
    }
    try {
        while ((entry = zipInputStream.getNextEntry()) != null) {
            String entryName = entry.getName();
            // hack for ignoring MACOS archive system folders
            if (entryName.contains("__MACOSX")) {
                continue;
            }
            // skip if directory
            if (entryName.endsWith("/")) {
                continue;
            }
            // if file is in media-folder - store it in CCR
            if (entryName.startsWith(MEDIA_FOLDER)) {
                // thumbs.db is ignored by EMM
                if (!StringUtils.endsWithIgnoreCase(entryName, THUMBS_DB)) {
                    byte[] fileData = getEntryData(zipInputStream, entry);
                    int mediaFileId = storeMediaFile(fileData, entryName, newTemplateId, request);
                    if (mediaFileId != -1) {
                        imageBindMap.put(entryName, mediaFileId);
                    }
                }
            } else if (entryName.endsWith(".html") && templateBody == null) {
                // first html file that was found in root folder of
                // zip-archive is considered to be a template-file
                byte[] templateData = getEntryData(zipInputStream, entry);
                templateBody = new String(templateData, Charset.forName(aForm.getCharset()).name());
            }
        }
        zipInputStream.close();
    } catch (IOException e) {
        AgnUtils.logger().error("Error occured reading CM template from zip: ", e);
    }
    if (templateBody == null) {
        getTemplateManager().deleteCMTemplate(newTemplateId);
        getMediaManager().removeMediaFilesForCMTemplateId(newTemplateId);
        return -1;
    } else {
        templateBody = replacePictureLinks(templateBody, imageBindMap);
        try {
            getTemplateManager().updateContent(newTemplateId,
                    templateBody.getBytes(Charset.forName("UTF-8").name()));
        } catch (UnsupportedEncodingException e) {
            AgnUtils.logger().warn("Wrong charset name", e);
        }
        return newTemplateId;
    }
}

From source file:org.apache.geode.management.internal.cli.GfshParser.java

/**
 *
 *///from ww  w . ja va 2  s .c  o m
public ParseResult parse(String userInput) {
    GfshParseResult parseResult = null;
    // First remove the trailing white spaces
    userInput = StringUtils.stripEnd(userInput, null);
    if ((ParserUtils.contains(userInput, SyntaxConstants.COMMAND_DELIMITER)
            && StringUtils.endsWithIgnoreCase(userInput, SyntaxConstants.COMMAND_DELIMITER))) {
        userInput = StringUtils.removeEnd(userInput, SyntaxConstants.COMMAND_DELIMITER);
    }

    try {
        boolean error = false;
        CliCommandOptionException coe = null;
        List<CommandTarget> targets = locateTargets(ParserUtils.trimBeginning(userInput), false);
        if (targets.size() > 1) {
            if (userInput.length() > 0) {
                handleCondition(CliStrings.format(
                        CliStrings.GFSHPARSER__MSG__AMBIGIOUS_COMMAND_0_FOR_ASSISTANCE_USE_1_OR_HINT_HELP,
                        new Object[] { userInput, AbstractShell.completionKeys }),
                        CommandProcessingException.COMMAND_NAME_AMBIGUOUS, userInput);
            }
        } else {
            if (targets.size() == 1) {
                OptionSet parse = null;
                List<MethodParameter> parameters = new ArrayList<MethodParameter>();
                Map<String, String> paramValMap = new HashMap<String, String>();
                CommandTarget commandTarget = targets.get(0);
                GfshMethodTarget gfshMethodTarget = commandTarget.getGfshMethodTarget();
                preConfigureConverters(commandTarget);

                try {
                    parse = commandTarget.getOptionParser().parse(gfshMethodTarget.getRemainingBuffer());
                } catch (CliException ce) {
                    if (ce instanceof CliCommandOptionException) {
                        coe = (CliCommandOptionException) ce;
                        coe.setCommandTarget(commandTarget);
                        parse = coe.getOptionSet();
                        error = true;
                    }
                }

                try {
                    checkOptionSetForValidCommandModes(parse, commandTarget);
                } catch (CliCommandMultiModeOptionException ce) {
                    error = true;
                    coe = ce;
                }

                error = processArguments(parse, commandTarget, paramValMap, parameters, error);
                // TODO: next call throws when space before closing "
                error = processOptions(parse, commandTarget, paramValMap, parameters, error);

                if (!error) {
                    Object[] methodParameters = new Object[parameters.size()];
                    for (MethodParameter parameter : parameters) {
                        methodParameters[parameter.getParameterNo()] = parameter.getParameter();
                    }
                    parseResult = new GfshParseResult(gfshMethodTarget.getMethod(),
                            gfshMethodTarget.getTarget(), methodParameters, userInput,
                            commandTarget.getCommandName(), paramValMap);
                } else {
                    if (coe != null) {
                        logWrapper.fine("Handling exception: " + coe.getMessage());
                        ExceptionHandler.handleException(coe); // TODO: this eats exception that would make it
                                                               // easier to debug GemfireDataCommandsDUnitTest
                                                               // ExceptionHandler.handleException() only logs it on console.
                                                               // When on member, we need to handle this.
                        if (!CliUtil.isGfshVM()) {
                            handleCondition(
                                    CliStrings.format(CliStrings.GFSHPARSER__MSG__INVALID_COMMAND_STRING_0,
                                            userInput),
                                    coe, CommandProcessingException.COMMAND_INVALID, userInput);
                        }
                    }
                }

            } else {
                String message = CliStrings.format(CliStrings.GFSHPARSER__MSG__COMMAND_0_IS_NOT_VALID,
                        userInput);
                CommandTarget commandTarget = locateExactMatchingTarget(userInput);
                if (commandTarget != null) {
                    String commandName = commandTarget.getCommandName();
                    AvailabilityTarget availabilityIndicator = commandTarget.getAvailabilityIndicator();
                    message = CliStrings.format(CliStrings.GFSHPARSER__MSG__0_IS_NOT_AVAILABLE_REASON_1,
                            new Object[] { commandName, availabilityIndicator.getAvailabilityDescription() });
                }
                handleCondition(message, CommandProcessingException.COMMAND_INVALID_OR_UNAVAILABLE, userInput);
            }
        }
    } catch (IllegalArgumentException e1) {
        logWrapper.warning(CliUtil.stackTraceAsString(e1));
    } catch (IllegalAccessException e1) {
        logWrapper.warning(CliUtil.stackTraceAsString(e1));
    } catch (InvocationTargetException e1) {
        logWrapper.warning(CliUtil.stackTraceAsString(e1));
    }
    return parseResult;
}

From source file:org.apache.openjpa.persistence.XMLPersistenceMetaDataParser.java

private void parseTypeAttr(FieldMetaData fmd, Attributes attrs) throws SAXException {

    String typeStr = attrs.getValue("type");
    if (!StringUtils.isEmpty(typeStr)) {
        if (StringUtils.endsWithIgnoreCase(typeStr, ".class")) {
            typeStr = typeStr.substring(0, StringUtils.lastIndexOf(typeStr, '.'));
        }//from www .jav a  2 s  . com
        Class<?> typeCls = parseTypeStr(typeStr);

        fmd.setTypeOverride(typeCls);
    }
}

From source file:org.apache.openjpa.persistence.XMLPersistenceMetaDataParser.java

private void parseElementTypeAttr(FieldMetaData fmd, Attributes attrs) throws SAXException {

    String typeStr = attrs.getValue("element-type");
    if (!StringUtils.isEmpty(typeStr)) {
        if (StringUtils.endsWithIgnoreCase(typeStr, ".class")) {
            typeStr = typeStr.substring(0, StringUtils.lastIndexOf(typeStr, '.'));
        }//w  w w.j a  v a 2 s  .c  o m
        Class<?> typeCls = parseTypeStr(typeStr);

        fmd.setTypeOverride(typeCls);
    }
}

From source file:org.apache.openjpa.persistence.XMLPersistenceMetaDataParser.java

private void parseKeyTypeAttr(FieldMetaData fmd, Attributes attrs) throws SAXException {

    String typeStr = attrs.getValue("key-type");
    if (!StringUtils.isEmpty(typeStr)) {
        if (StringUtils.endsWithIgnoreCase(typeStr, ".class")) {
            typeStr = typeStr.substring(0, StringUtils.lastIndexOf(typeStr, '.'));
        }//www  . ja v  a2  s  . c  o m
        Class<?> typeCls = parseTypeStr(typeStr);

        fmd.setTypeOverride(typeCls);
    }
}

From source file:org.apache.ranger.plugin.resourcematcher.RangerAbstractResourceMatcher.java

@Override
boolean isMatch(String resourceValue, Map<String, Object> evalContext) {
    return StringUtils.endsWithIgnoreCase(resourceValue, getExpandedValue(evalContext));
}

From source file:org.apache.sling.jcr.contentloader.ContentTypeUtil.java

public static String detectContentType(final String filename) {
    if (StringUtils.isNotBlank(filename)) {
        if (StringUtils.endsWithIgnoreCase(filename, EXT_JSON)) {
            return TYPE_JSON;
        }//from   w  w  w .j  ava2  s.c o  m
        if (StringUtils.endsWithIgnoreCase(filename, EXT_JCR_XML)) {
            return TYPE_JCR_XML;
        }
        if (StringUtils.endsWithIgnoreCase(filename, EXT_XML)) {
            return TYPE_XML;
        }
        if (StringUtils.endsWithIgnoreCase(filename, EXT_ZIP)) {
            return TYPE_ZIP;
        }
        if (StringUtils.endsWithIgnoreCase(filename, EXT_JAR)) {
            return TYPE_JAR;
        }
    }
    return null;
}

From source file:org.apache.sysml.api.DMLScript.java

/**
 * Single entry point for all public invocation alternatives (e.g.,
 * main, executeScript, JaqlUdf etc)//from   ww w. java2  s.c o m
 * 
 * @param conf Hadoop configuration
 * @param args arguments
 * @return true if success, false otherwise
 * @throws DMLException if DMLException occurs
 * @throws ParseException if ParseException occurs
 */
public static boolean executeScript(Configuration conf, String[] args) throws DMLException {
    //Step 1: parse arguments 
    //check for help 
    if (args.length == 0
            || (args.length == 1 && (args[0].equalsIgnoreCase("-help") || args[0].equalsIgnoreCase("-?")))) {
        System.err.println(USAGE);
        return true;
    }

    //check for clean
    else if (args.length == 1 && args[0].equalsIgnoreCase("-clean")) {
        cleanSystemMLWorkspace();
        return true;
    }

    //check number of args - print usage if incorrect
    if (args.length < 2) {
        System.err.println("ERROR: Unrecognized invocation arguments.");
        System.err.println(USAGE);
        return false;
    }

    //check script arg - print usage if incorrect
    if (!(args[0].equals("-f") || args[0].equals("-s"))) {
        System.err.println("ERROR: First argument must be either -f or -s");
        System.err.println(USAGE);
        return false;
    }

    //parse arguments and set execution properties
    RUNTIME_PLATFORM oldrtplatform = rtplatform; //keep old rtplatform
    ExplainType oldexplain = EXPLAIN; //keep old explain

    // Reset global flags to avoid errors in test suite
    ENABLE_DEBUG_MODE = false;

    boolean parsePyDML = false;
    try {
        String fnameOptConfig = null; //optional config filename
        String[] scriptArgs = null; //optional script arguments
        boolean namedScriptArgs = false;

        for (int i = 2; i < args.length; i++) {
            if (args[i].equalsIgnoreCase("-explain")) {
                EXPLAIN = ExplainType.RUNTIME;
                if (args.length > (i + 1) && !args[i + 1].startsWith("-"))
                    EXPLAIN = Explain.parseExplainType(args[++i]);
            } else if (args[i].equalsIgnoreCase("-stats")) {
                STATISTICS = true;
                if (args.length > (i + 1) && !args[i + 1].startsWith("-"))
                    STATISTICS_COUNT = Integer.parseInt(args[++i]);
            } else if (args[i].equalsIgnoreCase("-exec")) {
                rtplatform = parseRuntimePlatform(args[++i]);
                if (rtplatform == null)
                    return false;
            } else if (args[i].startsWith("-config=")) // legacy
                fnameOptConfig = args[i].substring(8).replaceAll("\"", "");
            else if (args[i].equalsIgnoreCase("-config"))
                fnameOptConfig = args[++i];
            else if (args[i].equalsIgnoreCase("-debug")) {
                ENABLE_DEBUG_MODE = true;
            } else if (args[i].equalsIgnoreCase("-gpu")) {
                USE_ACCELERATOR = true;
                if (args.length > (i + 1) && !args[i + 1].startsWith("-")) {
                    String flag = args[++i];
                    if (flag.startsWith("force=")) {
                        String[] flagOptions = flag.split("=");
                        if (flagOptions.length == 2)
                            FORCE_ACCELERATOR = Boolean.parseBoolean(flagOptions[1]);
                        else
                            throw new DMLRuntimeException("Unsupported \"force\" option for -gpu:" + flag);
                    } else {
                        throw new DMLRuntimeException("Unsupported flag for -gpu:" + flag);
                    }
                }
                GPUContext.createGPUContext(); // Set GPU memory budget
            } else if (args[i].equalsIgnoreCase("-python")) {
                parsePyDML = true;
            } else if (args[i].startsWith("-args") || args[i].startsWith("-nvargs")) {
                namedScriptArgs = args[i].startsWith("-nvargs");
                i++;
                scriptArgs = new String[args.length - i];
                System.arraycopy(args, i, scriptArgs, 0, scriptArgs.length);
                break;
            } else {
                System.err.println("ERROR: Unknown argument: " + args[i]);
                return false;
            }
        }

        //set log level
        if (!ENABLE_DEBUG_MODE)
            setLoggingProperties(conf);

        //Step 2: prepare script invocation
        if (StringUtils.endsWithIgnoreCase(args[1], ".pydml")) {
            parsePyDML = true;
        }
        String dmlScriptStr = readDMLScript(args[0], args[1]);
        Map<String, String> argVals = createArgumentsMap(namedScriptArgs, scriptArgs);

        DML_FILE_PATH_ANTLR_PARSER = args[1];

        //Step 3: invoke dml script
        printInvocationInfo(args[1], fnameOptConfig, argVals);
        if (ENABLE_DEBUG_MODE) {
            // inner try loop is just to isolate the debug exception, which will allow to manage the bugs from debugger v/s runtime
            launchDebugger(dmlScriptStr, fnameOptConfig, argVals, parsePyDML);
        } else {
            execute(dmlScriptStr, fnameOptConfig, argVals, args, parsePyDML);
        }

    } catch (ParseException pe) {
        throw pe;
    } catch (DMLScriptException e) {
        //rethrow DMLScriptException to propagate stop call
        throw e;
    } catch (Exception ex) {
        LOG.error("Failed to execute DML script.", ex);
        throw new DMLException(ex);
    } finally {
        //reset runtime platform and visualize flag
        rtplatform = oldrtplatform;
        EXPLAIN = oldexplain;
    }

    return true;
}

From source file:org.apache.usergrid.query.validator.QueryValidatorRunner.java

public synchronized void setup() throws InitializationError {
    if (initialize)
        return;//from  ww  w  .ja va  2 s . c  om

    try {
        logger.info("Loading initialize...");
        Thread.sleep(20 * 1000);
    } catch (InterruptedException e) {
    }

    validator = CassandraRunner.getBean(QueryValidator.class);
    properties = CassandraRunner.getBean("properties", Properties.class);

    if (validator == null || properties == null) {
        throw new InitializationError("Application context not loaded.");
    }

    String enableString = (String) properties.get("usergrid.query.validator.api.enablelocal");
    enableLocalServer = StringUtils.endsWithIgnoreCase("true", enableString);
    if (enableLocalServer) {
        startStandaloneServer();
        try {
            logger.info("Loading standalone server...");
            Thread.sleep(20 * 1000);
        } catch (InterruptedException e) {
        }
    }
    initialize = true;

    String endpoint = (String) properties.get("usergrid.query.validator.api.endpoint");
    String organization = (String) properties.get("usergrid.query.validator.api.organization");
    String app = (String) properties.get("usergrid.query.validator.api.app");
    String email = (String) properties.get("usergrid.query.validator.api.authorize.email");
    String password = (String) properties.get("usergrid.query.validator.api.authorize.password");

    String collection = "user";
    List<Entity> entities = loadEntities(collection);
    QueryValidationConfiguration configuration = new QueryValidationConfiguration();
    configuration.setEndpointUri(endpoint);
    configuration.setOrg(organization);
    configuration.setEmail(email);
    configuration.setPassword(password);
    configuration.setApp(app);
    configuration.setCollection(collection);
    configuration.setEntities(entities);
    validator.setConfiguration(configuration);
    validator.setup();

}