forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p.zzz.upnp' (head 8719ae9a1473d748947733043f465a4589cc23d5)
to branch 'i2p.i2p' (head 5ae9785903c4b9452f4241758e8ddc1338e94574)
This commit is contained in:
@@ -69,16 +69,15 @@ public class HTTP
|
|||||||
public static final String CONTENT_TYPE = "Content-Type";
|
public static final String CONTENT_TYPE = "Content-Type";
|
||||||
public static final String CHARSET = "charset";
|
public static final String CHARSET = "charset";
|
||||||
public static final String CONTENT_LENGTH = "Content-Length";
|
public static final String CONTENT_LENGTH = "Content-Length";
|
||||||
|
public static final String CONTENT_LANGUAGE = "Content-Language";
|
||||||
public static final String CONTENT_RANGE = "Content-Range";
|
public static final String CONTENT_RANGE = "Content-Range";
|
||||||
public static final String CONTENT_RANGE_BYTES = "bytes";
|
public static final String CONTENT_RANGE_BYTES = "bytes";
|
||||||
// Thanks for Brent Hills (10/20/04)
|
|
||||||
public static final String RANGE = "Range";
|
public static final String RANGE = "Range";
|
||||||
public static final String TRANSFER_ENCODING = "Transfer-Encoding";
|
public static final String TRANSFER_ENCODING = "Transfer-Encoding";
|
||||||
public static final String CHUNKED = "Chunked";
|
public static final String CHUNKED = "Chunked";
|
||||||
public static final String LOCATION = "Location";
|
public static final String LOCATION = "Location";
|
||||||
public static final String SERVER = "Server";
|
public static final String SERVER = "Server";
|
||||||
|
|
||||||
|
|
||||||
public static final String ST = "ST";
|
public static final String ST = "ST";
|
||||||
public static final String MX = "MX";
|
public static final String MX = "MX";
|
||||||
public static final String MAN = "MAN";
|
public static final String MAN = "MAN";
|
||||||
@@ -90,6 +89,9 @@ public class HTTP
|
|||||||
public static final String SEQ = "SEQ";
|
public static final String SEQ = "SEQ";
|
||||||
public final static String CALLBACK = "CALLBACK";
|
public final static String CALLBACK = "CALLBACK";
|
||||||
public final static String TIMEOUT = "TIMEOUT";
|
public final static String TIMEOUT = "TIMEOUT";
|
||||||
|
|
||||||
|
public final static String BOOTID_UPNP_ORG = "BOOTID.UPNP.ORG";
|
||||||
|
|
||||||
// Thanks for Brent Hills (10/20/04)
|
// Thanks for Brent Hills (10/20/04)
|
||||||
public final static String MYNAME = "MYNAME";
|
public final static String MYNAME = "MYNAME";
|
||||||
|
|
||||||
|
@@ -610,6 +610,20 @@ public class HTTPPacket
|
|||||||
return getHeaderValue(HTTP.CONTENT_TYPE);
|
return getHeaderValue(HTTP.CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
// ContentLanguage
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public void setContentLanguage(String code)
|
||||||
|
{
|
||||||
|
setHeader(HTTP.CONTENT_LANGUAGE, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContentLanguage()
|
||||||
|
{
|
||||||
|
return getHeaderValue(HTTP.CONTENT_LANGUAGE);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Charset
|
// Charset
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
@@ -34,21 +34,21 @@ public class SOAPResponse extends HTTPResponse
|
|||||||
public SOAPResponse()
|
public SOAPResponse()
|
||||||
{
|
{
|
||||||
setRootNode(SOAP.createEnvelopeBodyNode());
|
setRootNode(SOAP.createEnvelopeBodyNode());
|
||||||
setContentType(XML.CONTENT_TYPE);
|
setContentType(XML.DEFAULT_CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SOAPResponse(HTTPResponse httpRes)
|
public SOAPResponse(HTTPResponse httpRes)
|
||||||
{
|
{
|
||||||
super(httpRes);
|
super(httpRes);
|
||||||
setRootNode(SOAP.createEnvelopeBodyNode());
|
setRootNode(SOAP.createEnvelopeBodyNode());
|
||||||
setContentType(XML.CONTENT_TYPE);
|
setContentType(XML.DEFAULT_CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SOAPResponse(SOAPResponse soapRes)
|
public SOAPResponse(SOAPResponse soapRes)
|
||||||
{
|
{
|
||||||
super(soapRes);
|
super(soapRes);
|
||||||
setEnvelopeNode(soapRes.getEnvelopeNode());
|
setEnvelopeNode(soapRes.getEnvelopeNode());
|
||||||
setContentType(XML.CONTENT_TYPE);
|
setContentType(XML.DEFAULT_CONTENT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -47,6 +47,10 @@ public class Icon
|
|||||||
iconNode = node;
|
iconNode = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Icon() {
|
||||||
|
this(new Node(ELEM_NAME));
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// isIconNode
|
// isIconNode
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -72,6 +76,14 @@ public class Icon
|
|||||||
return getIconNode().getNodeValue(MIME_TYPE);
|
return getIconNode().getNodeValue(MIME_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasMimeType()
|
||||||
|
{
|
||||||
|
String iconMimeType = getMimeType();
|
||||||
|
if (iconMimeType == null)
|
||||||
|
return false;
|
||||||
|
return (0 < iconMimeType.length()) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// width
|
// width
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -139,9 +151,21 @@ public class Icon
|
|||||||
getIconNode().setNode(DEPTH, value);
|
getIconNode().setNode(DEPTH, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDepth()
|
public void setDepth(int value)
|
||||||
{
|
{
|
||||||
return getIconNode().getNodeValue(DEPTH);
|
try {
|
||||||
|
setDepth(Integer.toString(value));
|
||||||
|
}
|
||||||
|
catch (Exception e) {};
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDepth()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(getIconNode().getNodeValue(DEPTH));
|
||||||
|
}
|
||||||
|
catch (Exception e) {};
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -160,6 +184,24 @@ public class Icon
|
|||||||
return getIconNode().getNodeValue(URL);
|
return getIconNode().getNodeValue(URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasURL()
|
||||||
|
{
|
||||||
|
String iconURL = getURL();
|
||||||
|
if (iconURL == null)
|
||||||
|
return false;
|
||||||
|
return (0 < iconURL.length()) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isURL(String url)
|
||||||
|
{
|
||||||
|
if (url == null)
|
||||||
|
return false;
|
||||||
|
String iconURL = getURL();
|
||||||
|
if (iconURL == null)
|
||||||
|
return false;
|
||||||
|
return iconURL.equals(url);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// userData
|
// userData
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -175,4 +217,25 @@ public class Icon
|
|||||||
{
|
{
|
||||||
return userData;
|
return userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
// Bytes
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
|
private byte bytes[] = null;
|
||||||
|
|
||||||
|
public void setBytes(byte data[])
|
||||||
|
{
|
||||||
|
bytes = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasBytes()
|
||||||
|
{
|
||||||
|
return (bytes != null) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[]getBytes()
|
||||||
|
{
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -142,8 +142,8 @@ public class Service
|
|||||||
sp.addNode(m);
|
sp.addNode(m);
|
||||||
|
|
||||||
//Node scpd = new Node(SCPD_ROOTNODE,SCPD_ROOTNODE_NS); wrong!
|
//Node scpd = new Node(SCPD_ROOTNODE,SCPD_ROOTNODE_NS); wrong!
|
||||||
Node scpd = new Node(SCPD_ROOTNODE); // better (twa)
|
Node scpd = new Node(SCPD_ROOTNODE);
|
||||||
scpd.addAttribute("xmlns",SCPD_ROOTNODE_NS); // better (twa)
|
scpd.addAttribute("xmlns",SCPD_ROOTNODE_NS);
|
||||||
scpd.addNode(sp);
|
scpd.addNode(sp);
|
||||||
getServiceData().setSCPDNode(scpd);
|
getServiceData().setSCPDNode(scpd);
|
||||||
}
|
}
|
||||||
@@ -241,6 +241,31 @@ public class Service
|
|||||||
return getServiceNode().getNodeValue(SERVICE_ID);
|
return getServiceNode().getNodeValue(SERVICE_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
// configID
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
|
private final static String CONFIG_ID = "configId";
|
||||||
|
|
||||||
|
public void updateConfigId()
|
||||||
|
{
|
||||||
|
Node scpdNode = getSCPDNode();
|
||||||
|
if (scpdNode == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
String scpdXml = scpdNode.toString();
|
||||||
|
int configId = UPnP.caluculateConfigId(scpdXml);
|
||||||
|
scpdNode.setAttribute(CONFIG_ID, configId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getConfigId()
|
||||||
|
{
|
||||||
|
Node scpdNode = getSCPDNode();
|
||||||
|
if (scpdNode == null)
|
||||||
|
return 0;
|
||||||
|
return scpdNode.getAttributeIntegerValue(CONFIG_ID);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// isURL
|
// isURL
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -340,6 +365,7 @@ public class Service
|
|||||||
catch (ParserException e) {
|
catch (ParserException e) {
|
||||||
throw new InvalidDescriptionException(e);
|
throw new InvalidDescriptionException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,8 +375,10 @@ public class Service
|
|||||||
Node scpdNode = parser.parse(file);
|
Node scpdNode = parser.parse(file);
|
||||||
if (scpdNode == null)
|
if (scpdNode == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ServiceData data = getServiceData();
|
ServiceData data = getServiceData();
|
||||||
data.setSCPDNode(scpdNode);
|
data.setSCPDNode(scpdNode);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,8 +391,10 @@ public class Service
|
|||||||
Node scpdNode = parser.parse(input);
|
Node scpdNode = parser.parse(input);
|
||||||
if (scpdNode == null)
|
if (scpdNode == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ServiceData data = getServiceData();
|
ServiceData data = getServiceData();
|
||||||
data.setSCPDNode(scpdNode);
|
data.setSCPDNode(scpdNode);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,6 +436,9 @@ public class Service
|
|||||||
|
|
||||||
String scpdURLStr = getSCPDURL();
|
String scpdURLStr = getSCPDURL();
|
||||||
|
|
||||||
|
/****
|
||||||
|
* I2P - no, dont attempt to load local file
|
||||||
|
*
|
||||||
// Thanks for Robin V. (Sep 18, 2010)
|
// Thanks for Robin V. (Sep 18, 2010)
|
||||||
String rootDevPath = rootDev.getDescriptionFilePath();
|
String rootDevPath = rootDev.getDescriptionFilePath();
|
||||||
if(rootDevPath!=null) {
|
if(rootDevPath!=null) {
|
||||||
@@ -425,6 +458,7 @@ public class Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
****/
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URL scpdUrl = new URL(rootDev.getAbsoluteURL(scpdURLStr));
|
URL scpdUrl = new URL(rootDev.getAbsoluteURL(scpdURLStr));
|
||||||
@@ -434,8 +468,14 @@ public class Service
|
|||||||
return scpdNode;
|
return scpdNode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {}
|
catch (Exception e) {
|
||||||
|
// I2P
|
||||||
|
Debug.warning(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/****
|
||||||
|
* I2P - no, dont attempt to load local file
|
||||||
|
*
|
||||||
String newScpdURLStr = rootDev.getDescriptionFilePath() + HTTP.toRelativeURL(scpdURLStr);
|
String newScpdURLStr = rootDev.getDescriptionFilePath() + HTTP.toRelativeURL(scpdURLStr);
|
||||||
try {
|
try {
|
||||||
scpdNode = getSCPDNode(new File(newScpdURLStr));
|
scpdNode = getSCPDNode(new File(newScpdURLStr));
|
||||||
@@ -444,6 +484,7 @@ public class Service
|
|||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Debug.warning(e);
|
Debug.warning(e);
|
||||||
}
|
}
|
||||||
|
****/
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@@ -45,7 +45,7 @@ public class UPnP
|
|||||||
public final static String XML_CLASS_PROPERTTY="cyberlink.upnp.xml.parser";
|
public final static String XML_CLASS_PROPERTTY="cyberlink.upnp.xml.parser";
|
||||||
|
|
||||||
public final static String NAME = "CyberLinkJava";
|
public final static String NAME = "CyberLinkJava";
|
||||||
public final static String VERSION = "1.8";
|
public final static String VERSION = "3.0";
|
||||||
|
|
||||||
// I2P was 100
|
// I2P was 100
|
||||||
public final static int SERVER_RETRY_COUNT = 4;
|
public final static int SERVER_RETRY_COUNT = 4;
|
||||||
@@ -64,6 +64,8 @@ public class UPnP
|
|||||||
|
|
||||||
public final static String XML_DECLARATION = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
|
public final static String XML_DECLARATION = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
|
||||||
|
|
||||||
|
public final static int CONFIGID_UPNP_ORG_MAX = 16777215;
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Enable / Disable
|
// Enable / Disable
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -190,6 +192,34 @@ public class UPnP
|
|||||||
toUUID((int)((time2 >> 32) | 0xE000) & 0xFFFF);
|
toUUID((int)((time2 >> 32) | 0xE000) & 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
// BootId
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public static final int createBootId()
|
||||||
|
{
|
||||||
|
return (int)(System.currentTimeMillis() / 1000L);
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
// ConfigId
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public static final int caluculateConfigId(String configXml)
|
||||||
|
{
|
||||||
|
if (configXml == null)
|
||||||
|
return 0;
|
||||||
|
int configId = 0;
|
||||||
|
int configLen = configXml.length();
|
||||||
|
for (int n=0; n<configLen; n++) {
|
||||||
|
configId += configXml.codePointAt(n);
|
||||||
|
if (configId < CONFIGID_UPNP_ORG_MAX)
|
||||||
|
continue;
|
||||||
|
configId = configId % CONFIGID_UPNP_ORG_MAX;
|
||||||
|
}
|
||||||
|
return configId;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// XML Parser
|
// XML Parser
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
@@ -0,0 +1,23 @@
|
|||||||
|
/******************************************************************
|
||||||
|
*
|
||||||
|
* CyberUPnP for Java
|
||||||
|
*
|
||||||
|
* Copyright (C) Satoshi Konno 2002
|
||||||
|
*
|
||||||
|
* File: DeviceNotifyListener.java
|
||||||
|
*
|
||||||
|
* Revision;
|
||||||
|
*
|
||||||
|
* 11/18/02
|
||||||
|
* - first revision.
|
||||||
|
*
|
||||||
|
******************************************************************/
|
||||||
|
|
||||||
|
package org.cybergarage.upnp.device;
|
||||||
|
|
||||||
|
import org.cybergarage.http.HTTPRequest;
|
||||||
|
|
||||||
|
public interface PresentationListener
|
||||||
|
{
|
||||||
|
public void httpRequestRecieved(HTTPRequest httpReq);
|
||||||
|
}
|
@@ -130,7 +130,7 @@ public class NotifyRequest extends SOAPRequest
|
|||||||
setSID(sid);
|
setSID(sid);
|
||||||
setSEQ(notifyCnt);
|
setSEQ(notifyCnt);
|
||||||
|
|
||||||
setContentType(XML.CONTENT_TYPE);
|
setContentType(XML.DEFAULT_CONTENT_TYPE);
|
||||||
Node propSetNode = createPropertySetNode(varName, value);
|
Node propSetNode = createPropertySetNode(varName, value);
|
||||||
setContent(propSetNode);
|
setContent(propSetNode);
|
||||||
|
|
||||||
|
@@ -108,4 +108,18 @@ public class SSDPRequest extends HTTPRequest
|
|||||||
String cacheCtrl = getHeaderValue(HTTP.CACHE_CONTROL);
|
String cacheCtrl = getHeaderValue(HTTP.CACHE_CONTROL);
|
||||||
return SSDP.getLeaseTime(cacheCtrl);
|
return SSDP.getLeaseTime(cacheCtrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
// BootId
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public void setBootId(int bootId)
|
||||||
|
{
|
||||||
|
setHeader(HTTP.BOOTID_UPNP_ORG, bootId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBootId()
|
||||||
|
{
|
||||||
|
return getIntegerHeaderValue(HTTP.BOOTID_UPNP_ORG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -115,6 +115,20 @@ public class SSDPResponse extends HTTPResponse
|
|||||||
return SSDP.getLeaseTime(cacheCtrl);
|
return SSDP.getLeaseTime(cacheCtrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
// BootId
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public void setBootId(int bootId)
|
||||||
|
{
|
||||||
|
setHeader(HTTP.BOOTID_UPNP_ORG, bootId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBootId()
|
||||||
|
{
|
||||||
|
return getIntegerHeaderValue(HTTP.BOOTID_UPNP_ORG);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// getHeader (Override)
|
// getHeader (Override)
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
@@ -61,9 +61,6 @@ public class SSDPSearchSocketList extends Vector<SSDPSearchSocket>
|
|||||||
this.multicastIPv6 = multicastIPv6;
|
this.multicastIPv6 = multicastIPv6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Methods
|
// Methods
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
@@ -18,7 +18,6 @@ package org.cybergarage.util;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public final class FileUtil
|
public final class FileUtil
|
||||||
{
|
{
|
||||||
@@ -73,7 +72,7 @@ public final class FileUtil
|
|||||||
{
|
{
|
||||||
if (StringUtil.hasData(name) == false)
|
if (StringUtil.hasData(name) == false)
|
||||||
return false;
|
return false;
|
||||||
String lowerName = name.toLowerCase(Locale.US);
|
String lowerName = name.toLowerCase();
|
||||||
return lowerName.endsWith("xml");
|
return lowerName.endsWith("xml");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -26,10 +26,17 @@ public class Attribute
|
|||||||
|
|
||||||
public Attribute(String name, String value)
|
public Attribute(String name, String value)
|
||||||
{
|
{
|
||||||
|
this();
|
||||||
setName(name);
|
setName(name);
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Attribute(Attribute otherAttr)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
set(otherAttr);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// name
|
// name
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -57,5 +64,15 @@ public class Attribute
|
|||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
// set
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public void set(Attribute otherAttr)
|
||||||
|
{
|
||||||
|
setName(otherAttr.getName());
|
||||||
|
setValue(otherAttr.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -61,6 +61,12 @@ public class Node
|
|||||||
setName(ns, name);
|
setName(ns, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Node(Node otherNode)
|
||||||
|
{
|
||||||
|
this();
|
||||||
|
set(otherNode);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// parent node
|
// parent node
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -189,6 +195,11 @@ public class Node
|
|||||||
return removeAttribute(getAttribute(name));
|
return removeAttribute(getAttribute(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeAllAttributes()
|
||||||
|
{
|
||||||
|
attrList.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean hasAttributes()
|
public boolean hasAttributes()
|
||||||
{
|
{
|
||||||
if (0 < getNAttributes())
|
if (0 < getNAttributes())
|
||||||
@@ -239,6 +250,51 @@ public class Node
|
|||||||
setAttribute("xmlns:" + ns, value);
|
setAttribute("xmlns:" + ns, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
// set
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public boolean set(Node otherNode) {
|
||||||
|
if (otherNode == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
setName(otherNode.getName());
|
||||||
|
setValue(otherNode.getValue());
|
||||||
|
|
||||||
|
removeAllAttributes();
|
||||||
|
int nOtherAttributes = otherNode.getNAttributes();
|
||||||
|
for (int n=0; n<nOtherAttributes; n++) {
|
||||||
|
Attribute otherAttr = otherNode.getAttribute(n);
|
||||||
|
Attribute thisAttr = new Attribute(otherAttr);
|
||||||
|
addAttribute(thisAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeAllNodes();
|
||||||
|
int nOtherChildNodes = otherNode.getNNodes();
|
||||||
|
for (int n=0; n<nOtherChildNodes; n++) {
|
||||||
|
Node otherChildNode = otherNode.getNode(n);
|
||||||
|
Node thisChildNode = new Node();
|
||||||
|
thisChildNode.set(otherChildNode);
|
||||||
|
addNode(thisChildNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
// equals
|
||||||
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public boolean equals(Node otherNode) {
|
||||||
|
if (otherNode == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
String thisNodeString = toString();
|
||||||
|
String otherNodeString = otherNode.toString();
|
||||||
|
|
||||||
|
return thisNodeString.equals(otherNodeString);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
// Child node
|
// Child node
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
@@ -309,17 +365,31 @@ public class Node
|
|||||||
// Element (Child Node)
|
// Element (Child Node)
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
|
||||||
public void setNode(String name, String value) {
|
public boolean hasNode(String name) {
|
||||||
Node node = getNode(name);
|
Node node = getNode(name);
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
node.setValue(value);
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNode(String name) {
|
||||||
|
if (hasNode(name)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
node = new Node(name);
|
Node node = new Node(name);
|
||||||
node.setValue(value);
|
|
||||||
addNode(node);
|
addNode(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNode(String name, String value) {
|
||||||
|
Node node = getNode(name);
|
||||||
|
if (node == null) {
|
||||||
|
node = new Node(name);
|
||||||
|
addNode(node);
|
||||||
|
}
|
||||||
|
node.setValue(value);
|
||||||
|
}
|
||||||
|
|
||||||
public String getNodeValue(String name) {
|
public String getNodeValue(String name) {
|
||||||
Node node = getNode(name);
|
Node node = getNode(name);
|
||||||
if (node != null)
|
if (node != null)
|
||||||
|
@@ -20,7 +20,8 @@ package org.cybergarage.xml;
|
|||||||
|
|
||||||
public class XML
|
public class XML
|
||||||
{
|
{
|
||||||
public final static String CONTENT_TYPE = "text/xml; charset=\"utf-8\"";
|
public final static String DEFAULT_CONTENT_TYPE = "text/xml; charset=\"utf-8\"";
|
||||||
|
public final static String DEFAULT_CONTENT_LANGUAGE = "en";
|
||||||
public final static String CHARSET_UTF8 = "utf-8";
|
public final static String CHARSET_UTF8 = "utf-8";
|
||||||
|
|
||||||
////////////////////////////////////////////////
|
////////////////////////////////////////////////
|
||||||
|
Reference in New Issue
Block a user