Search in sources :

Example 1 with StylesheetContent

use of org.asqatasun.entity.audit.StylesheetContent in project Asqatasun by Asqatasun.

the class CSSJsoupPhlocContentAdapterImpl method getStylesheetFromInlineResource.

/**
     * 
     * @param resource
     * @return 
     */
private StylesheetContent getStylesheetFromInlineResource(String resource) {
    inlineCssCounter++;
    StylesheetContent cssContent = getContentDataService().getStylesheetContent(new Date(), getSSP().getURI() + INLINE_CSS_PREFIX + inlineCssCounter, getSSP(), resource, 200);
    cssContent.setAudit(getSSP().getAudit());
    return cssContent;
}
Also used : StylesheetContent(org.asqatasun.entity.audit.StylesheetContent)

Example 2 with StylesheetContent

use of org.asqatasun.entity.audit.StylesheetContent in project Asqatasun by Asqatasun.

the class CSSJsoupPhlocContentAdapterImpl method createNewExternalStyleSheet.

/**
     * 
     * @param cssAbsolutePath
     * @return 
     */
private StylesheetContent createNewExternalStyleSheet(String cssAbsolutePath) {
    LOGGER.debug("createNewExternalStyleSheet " + cssAbsolutePath);
    String cssSourceCode;
    try {
        cssSourceCode = HttpRequestHandler.getInstance().getHttpContent(cssAbsolutePath);
    } catch (URISyntaxException ex) {
        LOGGER.debug("the resource " + cssAbsolutePath + " can't be retrieved : URISyntaxException");
        cssSourceCode = CSS_ON_ERROR;
    } catch (UnknownHostException uhe) {
        LOGGER.debug("the resource " + cssAbsolutePath + " can't be retrieved : UnknownHostException");
        cssSourceCode = CSS_ON_ERROR;
    } catch (IOException ioe) {
        LOGGER.debug("the resource " + cssAbsolutePath + " can't be retrieved : IOException");
        try {
            cssSourceCode = FileUtils.readFileToString(new File(cssAbsolutePath));
        } catch (IOException ioe2) {
            LOGGER.debug("the resource " + cssAbsolutePath + " can't be retrieved : IOException");
            cssSourceCode = CSS_ON_ERROR;
        }
    } catch (IllegalCharsetNameException icne) {
        LOGGER.debug("the resource " + cssAbsolutePath + " can't be retrieved : IllegalCharsetNameException");
        cssSourceCode = CSS_ON_ERROR;
    } catch (IllegalStateException ise) {
        LOGGER.debug("the resource " + cssAbsolutePath + " can't be retrieved : IllegalStateException");
        cssSourceCode = CSS_ON_ERROR;
    }
    if (StringUtils.isBlank(cssSourceCode)) {
        LOGGER.debug("the resource " + cssAbsolutePath + " has an empty content");
        cssSourceCode = CSS_ON_ERROR;
    }
    StylesheetContent cssContent = getContentDataService().getStylesheetContent(new Date(), cssAbsolutePath, getSSP(), cssSourceCode, 200);
    cssContent.setAudit(getSSP().getAudit());
    externalCssSet.add(cssContent);
    // Some stylesheet may be retrieved during the adaptation. In this case
    // these new css are added "manually" to the externalCssRetriever which
    // is supposed to request the bdd once at the beginning of the adapting
    // phasis.
    externalCSSRetriever.addNewStylesheetContent(getSSP(), cssContent);
    return cssContent;
}
Also used : IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) StylesheetContent(org.asqatasun.entity.audit.StylesheetContent) UnknownHostException(java.net.UnknownHostException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) File(java.io.File)

Example 3 with StylesheetContent

use of org.asqatasun.entity.audit.StylesheetContent 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)

Example 4 with StylesheetContent

use of org.asqatasun.entity.audit.StylesheetContent in project Asqatasun by Asqatasun.

the class ExternalCSSRetrieverImpl method addNewStylesheetContent.

@Override
public void addNewStylesheetContent(SSP ssp, StylesheetContent stylesheetContent) {
    if (!externalCssMap.containsKey(ssp.getAudit().getId())) {
        LOGGER.debug(" the local external css Map doesn't contain any entry for" + "the ssp Id " + ssp.getAudit().getId());
        return;
    }
    for (StylesheetContent css : externalCssMap.get(ssp.getAudit().getId())) {
        if (stylesheetContent.getURI().equals(css.getURI())) {
            LOGGER.debug("the css " + stylesheetContent.getURI() + " already exists in the externalCssMap");
            return;
        }
    }
    externalCssMap.get(ssp.getAudit().getId()).add(stylesheetContent);
    LOGGER.debug(stylesheetContent.getURI() + " has been added to the externalCssMap");
}
Also used : StylesheetContent(org.asqatasun.entity.audit.StylesheetContent)

Example 5 with StylesheetContent

use of org.asqatasun.entity.audit.StylesheetContent in project Asqatasun by Asqatasun.

the class CSSJsoupPhlocContentAdapterImpl method getStylesheetFromLocaleResource.

/**
     * 
     * @param resource
     * @return 
     */
private StylesheetContent getStylesheetFromLocaleResource(String resource) {
    localeCssCounter++;
    StylesheetContent cssContent = getContentDataService().getStylesheetContent(new Date(), getSSP().getURI() + LOCALE_CSS_PREFIX + localeCssCounter, getSSP(), resource, 200);
    cssContent.setAudit(getSSP().getAudit());
    return cssContent;
}
Also used : StylesheetContent(org.asqatasun.entity.audit.StylesheetContent)

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