/** * Sets value for a single XML template variable. Variable name should be specified * without leading '${' and ending '}' placeholder markers. For example, for a placeholder * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. * * @param name variable name * @param value value to be set in the XML template */ public void setVariable(String name, Color value) { String r = byteToHex(value.getRed()); String g = byteToHex(value.getGreen()); String b = byteToHex(value.getBlue()); String a = byteToHex(value.getAlpha()); valueMap.put(name, "#" + r + g + b + a); }
/** * <p>getChildValue.</p> * * @param parentNode a {@link org.w3c.dom.Node} object. * @param childName a {@link java.lang.String} object. * @return a {@link java.lang.String} object. */ protected String getChildValue(Node parentNode, String childName) { return getChildValue(parentNode, childName, true); }
/** * <p>getValue.</p> * * @param parentNode a {@link org.w3c.dom.Node} object. * @return a {@link java.lang.String} object. */ protected String getValue(Node parentNode) { return getValue(parentNode, true); }
private void setProperties(XmlTemplate aTemplate, Map properties) { Iterator it = properties.keySet().iterator(); while (it.hasNext()) { String key = (String) it.next(); Object value = properties.get(key); if (value instanceof String) { aTemplate.setVariable(key, (String) value); } else if (value instanceof Calendar) { aTemplate.setVariable(key, (Calendar) value); } else if (value instanceof Long) { aTemplate.setVariable(key, ((Long) value).longValue()); } else if (value instanceof Date) { aTemplate.setVariable(key, (Date) value); } else { aTemplate.setVariable(key, String.valueOf(value)); } } }
protected void validateTagsOnlyOnce(Node parentNode, String[] allowedChildNames) { // validate node only once if (validatedNodes.contains(parentNode)) { return; } Node[] childs = getChildNodes(parentNode); main: for (Node child : childs) { String childName = child.getNodeName(); for (int j = 0; j < allowedChildNames.length; j++) { if (allowedChildNames[j].equals(childName)) { // only one such tag is allowed allowedChildNames[j] = "<--removed-->"; continue main; } else if (allowedChildNames[j].equals(childName + "*")) { // several tags allowed continue main; } } if (!isEmptyNode(child)) { throw new IllegalArgumentException("Unexpected tag encountered: <" + childName + ">"); } } // everything is OK validatedNodes.add(parentNode); } }
/** * <p>getValue.</p> * * @param parentNode a {@link org.w3c.dom.Node} object. * @param trim a boolean. * @return a {@link java.lang.String} object. */ protected String getValue(Node parentNode, boolean trim) { String value = Util.Xml.getValue(parentNode, trim); return resolveMappings(value); }
/** * Sets value for a single XML template variable. Variable name should be specified * without leading '${' and ending '}' placeholder markers. For example, for a placeholder * <code>${start}</code>, specify <code>start</code> for the <code>name</code> parameter. * * @param name variable name * @param value value to be set in the XML template */ public void setVariable(String name, Calendar value) { setVariable(name, Util.getTimestamp(value)); }
return; Node[] childs = getChildNodes(parentNode); main: for (Node child : childs) { if (!isEmptyNode(child)) { throw new IllegalArgumentException("Unexpected tag encountered: <" + childName + ">");
/** * <p>getChildValue.</p> * * @param parentNode a {@link org.w3c.dom.Node} object. * @param childName a {@link java.lang.String} object. * @param trim a boolean. * @return a {@link java.lang.String} object. */ protected String getChildValue(Node parentNode, String childName, boolean trim) { String value = Util.Xml.getChildValue(parentNode, childName, trim); return resolveMappings(value); }
protected String getValue(Node parentNode) { return getValue(parentNode, true); }
/** * Sets value for a single XML template variable. Variable name should be specified * without leading '${' and ending '}' placeholder markers. For example, for a placeholder * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. * * @param name variable name * @param value value to be set in the XML template */ public void setVariable(String name, Date value) { setVariable(name, Util.getTimestamp(value)); }
protected String getChildValue(Node parentNode, String childName) { return getChildValue(parentNode, childName, true); }
protected String getChildValue(Node parentNode, String childName, boolean trim) { String value = Util.Xml.getChildValue(parentNode, childName, trim); return resolveMappings(value); }
/** * Sets value for a single XML template variable. Variable name should be specified * without leading '${' and ending '}' placeholder markers. For example, for a placeholder * <code>${start}</code>, specify <code>start</code> for the <code>name</code> parameter. * * @param name variable name * @param value value to be set in the XML template */ public void setVariable(String name, Color value) { String r = byteToHex(value.getRed()); String g = byteToHex(value.getGreen()); String b = byteToHex(value.getBlue()); String a = byteToHex(value.getAlpha()); valueMap.put(name, "#" + r + g + b + a); }
/** * getValueAsInt. * * @param parentNode a {@link org.w3c.dom.Node} object. * @return a int. */ protected int getValueAsInt(Node parentNode) { String valueStr = getValue(parentNode); return Integer.parseInt(valueStr); }
/** * Sets value for a single XML template variable. Variable name should be specified * without leading '${' and ending '}' placeholder markers. For example, for a placeholder * <code>${start}</code>, specify <code>start</code> for the <code>name</code> parameter. * * @param name variable name * @param value value to be set in the XML template */ public void setVariable(String name, Date value) { setVariable(name, Util.getTimestamp(value)); }
/** * getChildValueAsLong. * * @param parentNode a {@link org.w3c.dom.Node} object. * @param childName a {@link java.lang.String} object. * @return a long. */ protected long getChildValueAsLong(Node parentNode, String childName) { String valueStr = getChildValue(parentNode, childName); return Long.parseLong(valueStr); }
protected String getValue(Node parentNode, boolean trim) { String value = Util.Xml.getValue(parentNode, trim); return resolveMappings(value); }
/** * getValueAsLong. * * @param parentNode a {@link org.w3c.dom.Node} object. * @return a long. */ protected long getValueAsLong(Node parentNode) { String valueStr = getValue(parentNode); return Long.parseLong(valueStr); }
/** * Sets value for a single XML template variable. Variable name should be specified * without leading '${' and ending '}' placeholder markers. For example, for a placeholder * <code>${start}</code>, specify <code>start</start> for the <code>name</code> parameter. * * @param name variable name * @param value value to be set in the XML template */ public void setVariable(String name, Calendar value) { setVariable(name, Util.getTimestamp(value)); }