List of usage examples for org.dom4j Namespace get
public static Namespace get(String uri)
From source file:com.cladonia.xml.XAttribute.java
License:Open Source License
/** * Constructs a default element with an initial type. * * @param name the unmutable name.// w w w. j a v a2s . c o m */ public XAttribute(String name, String namespace, String value) { this(new QName(name, Namespace.get(namespace)), value); }
From source file:com.cladonia.xml.XElement.java
License:Open Source License
/** * Constructs a default element with an initial type. * * @param name the unmutable name./* www .j a v a 2 s . com*/ */ public XElement(String name, String namespace) { this(new QName(name, Namespace.get(namespace)), true); }
From source file:com.cladonia.xml.XElement.java
License:Open Source License
/** * Constructs a default element with an initial type. * * @param name the unmutable name.//from ww w . j ava 2s . com * @param name the unmutable namespace. * @param parsed the element has been parsed from text. */ public XElement(String name, String namespace, boolean parsed) { this(new QName(name, Namespace.get(namespace)), parsed); }
From source file:com.hand.hemp.push.server.xmpp.handler.IQRegisterHandler.java
License:Open Source License
/** * Handles the received IQ packet.//from w w w . j a v a2 s . c o m * * @param packet the packet * @return the response to send back * @throws UnauthorizedException if the client is not authorized */ public IQ handleIQ(IQ packet) throws UnauthorizedException { IQ reply = null; ClientSession session = sessionManager.getSession(packet.getFrom()); if (session == null) { log.error("Session not found for key " + packet.getFrom()); reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.internal_server_error); return reply; } if (IQ.Type.get.equals(packet.getType())) { reply = IQ.createResultIQ(packet); if (session.getStatus() == Session.STATUS_AUTHENTICATED) { // TODO } else { reply.setTo((JID) null); reply.setChildElement(probeResponse.createCopy()); } } else if (IQ.Type.set.equals(packet.getType())) { try { Element query = packet.getChildElement(); if (query.element("remove") != null) { if (session.getStatus() == Session.STATUS_AUTHENTICATED) { // TODO } else { throw new UnauthorizedException(); } } else { // generate username from server side //String username = query.elementText("username"); String username = null; String password = query.elementText("password"); String email = query.elementText("email"); String name = query.elementText("name"); String androidId = query.elementText("androidId"); String resourceName = query.elementText("resourceName"); // Deny registration if androidId is null or resourceName is null if (androidId == null || "".equals(androidId) || resourceName == null || "".equals(resourceName)) { reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.not_acceptable); return reply; } else { username = IQRegisterHandler.genUsername(androidId, resourceName); log.debug("generated username: " + username); } // removed because username generate on server if (username != null) { Stringprep.nodeprep(username); } // Deny registration of users with no password if (password == null || password.trim().length() == 0) { reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); reply.setError(PacketError.Condition.not_acceptable); return reply; } if (email != null && email.matches("\\s*")) { email = null; } if (name != null && name.matches("\\s*")) { name = null; } HpnsClient client; boolean updateHpnsClient = false; if (session.getStatus() == Session.STATUS_AUTHENTICATED) { client = clientService.getUser(Long.valueOf(session.getUsername())); updateHpnsClient = true; } else { try { client = clientService.getUserByUsername(username); log.debug("update exist client"); updateHpnsClient = true; } catch (UserNotFoundException unfe) { log.debug("create new client: " + unfe.getMessage()); client = new HpnsClient(); } } client.setPassword(password); client.setEmail(email); client.setName(name); client.setAndroidId(androidId); client.setResourceName(resourceName); if (updateHpnsClient) { client.setLastUpdatedBy("system"); client.setLastUpdateDate(new Date()); clientService.updateUser(client); } else { client.setUsername(username); client.setCreatedBy("system"); client.setRegDate(new Date()); clientService.saveUser(client); } // HpnsClient hpnsClient; // if (session.getStatus() == Session.STATUS_AUTHENTICATED) { // hpnsClient = hpnsClientFacade.getClientByUsername(session.getUsername()); // } else { // hpnsClient = new HpnsClient(); // } // hpnsClient.setUsername(username); // hpnsClient.setPassword(password); // hpnsClient.setEmail(email); // hpnsClient.setName(name); // hpnsClientFacade.create(hpnsClient); reply = IQ.createResultIQ(packet); DOMElement queryEle = new DOMElement("query", Namespace.get("jabber:iq:register")); DOMElement usernameEle = new DOMElement("username", Namespace.get("jabber:iq:register")); usernameEle.setText(username); queryEle.add(usernameEle); reply.setChildElement(queryEle); } } catch (Exception ex) { log.error(ex); reply = IQ.createResultIQ(packet); reply.setChildElement(packet.getChildElement().createCopy()); if (ex instanceof UserExistsException) { reply.setError(PacketError.Condition.conflict); } else if (ex instanceof UserNotFoundException) { reply.setError(PacketError.Condition.bad_request); } else if (ex instanceof StringprepException) { reply.setError(PacketError.Condition.jid_malformed); } else if (ex instanceof IllegalArgumentException) { reply.setError(PacketError.Condition.not_acceptable); } else { reply.setError(PacketError.Condition.internal_server_error); } } } // Send the response directly to the session if (reply != null) { session.process(reply); } return null; }
From source file:com.zimbra.soap.JaxbUtil.java
License:Open Source License
/** * Use namespace inheritance in preference to prefixes * @param elem//from ww w .ja v a 2s . co m * @param defaultNs */ private static void removeNamespacePrefixes(org.dom4j.Element elem) { Namespace elemNs = elem.getNamespace(); if (elemNs != null) { if (!Strings.isNullOrEmpty(elemNs.getPrefix())) { Namespace newNs = Namespace.get(elemNs.getURI()); org.dom4j.QName newQName = new org.dom4j.QName(elem.getName(), newNs); elem.setQName(newQName); } } Iterator<?> elemIter = elem.elementIterator(); while (elemIter.hasNext()) { JaxbUtil.removeNamespacePrefixes((org.dom4j.Element) elemIter.next()); } }
From source file:de.fmaul.android.cmis.repo.CmisTypeDefinition.java
License:Apache License
public static CmisTypeDefinition createFromFeed(Document doc) { CmisTypeDefinition td = new CmisTypeDefinition(); final Namespace CMISRA = Namespace.get("http://docs.oasis-open.org/ns/cmis/restatom/200908/"); final QName CMISRA_TYPE = QName.get("type", CMISRA); Element type = doc.getRootElement().element(CMISRA_TYPE); td.id = type.elementTextTrim("id"); td.localName = type.elementTextTrim("localName"); td.localNamespace = type.elementTextTrim("localNamespace"); td.displayName = type.elementTextTrim("displayName"); td.queryName = type.elementTextTrim("queryName"); td.description = type.elementTextTrim("description"); td.baseId = type.elementTextTrim("baseId"); td.creatable = Boolean.valueOf(type.elementTextTrim("creatable")); td.fileable = Boolean.valueOf(type.elementTextTrim("fileable")); td.queryable = Boolean.valueOf(type.elementTextTrim("queryable")); td.fulltextIndexed = Boolean.valueOf(type.elementTextTrim("fulltextIndexed")); td.includedInSupertypeQuery = Boolean.valueOf(type.elementTextTrim("includedInSupertypeQuery")); td.controllablePolicy = Boolean.valueOf(type.elementTextTrim("controllablePolicy")); td.controllableACL = Boolean.valueOf(type.elementTextTrim("controllableACL")); td.versionable = Boolean.valueOf(type.elementTextTrim("versionable")); td.contentStreamAllowed = type.elementTextTrim("contentStreamAllowed"); List<Element> allElements = doc.getRootElement().element(CMISRA_TYPE).elements(); for (Element element : allElements) { if (element.getName().startsWith("property")) { CmisPropertyTypeDefinition propTypeDef = CmisPropertyTypeDefinition.createFromElement(element); td.propertyDefinition.put(propTypeDef.getId(), propTypeDef); }//from ww w .jav a 2 s. c o m } return td; }
From source file:de.innovationgate.webgate.api.query.rss.WGResultSetImpl.java
License:Open Source License
private List getItemsList() { if (this.itemsList == null) { if (isRSS1) { this.itemsList = this.doc.getRootElement().elements(new QName("item", Namespace.get(NS_RSS1_PURL))); if (this.itemsList.size() == 0) { this.itemsList = this.doc.getRootElement() .elements(new QName("item", Namespace.get(NS_RSS1_NETSCAPE))); }/*from w w w . jav a 2s . c om*/ } else { this.itemsList = this.doc.selectNodes("//item"); } } return this.itemsList; }
From source file:de.innovationgate.webgate.api.query.rss.WGResultSetImpl.java
License:Open Source License
private Element getChannel() { if (this.channel == null) { if (isRSS1) { this.channel = (Element) this.doc.getRootElement() .element(new QName("channel", Namespace.get(NS_RSS1_PURL))); if (this.channel == null) { this.channel = (Element) this.doc.getRootElement() .element(new QName("channel", Namespace.get(NS_RSS1_NETSCAPE))); }//from www . ja v a 2 s . c o m } else { this.channel = (Element) this.doc.selectSingleNode("//channel"); } } return this.channel; }
From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.Roster.java
License:Open Source License
/** * Adds a new item to the roster. If the roster packet already contains an item * using the same JID, the information in the existing item will be overwritten * with the new information.<p>/* w w w .j a va 2s . co m*/ * * The XMPP specification recommends that if the roster item is associated with another * instant messaging user (human), that the JID be in bare form (e.g. user@domain). * Use the {@link JID#toBareJID() toBareJID()} method for a bare JID. * * @param jid the JID. * @param name the nickname. * @param ask the ask type. * @param subscription the subscription type. * @param groups a Collection of groups. * @return the newly created item. */ @SuppressWarnings("unchecked") public Item addItem(JID jid, String name, Ask ask, Subscription subscription, Collection<String> groups) { if (jid == null) { throw new NullPointerException("JID cannot be null"); } if (subscription == null) { throw new NullPointerException("Subscription cannot be null"); } Element query = element.element(new QName("query", Namespace.get("jabber:iq:roster"))); if (query == null) { query = element.addElement("query", "jabber:iq:roster"); } Element item = null; for (Iterator<Element> i = query.elementIterator("item"); i.hasNext();) { Element el = i.next(); if (el.attributeValue("jid").equals(jid.toString())) { item = el; } } if (item == null) { item = query.addElement("item"); } item.addAttribute("jid", jid.toBareJID()); item.addAttribute("name", name); if (ask != null) { item.addAttribute("ask", ask.toString()); } item.addAttribute("subscription", subscription.toString()); // Erase existing groups in case the item previously existed. for (Iterator<Element> i = item.elementIterator("group"); i.hasNext();) { item.remove(i.next()); } // Add in groups. if (groups != null) { for (String group : groups) { item.addElement("group").setText(group); } } return new Item(jid, name, ask, subscription, groups); }
From source file:de.tu_berlin.cit.intercloud.xmpp.core.packet.Roster.java
License:Open Source License
/** * Removes an item from this roster./* w ww .ja v a 2 s .co m*/ * * @param jid the JID of the item to remove. */ @SuppressWarnings("unchecked") public void removeItem(JID jid) { 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(); if (item.attributeValue("jid").equals(jid.toString())) { query.remove(item); return; } } } }