private static CleanerProperties createCleanerProperties() { final CleanerProperties properties = new CleanerProperties() { // CHECKSTYLE:OFF analogous to the implementation that gets fixed here. ITagInfoProvider tagInfoProvider = new DefaultTagProvider(); // NOPMD // CHECKSTYLE:ON @Override public ITagInfoProvider getTagInfoProvider() { return tagInfoProvider; } }; properties.setOmitHtmlEnvelope(true); properties.setOmitDoctypeDeclaration(true); properties.setOmitXmlDeclaration(true); properties.setUseEmptyElementTags(true); return properties; }
/** * @param configuration the configuration to use for the cleaning * @return the default {@link CleanerProperties} to be used for cleaning. */ private CleanerProperties getDefaultCleanerProperties(HTMLCleanerConfiguration configuration) { CleanerProperties defaultProperties = new CleanerProperties(); defaultProperties.setOmitUnknownTags(true); defaultProperties.setNamespacesAware(true); // HTML Cleaner uses the compact notation by default but we don't want that since: // - it's more work and not required since not compact notation is valid XHTML // - expanded elements can also be rendered fine in browsers that only support HTML. defaultProperties.setUseEmptyElementTags(false); // Wrap script and style content in CDATA blocks defaultProperties.setUseCdataForScriptAndStyle(true); // Handle the NAMESPACE_AWARE configuration property String param = configuration.getParameters().get(HTMLCleanerConfiguration.NAMESPACES_AWARE); boolean namespacesAware = (param != null) ? Boolean.parseBoolean(param) : defaultProperties.isNamespacesAware(); defaultProperties.setNamespacesAware(namespacesAware); return defaultProperties; }
props.setUseEmptyElementTags( toBoolean(useEmptyElementTags) );
props.setUseEmptyElementTags(toBoolean(useEmptyElementTags));
defaultProperties.setUseEmptyElementTags(false);
props.setOmitDoctypeDeclaration(this.omitdoctypedecl); props.setOmitHtmlEnvelope(this.omithtmlenvelope); props.setUseEmptyElementTags(this.useemptyelementtags); props.setAllowMultiWordAttributes(this.allowmultiwordattributes); props.setAllowHtmlInsideAttributes(this.allowhtmlinsideattributes);
/** * Cleans the relevant file and generates a valid XML file ready for processing to Sel 2 java File. * * @param absoluteFilename - name of the file to convert. * @return String - location of the converted file. */ public String convertToXML(String absoluteFilename) throws Exception { FileHandler fromSelIDE = new FileHandler(absoluteFilename); FileHandler toXML = new FileHandler(System.getProperty("java.io.tmpdir") + File.separator + fromSelIDE.getFileName() + ".xml", true); if (fromSelIDE.getFile().isDirectory()) { LOGGER.error("Cannot convert directory {} into a Selenium Test!", fromSelIDE.getFileName()); return null; } //Clean up html so that we can read it as XML properly HtmlCleaner cleaner = new HtmlCleaner(); CleanerProperties XMLPrefs = cleaner.getProperties(); XMLPrefs.setUseEmptyElementTags(true); XMLPrefs.setTranslateSpecialEntities(true); XMLPrefs.setTransResCharsToNCR(true); XMLPrefs.setOmitComments(true); XMLPrefs.setOmitComments(true); XMLPrefs.setOmitDoctypeDeclaration(true); XMLPrefs.setNamespacesAware(false); TagNode tagNode = new HtmlCleaner(XMLPrefs).clean(fromSelIDE.getFile()); new PrettyXmlSerializer(XMLPrefs).writeToStream(tagNode, toXML.getWritableFileOutputStream(), "utf-8"); toXML.close(); return toXML.getAbsoluteFile(); }
props.setUseCdataForScriptAndStyle(false); props.setRecognizeUnicodeChars(true); props.setUseEmptyElementTags(true); props.setAdvancedXmlEscape(true); props.setTranslateSpecialEntities(false);