final MarinerPageContext pageContext = getPageContext(context);
// check the src attribute
final String src = getAttribute(XDIMEAttribute.SRC, attributes);
ScriptAssetReference scriptReference = null;
if (src != null) {
// Note:ATM script element is in the MCS namespace so there is no use
// of having a srctype attribute.
//
// final String srcType =
// getAttribute(XDIMEAttribute.SRC_TYPE, attributes);
// if (srcType != null && !srcType.equals("")) {
// // @to do find out what the srctype should be for mscr files
// throw new XDIMEException(
// "Invalid source type. Found: " + srcType + " expected: ");
// }
scriptReference = getScriptAssetReference(src, pageContext);
if (scriptReference == null) {
LOGGER.warn("cannot-create-script-asset-reference-for-url",
src);
}
}
// set the attributes
scriptAttributes = new ScriptAttributes();
final String id = getAttribute(XDIMEAttribute.ID, attributes);
scriptAttributes.setId(id);
if (scriptReference == null) {
// Ensure that type="text/javascript" which is the only value we
// currently support.
final String type = attributes.getValue("", "type");
if (type != null && !"text/javascript".equals(type)) {
throw new IllegalArgumentException(EXCEPTION_LOCALIZER.format(
"script-must-have-text-javascript"));
}
scriptAttributes.setType("text/javascript");
} else {
scriptAttributes.setScriptReference(scriptReference);
final ScriptAsset scriptAsset = scriptReference.getScriptAsset();
scriptAttributes.setCharSet(scriptAsset.getCharacterSet());
scriptAttributes.setLanguage(scriptAsset.getProgrammingLanguage());
scriptAttributes.setType(scriptAsset.getMimeType());
}