Search in sources :

Example 1 with Resource

use of org.asqatasun.contentadapter.Resource 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 2 with Resource

use of org.asqatasun.contentadapter.Resource in project Asqatasun by Asqatasun.

the class JSContentAdapterImpl method endDocument.

/**
     * Event fired at the end of the document parse
     *
     * @throws SAXException
     * @see org.xml.sax.ContentHandler#endDocument()
     */
@Override
public void endDocument() throws SAXException {
    if (resource != null) {
        resource.addAllResource(jsVector);
        for (Object object : resource.getResourceSet()) {
            Resource r = (Resource) object;
            if (r.getResource() != null) {
                parser.setResource((Resource) r);
                parser.run();
                jsSet.add(parser.getResult());
            }
        }
    }
}
Also used : Resource(org.asqatasun.contentadapter.Resource)

Example 3 with Resource

use of org.asqatasun.contentadapter.Resource 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 4 with Resource

use of org.asqatasun.contentadapter.Resource 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

Resource (org.asqatasun.contentadapter.Resource)4 StylesheetContent (org.asqatasun.entity.audit.StylesheetContent)3 Element (org.jsoup.nodes.Element)2 ExternalRsrc (org.asqatasun.contentadapter.util.ExternalRsrc)1 InlineRsrc (org.asqatasun.contentadapter.util.InlineRsrc)1 LocalRsrc (org.asqatasun.contentadapter.util.LocalRsrc)1