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);
}
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());
}
}
}
}
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);
}
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;
}
Aggregations