use of org.asqatasun.entity.audit.StylesheetContent in project Asqatasun by Asqatasun.
the class CSSJsoupPhlocContentAdapterImpl method adaptLocaleCSS.
/**
* Retrieve css content and adapt it for each locale resource
*/
private void adaptLocaleCSS() {
Set<Long> relatedCssIdSet = new HashSet<>();
for (Element el : localeCssElements) {
Resource cssResource;
String rawCss = el.data();
if (!StringUtils.isBlank(rawCss)) {
cssResource = new CSSResourceImpl(rawCss, 0, new LocalRsrc());
StylesheetContent cssContent = getStylesheetFromLocaleResource(cssResource.getResource());
adaptContent(cssContent, cssResource, getCurrentResourcePath(el.baseUri()), getListOfMediaFromAttributeValue(el));
relatedCssIdSet.add(getContentDataService().saveOrUpdate(cssContent).getId());
}
}
getContentDataService().saveContentRelationShip(getSSP(), relatedCssIdSet);
}
use of org.asqatasun.entity.audit.StylesheetContent in project Asqatasun by Asqatasun.
the class AbstractPageRuleCssImplementation method addCssOnErrorRemarks.
/**
* Each not adapted css generates a process remark to indicate that
* some selectors haven't been tested
*
* @param styleSheetsOnError
* @param testSolutionHandler
* @param processRemarkService
*/
private void addCssOnErrorRemarks(Collection<StylesheetContent> styleSheetsOnError, TestSolutionHandler testSolutionHandler, ProcessRemarkService processRemarkService) {
for (StylesheetContent stylesheetContent : styleSheetsOnError) {
List<EvidenceElement> evidenceElementList = new ArrayList<EvidenceElement>();
evidenceElementList.add(processRemarkService.getEvidenceElement(ProcessRemarkService.DEFAULT_EVIDENCE, stylesheetContent.getURI()));
processRemarkService.addSourceCodeRemarkOnElement(TestSolution.NEED_MORE_INFO, null, UNTESTED_RESOURCE_MSG_CODE, evidenceElementList);
}
testSolutionHandler.addTestSolution(TestSolution.NEED_MORE_INFO);
}
use of org.asqatasun.entity.audit.StylesheetContent in project Asqatasun by Asqatasun.
the class CSSJsoupPhlocContentAdapterImpl method adaptInlineCSS.
/**
* Retrieve css content and adapt it for each inline resource
*/
private void adaptInlineCSS() {
Set<Long> relatedCssIdSet = new HashSet<>();
for (Element el : inlineCssElements) {
String attributeValue = el.attr("style");
if (StringUtils.isNotBlank(attributeValue)) {
Resource cssResource = new CSSResourceImpl(el.nodeName() + "{" + attributeValue + "}", 0, new InlineRsrc());
StylesheetContent cssContent = getStylesheetFromInlineResource(cssResource.getResource());
adaptContent(cssContent, cssResource, getCurrentResourcePath(el.baseUri()), null);
relatedCssIdSet.add(getContentDataService().saveOrUpdate(cssContent).getId());
}
}
getContentDataService().saveContentRelationShip(getSSP(), relatedCssIdSet);
}
use of org.asqatasun.entity.audit.StylesheetContent in project Asqatasun by Asqatasun.
the class CSSJsoupPhlocContentAdapterImpl method initContext.
public void initContext() {
relatedExternalCssSet.clear();
// This list is not supposed to increase at this step.
if (externalCssSet.isEmpty()) {
LOGGER.debug("Starting retrieving external stylesheet " + externalCSSRetriever.getClass() + " " + getSSP().getURI());
externalCssSet.addAll(externalCSSRetriever.getExternalCSS(getSSP()));
for (StylesheetContent sc : externalCssSet) {
LOGGER.debug("The external stylesheet " + sc.getURI() + " has been retrieved");
}
} else {
for (StylesheetContent sc : externalCssSet) {
LOGGER.debug("StartDocument : The external stylesheet " + sc.getURI() + " has been retrieved");
}
}
}
use of org.asqatasun.entity.audit.StylesheetContent in project Asqatasun by Asqatasun.
the class CSSJsoupPhlocContentAdapterImpl method getExternalResourceAndAdapt.
/**
* Downloads an external resource and returns a Resource instance or null
* if the download has failed
* @param path
* @param mediaAttributeValue
* @return
*/
private boolean getExternalResourceAndAdapt(String path, @Nullable List<CSSMediaQuery> mediaList) {
if (StringUtils.isBlank(path)) {
return false;
}
// When an external css is found on the html, we start by getting the
// associated resource from the fetched Stylesheet and we populate the
// set of relatedExternalCssSet (needed to create the relation between the
// SSP and the css at the end of the adaptation)
StylesheetContent stylesheetContent = getExternalStylesheet(path);
if (stylesheetContent != null) {
if (stylesheetContent.getAdaptedContent() == null) {
Resource localResource;
localResource = new CSSResourceImpl(stylesheetContent.getSource(), 0, new ExternalRsrc());
currentLocalResourcePath = getCurrentResourcePath(path);
adaptContent(stylesheetContent, localResource, currentLocalResourcePath, mediaList);
}
relatedExternalCssSet.add(stylesheetContent);
LOGGER.debug("encountered external css : " + path + " " + relatedExternalCssSet.size() + " in " + getSSP().getURI());
return true;
}
return false;
}
Aggregations