use of org.asqatasun.entity.audit.SSP in project Asqatasun by Asqatasun.
the class ContentsAdapterImpl method run.
private Collection<Content> run(Collection<Content> contentList) {
Collection<Content> localResult = new ArrayList<>();
for (Content content : contentList) {
// We only handle here the fetched content (HttpStatus=200)
if (content instanceof SSP && content.getHttpStatusCode() == 200) {
Logger.getLogger(this.getClass()).debug("Adapting " + content.getURI());
SSP ssp = (SSP) content;
ssp.setDoctype(DocumentCaseInsensitiveAdapter.extractDoctypeDeclaration(ssp.getSource()));
String dirtyHtml;
if (xmlizeContent) {
dirtyHtml = DocumentCaseInsensitiveAdapter.removeDoctypeDeclaration(ssp.getSource());
} else {
dirtyHtml = ssp.getSource();
}
htmlCleaner.setDirtyHTML(dirtyHtml);
htmlCleaner.run();
ssp.setAdaptedContent(htmlCleaner.getResult());
htmlCleaner.setDirtyHTML(null);
if (writeCleanHtmlInFile) {
writeCleanDomInFile(ssp);
}
if (parseAndRetrievelRelatedContent) {
htmlParser.setSSP(ssp);
htmlParser.run();
} else {
Logger.getLogger(this.getClass()).debug("no Html parse executed for the current audit");
}
if (xmlizeContent) {
AbstractHTMLCleaner cleaner = new HTMLCleanerImpl();
cleaner.setDirtyHTML(ssp.getAdaptedContent());
cleaner.run();
ssp.setAdaptedContent(DocumentCaseInsensitiveAdapter.removeLowerCaseTags(cleaner.getResult()));
}
localResult.add(ssp);
}
}
return localResult;
}
use of org.asqatasun.entity.audit.SSP in project Asqatasun by Asqatasun.
the class DoctypePositionChecker method doCheck.
@Override
protected void doCheck(SSPHandler sspHandler, Elements elements, TestSolutionHandler testSolutionHandler) {
SSP ssp = sspHandler.getSSP();
// not applicable
if (StringUtils.isBlank(ssp.getDoctype())) {
testSolutionHandler.addTestSolution(TestSolution.NOT_APPLICABLE);
return;
}
String sourcePage = ssp.getAdaptedContent();
int indexOfDoctype = StringUtils.indexOfIgnoreCase(sourcePage, DOCTYPE_KEY);
int indexOfHtmlTag = StringUtils.indexOfIgnoreCase(sourcePage, HTML_ELEMENT_KEY);
if (indexOfHtmlTag < indexOfDoctype || StringUtils.indexOfIgnoreCase(sourcePage, DOCTYPE_KEY, indexOfHtmlTag) != -1) {
testSolutionHandler.addTestSolution(getFailureSolution());
addProcessRemark(getFailureSolution(), BAD_DOCTYPE_LOCATION_MSG);
} else {
testSolutionHandler.addTestSolution(getSuccessSolution());
}
}
use of org.asqatasun.entity.audit.SSP in project Asqatasun by Asqatasun.
the class AbstractRuleImplementationTestCase method setUpClass.
/**
*
*/
private void setUpClass() {
Test test = TEST_FACTORY.create();
test.setCode(this.getName());
test.setRuleClassName(ruleImplementationClassName);
test.setRuleArchiveName("MockArchiveName");
testList.add(test);
URL src = null;
LOGGER.info("setUpClass()");
for (WebResource webResource : webResourceMap.values()) {
LOGGER.info("webResource.getURL() " + webResource.getURL());
contentMap.put(webResource, CONTENT_LOADER_SERVICE.loadContent(webResource));
if (relatedContentMap.get(webResource) != null) {
for (String contentUrl : relatedContentMap.get(webResource)) {
if (contentMap.get(webResource).get(0) instanceof SSP) {
SSP ssp = (SSP) contentMap.get(webResource).get(0);
try {
src = new URL(ssp.getURI());
URL_IDENTIFIER.setUrl(src);
} catch (MalformedURLException ex) {
LOGGER.error(ex);
}
URL_IDENTIFIER.setUrl(src);
String relatedContentUrl = URL_IDENTIFIER.resolve(contentUrl).toExternalForm();
if (isContentCss(relatedContentUrl)) {
ssp.addRelatedContent(CONTENT_FACTORY.createStylesheetContent(new Date(), relatedContentUrl, ssp, getTextContent(relatedContentUrl), 200));
} else {
ssp.addRelatedContent(CONTENT_FACTORY.createImageContent(new Date(), relatedContentUrl, ssp, getBinaryImage(relatedContentUrl), 200));
}
}
}
}
contentMap.put(webResource, (List<Content>) CONTENT_ADAPTER_SERVICE.adaptContent((contentMap.get(webResource))));
}
}
use of org.asqatasun.entity.audit.SSP in project Asqatasun by Asqatasun.
the class ProcessorServiceImpl method process.
@Override
public Collection<ProcessResult> process(Collection<Content> contentList, Collection<Test> testList) {
Collection<ProcessResult> processResultList = new ArrayList<>();
Processor processor = processorFactory.create();
for (Content content : contentList) {
if (content instanceof SSP) {
processor.setSSP((SSP) content);
for (Test test : testList) {
if (!test.getNoProcess()) {
RuleImplementation ruleImplementation = ruleImplementationLoaderService.loadRuleImplementation(test);
processor.setRuleImplementation(ruleImplementation);
processor.run();
processResultList.add(processor.getResult());
}
}
}
}
return processResultList;
}
use of org.asqatasun.entity.audit.SSP in project Asqatasun by Asqatasun.
the class CrawlerImplTest method testIsRelCanonicalPageWithoutRelCanonical.
/**
* Test of isRelCanonicalPage method, of class CrawlerImpl. In this test,
* the rel canonical is not set.
*/
public void testIsRelCanonicalPageWithoutRelCanonical() {
System.out.println("isRelCanonicalPageWithoutRelCanonical");
SSP ssp = new MockSSP();
ssp.setURI(URL);
StringBuilder strb = new StringBuilder();
strb.append("<html>");
strb.append("<head>");
strb.append("</head>");
strb.append("</html>");
ssp.setSource(strb.toString());
CrawlerImpl instance = new CrawlerImpl();
boolean result = instance.isRelCanonicalPage(ssp);
assertFalse(result);
}
Aggregations