List of usage examples for org.apache.commons.lang StringUtils removeEndIgnoreCase
public static String removeEndIgnoreCase(String str, String remove)
Case insensitive removal of a substring if it is at the end of a source string, otherwise returns the source string.
From source file:com.haulmont.cuba.core.sys.dbupdate.DbUpdaterEngine.java
protected boolean executeGroovyScript(ScriptResource file) { try {/*from w ww.j a va2 s.c o m*/ ClassLoader classLoader = getClass().getClassLoader(); CompilerConfiguration cc = new CompilerConfiguration(); cc.setRecompileGroovySource(true); Binding bind = new Binding(); bind.setProperty("ds", getDataSource()); bind.setProperty("log", LoggerFactory.getLogger(String.format("%s$%s", DbUpdaterEngine.class.getName(), StringUtils.removeEndIgnoreCase(file.getName(), ".groovy")))); if (!StringUtils.endsWithIgnoreCase(file.getName(), "." + UPGRADE_GROOVY_EXTENSION)) { bind.setProperty("postUpdate", new PostUpdateScripts() { @Override public void add(Closure closure) { super.add(closure); log.warn("Added post update action will be ignored"); } }); } GroovyShell shell = new GroovyShell(classLoader, bind, cc); //noinspection UnnecessaryLocalVariable Script script = shell.parse(file.getContent()); script.run(); } catch (Exception e) { throw new RuntimeException(ERROR + "Error executing Groovy script " + file.name + "\n" + e.getMessage(), e); } return true; }
From source file:com.intuit.tank.tools.debugger.ActionProducer.java
/** * /* w w w. j a va 2s . com*/ * @return */ public Action getSelectTankAction() { Action ret = actionMap.get(ACTION_SELECT_TANK); if (ret == null) { ret = new AbstractAction(ACTION_SELECT_TANK) { private static final long serialVersionUID = 1L; final JComboBox cb = getComboBox(); @Override public void actionPerformed(ActionEvent event) { try { int selected = JOptionPane.showConfirmDialog(debuggerFrame, cb, "Enter the base URL to Tank:", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (selected == JOptionPane.OK_OPTION) { String url = (String) cb.getSelectedItem(); if (url != null) { int startInd = url.indexOf('('); int endInd = url.indexOf(')'); if (startInd != -1 && endInd != -1) { url = url.substring(startInd + 1, endInd); } url = StringUtils.removeEndIgnoreCase(url, "/"); if (!url.startsWith("http")) { url = "http://" + url; } try { new ScriptServiceClient(url).ping(); setServiceUrl(url); } catch (Exception e) { showError("Cannot connect to Tank at the url " + url + ". \nExample: http://tank.mysite.com/"); } } } } catch (HeadlessException e) { showError("Error opening file: " + e); } } }; ret.putValue(Action.SHORT_DESCRIPTION, "Enter a Tank URL."); actionMap.put(ACTION_SELECT_TANK, ret); } return ret; }
From source file:adalid.commons.velocity.Writer.java
private void writePlatform(WriterContext basicWriterContext, File platformPropertiesFile) { logger.info("propertiesFile=" + platformPropertiesFile.getPath()); try {/*from w ww. j a va 2 s .c om*/ VelocityContext platformContext = basicWriterContext.getVelocityContextClone(); String platform = StringUtils.removeEndIgnoreCase(platformPropertiesFile.getName(), PROPERTIES_SUFFIX); platformContext.put(VC_PLATFORM, platform); TLB.setProgrammers(basicWriterContext.programmers); TLB.setWrapperClasses(basicWriterContext.wrapperClasses); putProperties(platformContext, platformPropertiesFile); Properties properties = mergeProperties(platformContext, platformPropertiesFile); putStrings(platformContext, properties); ExtendedProperties mergeExtendedProperties = mergeExtendedProperties(platformContext, platformPropertiesFile); createDirectories(mergeExtendedProperties); deletePreviouslyGeneratedFiles(mergeExtendedProperties); WriterContext platformWriterContext = newWriterContext(platformContext); File platformsFolder = platformPropertiesFile.getParentFile(); ExtendedProperties platformExtendedProperties = PropertiesHandler .getExtendedProperties(platformPropertiesFile); String[] pathnames = platformExtendedProperties.getStringArray(FILE_RESOURCE_LOADER_PATH); String[] pathfilters = platformExtendedProperties.getStringArray(FILE_RESOURCE_LOADER_PATH_FILTER); Map<String, File> folders = new LinkedHashMap<>(); if (pathnames == null || pathnames.length == 0) { } else { for (File folder : bootstrappingPlatformsFolders) { folders.putAll(FilUtils.directoriesMap(folder, pathnames, folder)); } } if (pathfilters != null && pathfilters.length > 0) { String[] keyArray = folders.keySet().toArray(new String[folders.keySet().size()]); String slashedFilter, slashedPath; for (String pathfilter : pathfilters) { slashedFilter = pathfilter.replace(FILE_SEPARATOR, SLASH); for (String key : keyArray) { slashedPath = key.replace(FILE_SEPARATOR, SLASH) + SLASH; if (StringUtils.containsIgnoreCase(slashedPath, slashedFilter)) { folders.remove(key); logger.debug(pathfilter + " excludes " + key); } } } } File[] templateFiles; Properties templateProperties; String disabled; String disabledMissing; String pattern; String template; String message; String platformsFolderPath = platformsFolder.getPath(); // + FILE_SEPARATOR; for (File folder : folders.values()) { log(_detailLevel, "write", "path=" + StringUtils.removeStart(folder.getPath(), platformsFolderPath)); templateFiles = folder.listFiles(propertiesFileFilter); Arrays.sort(templateFiles); for (File templatePropertiesFile : templateFiles) { if (reject(templatePropertiesFile, pathfilters)) { continue; } templateProperties = PropertiesHandler.loadProperties(templatePropertiesFile); disabled = templateProperties.getProperty(TP_DISABLED, Boolean.FALSE.toString()); disabledMissing = templateProperties.getProperty(TP_DISABLED_MISSING); templates++; if (BitUtils.valueOf(disabled)) { disabledTemplates++; template = StringUtils.removeEndIgnoreCase(templatePropertiesFile.getName(), PROPERTIES_SUFFIX); pattern = "template \"{0}\" ignored, check property \"{1}\" at file \"{2}\""; message = MessageFormat.format(pattern, template, TP_DISABLED, templatePropertiesFile); log(_alertLevel, message); warnings++; } else if (missing(disabledMissing)) { disabledTemplates++; template = StringUtils.removeEndIgnoreCase(templatePropertiesFile.getName(), PROPERTIES_SUFFIX); pattern = "template \"{0}\" ignored because {3} is missing, check property \"{1}\" at file \"{2}\""; message = MessageFormat.format(pattern, template, TP_DISABLED_MISSING, templatePropertiesFile, disabledMissing); log(_alertLevel, message); warnings++; } else { writeTemplate(platformWriterContext, templatePropertiesFile); } } } platforms++; } catch (Throwable throwable) { error(throwable); } printSummary(); }
From source file:edu.monash.merc.system.parser.nextprot.NXHandler.java
private void findPeAnTiAnnURL(String xdatabase, String xcategory, String xaccession, String xrefUrl) { if (StringUtils.isNotBlank(xdatabase) && StringUtils.isNotBlank(xcategory) && StringUtils.isNotBlank(xaccession)) { if (StringUtils.equalsIgnoreCase(xdatabase, NXFields.XREF_DB_HPA) && StringUtils.equalsIgnoreCase(xcategory, NXFields.XREF_CA_ANTIBODY_DATABASES)) { //using the ENSG accession as perfer hyperlink if (StringUtils.startsWithIgnoreCase(xaccession, NXConts.XREF_AC_PREFIX_ENSG)) { if (StringUtils.isNotBlank(xrefUrl)) { peAntiURL = StringUtils.removeEndIgnoreCase(xrefUrl, NXFields.XREF_AC_ENSG_URL_END_PART); }//from w w w . j a va 2 s. c o m } //if no hyperlink for ensg then we have to use others if (StringUtils.startsWithIgnoreCase(xrefAccession, NXFields.XREF_AC_PREFIX_HPA) || StringUtils.startsWithIgnoreCase(xrefAccession, NXFields.XREF_AC_PREFIX_CAB)) { if (StringUtils.isBlank(peAntiURL)) { peAntiURL = xrefUrl; } } } } }
From source file:adalid.commons.velocity.Writer.java
private boolean accept(File templatePropertiesFile, String[] pathfilters) { if (templatePropertiesFile == null) { return false; }/*from ww w . j a v a2 s . c o m*/ if (pathfilters == null || pathfilters.length == 0) { return true; } String name = StringUtils.removeEndIgnoreCase(templatePropertiesFile.getName(), PROPERTIES_SUFFIX); String lowerName = name.toLowerCase(); String fileFilter; String anything = ".*"; String delimiters = "[\\W]"; String word = "[\\w\\-]*"; for (String pathfilter : pathfilters) { fileFilter = pathfilter.replace(FILE_SEPARATOR, SLASH); fileFilter = fileFilter.toLowerCase(); fileFilter = StringUtils.removeStart(fileFilter, SLASH); fileFilter = StringUtils.removeEnd(fileFilter, SLASH); if (fileFilter.isEmpty()) { continue; } if (fileFilter.matches(word)) { if (lowerName .matches(CARET + anything + delimiters + fileFilter + delimiters + anything + DOLLAR)) { logger.debug("filter " + ASTERISK + pathfilter + ASTERISK + " excludes " + name); return false; } if (lowerName.matches(CARET + fileFilter + delimiters + anything)) { logger.debug("filter " + pathfilter + ASTERISK + " excludes " + name); return false; } if (lowerName.matches(anything + delimiters + fileFilter + DOLLAR)) { logger.debug("filter " + ASTERISK + pathfilter + " excludes " + name); return false; } if (lowerName.matches(CARET + fileFilter + DOLLAR)) { logger.debug("filter " + pathfilter + " excludes " + name); return false; } } } return true; }
From source file:adalid.util.meta.sql.MetaPlatformSql.java
/** * Adds .string, .class, .instance, .programmer and .wrapper properties to the velocity context * *//* w ww .j a v a 2 s. co m*/ @SuppressWarnings("unchecked") // unchecked cast private void putProperties(VelocityContext context, File propertiesFile) { String hint = HINT + "check property \"{0}\" at file \"{1}\""; String pattern1 = "failed to load {2}" + hint; String pattern2 = "failed to initialise {2}" + hint; String pattern3 = "{2} does not implement {3}" + hint; String pattern4 = "{2} is not a valid wrapper for {3}" + hint; String string1; String string2; String message; String argument; Object object2; Class<?> clazz1; Class<?> clazz2; Class<? extends Wrapper> wrapperClass; Class<? extends Wrappable> wrappableClass; Class<?> parameterType; String velocityKey; Properties properties = PropertiesHandler.loadProperties(propertiesFile); Set<String> stringPropertyNames = properties.stringPropertyNames(); for (String name : stringPropertyNames) { checkPropertyName(name, propertiesFile); if (StringUtils.endsWithIgnoreCase(name, DOT_STRING)) { string1 = StringUtils.removeEndIgnoreCase(name, DOT_STRING); string2 = StringUtils.trimToEmpty(properties.getProperty(name)); velocityKey = StrUtils.getCamelCase(string1, true); context.put(velocityKey, string2); } else if (StringUtils.endsWithIgnoreCase(name, DOT_CLASS)) { string1 = StringUtils.removeEndIgnoreCase(name, DOT_CLASS); string2 = StringUtils.trimToEmpty(properties.getProperty(name)); message = MessageFormat.format(pattern1, name, propertiesFile, string2); object2 = getClassForName(string2, message); if (object2 != null) { velocityKey = StrUtils.getCamelCase(string1, true); context.put(velocityKey, object2); continue; } throw new RuntimeException(message, new IllegalArgumentException(string2)); } } }
From source file:edu.monash.merc.system.parser.nextprot.NxXMLParser.java
@SuppressWarnings("unchecked") private NXPeMsAntiEntryBean parseNXPeMSAntiAnn(Element protein) { NXPeMsAntiEntryBean peMsAntiEntryBean = new NXPeMsAntiEntryBean(); List<PEEvidenceBean> peMsEvidenceBeans = new ArrayList<PEEvidenceBean>(); Element xrefsEle = protein.getChild(ELE_XREFS); if (xrefsEle != null) { //PE MS ANTI ANN url String peMsAntiURL = null; //PE MS ANTI int peMsAntiCounter = 0; List<Element> xrefElements = xrefsEle.getChildren(ELE_XREF); for (Element xrefEle : xrefElements) { //create a pe ms evidence object PEEvidenceBean peMsAnnEvidenceBean = new PEEvidenceBean(); String xrefDatabase = null; String xrefCategory = null; String xrefAccession = null; String xrefId = null; String xrefUrl = null; //database Attribute xrefDbAtt = xrefEle.getAttribute(ATTR_XREF_DATABASE); if (xrefDbAtt != null) { xrefDatabase = xrefDbAtt.getValue(); }/*www . ja v a 2 s . c o m*/ //category Attribute xrefCategAtt = xrefEle.getAttribute(ATTR_XREF_CATEGORY); if (xrefCategAtt != null) { xrefCategory = xrefCategAtt.getValue(); } //accession Attribute xrefAccessionAtt = xrefEle.getAttribute(ATTR_XREF_ACCESSION); if (xrefAccessionAtt != null) { xrefAccession = xrefAccessionAtt.getValue(); } //id Attribute xrefIdAtt = xrefEle.getAttribute(ATTR_XREF_ID); if (xrefIdAtt != null) { xrefId = xrefIdAtt.getValue(); } //url Element xrefUrlEle = xrefEle.getChild(ELE_XREF_URL); if (xrefEle != null) { xrefUrl = xrefUrlEle.getTextNormalize(); } if (StringUtils.isNotBlank(xrefDatabase) && (StringUtils.isNotBlank(xrefCategory))) { //if category = Proteomic database and database = PRIDE if (StringUtils.equalsIgnoreCase(xrefDatabase, NXConts.XREF_DB_PRIDE) && StringUtils.equalsIgnoreCase(xrefCategory, NXConts.XREF_CA_PROTEOMIC_DATABASES)) { //set the color red peMsAnnEvidenceBean.setColorLevel(ColorType.RED.color()); //set the link value if (StringUtils.isNotBlank(xrefAccession)) { peMsAnnEvidenceBean.setHyperlink(xrefUrl); } //added the evidence String evidence = null; evidence = xrefDatabase; if (StringUtils.isNotBlank(xrefAccession)) { evidence += " - " + xrefAccession; } if (StringUtils.isNotBlank(evidence)) { peMsAnnEvidenceBean.setEvidenceValue(evidence); } //create a TPBDataTypeBean TPBDataTypeBean tpbDataTypeBean = new TPBDataTypeBean(); //set the data type tpbDataTypeBean.setDataType(DataType.PE_MS_ANN.type()); //set the traffic lights level to 3 tpbDataTypeBean.setLevel(TLLevel.TL3.level()); peMsAnnEvidenceBean.setTpbDataTypeBean(tpbDataTypeBean); //add the PE MS Annotation for PRIDE peMsEvidenceBeans.add(peMsAnnEvidenceBean); } //if category = Proteomic database and database = PeptideAtlas if (StringUtils.equalsIgnoreCase(xrefDatabase, NXConts.XREF_DB_PEPTIDE_ATLAS) && StringUtils.equalsIgnoreCase(xrefCategory, NXConts.XREF_CA_PROTEOMIC_DATABASES)) { //set the color yellow peMsAnnEvidenceBean.setColorLevel(ColorType.YELLOW.color()); if (StringUtils.isNotBlank(xrefAccession)) { peMsAnnEvidenceBean.setHyperlink(xrefUrl); } //added the evidence String evidence = null; evidence = xrefDatabase; if (StringUtils.isNotBlank(xrefAccession)) { evidence += " - " + xrefAccession; } if (StringUtils.isNotBlank(evidence)) { peMsAnnEvidenceBean.setEvidenceValue(evidence); } //create a TPBDataTypeBean TPBDataTypeBean tpbDataTypeBean = new TPBDataTypeBean(); //set the data type tpbDataTypeBean.setDataType(DataType.PE_MS_ANN.type()); //set the traffic lights level to 3 tpbDataTypeBean.setLevel(TLLevel.TL3.level()); peMsAnnEvidenceBean.setTpbDataTypeBean(tpbDataTypeBean); //add pe ms annotation for PeptideAtlas peMsEvidenceBeans.add(peMsAnnEvidenceBean); } } //find the PE ANTI ANN if (StringUtils.isNotBlank(xrefDatabase) && StringUtils.isNotBlank(xrefCategory) && StringUtils.isNotBlank(xrefAccession)) { if (StringUtils.equalsIgnoreCase(xrefDatabase, NXConts.XREF_DB_HPA) && StringUtils.equalsIgnoreCase(xrefCategory, NXConts.XREF_CA_ANTIBODY_DATABASES)) { // System.out.println("===================> PE ANTI Ann: Accession: " + xrefAccession); if (StringUtils.startsWithIgnoreCase(xrefAccession, NXConts.XREF_AC_PREFIX_ENSG)) { if (StringUtils.isNotBlank(xrefUrl)) { peMsAntiURL = StringUtils.removeEndIgnoreCase(xrefUrl, NXConts.XREF_AC_ENSG_URL_END_PART); // System.out.println("================== URL: " + peMsAntiURL); } } if (StringUtils.startsWithIgnoreCase(xrefAccession, NXConts.XREF_AC_PREFIX_HPA) || StringUtils.startsWithIgnoreCase(xrefAccession, NXConts.XREF_AC_PREFIX_CAB)) { if (StringUtils.isBlank(peMsAntiURL)) { peMsAntiURL = xrefUrl; } peMsAntiCounter++; } } } } //add the PE MS Ann Evidences if Any peMsAntiEntryBean.setPeMsAnnEvidenceBeans(peMsEvidenceBeans); //PE ANTI ANN if (peMsAntiCounter > 0) { //create a pe anti evidence object PEEvidenceBean peAntiAnnEvidenceBean = new PEEvidenceBean(); if (peMsAntiCounter == 1) { peAntiAnnEvidenceBean.setColorLevel(ColorType.RED.color()); } if (peMsAntiCounter > 1) { peAntiAnnEvidenceBean.setColorLevel(ColorType.YELLOW.color()); } peAntiAnnEvidenceBean.setEvidenceValue(peMsAntiCounter + " " + NXConts.XREF_HPA_ANTIBODY_DESC); if (StringUtils.isNotBlank(peMsAntiURL)) { peAntiAnnEvidenceBean.setHyperlink(peMsAntiURL); } //create a TPBDataTypeBean TPBDataTypeBean tpbDataTypeBean = new TPBDataTypeBean(); //set the data type tpbDataTypeBean.setDataType(DataType.PE_ANTI_ANN.type()); //set the traffic lights level to 3 tpbDataTypeBean.setLevel(TLLevel.TL3.level()); peAntiAnnEvidenceBean.setTpbDataTypeBean(tpbDataTypeBean); //set the pe anti ann object peMsAntiEntryBean.setPeAntiAnnEvidenceBean(peAntiAnnEvidenceBean); } } return peMsAntiEntryBean; }
From source file:adalid.commons.velocity.Writer.java
/** * Adds .string, .class, .instance, .programmer and .wrapper properties to the velocity context * *//*from www .j a v a 2 s. c o m*/ @SuppressWarnings("unchecked") // unchecked cast private void putProperties(VelocityContext context, File propertiesFile) { String hint = HINT + "check property \"{0}\" at file \"{1}\""; String pattern1 = "failed to load {2}" + hint; String pattern2 = "failed to initialise {2}" + hint; String pattern3 = "{2} does not implement {3}" + hint; String pattern4 = "{2} is not a valid wrapper for {3}" + hint; String string1; String string2; String message; String argument; // Object object1; Object object2; Class<?> clazz1; Class<?> clazz2; Class<? extends Wrapper> wrapperClass; Class<? extends Wrappable> wrappableClass; Class<?> parameterType; String velocityKey; Properties properties = PropertiesHandler.loadProperties(propertiesFile); Set<String> stringPropertyNames = properties.stringPropertyNames(); for (String name : stringPropertyNames) { checkPropertyName(name, propertiesFile); if (StringUtils.endsWithIgnoreCase(name, DOT_STRING)) { string1 = StringUtils.removeEndIgnoreCase(name, DOT_STRING); string2 = StringUtils.trimToEmpty(properties.getProperty(name)); velocityKey = StrUtils.getCamelCase(string1, true); context.put(velocityKey, string2); } else if (StringUtils.endsWithIgnoreCase(name, DOT_CLASS)) { string1 = StringUtils.removeEndIgnoreCase(name, DOT_CLASS); string2 = StringUtils.trimToEmpty(properties.getProperty(name)); message = MessageFormat.format(pattern1, name, propertiesFile, string2); object2 = getClassForName(string2, message); if (object2 != null) { velocityKey = StrUtils.getCamelCase(string1, true); context.put(velocityKey, object2); continue; } throw new RuntimeException(message, new IllegalArgumentException(string2)); } else if (StringUtils.endsWithIgnoreCase(name, DOT_INSTANCE)) { string1 = StringUtils.removeEndIgnoreCase(name, DOT_INSTANCE); string2 = StringUtils.trimToEmpty(properties.getProperty(name)); message = MessageFormat.format(pattern2, name, propertiesFile, string2); object2 = getNewInstanceForName(string2, message); if (object2 != null) { velocityKey = StrUtils.getCamelCase(string1, true); context.put(velocityKey, object2); continue; } throw new RuntimeException(message, new IllegalArgumentException(string2)); } else if (StringUtils.endsWithIgnoreCase(name, DOT_PROGRAMMER)) { string1 = StringUtils.removeEndIgnoreCase(name, DOT_PROGRAMMER); string2 = StringUtils.trimToEmpty(properties.getProperty(name)); message = MessageFormat.format(pattern2, name, propertiesFile, string2); object2 = getNewInstanceForName(string2, message); if (object2 != null) { if (object2 instanceof Programmer) { velocityKey = StrUtils.getCamelCase(string1, true); context.put(velocityKey, object2); TLB.setProgrammer(velocityKey, (Programmer) object2); continue; } else { message = MessageFormat.format(pattern3, name, propertiesFile, string2, Programmer.class); } } throw new RuntimeException(message, new IllegalArgumentException(string2)); } else if (StringUtils.endsWithIgnoreCase(name, DOT_WRAPPER)) { string1 = StringUtils.removeEndIgnoreCase(name, DOT_WRAPPER); string2 = StringUtils.trimToEmpty(properties.getProperty(name)); message = MessageFormat.format(pattern1, name, propertiesFile, string1); argument = string1; clazz1 = getClassForName(string1, message); if (clazz1 != null) { if (Wrappable.class.isAssignableFrom(clazz1)) { message = MessageFormat.format(pattern1, name, propertiesFile, string2); argument = string2; clazz2 = getClassForName(string2, message); if (clazz2 != null) { if (Wrapper.class.isAssignableFrom(clazz2)) { wrapperClass = (Class<? extends Wrapper>) clazz2; // unchecked cast wrappableClass = (Class<? extends Wrappable>) clazz1; // unchecked cast parameterType = getConstructorParameterType(wrapperClass, wrappableClass); if (parameterType != null) { TLB.setWrapperClass(wrappableClass, wrapperClass); continue; } else { message = MessageFormat.format(pattern4, name, propertiesFile, wrapperClass, wrappableClass); } } else { message = MessageFormat.format(pattern3, name, propertiesFile, string2, Wrapper.class); } } } else { message = MessageFormat.format(pattern3, name, propertiesFile, string1, Wrappable.class); } } throw new RuntimeException(message, new IllegalArgumentException(argument)); } } }
From source file:adalid.commons.velocity.Writer.java
private void putStrings(VelocityContext context, Properties properties) { String string1;/*from w w w. j a v a 2 s .c o m*/ String string2; String velocityKey; Set<String> stringPropertyNames = properties.stringPropertyNames(); for (String name : stringPropertyNames) { if (StringUtils.endsWithIgnoreCase(name, DOT_STRING)) { string1 = StringUtils.removeEndIgnoreCase(name, DOT_STRING); string2 = StringUtils.trimToEmpty(properties.getProperty(name)); velocityKey = StrUtils.getCamelCase(string1, true); context.put(velocityKey, string2); } } }
From source file:org.eclipse.wb.android.internal.model.property.event.AndroidEventProperty.java
/** * @return the layout ID corresponding to this xml-objects hierarchy. *//* w w w. ja v a 2s .c o m*/ private String getThisLayoutId() { IFile xmlFile = m_object.getContext().getFile(); return StringUtils.removeEndIgnoreCase(xmlFile.getName(), ".xml"); }