private Element getGroupElement(PGEGroup group, Document document) throws Exception { Element groupElem = document.createElement(GROUP_TAG_NAME); groupElem.setAttribute(NAME_ATTR, group.getName()); if (group.getNumScalars() > 0) { for (String scalarName : group.getScalars().keySet()) { PGEScalar scalar = group.getScalar(scalarName); Element scalarElem = document.createElement(SCALAR_TAG_NAME); scalarElem.setAttribute(NAME_ATTR, scalar.getName()); if (scalar.getValue() == null) { throw new Exception( "Attempt to write null value for scalar: [" + scalarName + "] to PGE config file!"); } if (urlEncoding) { try { scalarElem.appendChild( document.createTextNode(URLEncoder.encode(scalar.getValue(), "UTF-8"))); } catch (UnsupportedEncodingException e) { LOG.log( Level.WARNING, "Error creating text node for scalar element: " + scalar.getName() + " in pge group: " + group.getName() + " Message: " + e.getMessage()); } } else { scalarElem.appendChild(document.createTextNode(scalar.getValue())); } groupElem.appendChild(scalarElem); } } if (group.getNumVectors() > 0) { for (String vectorName : group.getVectors().keySet()) { PGEVector vector = group.getVector(vectorName); Element vectorElem = document.createElement(VECTOR_TAG_NAME); vectorElem.setAttribute(NAME_ATTR, vector.getName()); for (Object o : vector.getElements()) { String element = (String) o; if (element == null) { throw new Exception( "Attempt to write null value for vector: [" + vectorName + "] to PGE config file!"); } Element elementElem = document.createElement(VECTOR_ELEMENT_TAG); if (urlEncoding) { try { elementElem.appendChild(document.createTextNode(URLEncoder.encode(element, "UTF-8"))); } catch (UnsupportedEncodingException e) { LOG.log( Level.WARNING, "Error creating text node for vector element: " + vector.getName() + " in pge group: " + group.getName() + " Message: " + e.getMessage()); } } else { elementElem.appendChild(document.createTextNode(element)); } vectorElem.appendChild(elementElem); } groupElem.appendChild(vectorElem); } } if (group.getNumMatrixs() > 0) { for (String matrixName : group.getMatrixs().keySet()) { PGEMatrix matrix = group.getMatrix(matrixName); Element matrixElem = document.createElement(MATRIX_TAG_NAME); matrixElem.setAttribute(NAME_ATTR, matrix.getName()); int rowNum = 0; for (List<Object> objects : matrix.getRows()) { List rowValues = (List) objects; Element rowElem = document.createElement(MATRIX_ROW_TAG); int colNum = 0; for (Object rowValue : rowValues) { String colValue = (String) rowValue; Element colElem = document.createElement(MATRIX_COL_TAG); if (colValue == null) { throw new Exception( "Attempt to write null value for matrix: [" + matrixName + "]: " + "(" + rowNum + "," + colNum + ")"); } if (urlEncoding) { try { colElem.appendChild(document.createTextNode(URLEncoder.encode(colValue, "UTF-8"))); } catch (UnsupportedEncodingException e) { LOG.log( Level.WARNING, "Error creating node for matrix element: " + matrix.getName() + " (" + rowNum + "," + colNum + ") in pge group: " + group.getName() + " Message: " + e.getMessage()); } } else { colElem.appendChild(document.createTextNode(colValue)); } colNum++; } rowNum++; } groupElem.appendChild(matrixElem); } } if (group.getNumGroups() > 0) { for (String groupName : group.getGroups().keySet()) { PGEGroup subgroup = group.getGroup(groupName); Element subgroupElem = getGroupElement(subgroup, document); groupElem.appendChild(subgroupElem); } } return groupElem; }