List of usage examples for org.apache.commons.lang CharEncoding UTF_8
String UTF_8
To view the source code for org.apache.commons.lang CharEncoding UTF_8.
Click Source Link
Eight-bit Unicode Transformation Format.
From source file:org.sonar.plugins.web.rules.DefaultWebProfile.java
@Override public RulesProfile createProfile(ValidationMessages validation) { Reader reader = new InputStreamReader( DefaultWebProfile.class.getClassLoader().getResourceAsStream(ALL_RULES), Charset.forName(CharEncoding.UTF_8)); try {/*from ww w . j a v a 2 s . c o m*/ RulesProfile profile = profileParser.parse(reader, validation); profile.setDefaultProfile(true); return profile; } finally { IOUtils.closeQuietly(reader); } }
From source file:org.sonar.plugins.web.rules.JSFProfile.java
@Override public RulesProfile createProfile(ValidationMessages validationMessages) { Reader reader = new InputStreamReader( DefaultWebProfile.class.getClassLoader().getResourceAsStream(DefaultWebProfile.ALL_RULES), Charset.forName(CharEncoding.UTF_8)); RulesProfile profile = profileParser.parse(reader, validationMessages); profile.setName("JSF Profile"); // find rules not applicable for JSF List<ActiveRule> removeRules = new ArrayList<ActiveRule>(); for (ActiveRule activeRule : profile.getActiveRules()) { if (ArrayUtils.contains(notSupportedRules, activeRule.getConfigKey())) { removeRules.add(activeRule); }/* ww w . j a v a2s. c o m*/ } // remove not applicable rules profile.getActiveRules().removeAll(removeRules); return profile; }
From source file:org.sonar.plugins.web.rules.StrutsProfile.java
/** * Create a profile as a copy of the default web profile but add the OGNL Expression check. *//*w ww .j a v a 2s .c om*/ @Override public RulesProfile createProfile(ValidationMessages validation) { Reader reader = new InputStreamReader(StrutsProfile.class.getClassLoader().getResourceAsStream(ALL_RULES), Charset.forName(CharEncoding.UTF_8)); try { RulesProfile profile = profileParser.parse(reader, validation); profile.setName("Default Struts Profile"); // add OGNLExpressionCheck profile.activateRule(rulefinder.findByKey(WebRulesRepository.REPOSITORY_KEY, "OGNLExpressionCheck"), null); // remove UnifiedExpressionCheck for (ActiveRule activeRule : profile.getActiveRules()) { if (StringUtils.equalsIgnoreCase("UnifiedExpressionCheck", activeRule.getConfigKey())) { profile.removeActiveRule(activeRule); break; } } profile.setDefaultProfile(false); return profile; } finally { IOUtils.closeQuietly(reader); } }
From source file:org.sonar.server.configuration.Backup.java
protected SonarConfig getSonarConfigFromXml(String xml) { try {/*w w w .j a v a2 s .c o m*/ XStream xStream = getConfiguredXstream(); // Backward compatibility with old levels xml = xml.replace("<level><![CDATA[ERROR]]></level>", "<level><![CDATA[MAJOR]]></level>"); xml = xml.replace("<level><![CDATA[WARNING]]></level>", "<level><![CDATA[INFO]]></level>"); InputStream inputStream = IOUtils.toInputStream(xml, CharEncoding.UTF_8); return (SonarConfig) xStream.fromXML(inputStream); } catch (IOException e) { throw new RuntimeException("Can't read xml", e); } }
From source file:org.sonar.server.configuration.BackupTest.java
private String getFileFromClasspath(String file) { InputStream input = null;//from w w w . j a v a2 s . co m try { input = getClass().getClassLoader() .getResourceAsStream("org/sonar/server/configuration/BackupTest/" + file); return IOUtils.toString(input, CharEncoding.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(input); } }
From source file:org.sonar.server.configuration.PropertiesBackupTest.java
@Test public void shouldImportMultilineProperties() throws Exception { setupData("shouldImportMultilineProperties"); new Backup(getSession()).doImportXml(FileUtils.readFileToString( TestUtils.getResource(getClass(), "backup-with-multiline-property.xml"), CharEncoding.UTF_8)); getSession().commit();// w w w. ja v a 2 s .c om Property property = getSession().getSingleResult(Property.class, "key", "sonar.multiline.secured"); assertThat(property.getValue(), startsWith("ONQwdcwcwwdadalkdmaiQGMqMVnhtAbhxwjjoVkHbWgx")); assertThat(property.getValue(), endsWith("mmmm")); }
From source file:org.sonar.server.mavendeployer.Artifact.java
private void savePom(File dir) throws IOException { File pom = new File(dir, getArtifactName() + ".pom"); FileUtils.writeStringToFile(pom, getPom(), CharEncoding.UTF_8); saveDigests(pom);/* w w w .j av a 2 s.c om*/ }
From source file:org.sonar.server.mavendeployer.Artifact.java
private void saveDigests(File file) throws IOException { String path = file.getAbsolutePath(); byte[] content = FileUtils.readFileToByteArray(file); FileUtils.writeStringToFile(new File(path + ".md5"), DigestUtils.md5Hex(content), CharEncoding.UTF_8); FileUtils.writeStringToFile(new File(path + ".sha1"), DigestUtils.shaHex(content), CharEncoding.UTF_8); }
From source file:org.sonar.server.mavendeployer.Artifact.java
protected void saveMetadata(File dir) throws IOException { File metadataFile = new File(dir.getParentFile(), "maven-metadata.xml"); FileUtils.writeStringToFile(metadataFile, getMetadata(), CharEncoding.UTF_8); }
From source file:org.sonar.server.platform.ClassLoaderUtils.java
/** * Finds directories and files within a given directory and its subdirectories. * * @param classLoader/*from w ww . j a v a2 s . c o m*/ * @param rootPath the root directory, for example org/sonar/sqale, or a file in this root directory, for example org/sonar/sqale/index.txt * @param predicate * @return a list of relative paths, for example {"org/sonar/sqale", "org/sonar/sqale/foo", "org/sonar/sqale/foo/bar.txt}. Never null. */ static Collection<String> listResources(ClassLoader classLoader, String rootPath, Predicate<String> predicate) { String jarPath = null; JarFile jar = null; try { Collection<String> paths = Lists.newArrayList(); URL root = classLoader.getResource(rootPath); if (root != null) { checkJarFile(root); // Path of the root directory // Examples : // org/sonar/sqale/index.txt -> rootDirectory is org/sonar/sqale // org/sonar/sqale/ -> rootDirectory is org/sonar/sqale // org/sonar/sqale -> rootDirectory is org/sonar/sqale String rootDirectory = rootPath; if (StringUtils.substringAfterLast(rootPath, "/").indexOf('.') >= 0) { rootDirectory = StringUtils.substringBeforeLast(rootPath, "/"); } //strip out only the JAR file jarPath = root.getPath().substring(5, root.getPath().indexOf("!")); jar = new JarFile(URLDecoder.decode(jarPath, CharEncoding.UTF_8)); Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { String name = entries.nextElement().getName(); if (name.startsWith(rootDirectory) && predicate.apply(name)) { paths.add(name); } } } return paths; } catch (Exception e) { throw Throwables.propagate(e); } finally { closeJar(jar, jarPath); } }