use of org.w3c.dom.NamedNodeMap in project OpenClinica by OpenClinica.
the class FSItemProcessor method processFieldSubmissionGroupItems.
private void processFieldSubmissionGroupItems(ArrayList<HashMap> listOfUploadFilePaths, Node repeatNode, Node itemNode, SubmissionContainer container, ItemGroup itemGroup) throws Exception {
String itemName;
Integer itemOrdinal = 1;
String itemValue;
// Node repeatGroupNode = itemNode.getParentNode();
if (repeatNode != null) {
final NamedNodeMap attributes = repeatNode.getAttributes();
// check to see if groupNode has any enketo attributes
for (int attrIndex = 0; attrIndex < attributes.getLength(); attrIndex++) {
if (attributes.item(attrIndex).getNodeName().equals(ENKETO_ORDINAL)) {
logger.debug("found enketo attribute");
logger.debug(attributes.item(attrIndex).getNodeName());
logger.debug(attributes.item(attrIndex).getNodeValue());
itemOrdinal = new Integer(attributes.item(attrIndex).getNodeValue());
}
}
} else {
itemOrdinal = 1;
}
FormLayout formLayout = container.getFormLayout();
CrfVersion crfVersion = crfVersionDao.findAllByCrfId(formLayout.getCrf().getCrfId()).get(0);
container.setCrfVersion(crfVersion);
Item item = null;
ItemGroupMetadata igm = null;
if (container.getRequestType() == FieldRequestTypeEnum.DELETE_FIELD) {
List<ItemGroupMetadata> igms = itemGroupMetadataDao.findByItemGroupCrfVersion(itemGroup.getItemGroupId(), crfVersion.getCrfVersionId());
for (ItemGroupMetadata ig : igms) {
ItemData existingItemData = itemDataDao.findByItemEventCrfOrdinal(ig.getItem().getItemId(), container.getEventCrf().getEventCrfId(), itemOrdinal);
// ItemData existingItemData = lookupFieldItemData(itemGroup, itemOrdinal, container);
if (existingItemData != null) {
existingItemData.setDeleted(true);
existingItemData.setValue("");
existingItemData.setOldStatus(existingItemData.getStatus());
existingItemData.setUserAccount(container.getUser());
existingItemData.setStatus(Status.AVAILABLE);
existingItemData.setUpdateId(container.getUser().getUserId());
existingItemData.setInstanceId(container.getInstanceId());
existingItemData = itemDataDao.saveOrUpdate(existingItemData);
resetSdvStatus(container);
// Close discrepancy notes
closeItemDiscrepancyNotes(container, existingItemData);
}
}
return;
}
// igm = itemGroupMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
// Item loop
QueryServiceHelperBean helperBean = new QueryServiceHelperBean();
if (queryService.getQueryAttribute(helperBean, itemNode) != null) {
queryService.process(helperBean, container, itemNode, itemOrdinal);
} else if (shouldProcessItemNode(itemNode)) {
itemName = itemNode.getNodeName().trim();
itemValue = itemNode.getTextContent();
item = itemDao.findByNameCrfId(itemNode.getNodeName(), crfVersion.getCrf().getCrfId());
if (item == null) {
logger.error("Failed to lookup item: '" + itemName + "'. Continuing with submission.");
}
ItemFormMetadata itemFormMetadata = itemFormMetadataDao.findByItemCrfVersion(item.getItemId(), crfVersion.getCrfVersionId());
// Convert space separated Enketo multiselect values to comma separated OC multiselect values
Integer responseTypeId = itemFormMetadata.getResponseSet().getResponseType().getResponseTypeId();
if (responseTypeId == 3 || responseTypeId == 7) {
itemValue = itemValue.replaceAll(" ", ",");
}
if (responseTypeId == 4) {
/*
* for (HashMap uploadFilePath : listOfUploadFilePaths) {
* if ((boolean) uploadFilePath.containsKey(itemValue) && itemValue != "") {
* itemValue = (String) uploadFilePath.get(itemValue);
* break;
* }
* }
*/
FormLayoutMedia media = formLayoutMediaDao.findByEventCrfIdAndFileName(container.getEventCrf().getEventCrfId(), itemValue);
if (media == null) {
media = new FormLayoutMedia();
}
media.setName(itemValue);
media.setFormLayout(formLayout);
media.setEventCrfId(container.getEventCrf().getEventCrfId());
media.setPath("/" + container.getStudy().getOc_oid() + "/");
formLayoutMediaDao.saveOrUpdate(media);
}
ItemData newItemData = createItemData(item, itemValue, itemOrdinal, container);
Errors itemErrors = validateItemData(newItemData, item, responseTypeId);
if (itemErrors.hasErrors()) {
container.getErrors().addAllErrors(itemErrors);
throw new Exception("Item validation error. Rolling back submission changes.");
}
ItemData existingItemData = itemDataDao.findByItemEventCrfOrdinal(item.getItemId(), container.getEventCrf().getEventCrfId(), itemOrdinal);
if (existingItemData == null) {
newItemData.setStatus(Status.UNAVAILABLE);
itemDataDao.saveOrUpdate(newItemData);
resetSdvStatus(container);
} else if (existingItemData.getValue().equals(newItemData.getValue())) {
} else {
// Existing item. Value changed. Update existing value.
existingItemData.setInstanceId(container.getInstanceId());
existingItemData.setValue(newItemData.getValue());
existingItemData.setUpdateId(container.getUser().getUserId());
existingItemData.setDateUpdated(new Date());
itemDataDao.saveOrUpdate(existingItemData);
resetSdvStatus(container);
}
}
}
use of org.w3c.dom.NamedNodeMap in project jdk8u_jdk by JetBrains.
the class BmpDefaultImageMetadataTest method displayMetadata.
void displayMetadata(Node node, int level) {
// emit open tag
indent(level);
System.out.print("<" + node.getNodeName());
NamedNodeMap map = node.getAttributes();
if (map != null) {
// print attribute values
int length = map.getLength();
for (int i = 0; i < length; i++) {
Node attr = map.item(i);
System.out.print(" " + attr.getNodeName() + "=\"" + attr.getNodeValue() + "\"");
}
}
Node child = node.getFirstChild();
if (node.getNodeValue() != null && !node.getNodeValue().equals("")) {
System.out.println(">");
indent(level);
System.out.println(node.getNodeValue());
// emit close tag
indent(level);
System.out.println("</" + node.getNodeName() + ">");
} else if (child != null) {
// close current tag
System.out.println(">");
while (child != null) {
// emit child tags recursively
displayMetadata(child, level + 1);
child = child.getNextSibling();
}
// emit close tag
indent(level);
System.out.println("</" + node.getNodeName() + ">");
} else {
System.out.println("/>");
}
}
use of org.w3c.dom.NamedNodeMap in project midpoint by Evolveum.
the class PrettyPrinter method prettyPrint.
public static String prettyPrint(Element element, boolean displayTag) {
if (element == null) {
return "null";
}
StringBuilder sb = new StringBuilder();
if (displayTag) {
sb.append("<");
if (element.getLocalName() != null) {
sb.append(prettyPrint(new QName(element.getNamespaceURI(), element.getLocalName())));
} else {
sb.append("<null>");
}
sb.append(">");
}
NamedNodeMap attributes = element.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Node attr = attributes.item(i);
if ("xmlns".equals(attr.getPrefix())) {
// they are too long for prettyPrint
continue;
}
if ((attr.getPrefix() == null || attr.getPrefix().isEmpty()) && "xmlns".equals(attr.getLocalName())) {
// Skip default ns declaration as well
continue;
}
sb.append("@");
sb.append(attr.getLocalName());
sb.append("=");
sb.append(attr.getTextContent());
if (i < (attributes.getLength() - 1)) {
sb.append(",");
}
}
if (attributes.getLength() > 0) {
sb.append(":");
}
StringBuilder content = new StringBuilder();
Node child = element.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.TEXT_NODE) {
content.append(((Text) child).getTextContent());
} else if (child.getNodeType() == Node.COMMENT_NODE) {
// just ignore this
} else {
content = new StringBuilder("[complex content]");
break;
}
child = child.getNextSibling();
}
sb.append(content);
return sb.toString();
}
use of org.w3c.dom.NamedNodeMap in project midpoint by Evolveum.
the class DOMUtil method getNamespaceDeclarations.
/**
* Returns map of all namespace declarations from specified element (prefix -> namespace).
*/
public static Map<String, String> getNamespaceDeclarations(Element element) {
Map<String, String> nsDeclMap = new HashMap<>();
NamedNodeMap attributes = element.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Attr attr = (Attr) attributes.item(i);
if (isNamespaceDefinition(attr)) {
String prefix = getNamespaceDeclarationPrefix(attr);
String namespace = getNamespaceDeclarationNamespace(attr);
nsDeclMap.put(prefix, namespace);
}
}
return nsDeclMap;
}
use of org.w3c.dom.NamedNodeMap in project midpoint by Evolveum.
the class DOMUtil method isPrefixUsed.
public static boolean isPrefixUsed(Element targetElement, String prefix) {
if (comparePrefix(prefix, targetElement.getPrefix())) {
return true;
}
NamedNodeMap attributes = targetElement.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Attr attr = (Attr) attributes.item(i);
if (comparePrefix(prefix, attr.getPrefix())) {
return true;
}
}
NodeList childNodes = targetElement.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (node instanceof Element) {
Element element = (Element) node;
if (isPrefixUsed(element, prefix)) {
return true;
}
}
}
return false;
}
Aggregations