List of usage examples for org.dom4j Element elementText
String elementText(QName qname);
From source file:org.nuxeo.ecm.core.io.impl.AbstractDocumentModelWriter.java
License:Apache License
@SuppressWarnings("unchecked") private static Object getElementData(ExportedDocument xdoc, Element element, Type type) { // empty xml tag must be null value (not empty string) if (!element.hasContent()) { return null; }/*ww w . ja va 2s . co m*/ if (type.isSimpleType()) { return type.decode(element.getText()); } else if (type.isListType()) { ListType ltype = (ListType) type; List<Object> list = new ArrayList<>(); Iterator<Element> it = element.elementIterator(); while (it.hasNext()) { Element el = it.next(); list.add(getElementData(xdoc, el, ltype.getFieldType())); } Type ftype = ltype.getFieldType(); if (ftype.isSimpleType()) { // these are stored as arrays Class klass = getFieldClass(ftype); if (klass.isPrimitive()) { return PrimitiveArrays.toPrimitiveArray(list, klass); } else { return list.toArray((Object[]) Array.newInstance(klass, list.size())); } } return list; } else { ComplexType ctype = (ComplexType) type; if (TypeConstants.isContentType(ctype)) { String mimeType = element.elementText(ExportConstants.BLOB_MIME_TYPE); String encoding = element.elementText(ExportConstants.BLOB_ENCODING); String content = element.elementTextTrim(ExportConstants.BLOB_DATA); String filename = element.elementTextTrim(ExportConstants.BLOB_FILENAME); if ((content == null || content.length() == 0) && (mimeType == null || mimeType.length() == 0)) { return null; // remove blob } Blob blob = null; if (xdoc.hasExternalBlobs()) { blob = xdoc.getBlob(content); } if (blob == null) { // maybe the blob is embedded in Base64 // encoded data byte[] bytes = Base64.decodeBase64(content); blob = Blobs.createBlob(bytes); } blob.setMimeType(mimeType); blob.setEncoding(encoding); blob.setFilename(filename); return blob; } else { // a complex type Map<String, Object> map = new HashMap<>(); Iterator<Element> it = element.elementIterator(); while (it.hasNext()) { Element el = it.next(); String name = el.getName(); Object value = getElementData(xdoc, el, ctype.getField(el.getName()).getType()); map.put(name, value); } return map; } } }
From source file:org.nuxeo.ecm.core.io.impl.plugins.ExtensibleDocumentWriter.java
License:Open Source License
@Override protected DocumentModel createDocument(ExportedDocument xdoc, Path toPath) { Path parentPath = toPath.removeLastSegments(1); String name = toPath.lastSegment(); DocumentModel doc = new DocumentModelImpl(parentPath.toString(), name, xdoc.getType()); // set lifecycle state at creation Element system = xdoc.getDocument().getRootElement().element(ExportConstants.SYSTEM_TAG); String lifeCycleState = system.element(ExportConstants.LIFECYCLE_STATE_TAG).getText(); String lifeCyclePolicy = system.element(ExportConstants.LIFECYCLE_POLICY_TAG).getText(); doc.putContextData(CoreSession.IMPORT_LIFECYCLE_POLICY, lifeCyclePolicy); doc.putContextData(CoreSession.IMPORT_LIFECYCLE_STATE, lifeCycleState); // loadFacets before schemas so that additional schemas are not skipped loadFacetsInfo(doc, xdoc.getDocument()); // then load schemas data loadSchemas(xdoc, doc, xdoc.getDocument()); if (doc.hasSchema("uid")) { doc.putContextData(VersioningService.SKIP_VERSIONING, true); }//from ww w . j a va2 s . c o m String uuid = xdoc.getId(); if (uuid != null) { ((DocumentModelImpl) doc).setId(uuid); } Element version = xdoc.getDocument().getRootElement().element("version"); if (version != null) { Element e = version.element("isVersion"); String isVersion = version.elementText("isVersion"); if ("true".equals(isVersion)) { String label = version.elementText(IMPORT_VERSION_LABEL.substring(4)); String sourceId = version.elementText(IMPORT_VERSION_VERSIONABLE_ID.substring(4)); String desc = version.elementText(IMPORT_VERSION_DESCRIPTION.substring(4)); String created = version.elementText(IMPORT_VERSION_CREATED.substring(4)); if (label != null) { doc.putContextData(IMPORT_VERSION_LABEL, label); } if (sourceId != null) { doc.putContextData(IMPORT_VERSION_VERSIONABLE_ID, sourceId); } if (desc != null) { doc.putContextData(IMPORT_VERSION_DESCRIPTION, desc); } if (created != null) { doc.putContextData(IMPORT_VERSION_CREATED, (Serializable) new DateType().decode(created)); } doc.setPathInfo(null, name); ((DocumentModelImpl) doc).setIsVersion(true); doc.putContextData(CoreSession.IMPORT_VERSION_MAJOR, doc.getPropertyValue("uid:major_version")); doc.putContextData(CoreSession.IMPORT_VERSION_MINOR, doc.getPropertyValue("uid:minor_version")); doc.putContextData(CoreSession.IMPORT_IS_VERSION, true); } } if (doc.getId() != null) { session.importDocuments(Collections.singletonList(doc)); } else { doc = session.createDocument(doc); } // load into the document the system properties, document needs to exist loadSystemInfo(doc, xdoc.getDocument()); for (ImportExtension ext : extensions) { try { ext.updateImport(session, doc, xdoc); } catch (Exception e) { log.error("Error while processing extensions", e); throw new NuxeoException(e); } } unsavedDocuments += 1; saveIfNeeded(); return doc; }
From source file:org.olat.ims.qti.editor.beecom.parser.QTIMetadataParser.java
License:Apache License
/** * @see org.olat.ims.qti.editor.beecom.IParser#parse(org.dom4j.Element) */// w ww .ja va 2s . com @Override public Object parse(final Element element) { // assert element.getName().equalsIgnoreCase("qtimetadata"); final Metadata meta = new Metadata(); final List metadatafields = element.selectNodes("./qtimetadatafield"); for (final Iterator iter = metadatafields.iterator(); iter.hasNext();) { final Element metadatafield = (Element) iter.next(); final String key = metadatafield.elementText("fieldlabel"); final String value = metadatafield.elementText("fieldentry"); meta.setField(key, value); } return meta; }
From source file:org.olat.modules.cp.CPManifestTreeModel.java
License:Apache License
private GenericTreeNode buildNode(final Element item) { final GenericTreeNode gtn = new GenericTreeNode(); // extract title String title = item.elementText("title"); if (title == null) { title = item.attributeValue("identifier"); }/* w ww .j a va 2s . co m*/ gtn.setAltText(title); gtn.setTitle(title); if (item.getName().equals("organization")) { gtn.setIconCssClass("o_cp_org"); gtn.setAccessible(false); } else if (item.getName().equals("item")) { gtn.setIconCssClass("o_cp_item"); // set resolved file path directly final String identifierref = item.attributeValue("identifierref"); final XPath meta = rootElement.createXPath("//ns:resource[@identifier='" + identifierref + "']"); meta.setNamespaceURIs(nsuris); final String href = (String) resources.get(identifierref); if (href != null) { gtn.setUserObject(href); // allow lookup of a treenode given a href so we can quickly adjust the menu if the user clicks on hyperlinks within the text hrefToTreeNode.put(href, gtn); } else { gtn.setAccessible(false); } } final List chds = item.elements("item"); final int childcnt = chds.size(); for (int i = 0; i < childcnt; i++) { final Element childitem = (Element) chds.get(i); final GenericTreeNode gtnchild = buildNode(childitem); gtn.addChild(gtnchild); } return gtn; }
From source file:org.olat.modules.scorm.ScormCPManifestTreeModel.java
License:Apache License
private GenericTreeNode buildNode(final Element item) { final GenericTreeNode treeNode = new GenericTreeNode(); // extract title String title = item.elementText("title"); if (title == null) { title = item.attributeValue("identifier"); }//w w w . j a v a 2 s.c om treeNode.setAltText(title); treeNode.setTitle(title); if (item.getName().equals("organization")) { treeNode.setIconCssClass("o_scorm_org"); treeNode.setAccessible(false); } else if (item.getName().equals("item")) { scormIdToNode.put(new Integer(nodeId).toString(), treeNode); nodeToId.put(treeNode, new Integer(nodeId)); // set node images according to scorm sco status final String itemStatusDesc = (String) itemStatus.get(Integer.toString(nodeId)); treeNode.setIconCssClass("o_scorm_item"); if (itemStatusDesc != null) { // add icon decorator for current status treeNode.setIconDecorator1CssClass("o_scorm_" + itemStatusDesc); } nodeId++; // set resolved file path directly final String identifierref = item.attributeValue("identifierref"); final XPath meta = rootElement.createXPath("//ns:resource[@identifier='" + identifierref + "']"); meta.setNamespaceURIs(nsuris); final String href = (String) resources.get(identifierref); if (href != null) { treeNode.setUserObject(href); // allow lookup of a treenode given a href so we can quickly adjust the menu if the user clicks on hyperlinks within the text hrefToTreeNode.put(href, treeNode); } else { treeNode.setAccessible(false); } } final List chds = item.elements("item"); final int childcnt = chds.size(); for (int i = 0; i < childcnt; i++) { final Element childitem = (Element) chds.get(i); final GenericTreeNode gtnchild = buildNode(childitem); treeNode.addChild(gtnchild); } return treeNode; }
From source file:org.opencms.workplace.editors.CmsWorkplaceEditorConfiguration.java
License:Open Source License
/** * Initializes all member variables.<p> * //from ww w . ja v a 2s . c o m * @param document the XML configuration document * @param editorUri the editor workplace URI */ private void initialize(Document document, String editorUri) { // get the root element of the configuration Element rootElement = document.getRootElement(); // set the label of the editor setEditorLabel(rootElement.elementText(N_LABEL)); // set the widget editor class if available String widgetClass = rootElement.elementText(N_WIDGETEDITOR); if (CmsStringUtil.isNotEmpty(widgetClass)) { setWidgetEditor(widgetClass); } // set the URI of the editor setEditorUri(editorUri); // create the map of valid resource types Iterator i = rootElement.element(N_RESOURCETYPES).elementIterator(N_TYPE); Map resTypes = new HashMap(); while (i.hasNext()) { Element currentType = (Element) i.next(); float ranking; String name = currentType.elementText(N_NAME); if (CmsStringUtil.isEmpty(name)) { logConfigurationError(Messages.get().getBundle().key(Messages.ERR_INVALID_RESTYPE_NAME_0), null); continue; } try { ranking = Float.parseFloat(currentType.elementText(N_RANKING)); } catch (Throwable t) { logConfigurationError(Messages.get().getBundle().key(Messages.ERR_INVALID_RESTYPE_RANKING_1, name), t); continue; } String mapTo = currentType.elementText(N_MAPTO); if (CmsStringUtil.isEmpty(mapTo)) { mapTo = null; } resTypes.put(name, new String[] { "" + ranking, mapTo }); } // add the additional resource types i = rootElement.element(N_RESOURCETYPES).elementIterator(N_CLASS); while (i.hasNext()) { Element currentClass = (Element) i.next(); String name = currentClass.elementText(N_NAME); List assignedTypes = new ArrayList(); try { // get the editor type matcher class I_CmsEditorTypeMatcher matcher = (I_CmsEditorTypeMatcher) Class.forName(name).newInstance(); assignedTypes = matcher.getAdditionalResourceTypes(); } catch (Throwable t) { logConfigurationError(Messages.get().getBundle().key(Messages.ERR_INVALID_RESTYPE_CLASS_1, name), t); continue; } float ranking; try { ranking = Float.parseFloat(currentClass.elementText(N_RANKING)); } catch (Throwable t) { logConfigurationError(Messages.get().getBundle().key(Messages.ERR_INVALID_RESTYPE_RANKING_1, name), t); continue; } String mapTo = currentClass.elementText(N_MAPTO); if ("".equals(mapTo)) { mapTo = null; } // now loop through all types found and add them Iterator j = assignedTypes.iterator(); while (j.hasNext()) { String typeName = (String) j.next(); resTypes.put(typeName, new String[] { "" + ranking, mapTo }); } } setResourceTypes(resTypes); // create the list of user agents & compiled patterns for editor i = document.getRootElement().element(N_USERAGENTS).elementIterator(N_AGENT); List pattern = new ArrayList(); List userAgents = new ArrayList(); while (i.hasNext()) { Element currentAgent = (Element) i.next(); String agentName = currentAgent.getText(); if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(agentName)) { userAgents.add(agentName); try { pattern.add(Pattern.compile(agentName)); } catch (PatternSyntaxException e) { logConfigurationError( Messages.get().getBundle().key(Messages.ERR_COMPILE_EDITOR_REGEX_1, agentName), e); } } else { logConfigurationError(Messages.get().getBundle().key(Messages.ERR_INVALID_USERAGENT_DEF_0), null); } } setBrowserPattern(pattern); setUserAgentsRegEx(userAgents); }
From source file:org.openmeetings.servlet.outputhandler.BackupImportController.java
License:Apache License
private void importMembers(File membersFile) throws Exception { SAXReader reader = new SAXReader(); Document document = reader.read(membersFile); Element root = document.getRootElement(); Element extensions = root.element("members"); for (@SuppressWarnings("unchecked") Iterator<Element> iter = extensions.elementIterator("member"); iter.hasNext();) { Element extensionElem = iter.next(); String confno = extensionElem.elementText("confno"); try {/*from w w w . j a v a 2s . c om*/ MeetMe meetMe = new MeetMe(); meetMe.setConfno(unformatString(extensionElem.element("confno").getText())); meetMe.setPin(unformatString(extensionElem.element("pin").getText())); meetMe.setAdminpin(unformatString(extensionElem.element("adminpin").getText())); meetMe.setMembers(importIntegerType(unformatString(extensionElem.element("members").getText()))); asteriskDAOImpl.saveMeetMe(meetMe); } catch (Exception e) { log.debug("failed to add/update members confno: " + confno, e); } } }
From source file:org.openmeetings.servlet.outputhandler.BackupImportController.java
License:Apache License
private void importExtensions(File extensionsFile) throws Exception { SAXReader reader = new SAXReader(); Document document = reader.read(extensionsFile); Element root = document.getRootElement(); Element extensions = root.element("extensions"); for (@SuppressWarnings("unchecked") Iterator<Element> iter = extensions.elementIterator("extension"); iter.hasNext();) { Element extensionElem = iter.next(); String id = extensionElem.elementText("id"); try {/*from w w w .j a v a 2s . c om*/ Extensions extension = new Extensions(); //the primary key must be null for new objects if its an auto-increment extension.setExten(unformatString(extensionElem.element("exten").getText())); extension.setPriority( importIntegerType(unformatString(extensionElem.element("priority").getText()))); extension.setApp(unformatString(extensionElem.element("app").getText())); extension.setAppdata(unformatString(extensionElem.element("appdata").getText())); asteriskDAOImpl.saveExtensions(extension); } catch (Exception e) { log.debug("failed to add/update extensions id: " + id, e); } } }
From source file:org.openmeetings.servlet.outputhandler.BackupImportController.java
License:Apache License
private void importAsteriskSipUsers(File asteriskSipUsersFile) throws Exception { SAXReader reader = new SAXReader(); Document document = reader.read(asteriskSipUsersFile); Element root = document.getRootElement(); Element asterisksipusers = root.element("asterisksipusers"); for (@SuppressWarnings("unchecked") Iterator<Element> iter = asterisksipusers.elementIterator("asterisksipuser"); iter.hasNext();) { Element asterisksipuserElem = iter.next(); String id = asterisksipuserElem.elementText("id"); try {//from w w w . j a v a 2 s.c o m AsteriskSipUsers asterisksipuser = new AsteriskSipUsers(); //the primary key must be null for new objects if its an auto-increment asterisksipuser .setAccountcode(unformatString(asterisksipuserElem.element("accountcode").getText())); asterisksipuser.setDisallow(unformatString(asterisksipuserElem.element("disallow").getText())); asterisksipuser.setAllow(unformatString(asterisksipuserElem.element("allow").getText())); asterisksipuser .setAllowoverlap(unformatString(asterisksipuserElem.element("allowoverlap").getText())); asterisksipuser .setAllowsubscribe(unformatString(asterisksipuserElem.element("allowsubscribe").getText())); asterisksipuser .setAllowtransfer(unformatString(asterisksipuserElem.element("allowtransfer").getText())); asterisksipuser.setAmaflags(unformatString(asterisksipuserElem.element("amaflags").getText())); asterisksipuser .setAutoframing(unformatString(asterisksipuserElem.element("autoframing").getText())); asterisksipuser.setAuth(unformatString(asterisksipuserElem.element("auth").getText())); asterisksipuser.setBuggymwi(unformatString(asterisksipuserElem.element("buggymwi").getText())); asterisksipuser.setCallgroup(unformatString(asterisksipuserElem.element("callgroup").getText())); asterisksipuser.setCallerid(unformatString(asterisksipuserElem.element("callerid").getText())); asterisksipuser.setCid_number(unformatString(asterisksipuserElem.element("cid_number").getText())); asterisksipuser.setFullname(unformatString(asterisksipuserElem.element("fullname").getText())); asterisksipuser .setCallingpres(unformatString(asterisksipuserElem.element("callingpres").getText())); asterisksipuser .setCanreinvite(unformatString(asterisksipuserElem.element("canreinvite").getText())); asterisksipuser.setContext(unformatString(asterisksipuserElem.element("context").getText())); asterisksipuser.setDefaultip(unformatString(asterisksipuserElem.element("defaultip").getText())); asterisksipuser.setDtmfmode(unformatString(asterisksipuserElem.element("dtmfmode").getText())); asterisksipuser.setFromuser(unformatString(asterisksipuserElem.element("fromuser").getText())); asterisksipuser.setFromdomain(unformatString(asterisksipuserElem.element("fromdomain").getText())); asterisksipuser .setFullcontact(unformatString(asterisksipuserElem.element("fullcontact").getText())); asterisksipuser.setG726nonstandard( unformatString(asterisksipuserElem.element("g726nonstandard").getText())); asterisksipuser.setHost(unformatString(asterisksipuserElem.element("host").getText())); asterisksipuser.setInsecure(unformatString(asterisksipuserElem.element("insecure").getText())); asterisksipuser.setIpaddr(unformatString(asterisksipuserElem.element("ipaddr").getText())); asterisksipuser.setLanguage(unformatString(asterisksipuserElem.element("language").getText())); asterisksipuser.setLastms(unformatString(asterisksipuserElem.element("lastms").getText())); asterisksipuser.setMailbox(unformatString(asterisksipuserElem.element("mailbox").getText())); asterisksipuser.setMaxcallbitrate( importIntegerType(unformatString(asterisksipuserElem.element("maxcallbitrate").getText()))); asterisksipuser.setMohsuggest(unformatString(asterisksipuserElem.element("mohsuggest").getText())); asterisksipuser.setMd5secret(unformatString(asterisksipuserElem.element("md5secret").getText())); asterisksipuser .setMusiconhold(unformatString(asterisksipuserElem.element("musiconhold").getText())); asterisksipuser.setName(unformatString(asterisksipuserElem.element("name").getText())); asterisksipuser.setNat(unformatString(asterisksipuserElem.element("nat").getText())); asterisksipuser .setOutboundproxy(unformatString(asterisksipuserElem.element("outboundproxy").getText())); asterisksipuser.setDeny(unformatString(asterisksipuserElem.element("deny").getText())); asterisksipuser.setPermit(unformatString(asterisksipuserElem.element("permit").getText())); asterisksipuser .setPickupgroup(unformatString(asterisksipuserElem.element("pickupgroup").getText())); asterisksipuser.setPort(unformatString(asterisksipuserElem.element("port").getText())); asterisksipuser .setProgressinband(unformatString(asterisksipuserElem.element("progressinband").getText())); asterisksipuser .setPromiscredir(unformatString(asterisksipuserElem.element("promiscredir").getText())); asterisksipuser.setQualify(unformatString(asterisksipuserElem.element("qualify").getText())); asterisksipuser.setRegexten(unformatString(asterisksipuserElem.element("regexten").getText())); asterisksipuser.setRegseconds( importIntegerType(unformatString(asterisksipuserElem.element("regseconds").getText()))); asterisksipuser.setRfc2833compensate( unformatString(asterisksipuserElem.element("rfc2833compensate").getText())); asterisksipuser.setRtptimeout(unformatString(asterisksipuserElem.element("rtptimeout").getText())); asterisksipuser .setRtpholdtimeout(unformatString(asterisksipuserElem.element("rtpholdtimeout").getText())); asterisksipuser.setSecret(unformatString(asterisksipuserElem.element("secret").getText())); asterisksipuser.setSendrpid(unformatString(asterisksipuserElem.element("sendrpid").getText())); asterisksipuser.setSetvar(unformatString(asterisksipuserElem.element("setvar").getText())); asterisksipuser.setSubscribecontext( unformatString(asterisksipuserElem.element("subscribecontext").getText())); asterisksipuser .setSubscribemwi(unformatString(asterisksipuserElem.element("subscribemwi").getText())); asterisksipuser .setT38pt_udptl(unformatString(asterisksipuserElem.element("t38pt_udptl").getText())); asterisksipuser.setTrustrpid(unformatString(asterisksipuserElem.element("trustrpid").getText())); asterisksipuser.setType(unformatString(asterisksipuserElem.element("type").getText())); asterisksipuser .setUseclientcode(unformatString(asterisksipuserElem.element("useclientcode").getText())); asterisksipuser.setUsername(unformatString(asterisksipuserElem.element("username").getText())); asterisksipuser .setUsereqphone(unformatString(asterisksipuserElem.element("usereqphone").getText())); asterisksipuser .setVideosupport(unformatString(asterisksipuserElem.element("videosupport").getText())); asterisksipuser.setVmexten(unformatString(asterisksipuserElem.element("vmexten").getText())); asteriskDAOImpl.saveAsteriskSipUsers(asterisksipuser); } catch (Exception e) { log.debug("failed to add/update asterisksipuser id: " + id, e); } } }
From source file:org.openmeetings.servlet.outputhandler.BackupImportController.java
License:Apache License
private void importConfigs(File configsFile) throws Exception { SAXReader reader = new SAXReader(); Document document = reader.read(configsFile); Element root = document.getRootElement(); Element configs = root.element("configs"); for (@SuppressWarnings("unchecked") Iterator<Element> iter = configs.elementIterator("config"); iter.hasNext();) { Element cfgElem = iter.next(); String key = cfgElem.elementText("key"); try {// ww w.j a v a2 s.co m Configuration cfg = cfgManagement.getConfKey(3L, key); if (cfg == null) { cfg = new Configuration(); cfg.setConf_key(key); } cfg.setConf_value(cfgElem.elementText("value")); cfg.setUpdatetime(new Date()); cfg.setDeleted(cfgElem.elementText("deleted")); cfg.setComment(cfgElem.elementText("comment")); cfgManagement.updateConfig(cfg); } catch (Exception e) { log.debug("failed to add/update configuration: " + key, e); } } }