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