use of fi.otavanopisto.muikku.plugins.material.fieldmeta.FieldMeta in project muikku by otavanopisto.
the class MaterialFieldCollection method parseFields.
public void parseFields(String html) {
if (!materialFields.isEmpty()) {
materialFields.clear();
}
if (StringUtils.isNotBlank(html)) {
StringReader htmlReader = new StringReader(html);
try {
DOMParser parser = new DOMParser();
InputSource inputSource = new InputSource(htmlReader);
parser.parse(inputSource);
Document document = parser.getDocument();
NodeList objectNodeList = document.getElementsByTagName("object");
for (int i = 0, l = objectNodeList.getLength(); i < l; i++) {
Node objectNode = objectNodeList.item(i);
if (objectNode instanceof Element) {
Element objectElement = (Element) objectNode;
if (isMuikkuField(objectElement)) {
String fieldType = objectElement.getAttribute("type");
NodeList paramNodes = objectElement.getElementsByTagName("param");
String content = null;
for (int j = 0, jl = paramNodes.getLength(); j < jl; j++) {
Node paramNode = paramNodes.item(j);
if (paramNode instanceof Element) {
Element paramElement = (Element) paramNode;
if ("content".equals(paramElement.getAttribute("name"))) {
content = paramElement.getAttribute("value");
break;
}
}
}
if (StringUtils.isNotBlank(content)) {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
FieldMeta fieldMeta = objectMapper.readValue(content, FieldMeta.class);
materialFields.put(fieldMeta.getName(), new MaterialField(fieldMeta.getName(), fieldType, content));
}
}
}
}
} catch (Exception e) {
// TODO Proper exception handling
throw new IllegalArgumentException("Malformed document structure: " + html);
} finally {
htmlReader.close();
}
}
}
Aggregations