List of usage examples for org.apache.commons.lang StringUtils endsWith
public static boolean endsWith(String str, String suffix)
Check if a String ends with a specified suffix.
From source file:org.geoserver.security.iride.util.factory.template.freemarker.FreeMarkerConfigurationDefaultFactoryTest.java
/** * Test method for {@link org.geoserver.security.iride.util.factory.template.freemarker.FreeMarkerConfigurationFactory#create()}. * * @throws IOException// ww w . j ava 2 s . c o m * @throws URISyntaxException */ @Test public void testCreate() throws IOException, URISyntaxException { LOGGER.trace("BEGIN {}::testCreate", this.getClass().getName()); try { final Configuration templateConfiguration = this.templateConfigurationFactory.create(); assertThat(templateConfiguration, is(not(nullValue()))); // FreeMarker TemplateLoader Configuration final TemplateLoader templateLoader = templateConfiguration.getTemplateLoader(); assertThat(templateLoader, is(not(nullValue()))); assertThat(templateLoader, is(instanceOf(ClassTemplateLoader.class))); final String templateSource = ((ClassTemplateLoader) templateLoader).findTemplateSource("").toString(); assertThat(templateSource, is(not(nullValue()))); final Path templateSourcePath = Paths.get(new URI(templateSource)); final Path templateBasePath = Paths.get(FreeMarkerConfigurationFactory.TEMPLATE_BASE_PATH); assertThat(StringUtils.endsWith(templateSourcePath.toString(), templateBasePath.toString()), is(true)); // FreeMarker Default and Output Encoding Configuration assertThat(templateConfiguration.getDefaultEncoding(), is(StandardCharsets.UTF_8.name())); assertThat(templateConfiguration.getOutputEncoding(), is(templateConfiguration.getDefaultEncoding())); // FreeMarker TemplateExceptionHandler Configuration assertThat(templateConfiguration.getTemplateExceptionHandler(), is(TemplateExceptionHandler.RETHROW_HANDLER)); } finally { LOGGER.trace("END {}::testCreate", this.getClass().getName()); } }
From source file:org.geoserver.security.iride.util.factory.template.freemarker.FreeMarkerTemplateEngineFactoryTest.java
/** * Test method for {@link org.geoserver.security.iride.util.factory.template.freemarker.FreeMarkerTemplateEngineFactory#createTemplateEngine(freemarker.template.Configuration)}. * * @throws IOException//from w w w . j a v a 2 s.c om * @throws URISyntaxException */ @Test public void testCreateTemplateEngineConfiguration() throws IOException, URISyntaxException { LOGGER.trace("BEGIN {}::testCreateTemplateEngineConfiguration", this.getClass().getName()); try { final FreeMarkerTemplateEngine templateEngine = FreeMarkerTemplateEngineFactory .createTemplateEngine(this.defaultConfiguration); assertThat(templateEngine, is(not(nullValue()))); assertThat(templateEngine.getTemplateConfiguration(), is(not(nullValue()))); // FreeMarker Configuration final Configuration templateConfiguration = templateEngine.getTemplateConfiguration(); // - FreeMarker TemplateLoader Configuration final TemplateLoader templateLoader = templateConfiguration.getTemplateLoader(); assertThat(templateLoader, is(not(nullValue()))); assertThat(templateLoader, is(instanceOf(ClassTemplateLoader.class))); final String templateSource = ((ClassTemplateLoader) templateLoader).findTemplateSource("").toString(); assertThat(templateSource, is(not(nullValue()))); final Path templateSourcePath = Paths.get(new URI(templateSource)); final Path templateBasePath = Paths.get(FreeMarkerConfigurationFactory.TEMPLATE_BASE_PATH); assertThat(StringUtils.endsWith(templateSourcePath.toString(), templateBasePath.toString()), is(true)); // - FreeMarker Default and Output Encoding Configuration assertThat(templateConfiguration.getDefaultEncoding(), is(StandardCharsets.UTF_8.name())); assertThat(templateConfiguration.getOutputEncoding(), is(templateConfiguration.getDefaultEncoding())); // - FreeMarker TemplateExceptionHandler Configuration assertThat(templateConfiguration.getTemplateExceptionHandler(), is(TemplateExceptionHandler.RETHROW_HANDLER)); // FreeMarker Template Extension assertThat(templateEngine.getTemplateExtension(), is(nullValue())); } finally { LOGGER.trace("END {}::testCreateTemplateEngineConfiguration", this.getClass().getName()); } }
From source file:org.geoserver.security.iride.util.factory.template.freemarker.FreeMarkerTemplateEngineFactoryTest.java
/** * Test method for {@link org.geoserver.security.iride.util.factory.template.freemarker.FreeMarkerTemplateEngineFactory#createTemplateEngine(freemarker.template.Configuration, java.lang.String)}. * * @throws IOException//w ww . j a v a 2 s .com * @throws URISyntaxException */ @Test public void testCreateTemplateEngineConfigurationWithExtension() throws IOException, URISyntaxException { LOGGER.trace("BEGIN {}::testCreateTemplateEngineConfigurationWithExtension", this.getClass().getName()); try { final FreeMarkerTemplateEngine templateEngine = FreeMarkerTemplateEngineFactory .createTemplateEngine(this.defaultConfiguration, "xml"); assertThat(templateEngine, is(not(nullValue()))); assertThat(templateEngine.getTemplateConfiguration(), is(not(nullValue()))); // FreeMarker Configuration final Configuration templateConfiguration = templateEngine.getTemplateConfiguration(); // - FreeMarker TemplateLoader Configuration final TemplateLoader templateLoader = templateConfiguration.getTemplateLoader(); assertThat(templateLoader, is(not(nullValue()))); assertThat(templateLoader, is(instanceOf(ClassTemplateLoader.class))); final String templateSource = ((ClassTemplateLoader) templateLoader).findTemplateSource("").toString(); assertThat(templateSource, is(not(nullValue()))); final Path templateSourcePath = Paths.get(new URI(templateSource)); final Path templateBasePath = Paths.get(FreeMarkerConfigurationFactory.TEMPLATE_BASE_PATH); assertThat(StringUtils.endsWith(templateSourcePath.toString(), templateBasePath.toString()), is(true)); // - FreeMarker Default and Output Encoding Configuration assertThat(templateConfiguration.getDefaultEncoding(), is(StandardCharsets.UTF_8.name())); assertThat(templateConfiguration.getOutputEncoding(), is(templateConfiguration.getDefaultEncoding())); // - FreeMarker TemplateExceptionHandler Configuration assertThat(templateConfiguration.getTemplateExceptionHandler(), is(TemplateExceptionHandler.RETHROW_HANDLER)); // FreeMarker Template Extension assertThat(templateEngine.getTemplateExtension(), is("xml")); } finally { LOGGER.trace("END {}::testCreateTemplateEngineConfigurationWithExtension", this.getClass().getName()); } }
From source file:org.huahinframework.manager.rest.service.HiveService.java
@Path("/execute") @POST//from ww w. jav a2s.c om @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaTypeUtils.MULTIPART_FORM_DATA) public void execute(@Context HttpServletResponse response, InMultiPart inMP) throws IOException { OutputStreamWriter out = null; Map<String, String> status = new HashMap<String, String>(); Map<String, Object> result = new HashMap<String, Object>(); try { out = new OutputStreamWriter(response.getOutputStream()); if (!inMP.hasNext()) { status.put(Response.STATUS, "Query is empty"); out.write(new JSONObject(status).toString()); out.flush(); out.close(); return; } JSONObject argument = createJSON(inMP.next().getInputStream()); String query = argument.getString(JSON_QUERY); if (query == null || query.isEmpty()) { status.put(Response.STATUS, "Query is empty"); out.write(new JSONObject(status).toString()); out.flush(); out.close(); return; } Class.forName(driverName); Connection con = DriverManager.getConnection(String.format(connectionFormat, hiveserver), "", ""); Statement stmt = con.createStatement(); int queryNo = 1; String command = ""; for (String oneCmd : query.split(";")) { if (StringUtils.endsWith(oneCmd, "")) { command += StringUtils.chop(oneCmd) + ";"; continue; } else { command += oneCmd; } if (StringUtils.isBlank(command)) { continue; } boolean b = stmt.execute(command); if (b) { result.clear(); result.put(JSON_QUERY, queryNo); ResultSet resultSet = stmt.getResultSet(); while (resultSet.next()) { JSONObject jsonObject = new JSONObject(); for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) { jsonObject.put(resultSet.getMetaData().getColumnName(i), resultSet.getString(i)); } result.put(RESULT, jsonObject); out.write(new JSONObject(result).toString()); out.flush(); } if (result.size() == 1) { status.put(Response.STATUS, "SCCESS"); result.put(RESULT, status); JSONObject jsonObject = new JSONObject(result); out.write(jsonObject.toString()); out.flush(); } } else { result.clear(); status.clear(); result.put(JSON_QUERY, queryNo); status.put(Response.STATUS, "SCCESS"); result.put(RESULT, status); JSONObject jsonObject = new JSONObject(result); out.write(jsonObject.toString()); out.flush(); } command = ""; queryNo++; } con.close(); out.close(); } catch (Exception e) { e.printStackTrace(); log.error(e); if (out != null) { status.put(Response.STATUS, e.getMessage()); out.write(new JSONObject(status).toString()); out.flush(); out.close(); } } }
From source file:org.intellij.erlang.inspection.ErlangSpecificationForUndefinedFunctionInspection.java
@Override protected void checkFile(PsiFile file, final ProblemsHolder problemsHolder) { if (!StringUtils.endsWith(file.getName(), ErlangFileType.MODULE.getDefaultExtension())) return;/* w w w. j ava 2 s.c o m*/ file.accept(new ErlangRecursiveVisitor() { @Override public void visitSpecification(@NotNull ErlangSpecification o) { //supported functions without modules only for now ErlangFunTypeSigs signature = o.getSignature(); if (signature != null) { PsiReference reference = signature.getReference(); if (reference != null && reference.resolve() == null) { problemsHolder.registerProblem(o, "Specification for undefined function '" + signature.getSpecFun().getText() + "'"); } } } }); }
From source file:org.itracker.model.util.IssueUtilities.java
public static URL getIssueURL(Issue issue, String baseURL) throws MalformedURLException { return getIssueURL(issue, new URL(baseURL + (StringUtils.endsWith(baseURL, "/") ? "" : "/"))); }
From source file:org.itracker.services.implementations.ConfigurationServiceImpl.java
public boolean isConfigurationItemUpToDate(Configuration configuration) { if (null == configuration) { return false; }/*from w w w . j a va 2 s . c o m*/ if (StringUtils.endsWith(configuration.getVersion(), "-SNAPSHOT")) { return false; } long currentVersion = SystemConfigurationUtilities.getVersionAsLong(getInitializedVersionString()); if (configuration != null && configuration.getVersion() != null) { Collection<Configuration> configItems = configurationDAO.findByTypeAndValue(configuration.getType(), configuration.getValue()); for (Iterator<Configuration> iter = configItems.iterator(); iter.hasNext();) { Configuration configItem = (Configuration) iter.next(); if (null != configItem) { currentVersion = Math.max( SystemConfigurationUtilities.getVersionAsLong(configItem.getVersion()), currentVersion); } } if (currentVersion >= SystemConfigurationUtilities.getVersionAsLong(configuration.getVersion())) { return true; } } return false; }
From source file:org.jahia.data.templates.ModulesPackage.java
private ModulesPackage(JarFile jarFile) throws IOException { modules = new LinkedHashMap<String, PackagedModule>(); Attributes manifestAttributes = jarFile.getManifest().getMainAttributes(); version = new Version(manifestAttributes.getValue(Constants.ATTR_NAME_JAHIA_PACKAGE_VERSION)); name = manifestAttributes.getValue(Constants.ATTR_NAME_JAHIA_PACKAGE_NAME); description = manifestAttributes.getValue(Constants.ATTR_NAME_JAHIA_PACKAGE_DESCRIPTION); // read jars/* ww w . ja v a 2 s . c o m*/ Enumeration<JarEntry> jars = jarFile.entries(); while (jars.hasMoreElements()) { JarEntry jar = jars.nextElement(); JarFile moduleJarFile = null; OutputStream output = null; if (StringUtils.endsWith(jar.getName(), ".jar")) { try { InputStream input = jarFile.getInputStream(jar); File moduleFile = File.createTempFile(jar.getName(), ""); output = new FileOutputStream(moduleFile); int read = 0; byte[] bytes = new byte[1024]; while ((read = input.read(bytes)) != -1) { output.write(bytes, 0, read); } moduleJarFile = new JarFile(moduleFile); Attributes moduleManifestAttributes = moduleJarFile.getManifest().getMainAttributes(); String bundleName = moduleManifestAttributes.getValue(Constants.ATTR_NAME_BUNDLE_SYMBOLIC_NAME); String jahiaGroupId = moduleManifestAttributes.getValue(Constants.ATTR_NAME_GROUP_ID); if (bundleName == null || jahiaGroupId == null) { throw new IOException( "Jar file " + jar.getName() + " in package does not seems to be a DX bundle."); } modules.put(bundleName, new PackagedModule(bundleName, moduleManifestAttributes, moduleFile)); } finally { IOUtils.closeQuietly(output); if (moduleJarFile != null) { moduleJarFile.close(); } } } } // we finally sort modules based on dependencies try { sortByDependencies(modules); } catch (CycleDetectedException e) { throw new JahiaRuntimeException("A cyclic dependency detected in the modules of the supplied package", e); } }
From source file:org.jahia.modules.external.modules.ModulesDataSource.java
public void start() { final String fullFolderPath = module.getSourcesFolder().getPath() + File.separator; final String importFilesRootFolder = fullFolderPath + "src" + File.separator + "main" + File.separator + "import" + File.separator + "content" + File.separator + "modules" + File.separator + module.getId() + File.separator + "files" + File.separator; final String filesNodePath = "/modules/" + module.getIdWithVersion() + "/files"; FileMonitor monitor = new FileMonitor(new FileMonitorCallback() { @Override// w w w . j a v a2s . c o m public void process(FileMonitorResult result) { logger.info("Detected changes in sources of the module in folder {}: {}", fullFolderPath, result); if (logger.isDebugEnabled()) { logger.debug(result.getInfo()); } boolean nodeTypeLabelsFlushed = false; List<File> importFiles = new ArrayList<File>(); for (final File file : result.getAllAsList()) { invalidateVfsParentCache(fullFolderPath, file); if (file.getPath().startsWith(importFilesRootFolder)) { importFiles.add(file); continue; } String type; try { type = getDataType(getFile(file.getPath())); } catch (FileSystemException e) { if (logger.isDebugEnabled()) { logger.error(e.getMessage(), e); } // Unable to resolve file, continue continue; } if (StringUtils.equals(type, "jnt:propertiesFile")) { // we've detected a properties file, check if its parent is of type jnt:resourceBundleFolder // -> than this one gets the type jnt:resourceBundleFile; otherwise just jnt:file File parent = file.getParentFile(); type = parent != null && StringUtils.equals(Constants.JAHIANT_RESOURCEBUNDLE_FOLDER, folderTypeMapping.get(parent.getName())) ? Constants.JAHIANT_RESOURCEBUNDLE_FILE : type; } if (StringUtils.equals(type, "jnt:resourceBundleFile") && !nodeTypeLabelsFlushed) { NodeTypeRegistry.getInstance().flushLabels(); logger.debug("Flushing node type label caches"); for (NodeTypeRegistry registry : nodeTypeRegistryMap.values()) { registry.flushLabels(); } nodeTypeLabelsFlushed = true; try { JCRTemplate.getInstance().doExecuteWithSystemSession(new JCRCallback<Object>() { @Override public Object doInJCR(JCRSessionWrapper session) throws RepositoryException { JCRSiteNode site = (JCRSiteNode) session.getNode("/modules/" + module.getId()); Set<String> langs = new HashSet<String>(site.getLanguages()); boolean changed = false; if (file.getParentFile().listFiles() != null) { File[] files = file.getParentFile().listFiles(); if (files != null) { for (File f : files) { String s = StringUtils.substringAfterLast( StringUtils.substringBeforeLast(f.getName(), "."), "_"); if (!StringUtils.isEmpty(s) && !langs.contains(s)) { langs.add(s); changed = true; } } } if (changed) { site.setLanguages(langs); session.save(); } } return null; } }); } catch (RepositoryException e) { logger.error(e.getMessage(), e); } } else if (StringUtils.equals(type, JNT_DEFINITION_FILE)) { try { registerCndFiles(file); } catch (IOException | ParseException | RepositoryException e) { logger.error(e.getMessage(), e); } } else if (StringUtils.equals(type, Constants.JAHIANT_VIEWFILE)) { ModulesSourceHttpServiceTracker httpServiceTracker = modulesSourceSpringInitializer .getHttpServiceTracker(module.getId()); if (result.getCreated().contains(file)) { httpServiceTracker.registerResource(file); } else if (result.getDeleted().contains(file)) { httpServiceTracker.unregisterResouce(file); } // in case of jsp, flush the cache if (StringUtils.endsWith(file.getName(), ".jsp")) { httpServiceTracker.flushJspCache(file); } } } if (!importFiles.isEmpty()) { modulesImportExportHelper.updateImportFileNodes(importFiles, importFilesRootFolder, filesNodePath); } SourceControlManagement sourceControl = module.getSourceControl(); if (sourceControl != null) { sourceControl.invalidateStatusCache(); logger.debug("Invalidating SCM status caches for module {}", module.getId()); for (File file : result.getDeleted()) { try { sourceControl.remove(file); } catch (IOException e) { logger.error("An error occurred when trying to remove file from source control", e); } } for (File file : result.getCreated()) { try { sourceControl.add(file); } catch (IOException e) { logger.error("An error occurred when trying to add file in source control", e); } } } } }); monitor.setRecursive(true); Set<String> ignored = new HashSet<>(sourceControlFactory.getIgnoredFiles()); ignored.add(".svn"); ignored.add(".git"); monitor.setFilesToIgnore(ignored); monitor.addFile(module.getSourcesFolder()); fileMonitorJobName = "ModuleSourcesJob-" + module.getId(); FileMonitorJob.schedule(fileMonitorJobName, 5000, monitor); for (String cndFilePath : module.getDefinitionsFiles()) { try { registerCndFiles(new File(fullFolderPath + "src" + File.separator + "main" + File.separator + "resources" + File.separator + cndFilePath)); } catch (IOException | ParseException | RepositoryException e) { logger.error(e.getMessage(), e); } } }
From source file:org.jahia.modules.external.modules.ModulesDataSource.java
/** * Allows to know the nodetype associated to a filetype. * * @param fileObject the file object that we want to know the associated nodetype * @return the associated nodetype/* w w w.j a v a 2s . co m*/ * @throws FileSystemException */ @Override public String getDataType(FileObject fileObject) throws FileSystemException { String relativeName = getFile("/").getName().getRelativeName(fileObject.getName()); int relativeDepth = ".".equals(relativeName) ? 0 : StringUtils.split(relativeName, "/").length; String type = null; if (fileObject.getType().equals(FileType.FOLDER)) { if (relativeDepth == ROOT_DEPTH_TOKEN) { // we are in root type = Constants.JAHIANT_MODULEVERSIONFOLDER; } else { if (relativeDepth == TARGET_DEPTH_TOKEN && StringUtils.equals("target", fileObject.getName().getBaseName())) { type = "jnt:mavenTargetFolder"; } else if (StringUtils.equals("resources", fileObject.getName().getBaseName()) && relativeDepth == SOURCES_DEPTH_TOKEN) { type = "jnt:folder"; } else if (relativeDepth == NODETYPE_FOLDER_DEPTH_TOKEN && isNodeType(fileObject.getName().getBaseName())) { type = Constants.JAHIANT_NODETYPEFOLDER; } else if (relativeDepth == TEMPLATE_TYPE_FOLDER_DEPTH_TOKEN) { FileObject parent = fileObject.getParent(); if (parent != null && Constants.JAHIANT_NODETYPEFOLDER.equals(getDataType(parent))) { type = Constants.JAHIANT_TEMPLATETYPEFOLDER; } } else if (StringUtils.split(relativeName, "/").length >= SOURCES_DEPTH_TOKEN && StringUtils .equals(StringUtils.split(relativeName, "/")[SOURCES_DEPTH_TOKEN - 1], "java")) { type = "jnt:javaPackageFolder"; } } if (type == null) { type = folderTypeMapping.get(fileObject.getName().getBaseName()); } } else { String extension = fileObject.getName().getExtension(); if (StringUtils.isNotEmpty(extension)) { type = fileTypeMapping.get(extension); if (type == null) { try { if (ScriptEngineUtils.canFactoryForExtensionProcessViews(extension, module.getBundle().getHeaders())) { type = Constants.JAHIANT_VIEWFILE; } } catch (IllegalArgumentException e) { // ignore: no ScriptEngineFactory exists for the provided extension } } } } if (type != null && StringUtils.equals(type, "jnt:propertiesFile")) { // we've detected a properties file, check if its parent is of type jnt:resourceBundleFolder // -> than this one gets the type jnt:resourceBundleFile; otherwise just jnt:file FileObject parent = fileObject.getParent(); type = parent != null && StringUtils.equals(Constants.JAHIANT_RESOURCEBUNDLE_FOLDER, getDataType(parent)) ? Constants.JAHIANT_RESOURCEBUNDLE_FILE : type; } boolean isFile = fileObject.getType() == FileType.FILE; if (isFile && relativeDepth == VIEWS_FOLDER_DEPTH_TOKEN && (fileObject.getParent() != null && StringUtils.equals(Constants.JAHIANT_TEMPLATETYPEFOLDER, getDataType(fileObject.getParent())))) { if (StringUtils.endsWith(fileObject.getName().toString(), PROPERTIES_EXTENSION)) { type = JNT_EDITABLE_FILE; } else { type = Constants.JAHIANT_VIEWFILE; } } String contentType = getContentType(fileObject.getContent()); if (type == null && isFile) { boolean isMedia = contentType != null && (contentType.contains("image") || contentType.contains("video") || contentType.contains("audio") || contentType.contains("flash")); if (!isMedia) { type = JNT_EDITABLE_FILE; } } // in case of the file name ends with .xml.generated we should have no type. if (StringUtils.endsWith(fileObject.getName().toString(), ".xml.generated")) { type = null; } return type != null ? type : super.getDataType(fileObject); }