Search in sources :

Example 6 with StylesheetContent

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);
}
Also used : StylesheetContent(org.asqatasun.entity.audit.StylesheetContent) LocalRsrc(org.asqatasun.contentadapter.util.LocalRsrc) Element(org.jsoup.nodes.Element) Resource(org.asqatasun.contentadapter.Resource)

Example 7 with StylesheetContent

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);
}
Also used : StylesheetContent(org.asqatasun.entity.audit.StylesheetContent) EvidenceElement(org.asqatasun.entity.audit.EvidenceElement) ArrayList(java.util.ArrayList)

Example 8 with StylesheetContent

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);
}
Also used : StylesheetContent(org.asqatasun.entity.audit.StylesheetContent) Element(org.jsoup.nodes.Element) Resource(org.asqatasun.contentadapter.Resource) InlineRsrc(org.asqatasun.contentadapter.util.InlineRsrc)

Example 9 with StylesheetContent

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");
        }
    }
}
Also used : StylesheetContent(org.asqatasun.entity.audit.StylesheetContent)

Example 10 with StylesheetContent

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;
}
Also used : StylesheetContent(org.asqatasun.entity.audit.StylesheetContent) ExternalRsrc(org.asqatasun.contentadapter.util.ExternalRsrc) Resource(org.asqatasun.contentadapter.Resource)

Aggregations

StylesheetContent (org.asqatasun.entity.audit.StylesheetContent)10 Resource (org.asqatasun.contentadapter.Resource)3 Element (org.jsoup.nodes.Element)3 CSSMediaQuery (com.phloc.css.decl.CSSMediaQuery)1 File (java.io.File)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 UnknownHostException (java.net.UnknownHostException)1 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)1 ArrayList (java.util.ArrayList)1 PersistenceException (javax.persistence.PersistenceException)1 ExternalRsrc (org.asqatasun.contentadapter.util.ExternalRsrc)1 InlineRsrc (org.asqatasun.contentadapter.util.InlineRsrc)1 LocalRsrc (org.asqatasun.contentadapter.util.LocalRsrc)1 EvidenceElement (org.asqatasun.entity.audit.EvidenceElement)1 DataException (org.hibernate.exception.DataException)1