org.dom4j.Element.createCopy()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(336)

本文整理了Java中org.dom4j.Element.createCopy()方法的一些代码示例,展示了Element.createCopy()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.createCopy()方法的具体详情如下:
包路径:org.dom4j.Element
类名称:Element
方法名:createCopy

Element.createCopy介绍

[英]Creates a deep copy of this element The new element is detached from its parent, and getParent() on the clone will return null.
[中]创建此元素的深度副本新元素将与其父元素分离,克隆上的getParent()将返回null。

代码示例

代码示例来源:origin: igniterealtime/Openfire

Element asElement() {
  return itemElement.createCopy();
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Returns the vCard of a given user or null if none was defined before. Changes to the
 * returned vCard will not be stored in the database. Use the returned vCard as a
 * read-only vCard.
 *
 * @param username Username (not full JID) whose vCard to retrieve.
 * @return the vCard of a given user.
 */
public Element getVCard(String username) {
  Element vCardElement = getOrLoadVCard(username);
  return vCardElement == null ? null : vCardElement.createCopy();
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Loads the avatar element from the user's DB stored vcard.
 *
 * @param username User whose vcard/avatar element we are loading.
 * @return Loaded avatar element or null if not found.
 */
private Element loadAvatarFromDatabase(String username) {
  Element vcardElement = defaultProvider.loadVCard(username);
  Element avatarElement = null;
  if (vcardElement != null && vcardElement.element("PHOTO") != null) {
    avatarElement = vcardElement.element("PHOTO").createCopy();
  }
  return avatarElement;
}

代码示例来源:origin: igniterealtime/Openfire

public Route(Route route) {
  Element elementCopy = route.element.createCopy();
  docFactory.createDocument().add(elementCopy);
  this.element = elementCopy;
  // Copy cached JIDs (for performance reasons)
  this.toJID = route.toJID;
  this.fromJID = route.fromJID;
}

代码示例来源:origin: igniterealtime/Openfire

private static void overrideSidebar(Element sidebar, Element overrideSidebar) {
  // Override name.
  if (overrideSidebar.attributeValue("name") != null) {
    sidebar.addAttribute("name", overrideSidebar.attributeValue("name"));
  }
  if (overrideSidebar.attributeValue("plugin") != null) {
    sidebar.addAttribute("plugin", overrideSidebar.attributeValue("plugin"));
  }
  if (overrideSidebar.attributeValue("order") != null) {
    sidebar.addAttribute("order", overrideSidebar.attributeValue("order"));
  }
  // Override entries.
  for (Iterator i=overrideSidebar.elementIterator(); i.hasNext(); ) {
    Element entry = (Element)i.next();
    String id = entry.attributeValue("id");
    Element existingEntry = getElemnetByID(id);
    // Simple case, there is no existing sidebar with the same id.
    if (existingEntry == null) {
      sidebar.add(entry.createCopy());
    }
    // More complex case -- an entry with the same id already exists.
    // In this case, we have to overrite only the difference between
    // the two elements.
    else {
      overrideEntry(existingEntry, entry);
    }
  }
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Sends an IQ result packet confirming that the operation was successful.
 *
 * @param packet the original IQ packet.
 */
private void sendResultPacket(IQ packet) {
  IQ reply = IQ.createResultIQ(packet);
  reply.setChildElement(packet.getChildElement().createCopy());
  deliver(reply);
}

代码示例来源:origin: igniterealtime/Openfire

private void sendPacketError(Element stanza, PacketError.Condition condition) {
  Element reply = stanza.createCopy();
  reply.addAttribute("type", "error");
  reply.addAttribute("to", stanza.attributeValue("from"));
  reply.addAttribute("from", stanza.attributeValue("to"));
  reply.add(new PacketError(condition).getElement());
  deliver(reply.asXML());
}

代码示例来源:origin: igniterealtime/Openfire

private void updatePresence() {
  if (extendedInformation != null && presence != null) {
    // Remove any previous extendedInformation, then re-add it.
    Element mucUser = presence.getElement().element(QName.get("x", "http://jabber.org/protocol/muc#user"));
    if (mucUser != null) {
      // Remove any previous extendedInformation, then re-add it.
      presence.getElement().remove(mucUser);
    }
    Element exi = extendedInformation.createCopy();
    presence.getElement().add(exi);
  }
}

代码示例来源:origin: igniterealtime/Openfire

private void getDefaultNodeConfiguration(PubSubService service, IQ iq,
                     Element childElement, Element defaultElement) {
  String type = defaultElement.attributeValue("type");
  type = type == null ? "leaf" : type;
  boolean isLeafType = "leaf".equals(type);
  DefaultNodeConfiguration config = service.getDefaultNodeConfiguration(isLeafType);
  if (config == null) {
    // Service does not support the requested node type so return an error
    Element pubsubError = DocumentHelper.createElement(
        QName.get("unsupported", "http://jabber.org/protocol/pubsub#errors"));
    pubsubError.addAttribute("feature", isLeafType ? "leaf" : "collections");
    sendErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError);
    return;
  }
  // Return data form containing default node configuration
  IQ reply = IQ.createResultIQ(iq);
  Element replyChildElement = childElement.createCopy();
  reply.setChildElement(replyChildElement);
  replyChildElement.element("default").add(config.getConfigurationForm().getElement());
  router.route(reply);
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public void process(Packet packet) throws UnauthorizedException, PacketException {
  // Check if the packet is a disco request or a packet with namespace iq:register
  if (packet instanceof IQ) {
    if (handleIQ((IQ) packet)) {
      // Do nothing
    }
    else {
      IQ reply = IQ.createResultIQ((IQ) packet);
      reply.setChildElement(((IQ) packet).getChildElement().createCopy());
      reply.setError(PacketError.Condition.feature_not_implemented);
      router.route(reply);
    }
  }
}

代码示例来源:origin: igniterealtime/Openfire

private void sendErrorPacket(IQ originalPacket, PacketError.Condition condition) {
  if (IQ.Type.error == originalPacket.getType()) {
    Log.error("Cannot reply an IQ error to another IQ error: " + originalPacket.toXML());
    return;
  }
  if (originalPacket.getFrom() == null) {
    if (Log.isDebugEnabled()) {
      Log.debug("Original IQ has no sender for reply; dropped: " + originalPacket.toXML());
    }
    return;
  }
  IQ reply = IQ.createResultIQ(originalPacket);
  reply.setChildElement(originalPacket.getChildElement().createCopy());
  reply.setError(condition);
  // Check if the server was the sender of the IQ
  if (serverName.equals(originalPacket.getFrom().toString())) {
    // Just let the IQ router process the IQ error reply
    handle(reply);
    return;
  }
  // Route the error packet to the original sender of the IQ.
  routingTable.routePacket(reply.getTo(), reply, true);
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Implements UserItemsProvider, adding PEP related items to a disco#items
 * result.
 */
@Override
public Iterator<Element> getUserItems(String name, JID senderJID) {
  ArrayList<Element> items = new ArrayList<>();
  String recipientJID = XMPPServer.getInstance().createJID(name, null, true).toBareJID();
  PEPService pepService = pepServiceManager.getPEPService(recipientJID);
  if (pepService != null) {
    CollectionNode rootNode = pepService.getRootCollectionNode();
    Element defaultItem = DocumentHelper.createElement("item");
    defaultItem.addAttribute("jid", recipientJID);
    for (Node node : pepService.getNodes()) {
      // Do not include the root node as an item element.
      if (node == rootNode) {
        continue;
      }
      AccessModel accessModel = node.getAccessModel();
      if (accessModel.canAccessItems(node, senderJID, new JID(recipientJID))) {
        Element item = defaultItem.createCopy();
        item.addAttribute("node", node.getNodeID());
        items.add(item);
      }
    }
  }
  return items.iterator();
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Generate a conflict packet to indicate that the nickname being requested/used is already in
 * use by another user.
 *
 * @param packet the packet to be bounced.
 */
void sendErrorPacket(IQ packet, PacketError.Condition error, Element pubsubError) {
  IQ reply = IQ.createResultIQ(packet);
  reply.setChildElement(packet.getChildElement().createCopy());
  reply.setError(error);
  if (pubsubError != null) {
    // Add specific pubsub error if available
    reply.getError().getElement().add(pubsubError);
  }
  router.route(reply);
}

代码示例来源:origin: igniterealtime/Openfire

private void getNodeConfiguration(PubSubService service, IQ iq, Element childElement, String nodeID) {
  Node node = service.getNode(nodeID);
  if (node == null) {
    // Node does not exist. Return item-not-found error
    sendErrorPacket(iq, PacketError.Condition.item_not_found, null);
    return;
  }
  if (!node.isAdmin(iq.getFrom())) {
    // Requesting entity is prohibited from configuring this node. Return forbidden error
    sendErrorPacket(iq, PacketError.Condition.forbidden, null);
    return;
  }
  // Return data form containing node configuration to the owner
  IQ reply = IQ.createResultIQ(iq);
  Element replyChildElement = childElement.createCopy();
  reply.setChildElement(replyChildElement);
  replyChildElement.element("configure").add(node.getConfigurationForm().getElement());
  router.route(reply);
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Sends an IQ error with the specified condition to the sender of the original
 * IQ packet.
 *
 * @param packet     the packet to be bounced.
 * @param extraError application specific error or null if none.
 * @param error the error.
 */
private void sendErrorPacket(IQ packet, PacketError.Condition error, Element extraError) {
  IQ reply = IQ.createResultIQ(packet);
  reply.setChildElement(packet.getChildElement().createCopy());
  reply.setError(error);
  if (extraError != null) {
    // Add specific application error if available
    reply.getError().getElement().add(extraError);
  }
  deliver(reply);
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Sends the list of affiliations with the node to the owner that sent the IQ
 * request.
 *
 * @param iqRequest IQ request sent by an owner of the node.
 */
void sendAffiliations(IQ iqRequest) {
  IQ reply = IQ.createResultIQ(iqRequest);
  Element childElement = iqRequest.getChildElement().createCopy();
  reply.setChildElement(childElement);
  Element affiliations = childElement.element("affiliations");
  for (NodeAffiliate affiliate : affiliates) {
    if (affiliate.getAffiliation() == NodeAffiliate.Affiliation.none) {
      continue;
    }
    Element entity = affiliations.addElement("affiliation");
    entity.addAttribute("jid", affiliate.getJID().toString());
    entity.addAttribute("affiliation", affiliate.getAffiliation().name());
  }
  // Send reply
  service.send(reply);
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public IQ handleIQ(IQ packet) throws UnauthorizedException {
  IQ result = IQ.createResultIQ(packet);
  String username = packet.getFrom().getNode();
  if (!serverName.equals(packet.getFrom().getDomain()) || username == null) {
    // Users of remote servers are not allowed to get their "shared groups". Users of
    // remote servers cannot have shared groups in this server.
    // Besides, anonymous users do not belong to shared groups so answer an error
    result.setChildElement(packet.getChildElement().createCopy());
    result.setError(PacketError.Condition.not_allowed);
    return result;
  }
  Collection<Group> groups = rosterManager.getSharedGroups(username);
  Element sharedGroups = result.setChildElement("sharedgroup",
      "http://www.jivesoftware.org/protocol/sharedgroup");
  for (Group sharedGroup : groups) {
    String displayName = sharedGroup.getProperties().get("sharedRoster.displayName");
    if (displayName != null) {
      sharedGroups.addElement("group").setText(displayName);
    }
  }
  return result;
}

代码示例来源:origin: igniterealtime/Openfire

@Override
protected void processIQ(final IQ packet) {
  if (session.getStatus() != Session.STATUS_AUTHENTICATED) {
    // Session is not authenticated so return error
    IQ reply = new IQ();
    reply.setChildElement(packet.getChildElement().createCopy());
    reply.setID(packet.getID());
    reply.setTo(packet.getFrom());
    reply.setFrom(packet.getTo());
    reply.setError(PacketError.Condition.not_authorized);
    session.process(reply);
    return;
  }
  // Process the packet
  packetHandler.handle(packet);
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Generate a conflict packet to indicate that the nickname being requested/used is already in
 * use by another user.
 * 
 * @param packet the packet to be bounced.
 * @param error the reason why the operation failed.
 */
private void sendErrorPacket(Packet packet, PacketError.Condition error) {
  if (packet instanceof IQ) {
    IQ reply = IQ.createResultIQ((IQ) packet);
    reply.setChildElement(((IQ) packet).getChildElement().createCopy());
    reply.setError(error);
    router.route(reply);
  }
  else {
    Packet reply = packet.createCopy();
    reply.setError(error);
    reply.setFrom(packet.getTo());
    reply.setTo(packet.getFrom());
    router.route(reply);
  }
}

代码示例来源:origin: igniterealtime/Openfire

@Override
protected void processIQ(IQ packet) throws UnauthorizedException {
  if (session.getStatus() != Session.STATUS_AUTHENTICATED) {
    // Session is not authenticated so return error
    IQ reply = new IQ();
    reply.setChildElement(packet.getChildElement().createCopy());
    reply.setID(packet.getID());
    reply.setTo(packet.getFrom());
    reply.setFrom(packet.getTo());
    reply.setError(PacketError.Condition.not_authorized);
    session.process(reply);
    return;
  }
  // Keep track of the component that sent an IQ get/set
  if (packet.getType() == IQ.Type.get || packet.getType() == IQ.Type.set) {
    // Handle subsequent bind packets
    LocalComponentSession componentSession = (LocalComponentSession) session;
    // Get the external component of this session
    LocalComponentSession.LocalExternalComponent component =
        (LocalComponentSession.LocalExternalComponent) componentSession.getExternalComponent();
    component.track(packet);
  }
  super.processIQ(packet);
}

相关文章

微信公众号

最新文章

更多

Element类方法