📄 .#contentdirectoryservice.java.1.3
字号:
package no.auc.one.portableplayer.communication.mediaserver;
import java.io.*;
import java.util.*;
import javax.microedition.io.*;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import no.auc.one.portableplayer.communication.*;
import no.auc.one.portableplayer.communication.soap.*;
import no.auc.one.portableplayer.utils.*;
import no.auc.one.portableplayer.librarymanager.*;
import org.apache.log4j.*;
/**
* Describes a UPnP Content Directory service of a Media Server device.
*/
public class ContentDirectoryService extends UPnPService implements Cloneable {
private static Logger LOG;
/**
* To request all available content to be returned.
*/
public static final int REQUEST_ALL = 0;
private static final int BROWSEFLAG_DIRECT_CHILDREN = 0;
private static final int BROWSEFLAG_METADATA = 1;
// To support clone() method.
private ContentDirectoryService(
String type,
String id,
String scpd,
String eventSub,
String control)
{
super(type, id, scpd, eventSub, control);
LOG = Logger.getLogger("CDS");
}
/**
* Construct a new class instance based on the UPnPService.
*
* @param service Service to base this class instance on.
*/
public ContentDirectoryService(
UPnPService service)
{
super(
service.getServiceType(),
service.getServiceID(),
service.getScpdURL(),
service.getEventSubURL(),
service.getControlURL());
}
/**
* Create a clone of this class instance.
*
* @return Clone of this class instance.
*/
public Object clone() {
return new ContentDirectoryService(
getServiceType(),
getServiceID(),
getScpdURL(),
getEventSubURL(),
getControlURL());
}
/**
* Browse and retrieve all available children of a container.
*
* @param containerId ID for the requested container.
*/
public ContentContainer browseDirectChildren(String containerId)
throws IOException
{
return browseDirectChildren(containerId, 0, REQUEST_ALL);
}
/**
* Initial browsing of a container of the media server's content directory
* service.
*
* @param containerId ID for the container to retrieve content from.
* @param startIndex Index for elements to be retrieved.
* @param requestedCount Requested count of elements to be retrieved.
* REQUEST_ALL(=0) means get all available elements.
*
* @return Returns a ContentContainer object which includes the children of
* it in a MediaContent array.
*
* @throws IOException
*/
public ContentContainer browseDirectChildren(
String containerId,
int startIndex,
int requestedCount) throws IOException
{
ContentContainer cc = null;
try {
ContentContainerHandler ccHandler = new ContentContainerHandler();
invokeBrowse(
containerId,
BROWSEFLAG_DIRECT_CHILDREN,
startIndex,
requestedCount,
ccHandler);
MediaContent[] mc = ccHandler.getMediaContent();
System.out.println(
"browse result: total matches=" + ccHandler.getTotalMatches() +
"\tnumber returned=" + ccHandler.getNumberReturned() +
"\tmc length=" + mc.length);
cc = new ContentContainer(
containerId,
"0",
"container",
mc);
} catch (NoSuchElementException nse) {
LOG.fatal(nse);
}
return cc;
}
/**
* Continued browsing of a container. This method should be used to
* continue browsing a container already retrieved from the 'initial'
* browseDirectChildren method overload.
*/
public void browseDirectChildren(
ContentContainer container,
int startIndex,
int requestedCount) throws IOException
{
try {
ContentContainerHandler ccHandler = new ContentContainerHandler();
System.out.println(
"Invoking browse for container ID=" + container.getObjectID() +
", startindex=" + startIndex + ", reqcount=" + requestedCount);
invokeBrowse(
container.getObjectID(),
BROWSEFLAG_DIRECT_CHILDREN,
startIndex,
requestedCount,
ccHandler);
System.out.println(
"Total matches: " + ccHandler.getTotalMatches() +
", Elemements fetched: " + ccHandler.getNumberReturned());
if(container.totalLength() == -1) { // container is currently empty
System.out.println("Container is currently empty.");
/*
container = new ContentContainer(
container.getObjectID(),
container.getParentID(),
container.getName(),
ccHandler.getTotalMatches());
*/
container.setTotalLength(ccHandler.getTotalMatches());
container.insertMediaContentAt(
0,
ccHandler.getMediaContent());
/*
if (container.totalLength() != ccHandler.getTotalMatches()) {
System.out.println(
"container.totalLength(" + container.totalLength() +
" != totalMatches(" + ccHandler.getTotalMatches());
retContainer = new ContentContainer(
container.getObjectID(),
container.getParentID(),
container.getName());
retContainer.insertMediaContentAt(
ccHandler.getMediaContent());
*/
} else {
System.out.println(
"container.totalLength(" + container.totalLength() +
") == ccHHandler.totalMatches(" +
ccHandler.getTotalMatches() + ")");
MediaContent[] mc = ccHandler.getMediaContent();
// XXX Is this test redundant?
if (mc.length > (container.totalLength() - startIndex)) {
System.out.println(
"Ouch, mc.length(" + mc.length +
") > container.length(" + container.totalLength() +
") - startIndex(" + startIndex +
") Nope test is not redundant!");
}
/*
container = new ContentContainer(
container.getObjectID(),
container.getParentID(),
container.getName(),
ccHandler.getTotalMatches());
container.insertMediaContentAt(
0,
container.getMediaContent());
*/
container.insertMediaContentAt(
startIndex,
mc);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -