本文整理汇总了Java中org.dom4j.QName类的典型用法代码示例。如果您正苦于以下问题:Java QName类的具体用法?Java QName怎么用?Java QName使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
QName类属于org.dom4j包,在下文中一共展示了QName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toDsml
import org.dom4j.QName; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public Element toDsml( Element root )
{
Element element = super.toDsml( root );
// Request Name
if ( getDecorated().getRequestName() != null )
{
element.addElement( "requestName" ).setText(
getDecorated().getRequestName() );
}
// Request Value
Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI );
Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI );
element.getDocument().getRootElement().add( xsdNamespace );
element.getDocument().getRootElement().add( xsiNamespace );
Element valueElement = element.addElement( "requestValue" ).addText(
ParserUtils.base64Encode( getRequestValue() ) );
valueElement.addAttribute( new QName( "type", xsiNamespace ),
"xsd:" + ParserUtils.BASE64BINARY );
return element;
}
示例2: resolveQName
import org.dom4j.QName; //导入依赖的package包/类
/**
* Tries to resolve give QName into a "top-level" namespace and prefix. If the
* there is no prefix and the namespace is the default namespace, assign the
* NAMED defaultNamespace.
*
* @param qName Description of the Parameter
* @return Description of the Return Value
* @exception Exception Description of the Exception
*/
private QName resolveQName(QName qName) throws Exception {
String prefix = qName.getNamespacePrefix();
String name = qName.getName();
String uri = qName.getNamespaceURI();
prtln("\n\t resolveQName: ", 1);
prtln("\t\t name: " + name, 1);
prtln("\t\t prefix: " + prefix, 1);
prtln("\t\t uri: " + uri, 1);
Namespace topLevelNS = namespaces.getNSforUri(uri);
if (topLevelNS == null) {
prtlnErr("ERROR: resolveQName could not find top-level namespace for " + uri);
return null;
}
else if (topLevelNS == namespaces.getDefaultNamespace()) {
topLevelNS = namespaces.getNamedDefaultNamespace();
}
return df.createQName(name, topLevelNS);
}
示例3: createChildElement
import org.dom4j.QName; //导入依赖的package包/类
/**
* Resolve qualified name against top-level namespace registry
*
* @param name NOT YET DOCUMENTED
* @return NOT YET DOCUMENTED
*/
private Element createChildElement(String name) {
prtln("\n createChildElement() name: " + name, 1);
Namespace ns = getCurrentNamespace();
prtln("\t currentNamespace -- " + ns.getPrefix() + ": " + ns.getURI(), 1);
Element child = null;
if (ns == null || !namespaceEnabled) {
child = df.createElement(name);
}
else {
QName baseQName = df.createQName(name, ns);
try {
child = df.createElement(resolveQName(baseQName));
} catch (Exception e) {
prtlnErr("createChildElement error: " + e.getMessage());
e.printStackTrace();
return null;
}
}
prtln(" ... child: " + child.asXML(), 1);
return child;
}
示例4: removeNamespaces
import org.dom4j.QName; //导入依赖的package包/类
/**
* Remove namespaces from element recursively.
*/
@SuppressWarnings("unchecked")
public void removeNamespaces( Element elem )
{
elem.setQName( QName.get( elem.getName(), Namespace.NO_NAMESPACE, elem.getQualifiedName() ) );
Node n;
Iterator<Node> it = elem.elementIterator();
while ( it.hasNext() )
{
n = it.next();
switch ( n.getNodeType() )
{
case Node.ATTRIBUTE_NODE:
( (Attribute) n ).setNamespace( Namespace.NO_NAMESPACE );
break;
case Node.ELEMENT_NODE:
removeNamespaces( (Element) n );
break;
}
}
}
示例5: createNotificationIQ
import org.dom4j.QName; //导入依赖的package包/类
/**
* 创建一个新的通知IQ,并返回它。
*
* @param imageUrl
*/
private IQ createNotificationIQ(String id, String apiKey, String title,
String message, String uri, String imageUrl) {
// Random random = new Random();
// String id = Integer.toHexString(random.nextInt());
// String id = String.valueOf(System.currentTimeMillis());
Element notification = DocumentHelper.createElement(QName.get(
"notification", NOTIFICATION_NAMESPACE));
notification.addElement("id").setText(id);
notification.addElement("apiKey").setText(apiKey);
notification.addElement("title").setText(title);
notification.addElement("message").setText(message);
notification.addElement("uri").setText(uri);
notification.addElement("imageUrl").setText(imageUrl);
IQ iq = new IQ();
iq.setType(IQ.Type.set);
iq.setChildElement(notification);
return iq;
}
示例6: resolveQName
import org.dom4j.QName; //导入依赖的package包/类
/**
* Tries to resolve give QName into a "top-level" namespace and prefix. If the
* there is no prefix and the namespace is the default namespace, assign the
* NAMED defaultNamespace.
*
* @param qName Description of the Parameter
* @return Description of the Return Value
* @exception Exception Description of the Exception
*/
private QName resolveQName(QName qName) throws Exception {
String prefix = qName.getNamespacePrefix();
String name = qName.getName();
String uri = qName.getNamespaceURI();
prtln("\n\t resolveQName: ", 1);
prtln("\t\t name: " + name, 1);
prtln("\t\t prefix: " + prefix, 1);
prtln("\t\t uri: " + uri, 1);
Namespace topLevelNS = namespaces.getNSforUri(uri);
if (topLevelNS == null) {
prtlnErr("ERROR: resolveQName could not find top-level namespace for " + uri);
return null;
}
else if (topLevelNS == namespaces.getDefaultNamespace()) {
topLevelNS = namespaces.getNamedDefaultNamespace();
}
return DocumentHelper.createQName(name, topLevelNS);
}
示例7: createChildElement
import org.dom4j.QName; //导入依赖的package包/类
/**
* Resolve qualified name against top-level namespace registry
*
* @param name NOT YET DOCUMENTED
* @return NOT YET DOCUMENTED
*/
private Element createChildElement(String name) {
prtln("\n createChildElement() name: " + name, 1);
Namespace ns = getCurrentNamespace();
prtln("\t currentNamespace -- " + ns.getPrefix() + ": " + ns.getURI(), 1);
Element child = null;
if (ns == null || !namespaceEnabled) {
child = DocumentHelper.createElement(name);
}
else {
QName baseQName = DocumentHelper.createQName(name, ns);
try {
child = DocumentHelper.createElement(resolveQName(baseQName));
} catch (Exception e) {
prtlnErr("createChildElement error: " + e.getMessage());
e.printStackTrace();
return null;
}
}
prtln(" ... child: " + child.asXML(), 1);
return child;
}
示例8: generateSetElementFromResults
import org.dom4j.QName; //导入依赖的package包/类
/**
* Generates a Result Set Management 'set' element that describes the parto
* of the result set that was generated. You typically would use the List
* that was returned by {@link #applyRSMDirectives(Element)} as an argument
* to this method.
*
* @param returnedResults
* The subset of Results that is returned by the current query.
* @return An Element named 'set' that can be included in the result IQ
* stanza, which returns the subset of results.
*/
public Element generateSetElementFromResults(List<E> returnedResults) {
if (returnedResults == null) {
throw new IllegalArgumentException(
"Argument 'returnedResults' cannot be null.");
}
final Element setElement = DocumentHelper.createElement(QName.get(
"set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT));
// the size element contains the size of this entire result set.
setElement.addElement("count").setText(String.valueOf(size()));
// if the query wasn't a 'count only' query, add two more elements
if (returnedResults.size() > 0) {
final Element firstElement = setElement.addElement("first");
firstElement.addText(returnedResults.get(0).getUID());
firstElement.addAttribute("index", String
.valueOf(indexOf(returnedResults.get(0))));
setElement.addElement("last").addText(
returnedResults.get(returnedResults.size() - 1).getUID());
}
return setElement;
}
示例9: getItems
import org.dom4j.QName; //导入依赖的package包/类
/**
* Returns an unmodifiable copy of the {@link Item Items} in the roster packet.
*
* @return an unmodifable copy of the {@link Item Items} in the roster packet.
*/
@SuppressWarnings("unchecked")
public Collection<Item> getItems() {
Collection<Item> items = new ArrayList<Item>();
Element query = element.element(new QName("query", Namespace.get("jabber:iq:roster")));
if (query != null) {
for (Iterator<Element> i=query.elementIterator("item"); i.hasNext(); ) {
Element item = i.next();
String jid = item.attributeValue("jid");
String name = item.attributeValue("name");
String ask = item.attributeValue("ask");
String subscription = item.attributeValue("subscription");
Collection<String> groups = new ArrayList<String>();
for (Iterator<Element> j=item.elementIterator("group"); j.hasNext(); ) {
Element group = j.next();
groups.add(group.getText().trim());
}
Ask askStatus = ask == null ? null : Ask.valueOf(ask);
Subscription subStatus = subscription == null ?
null : Subscription.valueOf(subscription);
items.add(new Item(new JID(jid), name, askStatus, subStatus, groups));
}
}
return Collections.unmodifiableCollection(items);
}
示例10: getExtension
import org.dom4j.QName; //导入依赖的package包/类
/**
* Returns a {@link PacketExtension} on the first element found in this packet's
* child element for the specified <tt>name</tt> and <tt>namespace</tt> or <tt>null</tt> if
* none was found. If the IQ packet does not have a child element then <tt>null</tt>
* will be returned.<p>
*
* Note: packet extensions on IQ packets are only for use in specialized situations.
* In most cases, you should only need to set the child element of the IQ.
*
* @param name the child element name.
* @param namespace the child element namespace.
* @return a PacketExtension on the first element found in this packet for the specified
* name and namespace or <tt>null</tt> if none was found.
*/
@SuppressWarnings("unchecked")
public PacketExtension getExtension(String name, String namespace) {
Element childElement = getChildElement();
if (childElement == null) {
return null;
}
// Search for extensions in the child element
List<Element> extensions = childElement.elements(QName.get(name, namespace));
if (!extensions.isEmpty()) {
Class<? extends PacketExtension> extensionClass = PacketExtension.getExtensionClass(name, namespace);
if (extensionClass != null) {
try {
Constructor<? extends PacketExtension> constructor = extensionClass.getDeclaredConstructor(new Class[]{
Element.class});
return constructor.newInstance(new Object[]{
extensions.get(0)});
}
catch (Exception e) {
Log.warn("Packet extension (name "+name+", namespace "+namespace+") cannot be found.", e);
}
}
}
return null;
}
示例11: setText
import org.dom4j.QName; //导入依赖的package包/类
/**
* Sets the text description of the error. Optionally, a language code
* can be specified to indicate the language of the description.
*
* @param text the text description of the error.
* @param lang the language code of the description, or <tt>null</tt> to specify
* no language code.
*/
public void setText(String text, String lang) {
Element textElement = element.element("text");
// If text is null, clear the text.
if (text == null) {
if (textElement != null) {
element.remove(textElement);
}
return;
}
if (textElement == null) {
textElement = docFactory.createElement("text", ERROR_NAMESPACE);
if (lang != null) {
textElement.addAttribute(QName.get("lang", "xml",
"http://www.w3.org/XML/1998/namespace"), lang);
}
element.add(textElement);
}
textElement.setText(text);
}
示例12: setText
import org.dom4j.QName; //导入依赖的package包/类
/**
* Sets the text description of the error. Optionally, a language code
* can be specified to indicate the language of the description.
*
* @param text the text description of the error.
* @param language the language code of the description, or <tt>null</tt> to specify
* no language code.
*/
public void setText(String text, String language) {
Element textElement = element.element("text");
// If text is null, clear the text.
if (text == null) {
if (textElement != null) {
element.remove(textElement);
}
return;
}
if (textElement == null) {
textElement = docFactory.createElement("text", ERROR_NAMESPACE);
if (language != null) {
textElement.addAttribute(QName.get("lang", "xml",
"http://www.w3.org/XML/1998/namespace"), language);
}
element.add(textElement);
}
textElement.setText(text);
}
示例13: getExtension
import org.dom4j.QName; //导入依赖的package包/类
/**
* Returns a {@link PacketExtension} on the first element found in this packet
* for the specified <tt>name</tt> and <tt>namespace</tt> or <tt>null</tt> if
* none was found.
*
* @param name the child element name.
* @param namespace the child element namespace.
* @return a PacketExtension on the first element found in this packet for the specified
* name and namespace or null if none was found.
*/
@SuppressWarnings("unchecked")
public PacketExtension getExtension(String name, String namespace) {
List<Element> extensions = element.elements(QName.get(name, namespace));
if (!extensions.isEmpty()) {
Class<? extends PacketExtension> extensionClass = PacketExtension.getExtensionClass(name, namespace);
// If a specific PacketExtension implementation has been registered, use that.
if (extensionClass != null) {
try {
Constructor<? extends PacketExtension> constructor = extensionClass.getDeclaredConstructor(Element.class);
return constructor.newInstance(extensions.get(0));
}
catch (Exception e) {
Log.warn("Packet extension (name "+name+", namespace "+namespace+") cannot be found.", e);
}
}
// Otherwise, use a normal PacketExtension.
else {
return new PacketExtension(extensions.get(0));
}
}
return null;
}
示例14: addAttribute
import org.dom4j.QName; //导入依赖的package包/类
public void addAttribute(QName name, AX2JMethod method, int methodType) {
AX2JAttribute attribute = findAttribute(name);
if (attribute == null) {
attribute = new AX2JAttribute(name, type);
attributeList.add(attribute);
}
AX2JMethod oldMethod = findMethod(method);
if (oldMethod != null) {
method = oldMethod;
} else {
methodList.add(method);
}
if (method.findAttribute(attribute) == null) {
method.addRelativeAttribute(attribute);
}
if (attribute.findMethod(method) == null) {
attribute.addRelativeMethod(method, methodType);
}
}
示例15: construct
import org.dom4j.QName; //导入依赖的package包/类
@Override
protected void construct() {
try {
defaultHeader().action(new URI("http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command"))
.resourceURI(new URI("http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd")).shellId(shellId);
Element body = DocumentHelper.createElement(QName.get("Signal", Namespaces.NS_WIN_SHELL)).addAttribute(
"CommandId",
commandId);
body.addElement(QName.get("Code", Namespaces.NS_WIN_SHELL))
.addText("http://schemas.microsoft.com/wbem/wsman/1/windows/shell/signal/terminate");
setBody(body);
} catch (URISyntaxException e) {
throw new RuntimeException("Error while building request content", e);
}
}