本文整理汇总了Java中org.jdom2.CDATA类的典型用法代码示例。如果您正苦于以下问题:Java CDATA类的具体用法?Java CDATA怎么用?Java CDATA使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CDATA类属于org.jdom2包,在下文中一共展示了CDATA类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: objectToString
import org.jdom2.CDATA; //导入依赖的package包/类
/**
* Returns the string value of the given XML node object, depending on its type.
*
* @param object
* @return String
*/
public static String objectToString(Object object) {
if (object instanceof Element) {
return ((Element) object).getText();
} else if (object instanceof Attribute) {
return ((Attribute) object).getValue();
} else if (object instanceof Text) {
return ((Text) object).getText();
} else if (object instanceof CDATA) {
return ((CDATA) object).getText();
} else if (object instanceof Comment) {
return ((Comment) object).getText();
} else if (object instanceof Double) {
return String.valueOf(object);
} else if (object instanceof Boolean) {
return String.valueOf(object);
} else if (object instanceof String) {
return (String) object;
} else if (object != null) {
logger.error("Unknown object type: {}", object.getClass().getName());
return null;
} else {
return null;
}
}
示例2: musicMessageToXml
import org.jdom2.CDATA; //导入依赖的package包/类
/**
* 音乐消息对象转换成xml
*
* @param musicMessage
* 音乐消息对象
* @return xml
*/
public static String musicMessageToXml(MusicMessage message) {
Document document = new Document();
Element root = new Element("xml");
Element music = new Element("Music");
music.addContent(new Element("Title").setContent(new CDATA(message.getMusic().getTitle())));
music.addContent(new Element("Description").setContent(new CDATA(message.getMusic().getDescription())));
music.addContent(new Element("MusicUrl").setContent(new CDATA(message.getMusic().getMusicUrl())));
music.addContent(new Element("HQMusicUrl").setContent(new CDATA(message.getMusic().getHQMusicUrl())));
root.addContent(new Element("ToUserName").setContent(new CDATA(message.getToUserName())));
root.addContent(new Element("FromUserName").setContent(new CDATA(message.getFromUserName())));
root.addContent(new Element("CreateTime").setContent(new CDATA(String.valueOf(message.getCreateTime()))));
root.addContent(new Element("MsgType").setContent(new CDATA(message.getMsgType())));
root.addContent(new Element("FuncFlag").setContent(new CDATA(String.valueOf(message.getFuncFlag()))));
root.addContent(music);
document.addContent(root);
XMLOutputter out = new XMLOutputter(Format.getRawFormat().setOmitDeclaration(true));
return out.outputString(document);
}
示例3: setValue
import org.jdom2.CDATA; //导入依赖的package包/类
private static void setValue(Element e, Object v, String name) {
if (v instanceof Map)
e.addContent(msg2xml(v, name));
else if (v instanceof List)
e.addContent(msg2xml(v, name));
else {
Element n = new Element(name);
if (v instanceof Number || v instanceof Boolean)
n.addContent(String.valueOf(v));
else {
n.addContent(new CDATA(String.valueOf(v)));
}
e.addContent(n);
}
}
示例4: writeChildren
import org.jdom2.CDATA; //导入依赖的package包/类
private void writeChildren(TreeItem<Clip> parentTreeItem, Element parentElement)
{
List<TreeItem<Clip>> treeItems = parentTreeItem.getChildren();
for (TreeItem<Clip> treeItem : treeItems)
{
if (treeItem.getValue().isGroup())
{
Element groupElement = new Element("group");
groupElement.setAttribute("name", treeItem.getValue().getName());
writeChildren(treeItem, groupElement);
parentElement.addContent(groupElement);
}
else
{
Element clipElement = new Element("clip");
parentElement.addContent(clipElement);
Element nameElement = new Element("name");
clipElement.addContent(nameElement);
nameElement.setText(treeItem.getValue().getName());
Element contentElement = new Element("content");
clipElement.addContent(contentElement);
contentElement.setContent(new CDATA(treeItem.getValue().getContent()));
}
}
}
示例5: xml2dbo
import org.jdom2.CDATA; //导入依赖的package包/类
/**
* 将微信XML转换化DBO
*
* @param xml
* MESSAGE XML
* @return DBO
*/
public static BasicDBObject xml2dbo(Document xml) {
if (xml == null)
return null;
List<Element> params = xml.getRootElement().getChildren();
if (params == null || params.size() <= 0)
return null;
//log.info(xml2str(xml));
BasicDBObject dbo = new BasicDBObject();
for (Element e : params) {
List<Content> cs = e.getContent();
if (cs != null && cs.size() > 0) {
for (Content c : cs) {
if (c != null) {
Object o = null;
switch (c.getCType()) {
case Text:
case CDATA:
o = c.getValue();
break;
default:;
}
if (!CommonUtil.isEmpty(o)) {
if (e.getName().equalsIgnoreCase("createtime"))
o = Integer.parseInt(o.toString());
dbo.append(e.getName(), o);
}
}
}
}
}
return dbo;
}
示例6: createElement
import org.jdom2.CDATA; //导入依赖的package包/类
private Element createElement(Item item) {
Element element = new Element("item");
if (item.getUid() != null) {
element.setAttribute(new Attribute("uid", item.getUid()));
}
if (item.getArg() != null) {
element.setAttribute(new Attribute("arg", item.getArg()));
}
if (item.getType() != null) {
element.setAttribute(new Attribute("arg", item.getType().getName()));
} else {
element.setAttribute(new Attribute("arg", Type.FILE.getName()));
}
if (item.getTitle() != null) {
element.addContent(new Element("title").setText(item.getTitle()));
}
if (item.getSubTitle() != null) {
element.addContent(new Element("subtitle").setText(item.getSubTitle()));
}
if (item.getIcon() != null && item.getIconType() != null) {
Element iconElement = new Element("icon");
iconElement.setAttribute(new Attribute("type", item.getIconType().getName()));
iconElement.setContent(new CDATA(item.getIcon()));
element.addContent(iconElement);
}
return element;
}
示例7: generateCDATAElement
import org.jdom2.CDATA; //导入依赖的package包/类
protected Element generateCDATAElement(String name, String value) {
Element element = new Element(name, CONTENT_NS);
CDATA cdata = new CDATA(value);
element.addContent(cdata);
return element;
}
示例8: generateCDATAElement
import org.jdom2.CDATA; //导入依赖的package包/类
protected Element generateCDATAElement(final String name, final String value) {
final Element element = new Element(name, CONTENT_NS);
final CDATA cdata = new CDATA(value);
element.addContent(cdata);
return element;
}
示例9: testTrimContents
import org.jdom2.CDATA; //导入依赖的package包/类
public void testTrimContents() {
Content whitespace = new Text(" \n\t\t");
Content cdata = new CDATA("Test");
List<Content> content;
List newList;
// Empty content list
content = new ArrayList<>();
assertEquals(0, AtomParserUtils.trimContents(content).size());
// Whitespace
content = new ArrayList<>(1);
content.add(whitespace);
assertEquals(0, AtomParserUtils.trimContents(content).size());
// Two whitespaces
content = new ArrayList<>(2);
content.add(whitespace);
content.add(whitespace);
assertEquals(0, AtomParserUtils.trimContents(content).size());
// CDATA alone
content = new ArrayList<>(1);
content.add(cdata);
newList = AtomParserUtils.trimContents(content);
assertEquals(1, newList.size());
assertTrue(newList.get(0) == cdata);
// Whitespace + CDATA
content = new ArrayList<>(2);
content.add(whitespace);
content.add(cdata);
newList = AtomParserUtils.trimContents(content);
assertEquals(1, newList.size());
assertTrue(newList.get(0) == cdata);
// CDATA + whitespace
content = new ArrayList<>(2);
content.add(cdata);
content.add(whitespace);
newList = AtomParserUtils.trimContents(content);
assertEquals(1, newList.size());
assertTrue(newList.get(0) == cdata);
// CDATA surrounded with whitespaces
content = new ArrayList<>(2);
content.add(whitespace);
content.add(cdata);
content.add(whitespace);
newList = AtomParserUtils.trimContents(content);
assertEquals(1, newList.size());
assertTrue(newList.get(0) == cdata);
// Two CDATA's surrounded with couples of whitespaces
content = new ArrayList<>(2);
content.add(whitespace);
content.add(whitespace);
content.add(cdata);
content.add(cdata);
content.add(whitespace);
content.add(whitespace);
newList = AtomParserUtils.trimContents(content);
assertEquals(2, newList.size());
assertTrue(newList.get(0) == cdata);
assertTrue(newList.get(1) == cdata);
}
示例10: setCdataValue
import org.jdom2.CDATA; //导入依赖的package包/类
public void setCdataValue(String value) {
if (value != null) {
element.setContent(new CDATA(value));
}
}