private void generateActionArgument(ActionArgument actionArgument, Document descriptor, Element actionElement) { Element actionArgumentElement = appendNewElement(descriptor, actionElement, ELEMENT.argument); appendNewElementIfNotNull(descriptor, actionArgumentElement, ELEMENT.name, actionArgument.getName()); appendNewElementIfNotNull(descriptor, actionArgumentElement, ELEMENT.direction, actionArgument.getDirection().toString().toLowerCase(Locale.ROOT)); if (actionArgument.isReturnValue()) { // TODO: UPNP VIOLATION: WMP12 will discard RenderingControl service if it contains <retval> tags log.warning("UPnP specification violation: Not producing <retval> element to be compatible with WMP12: " + actionArgument); // appendNewElement(descriptor, actionArgumentElement, ELEMENT.retval); } appendNewElementIfNotNull(descriptor, actionArgumentElement, ELEMENT.relatedStateVariable, actionArgument.getRelatedStateVariableName()); }
public String generate(Event event) throws Exception { return XMLUtil.documentToFragmentString(buildDOM(event)); }
public static String documentToString(Document document) throws Exception { return documentToString(document, true); }
b.append(">"); for (int i = 0; i < children.getLength(); i++) { b.append(nodeToString(children.item(i), parentPrefixes, children.item(i).getNamespaceURI())); b.append(encodeText(node.getNodeValue(), node instanceof Attr));
public static Element appendNewElementIfNotNull(Document document, Element parent, String element, Object content, String namespace) { if (content == null) return parent; return appendNewElement(document, parent, element, content, namespace); }
public void hydrateSpecVersion(MutableDevice descriptor, Node specVersionNode) throws DescriptorBindingException { NodeList specVersionChildren = specVersionNode.getChildNodes(); for (int i = 0; i < specVersionChildren.getLength(); i++) { Node specVersionChild = specVersionChildren.item(i); if (specVersionChild.getNodeType() != Node.ELEMENT_NODE) continue; if (ELEMENT.major.equals(specVersionChild)) { String version = XMLUtil.getTextContent(specVersionChild).trim(); if (!version.equals("1")) { log.warning("Unsupported UDA major version, ignoring: " + version); version = "1"; } descriptor.udaVersion.major = Integer.valueOf(version); } else if (ELEMENT.minor.equals(specVersionChild)) { String version = XMLUtil.getTextContent(specVersionChild).trim(); if (!version.equals("0")) { log.warning("Unsupported UDA minor version, ignoring: " + version); version = "0"; } descriptor.udaVersion.minor = Integer.valueOf(version); } } }
public static Element appendNewElementIfNotNull(Document document, Element parent, String element, Object content) { return appendNewElementIfNotNull(document, parent, element, content, null); }
public static String documentToString(Document document, boolean standalone) throws Exception { String prol = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"" + (standalone ? "yes" : "no") + "\"?>"; return prol + nodeToString(document.getDocumentElement(), new HashSet<String>(), document.getDocumentElement().getNamespaceURI()); }
public static String encodeText(String s) { return encodeText(s, true); }
public static Element appendNewElement(Document document, Element parent, String element, Object content) { return appendNewElement(document, parent, element, content, null); }
public void hydrateActionArgument(MutableActionArgument actionArgument, Node actionArgumentNode) { NodeList argumentNodeChildren = actionArgumentNode.getChildNodes(); for (int i = 0; i < argumentNodeChildren.getLength(); i++) { Node argumentNodeChild = argumentNodeChildren.item(i); if (argumentNodeChild.getNodeType() != Node.ELEMENT_NODE) continue; if (ELEMENT.name.equals(argumentNodeChild)) { actionArgument.name = XMLUtil.getTextContent(argumentNodeChild); } else if (ELEMENT.direction.equals(argumentNodeChild)) { String directionString = XMLUtil.getTextContent(argumentNodeChild); try { actionArgument.direction = ActionArgument.Direction.valueOf(directionString.toUpperCase(Locale.ROOT)); } catch (IllegalArgumentException ex) { // TODO: UPNP VIOLATION: Pelco SpectraIV-IP uses illegal value INOUT log.warning("UPnP specification violation: Invalid action argument direction, assuming 'IN': " + directionString); actionArgument.direction = ActionArgument.Direction.IN; } } else if (ELEMENT.relatedStateVariable.equals(argumentNodeChild)) { actionArgument.relatedStateVariable = XMLUtil.getTextContent(argumentNodeChild); } else if (ELEMENT.retval.equals(argumentNodeChild)) { actionArgument.retval = true; } } }
public static Element appendNewElementIfNotNull(Document document, Element parent, Enum el, Object content) { return appendNewElementIfNotNull(document, parent, el, content, null); }
b.append(">"); for (int i = 0; i < children.getLength(); i++) { b.append(nodeToString(children.item(i), parentPrefixes, children.item(i).getNamespaceURI())); b.append(encodeText(node.getNodeValue()));
public static String documentToFragmentString(Document document) throws Exception { return nodeToString(document.getDocumentElement(), new HashSet<String>(), document.getDocumentElement().getNamespaceURI()); }
fixedLastChange = XMLUtil.encodeText(fixedLastChange); } else {
protected void generateSpecVersion(Namespace namespace, Device deviceModel, Document descriptor, Element rootElement) { Element specVersionElement = appendNewElement(descriptor, rootElement, ELEMENT.specVersion); appendNewElementIfNotNull(descriptor, specVersionElement, ELEMENT.major, deviceModel.getVersion().getMajor()); appendNewElementIfNotNull(descriptor, specVersionElement, ELEMENT.minor, deviceModel.getVersion().getMinor()); }
public static Element appendNewElement(Document document, Element parent, Enum el) { return appendNewElement(document, parent, el.toString()); }
public void hydrateAction(MutableAction action, Node actionNode) { NodeList actionNodeChildren = actionNode.getChildNodes(); for (int i = 0; i < actionNodeChildren.getLength(); i++) { Node actionNodeChild = actionNodeChildren.item(i); if (actionNodeChild.getNodeType() != Node.ELEMENT_NODE) continue; if (ELEMENT.name.equals(actionNodeChild)) { action.name = XMLUtil.getTextContent(actionNodeChild); } else if (ELEMENT.argumentList.equals(actionNodeChild)) { NodeList argumentChildren = actionNodeChild.getChildNodes(); for (int j = 0; j < argumentChildren.getLength(); j++) { Node argumentChild = argumentChildren.item(j); if (argumentChild.getNodeType() != Node.ELEMENT_NODE) continue; MutableActionArgument actionArgument = new MutableActionArgument(); hydrateActionArgument(actionArgument, argumentChild); action.arguments.add(actionArgument); } } } }
public static Element appendNewElementIfNotNull(Document document, Element parent, Enum el, Object content, String namespace) { return appendNewElementIfNotNull(document, parent, el.toString(), content, namespace); }
protected String toString(Document d) throws Exception { // Just to be safe, no newline at the end String output = XMLUtil.documentToString(d); while (output.endsWith("\n") || output.endsWith("\r")) { output = output.substring(0, output.length() - 1); } return output; }