Search in sources :

Example 1 with CSSMediaQuery

use of com.phloc.css.decl.CSSMediaQuery in project Asqatasun by Asqatasun.

the class CSSJsoupPhlocContentAdapterImpl method adaptExternalCss.

/**
     * Adapt the external css. 
     */
private void adaptExternalCss() {
    for (Element el : externalCssElements) {
        List<CSSMediaQuery> mediaList = getListOfMediaFromAttributeValue(el);
        String resourcePath = el.attr("abs:href");
        getExternalResourceAndAdapt(resourcePath, mediaList);
    }
    Set<Long> relatedCssIdSet = new HashSet<>();
    // At the end of the document we link each external css that are
    // already fetched and that have been encountered in the SSP to the SSP.
    LOGGER.debug("Found " + relatedExternalCssSet.size() + " external css in " + getSSP().getURI());
    for (StylesheetContent cssContent : relatedExternalCssSet) {
        if (cssContent.getAdaptedContent() == null) {
            cssContent.setAdaptedContent(CSS_ON_ERROR);
        }
        LOGGER.debug("Create relation between " + getSSP().getURI() + " and " + cssContent.getURI());
        // to avoid fatal error when persist weird sourceCode
        try {
            // with the current SSP
            if (cssContent.getId() == null) {
                cssContent = (StylesheetContent) getContentDataService().saveOrUpdate(cssContent);
            }
            relatedCssIdSet.add(cssContent.getId());
        } catch (PersistenceException | DataException pe) {
            adaptedContentOnError(cssContent, relatedCssIdSet);
        }
    }
    getContentDataService().saveContentRelationShip(getSSP(), relatedCssIdSet);
}
Also used : CSSMediaQuery(com.phloc.css.decl.CSSMediaQuery) StylesheetContent(org.asqatasun.entity.audit.StylesheetContent) DataException(org.hibernate.exception.DataException) Element(org.jsoup.nodes.Element) PersistenceException(javax.persistence.PersistenceException)

Aggregations

CSSMediaQuery (com.phloc.css.decl.CSSMediaQuery)1 PersistenceException (javax.persistence.PersistenceException)1 StylesheetContent (org.asqatasun.entity.audit.StylesheetContent)1 DataException (org.hibernate.exception.DataException)1 Element (org.jsoup.nodes.Element)1