List of usage examples for org.dom4j Attribute getValue
String getValue();
From source file:org.olat.ims.qti.editor.beecom.parser.MaterialParser.java
License:Apache License
/** * @see org.olat.ims.qti.editor.beecom.parser.IParser#parse(org.dom4j.Element) *///from www. j a v a 2s . c o m @Override public Object parse(final Element element) { // assert element.getName().equalsIgnoreCase("material"); final List materials = element.elements(); if (materials.size() == 0) { return null; } final Material material = new Material(); // ATTRIBUTES final Attribute label = element.attribute("label"); if (label != null) { material.setLable(label.getValue()); } // ELEMENTS for (final Iterator i = materials.iterator(); i.hasNext();) { final QTIObject obj = (QTIObject) parserManager.parse((Element) i.next()); if (obj != null) { material.getElements().add(obj); } } return material; }
From source file:org.olat.ims.qti.editor.beecom.parser.OutcomesProcessingParser.java
License:Apache License
/** * @see org.olat.ims.qti.editor.beecom.IParser#parse(org.dom4j.Element) *///ww w. j ava 2s . c om @Override public Object parse(final Element element) { // assert element.getName().equalsIgnoreCase("outcomes_processing"); final OutcomesProcessing outcomesProcessing = new OutcomesProcessing(); final List decvars = element.selectNodes("*/decvar"); if (decvars.size() == 0) { return outcomesProcessing; } final Element decvar = (Element) decvars.get(0); for (final Iterator iter = decvar.attributeIterator(); iter.hasNext();) { final Attribute attr = (Attribute) iter.next(); outcomesProcessing.setField(attr.getName(), attr.getValue()); } return outcomesProcessing; }
From source file:org.olat.ims.qti.fileresource.SurveyFileResource.java
License:Apache License
private static ResourceEvaluation validateQti(Document doc, ResourceEvaluation eval) { if (doc == null) { eval.setValid(false);/*from w w w.j a v a 2 s . c o m*/ } else { List assessment = doc.selectNodes("questestinterop/assessment"); if (assessment.size() == 1) { Object assessmentObj = assessment.get(0); if (assessmentObj instanceof Element) { Element assessmentEl = (Element) assessmentObj; Attribute title = assessmentEl.attribute("title"); if (title != null) { eval.setDisplayname(title.getValue()); } List metas = assessmentEl.selectNodes("qtimetadata/qtimetadatafield"); for (Iterator iter = metas.iterator(); iter.hasNext();) { Element el_metafield = (Element) iter.next(); Element el_label = (Element) el_metafield.selectSingleNode("fieldlabel"); String label = el_label.getText(); if (label.equals(AssessmentInstance.QMD_LABEL_TYPE)) { // type meta Element el_entry = (Element) el_metafield.selectSingleNode("fieldentry"); String entry = el_entry.getText(); if (entry.equals(AssessmentInstance.QMD_ENTRY_TYPE_SURVEY)) { eval.setValid(true); } } } } } } return eval; }
From source file:org.olat.ims.qti.process.QTIHelper.java
License:Apache License
public static float attributeToFloat(final Attribute att) { float val = -1; if (att != null) { String sval = att.getValue(); sval = sval.trim();/*w w w .j a v a 2 s . com*/ // assume int value, even so dtd cannot enforce it val = Integer.parseInt(sval); } return val; }
From source file:org.olat.ims.qti.qpool.QTIExportProcessor.java
License:Apache License
/** * Collect the file and rewrite the //from w ww. j a v a2 s . c o m * @param el * @param container * @param materials * @param paths */ private void collectResourcesInMatText(Element el, VFSContainer container, ItemsAndMaterials materials) { //mattext @SuppressWarnings("unchecked") List<Element> mattextList = el.selectNodes(".//mattext"); for (Element mat : mattextList) { Attribute texttypeAttr = mat.attribute("texttype"); String texttype = texttypeAttr.getValue(); if ("text/html".equals(texttype)) { @SuppressWarnings("unchecked") List<Node> childElList = new ArrayList<Node>(mat.content()); for (Node childEl : childElList) { mat.remove(childEl); } for (Node childEl : childElList) { if (Node.CDATA_SECTION_NODE == childEl.getNodeType()) { CDATA data = (CDATA) childEl; boolean changed = false; String text = data.getText(); List<String> materialPaths = findMaterialInMatText(text); for (String materialPath : materialPaths) { VFSItem matVfsItem = container.resolve(materialPath); if (matVfsItem instanceof VFSLeaf) { String exportUri = generateExportPath(materials.getPaths(), matVfsItem); materials.addMaterial(new ItemMaterial((VFSLeaf) matVfsItem, exportUri)); text = text.replaceAll(materialPath, exportUri); changed = true; } } if (changed) { mat.addCDATA(text); } else { mat.add(childEl); } } else { mat.add(childEl); } } } } }
From source file:org.olat.ims.qti.qpool.QTIExportProcessor.java
License:Apache License
@SuppressWarnings("unchecked") private void collectResourcesInMatMedias(Element el, VFSContainer container, ItemsAndMaterials materials) { //matimage uri List<Element> matList = new ArrayList<Element>(); matList.addAll(el.selectNodes(".//matimage")); matList.addAll(el.selectNodes(".//mataudio")); matList.addAll(el.selectNodes(".//matvideo")); for (Element mat : matList) { Attribute uriAttr = mat.attribute("uri"); String uri = uriAttr.getValue(); VFSItem matVfsItem = container.resolve(uri); if (matVfsItem instanceof VFSLeaf) { String exportUri = generateExportPath(materials.getPaths(), matVfsItem); ItemMaterial iMat = new ItemMaterial((VFSLeaf) matVfsItem, exportUri); materials.addMaterial(iMat); mat.addAttribute("uri", exportUri); }//from ww w . java2s . c om } }
From source file:org.olat.ims.qti.qpool.QTIImportProcessor.java
License:Apache License
@SuppressWarnings("unchecked") protected List<String> getMaterials(Element el) { List<String> materialPath = new ArrayList<String>(); //mattext/*from www.ja v a 2 s . c o m*/ List<Element> mattextList = el.selectNodes(".//mattext"); for (Element mat : mattextList) { Attribute texttypeAttr = mat.attribute("texttype"); if (texttypeAttr != null) { String texttype = texttypeAttr.getValue(); if ("text/html".equals(texttype)) { String content = mat.getStringValue(); findMaterialInMatText(content, materialPath); } } } //matimage uri List<Element> matList = new ArrayList<Element>(); matList.addAll(el.selectNodes(".//matimage")); matList.addAll(el.selectNodes(".//mataudio")); matList.addAll(el.selectNodes(".//matvideo")); for (Element mat : matList) { Attribute uriAttr = mat.attribute("uri"); String uri = uriAttr.getValue(); materialPath.add(uri); } return materialPath; }
From source file:org.onesocialweb.openfire.handler.activity.ActivitySubscribeHandler.java
License:Apache License
@SuppressWarnings({ "deprecation" }) @Override//w ww .j a v a2s .c om public IQ handleIQ(IQ packet) throws UnauthorizedException { JID sender = packet.getFrom(); JID recipient = packet.getTo(); // Process the request inside a try/catch so that unhandled exceptions // (oufofbounds etc...) can trigger a server error and we can send a // error result packet try { // A valid request is an IQ of type set, for a valid and local recipient if (!(packet.getType().equals(IQ.Type.set) && recipient != null && recipient.getNode() != null && userManager.isRegisteredUser(recipient.getNode()))) { IQ result = IQ.createResultIQ(packet); result.setChildElement(packet.getChildElement().createCopy()); result.setError(PacketError.Condition.bad_request); return result; } // A valid request has a (bare) JID attribute Element pubsubElement = packet.getChildElement(); Element subscribeElement = pubsubElement.element("subscribe"); Attribute jidAttribute = subscribeElement.attribute("jid"); if (jidAttribute == null || !sender.toBareJID().equals(jidAttribute.getValue())) { IQ result = IQ.createResultIQ(packet); result.setChildElement(packet.getChildElement().createCopy()); result.setError(PacketError.Condition.bad_request); return result; } // Add the relation to the database ActivityManager.getInstance().subscribe(sender.toBareJID(), recipient.toBareJID()); // Return and send a result packet IQ result = IQ.createResultIQ(packet); Element resultPubsubElement = result.setChildElement("pubsub", "http://jabber.org/protocol/pubsub"); Element resultSubscriptionElement = resultPubsubElement.addElement("subscription", "http://jabber.org/protocol/pubsub"); resultSubscriptionElement.addAttribute("node", PEPActivityHandler.NODE); resultSubscriptionElement.addAttribute("jid", recipient.toBareJID()); resultSubscriptionElement.addAttribute("subscription", "subscribed"); return result; } catch (Exception e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); IQ result = IQ.createResultIQ(packet); result.setChildElement(packet.getChildElement().createCopy()); result.setError(PacketError.Condition.internal_server_error); return result; } }
From source file:org.onesocialweb.openfire.handler.activity.ActivityUnsubscribeHandler.java
License:Apache License
@SuppressWarnings({ "deprecation" }) @Override//from w ww. j a va2 s . c o m public IQ handleIQ(IQ packet) throws UnauthorizedException { JID sender = packet.getFrom(); JID recipient = packet.getTo(); // Process the request inside a try/catch so that unhandled exceptions // (oufofbounds etc...) can trigger a server error and we can send a // error result packet try { // A valid request is an IQ of type set, for a valid and local recipient if (!(packet.getType().equals(IQ.Type.set) && recipient != null && recipient.getNode() != null && userManager.isRegisteredUser(recipient.getNode()))) { IQ result = IQ.createResultIQ(packet); result.setChildElement(packet.getChildElement().createCopy()); result.setError(PacketError.Condition.bad_request); return result; } // A valid request has a (bare) JID attribute Element pubsubElement = packet.getChildElement(); Element subscribeElement = pubsubElement.element("unsubscribe"); Attribute jidAttribute = subscribeElement.attribute("jid"); if (jidAttribute == null || !sender.toBareJID().equals(jidAttribute.getValue())) { IQ result = IQ.createResultIQ(packet); result.setChildElement(packet.getChildElement().createCopy()); result.setError(PacketError.Condition.bad_request); return result; } // Add the relation to the database ActivityManager.getInstance().unsubscribe(sender.toBareJID(), recipient.toBareJID()); // Return and send a result packet IQ result = IQ.createResultIQ(packet); return result; } catch (Exception e) { Log.error(LocaleUtils.getLocalizedString("admin.error"), e); IQ result = IQ.createResultIQ(packet); result.setChildElement(packet.getChildElement().createCopy()); result.setError(PacketError.Condition.internal_server_error); return result; } }
From source file:org.onesocialweb.openfire.handler.activity.IQSubscribeInterceptor.java
License:Apache License
public void interceptPacket(Packet packet, Session session, boolean incoming, boolean processed) throws PacketRejectedException { // We only care for incoming IQ that have not yet been processed if (incoming && !processed && packet instanceof IQ) { final IQ iq = (IQ) packet; final JID fromJID = iq.getFrom(); final JID toJID = iq.getTo(); // Must be iq of type set and sent to remote users if (!iq.getType().equals(IQ.Type.set) || server.isLocal(toJID)) { return; }/* ww w . j a v a 2 s. co m*/ // With a pubsub requests Element requestElement = iq.getChildElement(); if (!requestElement.getNamespace().equals(Namespace.get("http://jabber.org/protocol/pubsub"))) { return; } // With a subscibe or unsubscribe command Element commandElement = requestElement.element("subscribe"); if (commandElement == null) { commandElement = requestElement.element("unsubscribe"); if (commandElement == null) { return; } } // Relating to the microblogging node Attribute nodeAttribute = commandElement.attribute("node"); if (!(nodeAttribute != null && nodeAttribute.getValue().equals(PEPActivityHandler.NODE))) { return; } // Then we keep track of the subscribe/unsubscribe request if (commandElement.getName().equals("subscribe")) { ActivityManager.getInstance().subscribe(fromJID.toBareJID(), toJID.toBareJID()); } else { ActivityManager.getInstance().unsubscribe(fromJID.toBareJID(), toJID.toBareJID()); } } }