Search in sources :

Example 41 with Node

use of org.cybergarage.xml.Node in project i2p.i2p by i2p.

the class Service method addStateVariable.

/**
 * Add the StateVariable to the service.<br>
 * <br>
 * Note: This method should be used to create a dynamic<br>
 * Device withtout writing any XML that describe the device<br>.
 * <br>
 * Note: that no control for duplicate StateVariable is done.
 *
 * @param var StateVariable that will be added
 */
public void addStateVariable(StateVariable var) {
    // TODO Some test are done not stable
    Node stateTableNode = getSCPDNode().getNode(ServiceStateTable.ELEM_NAME);
    if (stateTableNode == null) {
        stateTableNode = new Node(ServiceStateTable.ELEM_NAME);
        /*
			 * Force the node <serviceStateTable> to be the first node inside <scpd>
			 */
        // getSCPDNode().insertNode(stateTableNode,0);
        getSCPDNode().addNode(stateTableNode);
    }
    var.setServiceNode(getServiceNode());
    stateTableNode.addNode(var.getStateVariableNode());
}
Also used : Node(org.cybergarage.xml.Node)

Example 42 with Node

use of org.cybergarage.xml.Node in project i2p.i2p by i2p.

the class Service method updateConfigId.

public void updateConfigId() {
    Node scpdNode = getSCPDNode();
    if (scpdNode == null)
        return;
    String scpdXml = scpdNode.toString();
    int configId = UPnP.caluculateConfigId(scpdXml);
    scpdNode.setAttribute(CONFIG_ID, configId);
}
Also used : Node(org.cybergarage.xml.Node)

Example 43 with Node

use of org.cybergarage.xml.Node in project i2p.i2p by i2p.

the class Service method loadSCPD.

public boolean loadSCPD(File file) throws ParserException {
    Parser parser = UPnP.getXMLParser();
    Node scpdNode = parser.parse(file);
    if (scpdNode == null)
        return false;
    ServiceData data = getServiceData();
    data.setSCPDNode(scpdNode);
    return true;
}
Also used : Node(org.cybergarage.xml.Node) ServiceData(org.cybergarage.upnp.xml.ServiceData) Parser(org.cybergarage.xml.Parser)

Example 44 with Node

use of org.cybergarage.xml.Node in project i2p.i2p by i2p.

the class Service method loadSCPD.

// //////////////////////////////////////////////
// SCPD node
// //////////////////////////////////////////////
public boolean loadSCPD(String scpdStr) throws InvalidDescriptionException {
    try {
        Parser parser = UPnP.getXMLParser();
        Node scpdNode = parser.parse(scpdStr);
        if (scpdNode == null)
            return false;
        ServiceData data = getServiceData();
        data.setSCPDNode(scpdNode);
    } catch (ParserException e) {
        throw new InvalidDescriptionException(e);
    }
    return true;
}
Also used : ParserException(org.cybergarage.xml.ParserException) Node(org.cybergarage.xml.Node) InvalidDescriptionException(org.cybergarage.upnp.device.InvalidDescriptionException) ServiceData(org.cybergarage.upnp.xml.ServiceData) Parser(org.cybergarage.xml.Parser)

Example 45 with Node

use of org.cybergarage.xml.Node in project i2p.i2p by i2p.

the class StateVariable method setAllowedValueList.

/**
 * This method ovverride the value of the AllowedValueList Node<br>
 * of this object. <br>
 * <br>
 * Note: This method should be used to create a dynamic<br>
 * Device withtout writing any XML that describe the device<br>.
 * <br>
 * Note2: The enforce the constraint of the SCPD rule the<br>
 * AllowedValueList and AllowedValueRange are mutal exclusive<br>
 * the last set will be the only present<br>
 *
 * @param avl The new AllowedValueList
 */
public void setAllowedValueList(AllowedValueList avl) {
    // TODO Some test done not stable
    getStateVariableNode().removeNode(AllowedValueList.ELEM_NAME);
    getStateVariableNode().removeNode(AllowedValueRange.ELEM_NAME);
    Node n = new Node(AllowedValueList.ELEM_NAME);
    Iterator<AllowedValue> i = avl.iterator();
    while (i.hasNext()) {
        AllowedValue av = i.next();
        // n.addNode(new Node(AllowedValue.ELEM_NAME,av.getValue())); wrong!
        // better (twa)
        n.addNode(av.getAllowedValueNode());
    }
    getStateVariableNode().addNode(n);
}
Also used : Node(org.cybergarage.xml.Node)

Aggregations

Node (org.cybergarage.xml.Node)58 ParserException (org.cybergarage.xml.ParserException)7 ArrayList (java.util.ArrayList)5 ServiceData (org.cybergarage.upnp.xml.ServiceData)5 Parser (org.cybergarage.xml.Parser)5 IOException (java.io.IOException)4 File (java.io.File)3 Device (org.cybergarage.upnp.Device)3 DeviceData (org.cybergarage.upnp.xml.DeviceData)3 UPnPDevice (org.osgi.service.upnp.UPnPDevice)3 URL (java.net.URL)2 Log (net.i2p.util.Log)2 InvalidDescriptionException (org.cybergarage.upnp.device.InvalidDescriptionException)2 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1