Java Code Examples for net.htmlparser.jericho.Source#getFirstElement()
The following examples show how to use
net.htmlparser.jericho.Source#getFirstElement() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StyleEditor.java From weblaf with GNU General Public License v3.0 | 6 votes |
protected void loadFirstResource ( final List<ClassResource> resources, final List<String> xmlContent, final List<String> xmlNames, final List<ClassResource> xmlFiles ) throws IOException { final ClassResource rf = resources.get ( 0 ); final Source xmlSource = new Source ( ReflectUtils.getClassSafely ( rf.getClassName () ).getResource ( rf.getPath () ) ); xmlSource.setLogger ( null ); xmlSource.fullSequentialParse (); final Element baseClassTag = xmlSource.getFirstElement ( SkinInfoConverter.CLASS_NODE ); final String baseClass = baseClassTag != null ? baseClassTag.getContent ().toString () : null; for ( final Element includeTag : xmlSource.getAllElements ( SkinInfoConverter.INCLUDE_NODE ) ) { final String includeClass = includeTag.getAttributeValue ( SkinInfoConverter.NEAR_CLASS_ATTRIBUTE ); final String finalClass = includeClass != null ? includeClass : baseClass; final String src = includeTag.getContent ().toString (); resources.add ( new ClassResource ( finalClass, src ) ); } xmlContent.add ( xmlSource.toString () ); xmlNames.add ( new File ( rf.getPath () ).getName () ); xmlFiles.add ( rf ); resources.remove ( 0 ); }
Example 2
Source File: HtAccessScanner.java From zap-extensions with Apache License 2.0 | 5 votes |
@Override public boolean isFalsePositive(HttpMessage msg) { if (msg.getResponseBody().length() == 0) { // No content return true; } if (msg.getResponseHeader().isXml()) { // Pretty unlikely to be an htaccess file return true; } if (msg.getResponseHeader().isJson()) { // Pretty unlikely to be an htaccess file return true; } if (msg.getResponseHeader().isHtml()) { // Double check it does really look like HTML try { Source src = new Source(msg.getResponseBody().toString()); if (src.getFirstElement(HTMLElementName.HTML) != null) { // Yep, it really looks like HTML return true; } } catch (Exception e) { // Ignore exceptions - they indicate its probably not really HTML } } return false; }
Example 3
Source File: ModernAppDetectionScanRule.java From zap-extensions with Apache License 2.0 | 4 votes |
@Override public void scanHttpResponseReceive(HttpMessage msg, int id, Source source) { if (!msg.getResponseHeader().isHtml()) { // Only check HTML responses } String evidence = null; String otherInfo = null; List<Element> links = source.getAllElements(HTMLElementName.A); if (links.size() == 0) { // if no links but there are scripts then thats another indication List<Element> scripts = source.getAllElements(HTMLElementName.SCRIPT); if (scripts.size() > 0) { evidence = scripts.get(0).toString(); otherInfo = Constant.messages.getString(MESSAGE_PREFIX + "other.nolinks"); } } else { // check all of the links for (Element link : links) { String href = link.getAttributeValue("href"); if (href == null || href.length() == 0 || href.equals("#")) { evidence = link.toString(); otherInfo = Constant.messages.getString(MESSAGE_PREFIX + "other.links"); break; } String target = link.getAttributeValue("target"); if (target != null && target.equals("_self")) { evidence = link.toString(); otherInfo = Constant.messages.getString(MESSAGE_PREFIX + "other.self"); break; } } } if (evidence == null) { Element noScript = source.getFirstElement(HTMLElementName.NOSCRIPT); if (noScript != null) { // Its an indication the app works differently with JavaScript evidence = noScript.toString(); otherInfo = Constant.messages.getString(MESSAGE_PREFIX + "other.noscript"); } } if (evidence != null && evidence.length() > 0) { // we found something newAlert() .setRisk(Alert.RISK_INFO) .setConfidence(Alert.CONFIDENCE_MEDIUM) .setDescription(getDescription()) .setOtherInfo(otherInfo) .setSolution(getSolution()) .setEvidence(evidence) .raise(); } }