List of usage examples for org.apache.commons.lang3 StringUtils contains
public static boolean contains(final CharSequence seq, final CharSequence searchSeq)
Checks if CharSequence contains a search CharSequence, handling null .
From source file:org.apache.sling.servlethelpers.MockSlingHttpServletRequest.java
public void setContentType(String type) { this.contentType = type; if (StringUtils.contains(this.contentType, CHARSET_SEPARATOR)) { this.characterEncoding = StringUtils.substringAfter(this.contentType, CHARSET_SEPARATOR); this.contentType = StringUtils.substringBefore(this.contentType, CHARSET_SEPARATOR); }/*from ww w . ja va 2 s.c o m*/ }
From source file:org.apache.sling.servlethelpers.MockSlingHttpServletResponse.java
@Override public void setContentType(String type) { this.contentType = type; if (StringUtils.contains(this.contentType, CHARSET_SEPARATOR)) { this.characterEncoding = StringUtils.substringAfter(this.contentType, CHARSET_SEPARATOR); this.contentType = StringUtils.substringBefore(this.contentType, CHARSET_SEPARATOR); }// ww w.ja va 2s . co m }
From source file:org.apache.struts2.components.template.TemplateEngineManager.java
/** * <p>/*from w ww . ja v a 2 s . c o m*/ * Gets the TemplateEngine for the template name. If the template name has an extension (for instance foo.jsp), then * this extension will be used to look up the appropriate TemplateEngine. If it does not have an extension, it will * look for a Configuration setting "struts.ui.templateSuffix" for the extension, and if that is not set, it * will fall back to "ftl" as the default. * </p> * * @param template Template used to determine which TemplateEngine to return * @param templateTypeOverride Overrides the default template type * @return the engine. */ public TemplateEngine getTemplateEngine(Template template, String templateTypeOverride) { String templateType = DEFAULT_TEMPLATE_TYPE; String templateName = template.toString(); if (StringUtils.contains(templateName, ".")) { templateType = StringUtils.substring(templateName, StringUtils.indexOf(templateName, ".") + 1); } else if (StringUtils.isNotBlank(templateTypeOverride)) { templateType = templateTypeOverride; } else { String type = defaultTemplateType; if (type != null) { templateType = type; } } return templateEngines.get(templateType).create(); }
From source file:org.apache.struts2.convention.PackageBasedActionConfigBuilder.java
/** * Creates a single ActionConfig object. * * @param pkgCfg The package the action configuration instance will belong to. * @param actionClass The action class. * @param actionName The name of the action. * @param actionMethod The method that the annotation was on (if the annotation is not null) or * the default method (execute). * @param annotation The ActionName annotation that might override the action name and possibly */// w ww. j a v a 2 s.com protected void createActionConfig(PackageConfig.Builder pkgCfg, Class<?> actionClass, String actionName, String actionMethod, Action annotation) { String className = actionClass.getName(); if (annotation != null) { actionName = annotation.value() != null && annotation.value().equals(Action.DEFAULT_VALUE) ? actionName : annotation.value(); actionName = StringUtils.contains(actionName, "/") && !slashesInActionNames ? StringUtils.substringAfterLast(actionName, "/") : actionName; if (!Action.DEFAULT_VALUE.equals(annotation.className())) { className = annotation.className(); } } ActionConfig.Builder actionConfig = new ActionConfig.Builder(pkgCfg.getName(), actionName, className); actionConfig.methodName(actionMethod); if (LOG.isDebugEnabled()) { LOG.debug("Creating action config for class [#0], name [#1] and package name [#2] in namespace [#3]", actionClass.toString(), actionName, pkgCfg.getName(), pkgCfg.getNamespace()); } //build interceptors List<InterceptorMapping> interceptors = interceptorMapBuilder.build(actionClass, pkgCfg, actionName, annotation); actionConfig.addInterceptors(interceptors); //build results Map<String, ResultConfig> results = resultMapBuilder.build(actionClass, annotation, actionName, pkgCfg.build()); actionConfig.addResultConfigs(results); //add params if (annotation != null) actionConfig.addParams(StringTools.createParameterMap(annotation.params())); //add exception mappings from annotation if (annotation != null && annotation.exceptionMappings() != null) actionConfig.addExceptionMappings(buildExceptionMappings(annotation.exceptionMappings(), actionName)); //add exception mapping from class ExceptionMappings exceptionMappings = actionClass.getAnnotation(ExceptionMappings.class); if (exceptionMappings != null) actionConfig.addExceptionMappings(buildExceptionMappings(exceptionMappings.value(), actionName)); //add pkgCfg.addActionConfig(actionName, actionConfig.build()); //check if an action with the same name exists on that package (from XML config probably) PackageConfig existingPkg = configuration.getPackageConfig(pkgCfg.getName()); if (existingPkg != null) { // there is a package already with that name, check action ActionConfig existingActionConfig = existingPkg.getActionConfigs().get(actionName); if (existingActionConfig != null && LOG.isWarnEnabled()) LOG.warn("Duplicated action definition in package [#0] with name [#1].", pkgCfg.getName(), actionName); } //watch class file if (isReloadEnabled()) { URL classFile = actionClass.getResource(actionClass.getSimpleName() + ".class"); fileManager.monitorFile(classFile); loadedFileUrls.add(classFile.toString()); } }
From source file:org.apache.struts2.convention.PackageBasedActionConfigBuilder.java
protected PackageConfig.Builder getPackageConfig(final Map<String, PackageConfig.Builder> packageConfigs, String actionNamespace, final String actionPackage, final Class<?> actionClass, Action action) { if (action != null && !action.value().equals(Action.DEFAULT_VALUE)) { if (LOG.isTraceEnabled()) { LOG.trace("Using non-default action namespace from the Action annotation of [#0]", action.value()); }/*ww w .j a va 2s .c o m*/ String actionName = action.value(); actionNamespace = StringUtils.contains(actionName, "/") ? StringUtils.substringBeforeLast(actionName, "/") : StringUtils.EMPTY; } // Next grab the parent annotation from the class ParentPackage parent = AnnotationUtils.findAnnotation(actionClass, ParentPackage.class); String parentName = null; if (parent != null) { if (LOG.isTraceEnabled()) { LOG.trace("Using non-default parent package from annotation of [#0]", parent.value()); } parentName = parent.value(); } // Finally use the default if (parentName == null) { parentName = defaultParentPackage; } if (parentName == null) { throw new ConfigurationException("Unable to determine the parent XWork package for the action class [" + actionClass.getName() + "]"); } PackageConfig parentPkg = configuration.getPackageConfig(parentName); if (parentPkg == null) { throw new ConfigurationException("Unable to locate parent package [" + parentName + "]"); } // Grab based on package-namespace and if it exists, we need to ensure the existing one has // the correct parent package. If not, we need to create a new package config String name = actionPackage + "#" + parentPkg.getName() + "#" + actionNamespace; PackageConfig.Builder pkgConfig = packageConfigs.get(name); if (pkgConfig == null) { pkgConfig = new PackageConfig.Builder(name).namespace(actionNamespace).addParent(parentPkg); packageConfigs.put(name, pkgConfig); //check for @DefaultInterceptorRef in the package DefaultInterceptorRef defaultInterceptorRef = AnnotationUtils.findAnnotation(actionClass, DefaultInterceptorRef.class); if (defaultInterceptorRef != null) { pkgConfig.defaultInterceptorRef(defaultInterceptorRef.value()); if (LOG.isTraceEnabled()) LOG.trace("Setting [#0] as the default interceptor ref for [#1]", defaultInterceptorRef.value(), pkgConfig.getName()); } } if (LOG.isTraceEnabled()) { LOG.trace("Created package config named [#0] with a namespace [#1]", name, actionNamespace); } return pkgConfig; }
From source file:org.apache.struts2.dispatcher.Dispatcher.java
private void init_CheckWebLogicWorkaround(Container container) { // test whether param-access workaround needs to be enabled if (servletContext != null && StringUtils.contains(servletContext.getServerInfo(), "WebLogic")) { LOG.info("WebLogic server detected. Enabling Struts parameter access work-around."); paramsWorkaroundEnabled = true;//w w w . ja v a2 s .com } else { paramsWorkaroundEnabled = "true".equals( container.getInstance(String.class, StrutsConstants.STRUTS_DISPATCHER_PARAMETERSWORKAROUND)); } }
From source file:org.apache.struts2.views.jsp.ui.DebugTagTest.java
public void testDevModeEnabled() throws Exception { setDevMode(true);//from w w w . jav a2s .c o m tag.doStartTag(); tag.doEndTag(); String result = writer.toString(); assertTrue(StringUtils.isNotEmpty(result)); assertTrue("Property 'checkStackProperty' should be in Debug Tag output", StringUtils.contains(result, "<td>checkStackProperty</td>")); }
From source file:org.apache.struts2.views.jsp.ui.DebugTagTest.java
public void testTagAttributeOverrideDevModeTrue() throws Exception { setDevMode(false);/*from w ww . j av a 2 s.co m*/ PrepareOperations.overrideDevMode(true); tag.doStartTag(); tag.doEndTag(); String result = writer.toString(); assertTrue(StringUtils.isNotEmpty(result)); assertTrue("Property 'checkStackProperty' should be in Debug Tag output", StringUtils.contains(result, "<td>checkStackProperty</td>")); }
From source file:org.apache.syncope.client.enduser.SyncopeEnduserApplication.java
@Override protected void init() { super.init(); // read enduser.properties Properties props = PropertyUtils.read(getClass(), ENDUSER_PROPERTIES, "enduser.directory").getLeft(); domain = props.getProperty("domain", SyncopeConstants.MASTER_DOMAIN); adminUser = props.getProperty("adminUser"); Args.notNull(adminUser, "<adminUser>"); anonymousUser = props.getProperty("anonymousUser"); Args.notNull(anonymousUser, "<anonymousUser>"); anonymousKey = props.getProperty("anonymousKey"); Args.notNull(anonymousKey, "<anonymousKey>"); captchaEnabled = Boolean.parseBoolean(props.getProperty("captcha")); Args.notNull(captchaEnabled, "<captcha>"); xsrfEnabled = Boolean.parseBoolean(props.getProperty("xsrf")); Args.notNull(xsrfEnabled, "<xsrf>"); String scheme = props.getProperty("scheme"); Args.notNull(scheme, "<scheme>"); String host = props.getProperty("host"); Args.notNull(host, "<host>"); String port = props.getProperty("port"); Args.notNull(port, "<port>"); String rootPath = props.getProperty("rootPath"); Args.notNull(rootPath, "<rootPath>"); String useGZIPCompression = props.getProperty("useGZIPCompression"); Args.notNull(useGZIPCompression, "<useGZIPCompression>"); maxUploadFileSizeMB = props.getProperty("maxUploadFileSizeMB") == null ? null : Integer.valueOf(props.getProperty("maxUploadFileSizeMB")); clientFactory = new SyncopeClientFactoryBean() .setAddress(scheme + "://" + host + ":" + port + "/" + rootPath) .setContentType(SyncopeClientFactoryBean.ContentType.JSON) .setUseCompression(BooleanUtils.toBoolean(useGZIPCompression)); // read customForm.json try (InputStream is = getClass().getResourceAsStream("/" + CUSTOM_FORM_FILE)) { customForm = MAPPER.readValue(is, new TypeReference<HashMap<String, CustomAttributesInfo>>() { });/*from ww w . j a v a 2 s.c o m*/ File enduserDir = new File(props.getProperty("enduser.directory")); boolean existsEnduserDir = enduserDir.exists() && enduserDir.canRead() && enduserDir.isDirectory(); if (existsEnduserDir) { File customFormFile = FileUtils.getFile(enduserDir, CUSTOM_FORM_FILE); if (customFormFile.exists() && customFormFile.canRead() && customFormFile.isFile()) { customForm = MAPPER.readValue(FileUtils.openInputStream(customFormFile), new TypeReference<HashMap<String, CustomAttributesInfo>>() { }); } } FileAlterationObserver observer = existsEnduserDir ? new FileAlterationObserver(enduserDir, pathname -> StringUtils.contains(pathname.getPath(), CUSTOM_FORM_FILE)) : new FileAlterationObserver(getClass().getResource("/" + CUSTOM_FORM_FILE).getFile(), pathname -> StringUtils.contains(pathname.getPath(), CUSTOM_FORM_FILE)); FileAlterationMonitor monitor = new FileAlterationMonitor(5000); FileAlterationListener listener = new FileAlterationListenerAdaptor() { @Override public void onFileChange(final File file) { try { LOG.trace("{} has changed. Reloading form customization configuration.", CUSTOM_FORM_FILE); customForm = MAPPER.readValue(FileUtils.openInputStream(file), new TypeReference<HashMap<String, CustomAttributesInfo>>() { }); } catch (IOException e) { e.printStackTrace(System.err); } } @Override public void onFileCreate(final File file) { try { LOG.trace("{} has been created. Loading form customization configuration.", CUSTOM_FORM_FILE); customForm = MAPPER.readValue(FileUtils.openInputStream(file), new TypeReference<HashMap<String, CustomAttributesInfo>>() { }); } catch (IOException e) { e.printStackTrace(System.err); } } @Override public void onFileDelete(final File file) { LOG.trace("{} has been deleted. Resetting form customization configuration.", CUSTOM_FORM_FILE); customForm = null; } }; observer.addListener(listener); monitor.addObserver(observer); monitor.start(); } catch (Exception e) { throw new WicketRuntimeException("Could not read " + CUSTOM_FORM_FILE, e); } // mount resources ClassPathScanImplementationLookup classPathScanImplementationLookup = (ClassPathScanImplementationLookup) getServletContext() .getAttribute(EnduserInitializer.CLASSPATH_LOOKUP); for (final Class<? extends AbstractResource> resource : classPathScanImplementationLookup.getResources()) { Resource annotation = resource.getAnnotation(Resource.class); if (annotation == null) { LOG.debug("No @Resource annotation found on {}, ignoring", resource.getName()); } else { try { final AbstractResource instance = resource.newInstance(); mountResource(annotation.path(), new ResourceReference(annotation.key()) { private static final long serialVersionUID = -128426276529456602L; @Override public IResource getResource() { return instance; } }); } catch (Exception e) { LOG.error("Could not instantiate {}", resource.getName(), e); } } } //mount captcha resource only if captcha is enabled if (captchaEnabled) { mountResource("/api/captcha", new ResourceReference("captcha") { private static final long serialVersionUID = -128426276529456602L; @Override public IResource getResource() { return new CaptchaResource(); } }); } }
From source file:org.apache.syncope.fit.core.LoggerITCase.java
@Test public void customAuditAppender() throws IOException, InterruptedException { try (InputStream propStream = getClass().getResourceAsStream("/core-test.properties")) { Properties props = new Properties(); props.load(propStream);/*from w w w. j av a2 s .c o m*/ String auditFilePath = props.getProperty("test.log.dir") + File.separator + "audit_for_Master_file.log"; String auditNoRewriteFilePath = props.getProperty("test.log.dir") + File.separator + "audit_for_Master_norewrite_file.log"; // 1. Enable audit for resource update -> catched by FileRewriteAuditAppender AuditLoggerName auditLoggerResUpd = new AuditLoggerName(EventCategoryType.LOGIC, ResourceLogic.class.getSimpleName(), null, "update", AuditElements.Result.SUCCESS); LoggerTO loggerTOUpd = new LoggerTO(); loggerTOUpd.setKey(auditLoggerResUpd.toLoggerName()); loggerTOUpd.setLevel(LoggerLevel.DEBUG); loggerService.update(LoggerType.AUDIT, loggerTOUpd); // 2. Enable audit for connector update -> NOT catched by FileRewriteAuditAppender AuditLoggerName auditLoggerConnUpd = new AuditLoggerName(EventCategoryType.LOGIC, ConnectorLogic.class.getSimpleName(), null, "update", AuditElements.Result.SUCCESS); LoggerTO loggerTOConnUpd = new LoggerTO(); loggerTOConnUpd.setKey(auditLoggerConnUpd.toLoggerName()); loggerTOConnUpd.setLevel(LoggerLevel.DEBUG); loggerService.update(LoggerType.AUDIT, loggerTOConnUpd); // 3. check that resource update is transformed and logged onto an audit file. ResourceTO resource = resourceService.read(RESOURCE_NAME_CSV); assertNotNull(resource); resource.setPropagationPriority(100); resourceService.update(resource); ConnInstanceTO connector = connectorService.readByResource(RESOURCE_NAME_CSV, null); assertNotNull(connector); connector.setPoolConf(new ConnPoolConfTO()); connectorService.update(connector); File auditTempFile = new File(auditFilePath); // check audit_for_Master_file.log, it should contain only a static message String auditLog = FileUtils.readFileToString(auditTempFile, Charset.defaultCharset()); assertTrue(StringUtils.contains(auditLog, "DEBUG Master.syncope.audit.[LOGIC]:[ResourceLogic]:[]:[update]:[SUCCESS]" + " - This is a static test message")); File auditNoRewriteTempFile = new File(auditNoRewriteFilePath); // check audit_for_Master_file.log, it should contain only a static message String auditLogNoRewrite = FileUtils.readFileToString(auditNoRewriteTempFile, Charset.defaultCharset()); assertFalse(StringUtils.contains(auditLogNoRewrite, "DEBUG Master.syncope.audit.[LOGIC]:[ResourceLogic]:[]:[update]:[SUCCESS]" + " - This is a static test message")); // clean audit_for_Master_file.log FileUtils.writeStringToFile(auditTempFile, StringUtils.EMPTY, Charset.defaultCharset()); loggerService.delete(LoggerType.AUDIT, "syncope.audit.[LOGIC]:[ResourceLogic]:[]:[update]:[SUCCESS]"); resource = resourceService.read(RESOURCE_NAME_CSV); assertNotNull(resource); resource.setPropagationPriority(200); resourceService.update(resource); // check that nothing has been written to audit_for_Master_file.log assertTrue(StringUtils.isEmpty(FileUtils.readFileToString(auditTempFile, Charset.defaultCharset()))); } catch (IOException e) { fail("Unable to read/write log files" + e.getMessage()); } }