List of usage examples for org.dom4j Element getNamespaceURI
String getNamespaceURI();
String
is returned. From source file:org.b5chat.crossfire.xmpp.route.SessionPacketRouter.java
License:Open Source License
private IQ getIQ(Element doc) { Element query = doc.element("query"); if (query != null && "jabber:iq:roster".equals(query.getNamespaceURI())) { return new Roster(doc); } else {//from w w w. j ava 2 s . c om return new IQ(doc, skipJIDValidation); } }
From source file:org.efaps.webdav4vfs.data.AbstractDavResource.java
License:Apache License
/** * Get property values. This method expects one of either <allprop>, * <propnames> or <prop>. If the element is <prop> it * will go through the list of it's children and request the values. For * <allprop> it will get values of all known properties and * <propnames> will return the names of all known properties. * * @param root the root of the result document * @param propertyEl the prop, propname or allprop element * @return the root of the result document *//*from w w w. j a v a2 s. c o m*/ public Element getPropertyValues(final Element root, final Element propertyEl) { // initialize the <propstat> for 200 final Element okPropStatEl = root.addElement(TAG_PROPSTAT); final Element okPropEl = okPropStatEl.addElement(TAG_PROP); // initialize the <propstat> element for 404 final Element failPropStatEl = root.addElement(TAG_PROPSTAT); final Element failPropEl = failPropStatEl.addElement(TAG_PROP); if (TAG_ALLPROP.equalsIgnoreCase(propertyEl.getName()) || TAG_PROPNAMES.equalsIgnoreCase(propertyEl.getName())) { boolean ignoreValue = TAG_PROPNAMES.equalsIgnoreCase(propertyEl.getName()); // get all known standard properties for (String propName : ALL_PROPERTIES) { if (!getPropertyValue(okPropEl, propName, ignoreValue)) { failPropEl.addElement(propName); } } // additionally try to add all the custom properties try { final FileContent objectContent = object.getContent(); for (String attributeName : objectContent.getAttributeNames()) { if (!getPropertyValue(okPropEl, attributeName, ignoreValue)) { failPropEl.addElement(attributeName); } } } catch (final FileSystemException e) { LogFactory.getLog(getClass()) .error(String.format("can't read attribute properties from '%s'", object.getName()), e); } } else { final List<?> requestedProperties = propertyEl.elements(); for (Object propertyElObject : requestedProperties) { final Element propEl = (Element) propertyElObject; final String nameSpace = propEl.getNamespaceURI(); if (!getPropertyValue(okPropEl, getFQName(nameSpace, propEl.getName()), false)) { failPropEl.addElement(propEl.getQName()); } } } // only add the OK section, if there is content if (okPropEl.elements().size() > 0) { okPropStatEl.addElement(TAG_STATUS).addText(STATUS_200); } else { okPropStatEl.detach(); } // only add the failed section, if there is content if (failPropEl.elements().size() > 0) { failPropStatEl.addElement(TAG_STATUS).addText(STATUS_404); } else { failPropStatEl.detach(); } return root; }
From source file:org.efaps.webdav4vfs.data.DavResource.java
License:Apache License
@Override() protected boolean setPropertyValue(Element root, Element propertyEl) { LogFactory.getLog(getClass()).debug(String.format("[%s].set('%s')", object.getName(), propertyEl.asXML())); if (!ALL_PROPERTIES.contains(propertyEl.getName())) { final String nameSpace = propertyEl.getNamespaceURI(); final String attributeName = getFQName(nameSpace, propertyEl.getName()); try {//from w w w . j a v a2 s .co m FileContent objectContent = object.getContent(); final String command = propertyEl.getParent().getParent().getName(); if (TAG_PROP_SET.equals(command)) { StringWriter propertyValueWriter = new StringWriter(); propertyEl.write(propertyValueWriter); propertyValueWriter.close(); objectContent.setAttribute(attributeName, propertyValueWriter.getBuffer().toString()); } else if (TAG_PROP_REMOVE.equals(command)) { objectContent.setAttribute(attributeName, null); } root.addElement(propertyEl.getQName()); return true; } catch (IOException e) { LogFactory.getLog(getClass()).error(String.format("can't store attribute property '%s' = '%s'", attributeName, propertyEl.asXML()), e); } } return false; }
From source file:org.etudes.component.app.melete.MeleteAbstractExportServiceImpl.java
License:Apache License
/** * creates document root element "manifest" from the default manifest file * and adds the namespaces//from ww w .j av a 2 s .c o m * @param xmlFile - Default manifest file * @return returns the manifest element * @throws Exception */ public Element getManifest(File xmlFile) throws Exception { try { Document document = XMLHelper.getSaxReader().read(xmlFile); Element root = document.getRootElement(); Element rootnew = root.createCopy(); List childEleList = rootnew.elements(); childEleList.clear(); this.DEFAULT_NAMESPACE_URI = rootnew.getNamespaceURI(); List nslist = rootnew.declaredNamespaces(); for (int i = 0; i < nslist.size(); i++) { if (((Namespace) nslist.get(i)).getPrefix().equals("imsmd")) { setMetaDataNameSpace(((Namespace) nslist.get(i)).getURI()); break; } } rootnew.addAttribute("identifier", "Manifest-" + getUUID()); return rootnew; } catch (DocumentException de) { throw de; } catch (SAXException se) { throw se; } catch (Exception e) { throw e; } }
From source file:org.etudes.jforum.view.admin.ImportExportAction.java
License:Apache License
/** * creates document root element "manifest" from the default manifest file * and adds the namespaces// www. ja va 2 s.co m * * @param xmlFile * - Default manifest file * @return returns the manifest element * @throws Exception */ private Element getManifest(File xmlFile) throws Exception { try { Document document = XMLHelper.getSaxReader().read(xmlFile); Element root = document.getRootElement(); Element rootnew = root.createCopy(); List childEleList = rootnew.elements(); childEleList.clear(); this.DEFAULT_NAMESPACE_URI = rootnew.getNamespaceURI(); List nslist = rootnew.declaredNamespaces(); for (int i = 0; i < nslist.size(); i++) { if (((Namespace) nslist.get(i)).getPrefix().equals("imsmd")) { this.IMSMD_NAMESPACE_URI = ((Namespace) nslist.get(i)).getURI(); break; } } rootnew.addAttribute("identifier", "Manifest-" + IdManager.createUuid()); return rootnew; } catch (DocumentException de) { throw de; } catch (SAXException se) { throw se; } catch (Exception e) { throw e; } }
From source file:org.firesoa.common.jxpath.model.dom4j.Dom4JNodePointer.java
License:Open Source License
/** * Get the ns uri of the specified node. * @param node Node to check/*from www . j ava2 s . c o m*/ * @return String ns uri */ public static String getNamespaceURI(Node node) { if (node == null) return null; Element element = null; if (node instanceof Document) { element = ((Document) node).getRootElement(); } else if (node instanceof Element) { element = (Element) node; } else { return null; } if (element == null) return null; String uri = element.getNamespaceURI(); if (uri != null && uri.trim().equals("")) { uri = null; } return uri; }
From source file:org.frogx.service.core.DefaultMUGService.java
License:Open Source License
/** * Returns true if the IQ packet was processed. This method should only process disco packets * as well as jabber:iq:search packets sent to the MUG service. * * @param iq the IQ packet to process.//from w w w . j av a2 s. c om * @return true if the IQ packet was processed. */ private boolean process(IQ iq) { Element childElement = iq.getChildElement(); String namespace = null; IQ reply = null; // Ignore IQs of type ERROR if (IQ.Type.error == iq.getType()) { return false; } if (iq.getTo().getResource() != null) { // Ignore here IQ packets sent to room occupants // these are handled in MUGRooms return false; } if (childElement != null) { namespace = childElement.getNamespaceURI(); } if ("jabber:iq:search".equals(namespace)) { reply = iqSearchHandler.handleIQ(iq); } else if ("http://jabber.org/protocol/disco#info".equals(namespace)) { reply = iqDiscoInfoHandler.handleIQ(iq); } else if ("http://jabber.org/protocol/disco#items".equals(namespace)) { reply = iqDiscoItemsHandler.handleIQ(iq); } else { return false; } try { // TODO: Remove debug output log.debug("[MUG]: Sending: " + reply.toXML()); mugManager.sendPacket(this, reply); } catch (Exception e) { log.error("[MUG] Error while sending an IQ stanza.", e); } return true; }
From source file:org.frogx.service.core.DefaultMUGSession.java
License:Open Source License
/** * This method handles an {@see IQ} requests send to a * {@see MUGRoom} whithin the owner namespace or to an * {@see MUGOccupant}.//ww w .j a v a2 s .c o m * * @param iq The XMPP stanza which should be handled. * @throws ComponentException */ protected void process(IQ iq) throws ComponentException { /* Handle IOs whith childs: * - <save xmlns='...#owner'> -> save room * - <load xmlns='...#owner'> -> load room * all others (config, memberlist, transfer owner): * -> room iqOwnerhandler */ JID recipient = iq.getTo(); String room = recipient.getNode(); // Ignore packets to the game component if (room == null) { return; } MUGOccupant occupant = occupants.get(room); Element childElement = iq.getChildElement(); // Try to send a private message if (recipient.getResource() != null && recipient.getResource().trim().length() > 0) { // Try to send a private message if (occupant != null) { // Verify occupant if (!occupant.getUserAddress().equals(iq.getFrom())) throw new ConflictException(); occupant.getGameRoom().sendPrivatePacket(iq, occupant); return; } else { // The sender is not an occupant of the room throw new NotAcceptableException(); } } // Ignore IQs of type result or error if ((IQ.Type.result == iq.getType()) || (IQ.Type.error == iq.getType())) { return; } // Check child element and namespace if (childElement == null || !MUGService.mugOwnerNS.equals(childElement.getNamespaceURI())) { // No idea what to do with this packet throw new UnsupportedGameException(); } // Try to load a game room if (occupant == null) { if ("load".equals(childElement.getName())) { //TODO: Implement loading a game room throw new UnsupportedGameException(); } else { // The sender is not an occupant of the room throw new NotAcceptableException(); } } // Check senders address and reject conflicting packets if (!occupant.getUserAddress().equals(iq.getFrom())) { throw new ConflictException(); } if ("save".equals(childElement.getName())) { //TODO: Implement saving a game room throw new UnsupportedGameException(); } else { // Another request within the owner namespace occupant.getGameRoom().handleOwnerIQ(iq, occupant); } }
From source file:org.frogx.service.core.iq.IQOwnerHandler.java
License:Open Source License
/** * Handle game room requests within the Owner namespace. * //from w ww. j av a2 s . c om * @param packet The IQ stanza which should be handled. * @param occupant The Sender of the IQ request. * * @throws ForbiddenException if the sender don't have the permission for his request. * @throws IllegalArgumentException if we don't understand the request. * @throws GameConfigurationException if the room or match state is not correct. * @throws UnsupportedGameException if the request is unsupported or not implemented. */ public void handleIQ(IQ packet, MUGOccupant occupant) throws ForbiddenException, IllegalArgumentException, GameConfigurationException, UnsupportedGameException { // Ignore packets with type error or result if (packet.getType() == IQ.Type.error || packet.getType() == IQ.Type.result) { return; } IQ reply = IQ.createResultIQ(packet); Element query = packet.getChildElement(); // Check if the sender is an owner // (Only in non-anonymous rooms we handle member lists for other Occupants) if (!room.isNonAnonymous() && (MUGOccupant.Affiliation.owner != occupant.getAffiliation())) { throw new ForbiddenException(); } if ("query".equals(query.getName())) { for (Iterator<Element> it = query.elementIterator(); it.hasNext();) { Element element = (Element) it.next(); if ("options".equals(element.getName())) { Iterator<Element> optionElementIt = element.elementIterator(); if (MUGOccupant.Affiliation.owner != occupant.getAffiliation()) { throw new ForbiddenException(); } if (!optionElementIt.hasNext()) { // Send a room configuration form refreshConfigurationFormValues(); reply.setChildElement(probeResult); } else { if ((room.getMatch().getStatus() == MUGMatch.Status.created) || (room.getMatch().getStatus() == MUGMatch.Status.inactive)) { boolean roomConfigChanged = false; for (optionElementIt = element.elementIterator(); optionElementIt.hasNext();) { Element el = optionElementIt.next(); // process the room configuration form if (el.getName().equals("x") && el.getNamespaceURI().equals("jabber:x:data")) { DataForm completedForm = new DataForm(el); if (DataForm.Type.cancel.equals(completedForm.getType())) { // If the room was just created and the owner cancels // the configuration form then destroy the room if (room.getMatch().getStatus() == MUGMatch.Status.created) { log.debug(locale.getLocalizedString("mug.config.debug.destroy") + room.getName()); service.removeGameRoom(room.getName()); } } else if (DataForm.Type.submit.equals(completedForm.getType())) { // The owner is changing the current room configuration if (completedForm.getFields().size() != 0) { processConfigurationForm(completedForm); } room.getMatch().setConfiguration(null); roomConfigChanged = true; } } // process the match configuration else if (el.getName().equals("options")) { if (!el.getNamespaceURI().equals(room.getGame().getNamespace())) throw new UnsupportedGameException(); room.getMatch().setConfiguration(el.elements()); roomConfigChanged = true; } // An unknown and possibly incorrect element was included in the // options element so answer a BAD_REQUEST error else { throw new IllegalArgumentException(); } } // Inform the occupants that the configuration has changed if (roomConfigChanged) room.broadcastRoomPresence(); } else { // The room can not be changed in an active or paused match status throw new GameConfigurationException(); } } } else if ("state".equals(element.getName())) { // The owner requests a constructed match if (MUGOccupant.Affiliation.owner != occupant.getAffiliation()) { throw new ForbiddenException(); } if (element.getNamespaceURI().equals(room.getGame().getNamespace())) { room.getMatch().setConstructedState(element); } else { throw new IllegalArgumentException(); } } else if ("item".equals(element.getName())) { //TODO: Implement Member lists, Revoke and Assign Roles, Ownership Transfer throw new UnsupportedGameException(); } else { throw new UnsupportedGameException(); } } } else { // No valid request, feature not implemented... throw new UnsupportedGameException(); } // Send a reply only if the sender of the original packet was from a real JID. // (i.e. not a packet generated locally) if (reply.getTo() != null) { try { // TODO: Remove debug output log.debug("[MUG]: Sending: " + reply.toXML()); mugManager.sendPacket(service, reply); } catch (ComponentException e) { log.error(locale.getLocalizedString("mug.config.error.response") + room.getName(), e); } } }
From source file:org.frogx.service.core.iq.IQSearchHandler.java
License:Open Source License
/** * Handle a Jabber Search query and get the resulting IQ packet. * //from w ww .j a v a2 s . c o m * @param packet The IQ Query. * @return The IQ reply resulting from the query. */ public IQ handleIQ(IQ packet) { // Ignore packets with type error or result if (packet.getType() == IQ.Type.error || packet.getType() == IQ.Type.result) { return null; } IQ reply = IQ.createResultIQ(packet); Element query = packet.getChildElement(); Element formElement = query.element(QName.get("x", "jabber:x:data")); // check if its a jabber search request if (!query.getName().equals("query") || !query.getNamespaceURI().equals("jabber:iq:search")) { reply.setError(PacketError.Condition.bad_request); return reply; } if (formElement == null) { // return an empty form reply.setChildElement(getSearchForm()); } else { // get the list of the found rooms List<MUGRoom> mugrsm = processSearchForm(formElement); // handle jabber resulting set management Element set = query.element(QName.get("set", ResultSet.NAMESPACE_RESULT_SET_MANAGEMENT)); ResultSet<MUGRoom> resultSet = new ResultSetImpl<MUGRoom>(sortByUserAmount(mugrsm)); if (set != null) { if (!ResultSet.isValidRSMRequest(set)) { reply.setError(Condition.bad_request); return reply; } try { mugrsm = resultSet.applyRSMDirectives(set); } catch (NullPointerException e) { reply.setError(Condition.item_not_found); return reply; } } Element resultQuery = reply.setChildElement("query", "jabber:iq:search"); DataForm resultForm = createResultingForm(mugrsm); if (resultForm != null) { resultQuery.add(resultForm.getElement()); if (set != null) resultQuery.add(resultSet.generateSetElementFromResults(mugrsm)); } } return reply; }