List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:org.jessma.dao.jdbc.DruidSessionMgr.java
License:Apache License
@SuppressWarnings("unchecked") private void loadXmlCfg(Properties props) throws Exception { SAXReader sr = new SAXReader(); Document doc = sr.read(new File(configFile)); Element root = doc.getRootElement(); List<Element> list = root.elements("property"); for (Element e : list) { String key = e.attributeValue("name"); String value = e.getTextTrim(); props.put(key, value);/*w w w. j a v a 2 s . co m*/ } }
From source file:org.jessma.dao.jdbc.JndiSessionMgr.java
License:Apache License
@SuppressWarnings("unchecked") private void loadXmlCfg(Properties props) throws Exception { SAXReader sr = new SAXReader(); Document doc = sr.read(new File(configFile)); Element root = doc.getRootElement(); jndiName = root.attributeValue(JNDI_NAME_KEY); if (GeneralHelper.isStrEmpty(jndiName)) throw new RuntimeException( String.format("'%s' attribute must be set for 'root' element", JNDI_NAME_KEY)); List<Element> list = root.elements("property"); for (Element e : list) { String key = e.attributeValue("name"); String value = e.getTextTrim(); props.put(key, value);/* w ww. j av a 2s. c om*/ } }
From source file:org.jessma.ext.rest.RestDispatcher.java
License:Apache License
private void parseGlobal(Element root) { Element global = root.element(GLOBAL_KEY); if (global != null) { Element enc = global.element(ENCODING_KEY); if (enc != null) { String str = enc.getTextTrim(); if (GeneralHelper.isStrNotEmpty(str)) encoding = str;//from w ww. jav a2 s. co m } Element acSuffix = global.element(ACTION_SUFFIX_KEY); if (acSuffix != null) { String str = acSuffix.getTextTrim(); if (GeneralHelper.isStrNotEmpty(str)) { if (str.startsWith(SUFFIX_CHARACTER)) actionSuffix = str; else actionSuffix = SUFFIX_CHARACTER + str; } } Element rbPath = global.element(REST_BASE_PATH_KEY); if (rbPath != null) { String str = rbPath.getTextTrim(); if (GeneralHelper.isStrNotEmpty(str)) restBasePath = HttpHelper.ensurePath(str, DEFAULT_REST_BASE_PATH); } Element defAcPath = global.element(DEFAULT_ACTION_PATH_KEY); if (defAcPath != null) { String str = defAcPath.getTextTrim(); if (GeneralHelper.isStrNotEmpty(str)) defaultActionPath = HttpHelper.ensurePath(str, DEFAULT_DEF_ACTION_PATH); } } parseSupportRenderTypes(global); }
From source file:org.jessma.ext.rest.RestDispatcher.java
License:Apache License
private void parseSupportRenderTypes(Element global) { String types = DEFAULT_SUPPORT_RENDER_TYPES; if (global != null) { Element srTypes = global.element(SUPPORT_RENDER_TYPES_KEY); if (srTypes != null) { String str = srTypes.getTextTrim(); if (GeneralHelper.isStrNotEmpty(str)) types = str;// w w w . j a v a 2 s . c om } } String[] ts = GeneralHelper.splitStr(types); for (int i = 0; i < ts.length; i++) { String type = ts[i]; RenderType rt = SUPPORTED_RENDER_TYPES_MAP.get(type); if (rt == null) { String msg = String.format("parse '%s' fail, only support %s", SUPPORT_RENDER_TYPES_KEY, SUPPORTED_RENDER_TYPES_MAP.keySet()); throw new RestException(msg); } if (i == 0) defaultRenderType = rt; supportRenderTypes.put(type, rt); } }
From source file:org.jessma.logcutter.global.AppConfig.java
License:Apache License
private static void parseGlobal(Element global) { if (global != null) { // <start-check-delay> Element chkDelay = global.element("start-check-delay"); if (chkDelay != null) { String value = chkDelay.getTextTrim(); startCheckDelay = parseDelay(value); if (startCheckDelay < 0) { startCheckDelay = str2Long(value, -1); if (startCheckDelay < 0) startCheckDelay = DEF_START_CHK_DELAY; else startCheckDelay *= 60; }/* w ww . ja va 2s . c o m*/ } // <check-interval> Element chkIntv = global.element("check-interval"); if (chkIntv != null) { checkInterval = str2Long(chkIntv.getTextTrim(), -1); if (checkInterval <= 0) checkInterval = DEF_CHK_INTERVAL; else checkInterval *= 60; } // <log4j-config-file> Element log4jCfg = global.element("log4j-config-file"); if (log4jCfg != null) { String config = log4jCfg.getTextTrim(); if (isStrNotEmpty(config)) log4jConfigFile = config; } // <lock-file> Element lcFile = global.element("lock-file"); if (lcFile != null) { String lock = lcFile.getTextTrim(); if (isStrNotEmpty(lock)) lockFile = lock; } } }
From source file:org.jessma.logcutter.global.AppConfig.java
License:Apache License
private static void parseFilePath(Element file, FilePath fp) { Attribute p = file.attribute("path"); if (p == null) throw new RuntimeException("'file' element must have 'path' attribute"); String path = p.getValue();/*from w w w . ja v a 2 s . c o m*/ if (isStrEmpty(path)) throw new RuntimeException("'file.path' attribute must not empty"); if (!path.endsWith(File.separator)) path = path + File.separator; String name = file.getTextTrim(); if (isStrEmpty(name)) throw new RuntimeException("'file' element must not empty"); fp.setPath(path); fp.setName(name); }
From source file:org.jessma.mvc.ActionDispatcher.java
License:Apache License
private void parseEncoding(Element enc) { String str = enc.getTextTrim(); if (GeneralHelper.isStrNotEmpty(str)) encoding = str;/*from w w w . ja va2s . com*/ }
From source file:org.jessma.mvc.ActionDispatcher.java
License:Apache License
private void parseActionSuffix(Element acSuffix) { String str = acSuffix.getTextTrim(); if (GeneralHelper.isStrNotEmpty(str)) { if (str.startsWith(SUFFIX_CHARACTER)) actionSuffix = str;/*from w ww . ja v a 2 s.c o m*/ else actionSuffix = SUFFIX_CHARACTER + str; } }
From source file:org.jessma.mvc.ActionDispatcher.java
License:Apache License
@SuppressWarnings("unchecked") private Map<String, ActionResult> parseResults(Element rsElement) { Map<String, ActionResult> map = new HashMap<String, ActionResult>(); List<Element> results = rsElement.elements(RESULT_KEY); for (Element result : results) { ActionResult ars = new ActionResult(); ars.name = result.attributeValue(RESULT_NAME_KEY); String type = result.attributeValue(RESULT_TYPE_KEY); ars.path = parseResultPath(result.getTextTrim()); if (ars.name == null) ars.name = Action.SUCCESS; if (type == null || type.equals(Action.ResultType.DEFAULT.toString())) { if (!ars.name.equals(Action.NONE)) ars.type = Action.ResultType.DISPATCH; else/*from w w w .j av a 2 s .c o m*/ ars.type = Action.ResultType.FINISH; } else ars.type = Action.ResultType.fromString(type); map.put(ars.name, ars); } return map.isEmpty() ? null : map; }
From source file:org.jivesoftware.admin.LdapUserProfile.java
License:Open Source License
/** * Returns true if the vCard mappings where successfully loaded from the XML/DB * properties./*from w w w . j a va2 s. c om*/ * * @return true if mappings where loaded from saved property. */ public boolean loadFromProperties() { String xmlProperty = JiveGlobals.getProperty("ldap.vcard-mapping"); if (xmlProperty == null || xmlProperty.trim().length() == 0) { return false; } try { // Remove CDATA wrapping element if (xmlProperty.startsWith("<![CDATA[")) { xmlProperty = xmlProperty.substring(9, xmlProperty.length() - 3); } // Parse XML Document document = DocumentHelper.parseText(xmlProperty); Element vCard = document.getRootElement(); Element element = vCard.element("N"); if (element != null) { name = element.elementTextTrim("GIVEN"); } element = vCard.element("EMAIL"); if (element != null) { email = element.elementTextTrim("USERID"); } element = vCard.element("FN"); if (element != null) { fullName = element.getTextTrim(); } element = vCard.element("NICKNAME"); if (element != null) { nickname = element.getTextTrim(); } element = vCard.element("BDAY"); if (element != null) { birthday = element.getTextTrim(); } // Parse addresses Iterator addresses = vCard.elementIterator("ADR"); while (addresses.hasNext()) { element = (Element) addresses.next(); if (element.element("HOME") != null) { if (element.element("STREET") != null) { homeStreet = element.elementTextTrim("STREET"); } if (element.element("LOCALITY") != null) { homeCity = element.elementTextTrim("LOCALITY"); } if (element.element("REGION") != null) { homeState = element.elementTextTrim("REGION"); } if (element.element("PCODE") != null) { homeZip = element.elementTextTrim("PCODE"); } if (element.element("CTRY") != null) { homeCountry = element.elementTextTrim("CTRY"); } } else if (element.element("WORK") != null) { if (element.element("STREET") != null) { businessStreet = element.elementTextTrim("STREET"); } if (element.element("LOCALITY") != null) { businessCity = element.elementTextTrim("LOCALITY"); } if (element.element("REGION") != null) { businessState = element.elementTextTrim("REGION"); } if (element.element("PCODE") != null) { businessZip = element.elementTextTrim("PCODE"); } if (element.element("CTRY") != null) { businessCountry = element.elementTextTrim("CTRY"); } } } // Parse telephones Iterator telephones = vCard.elementIterator("TEL"); while (telephones.hasNext()) { element = (Element) telephones.next(); if (element.element("HOME") != null) { if (element.element("VOICE") != null) { homePhone = element.elementTextTrim("NUMBER"); } else if (element.element("CELL") != null) { homeMobile = element.elementTextTrim("NUMBER"); } else if (element.element("FAX") != null) { homeFax = element.elementTextTrim("NUMBER"); } else if (element.element("PAGER") != null) { homePager = element.elementTextTrim("NUMBER"); } } else if (element.element("WORK") != null) { if (element.element("VOICE") != null) { businessPhone = element.elementTextTrim("NUMBER"); } else if (element.element("CELL") != null) { businessMobile = element.elementTextTrim("NUMBER"); } else if (element.element("FAX") != null) { businessFax = element.elementTextTrim("NUMBER"); } else if (element.element("PAGER") != null) { businessPager = element.elementTextTrim("NUMBER"); } } } element = vCard.element("TITLE"); if (element != null) { businessJobTitle = element.getTextTrim(); } element = vCard.element("ORG"); if (element != null) { if (element.element("ORGUNIT") != null) { businessDepartment = element.elementTextTrim("ORGUNIT"); } } avatarStoredInDB = JiveGlobals.getBooleanProperty("ldap.override.avatar", false); } catch (DocumentException e) { Log.error("Error loading vcard mappings from property", e); return false; } return true; }