/*
* Copyright (C) 2011 Teleal GmbH, Switzerland
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.teleal.cling.support.contentdirectory;
import org.teleal.cling.model.types.Datatype;
import org.teleal.cling.model.types.InvalidValueException;
import org.teleal.cling.support.model.DIDLAttribute;
import org.teleal.cling.support.model.DIDLContent;
import org.teleal.cling.support.model.DIDLObject;
import org.teleal.cling.support.model.DescMeta;
import org.teleal.cling.support.model.Person;
import org.teleal.cling.support.model.PersonWithRole;
import org.teleal.cling.support.model.ProtocolInfo;
import org.teleal.cling.support.model.Res;
import org.teleal.cling.support.model.StorageMedium;
import org.teleal.cling.support.model.WriteStatus;
import org.teleal.cling.support.model.container.Container;
import org.teleal.cling.support.model.item.Item;
import org.teleal.common.io.IO;
import org.teleal.common.util.Exceptions;
import org.teleal.common.xml.SAXParser;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.InputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.teleal.cling.model.XMLUtil.appendNewElement;
import static org.teleal.cling.model.XMLUtil.appendNewElementIfNotNull;
/**
* DIDL parser based on SAX for reading and DOM for writing.
* <p>
* This parser requires Android platform level 8 (2.2).
* </p>
* <p>
* Override the {@link #createDescMetaHandler(org.teleal.cling.support.model.DescMeta, org.teleal.common.xml.SAXParser.Handler)}
* method to read vendor extension content of {@code <desc>} elements. You then should also override the
* {@link #populateDescMetadata(org.w3c.dom.Element, org.teleal.cling.support.model.DescMeta)} method for writing.
* </p>
* <p>
* Override the {@link #createItemHandler(org.teleal.cling.support.model.item.Item, org.teleal.common.xml.SAXParser.Handler)}
* etc. methods to register custom handlers for vendor-specific elements and attributes within items, containers,
* and so on.
* </p>
*
* @author Christian Bauer
* @author Mario Franco
*/
public class DIDLParser extends SAXParser {
final private static Logger log = Logger.getLogger(DIDLParser.class.getName());
/**
* Uses the current thread's context classloader to read and unmarshall the given resource.
*
* @param resource The resource on the classpath.
* @return The unmarshalled DIDL content model.
* @throws Exception
*/
public DIDLContent parseResource(String resource) throws Exception {
InputStream is = null;
try {
is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
return parse(IO.readLines(is));
} finally {
if (is != null) is.close();
}
}
/**
* Reads and unmarshalls an XML representation into a DIDL content model.
*
* @param xml The XML representation.
* @return A DIDL content model.
* @throws Exception
*/
public DIDLContent parse(String xml) throws Exception {
if (xml == null || xml.length() == 0) {
throw new RuntimeException("Null or empty XML");
}
DIDLContent content = new DIDLContent();
createRootHandler(content, this);
log.fine("Parsing DIDL XML content");
parse(new InputSource(new StringReader(xml)));
return content;
}
protected RootHandler createRootHandler(DIDLContent instance, SAXParser parser) {
return new RootHandler(instance, parser);
}
protected ContainerHandler createContainerHandler(Container instance, Handler parent) {
return new ContainerHandler(instance, parent);
}
protected ItemHandler createItemHandler(Item instance, Handler parent) {
return new ItemHandler(instance, parent);
}
protected ResHandler createResHandler(Res instance, Handler parent) {
return new ResHandler(instance, parent);
}
protected DescMetaHandler createDescMetaHandler(DescMeta instance, Handler parent) {
return new DescMetaHandler(instance, parent);
}
protected Container createContainer(Attributes attributes) {
Container container = new Container();
container.setId(attributes.getValue("id"));
container.setParentID(attributes.getValue("parentID"));
if ((attributes.getValue("childCount") != null))
container.setChildCount(Integer.valueOf(attributes.getValue("childCount")));
try {
Boolean value = (Boolean)Datatype.Builtin.BOOLEAN.getDatatype().valueOf(
attributes.getValue("restricted")
);
if (value != null)
container.setRestricted(value);
value = (Boolean)Datatype.Builtin.BOOLEAN.getDatatype().valueOf(
attributes.getValue("searchable")
);
if (value != null)
container.setSearchable(value);
} catch (Exception ex) {
// Ignore
}
return container;
}
protected Item createItem(Attributes attributes) {
Item item = new Item();
item.setId(attributes.getValue("id"));
item.setParentID(attributes.getValue("parentID"));
try {
Boolean value = (Boolean)Datatype.Builtin.BOOLEAN.getDatatype().valueOf(
attributes.getValue("restricted")
);
if (value != null)
item.setRestricted(value);
} catch (Exception ex) {
// Ignore
}
if ((attributes.getValue("refID") != null))
item.setRefID(attributes.getValue("refID"));
return item;
}
protected Res createResource(Attributes attributes) {
Res res = new Res();
if (attributes.getValue("importUri") != null)
res.setImportUri(URI.create(attributes.getValue("importUri")));
try {
res.setProtocolInfo(
new ProtocolInfo(attributes.getValue("protocolInfo"))
);
} catch (InvalidValueException ex) {
log.warning("In DIDL content, invalid resource protocol info: " + Exceptions.unwrap(ex));
return null;
}
if (attributes.getValue("size") != null)
res.setSize(Long.valueOf(attributes.getValue("size")));
if (attributes.getValue("duration") != null)
res.setDuration(attributes.getValue("duration"));
if (attributes.getValue("bitrate") != null)
res.setBitrate(Long.valueOf(attributes.getValue("bitrate")));
if (attributes.getValue("sampleFrequency") != null)
res.setSampleFrequency(Long.valueOf(attributes.getValue("sampleFrequency")));
if (attributes.getValue("bitsPerSample") != null)
res.setBitsPerSample(Long.valueOf(attrib
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
android DLNA实现代码 (410个子文件)
resources.ap_ 12KB
Wireme.apk 402KB
jarlist.cache 119B
proguard.cfg 1KB
DIDLParser.class 22KB
MainActivity.class 15KB
AVTransportService.class 13KB
HttpServer$HTTPSession.class 13KB
HttpServer.class 12KB
DIDLObject.class 12KB
DIDLParser$DIDLObjectHandler.class 11KB
AbstractPeeringConnectionManagerService.class 9KB
Container.class 9KB
TextItem.class 9KB
MusicAlbum.class 9KB
GPlayer.class 8KB
LastChangeParser.class 8KB
VideoItem.class 8KB
PlaylistContainer.class 8KB
AbstractContentDirectoryService.class 8KB
AbstractAVTransportService.class 8KB
MusicTrack.class 8KB
DIDLContent.class 7KB
ConnectionManagerService.class 7KB
MusicVideoClip.class 7KB
Album.class 7KB
AudioItem.class 7KB
PlaylistItem.class 6KB
ImageItem.class 6KB
AbstractMap.class 6KB
PortMapping.class 6KB
Browse.class 6KB
AudioBook.class 6KB
LastChange.class 6KB
DIDLParser$ContainerHandler.class 5KB
MediaInfo.class 5KB
PositionInfo.class 5KB
Res.class 5KB
Movie.class 5KB
DIDLObject$Property.class 5KB
StorageMedium.class 5KB
StorageSystem.class 5KB
Item.class 4KB
ContentDirectoryService.class 4KB
PhotoAlbum.class 4KB
LogCategories.class 4KB
StorageVolume.class 4KB
ContentBrowseActionCallback.class 4KB
MediaServer.class 4KB
Playing.class 4KB
Stopped.class 4KB
DIDLParser$ItemHandler.class 4KB
AVTransportErrorCode.class 4KB
GetCurrentConnectionInfo.class 4KB
AbstractPeeringConnectionManagerService$1.class 4KB
DIDLParser$RootHandler.class 4KB
MainActivity$1.class 4KB
ConnectionInfo.class 4KB
PausedPlay.class 4KB
ContentBrowseActionCallback$1.class 4KB
AVTransport.class 4KB
MusicArtist.class 4KB
Event.class 4KB
DIDLParser$DescMetaHandler.class 4KB
MainActivity$DeviceListRegistryListener.class 4KB
NoMediaPresent.class 4KB
AudioBroadcast.class 3KB
DIDLObject$Property$UPNP.class 3KB
LastChangeParser$InstanceIDHandler.class 3KB
AVTransportVariable$1.class 3KB
ProtocolInfo.class 3KB
VideoBroadcast.class 3KB
AVTransportVariable.class 3KB
MainActivity$2.class 3KB
RecordQualityMode.class 3KB
MainActivity$3.class 3KB
EventedValue.class 3KB
PrepareForConnection.class 3KB
DescMeta.class 3KB
ConnectionManagerErrorCode.class 3KB
LastChangeParser$RootHandler.class 3KB
TransportInfo.class 3KB
StorageFolder.class 3KB
GetProtocolInfo.class 3KB
ContentTree.class 3KB
DeviceCapabilities.class 3KB
Connection$StatusInfo.class 3KB
Photo.class 3KB
DeviceItem.class 3KB
AbstractMap$SimpleImmutableEntry.class 3KB
AbstractMap$SimpleEntry.class 3KB
SortCriterion.class 3KB
SetAVTransportURI.class 3KB
PersonContainer.class 3KB
Seek.class 3KB
TransportAction.class 2KB
GetCurrentTransportActions.class 2KB
ContentItem.class 2KB
EventedValueURI.class 2KB
FixedAndroidHandler.class 2KB
共 410 条
- 1
- 2
- 3
- 4
- 5
资源评论
- 小小哈哈2013-02-27又是这个WireMe,我已经下过了。分这么高,坑人啊。
- tedyu2013-05-25连续下载了好几个WireMe
- liubofei741102014-05-24又是这个WireMe,
- lgj19912015-01-28本来是为毕业设计找资源的,可是好像找到的都是WireMe
kyrinleo
- 粉丝: 14
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功