List of usage examples for org.dom4j Element getTextTrim
String getTextTrim();
From source file:cz.mzk.editor.server.newObject.MonographBuilder.java
License:Open Source License
@SuppressWarnings("unchecked") private void updateLanguages(Document doc, XPath xpath) { List<? extends Node> nodes = xpath.selectNodes(doc); for (Node languageNode : nodes) { Element languageEl = (Element) languageNode; String originalLang = languageEl.getTextTrim(); languageEl.clearContent();// www.ja va 2s .c o m languageEl.addText(transformLanguage(originalLang)); } }
From source file:darks.orm.core.config.SessionConfigFactory.java
License:Apache License
/** * Parse SqlMap config/*from w ww. j ava2 s.co m*/ * * @param doc Document * @param cfg Configuration config * @throws ConfigException */ private static void parseSqlMapXpath(Document doc, Configuration cfg) throws ConfigException { List<String> sqlMapsPath = cfg.getSqlMapsPath(); String xpath = "/darks/sqlMapGroup"; Element node = (Element) doc.selectSingleNode(xpath); if (node == null) return; List<?> nodes = node.selectNodes("sqlMap"); Iterator<?> it = nodes.iterator(); while (it.hasNext()) { Element el = (Element) it.next(); String path = el.getTextTrim(); if (path.indexOf("*") >= 0) { List<String> list = FileHelper.getRegexResourceFiles(path); for (String fpath : list) { sqlMapsPath.add(fpath); } } else { if (!"".equals(path)) { sqlMapsPath.add(path); } } } }
From source file:darks.orm.core.config.sqlmap.DDLConfigReader.java
License:Apache License
/** * /*from w w w.j av a2s . c o m*/ * * @param element * @param type */ public void readLabel(Element element, DDLType type) { DDLData ddlData = new DDLData(); String sql = element.getTextTrim(); String strRndId = UUIDHelper.getUUID(); ddlData.setId(strRndId); ddlData.setSql(sql); ddlData.setType(type); for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { try { Attribute at = it.next(); String name = at.getName().trim(); String value = at.getValue().trim(); if ("id".equalsIgnoreCase(name)) { ddlData.setId(value); } else if ("tableName".equalsIgnoreCase(name)) { ddlData.setTableName(value); } else if ("checkTable".equalsIgnoreCase(name)) { if ("true".equalsIgnoreCase(value)) ddlData.setCheckTable(true); else if ("false".equalsIgnoreCase(value)) ddlData.setCheckTable(false); } else if ("autoRunable".equalsIgnoreCase(name)) { if ("true".equalsIgnoreCase(value)) ddlData.setAutoRunable(true); else if ("false".equalsIgnoreCase(value)) ddlData.setAutoRunable(false); } } catch (Exception e) { e.printStackTrace(); } } sqlMapConfig.addDDLData(ddlData.getId(), ddlData); }
From source file:darks.orm.core.config.sqlmap.DMLConfigReader.java
License:Apache License
/** * Read and parse query tags//from w ww . j a va 2 s. co m * * @param element Query tag element * @param namesp namespace * @throws Exception */ private DMLData readQuery(Element element, String namesp) throws Exception { if (!"".equals(namesp)) { if (!namesp.endsWith(".")) namesp += "."; } DMLData dmlData = new DMLData(); dmlData.setType(DMLType.Query); DMLQueryData queryData = new DMLQueryData(); queryData.setQueryType(QueryEnumType.Auto); queryData.setAutoCascade(true); dmlData.setQueryData(queryData); try { for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { Attribute attr = it.next(); readQueryAttribute(attr, dmlData, queryData); } } catch (Exception e) { throw new ConfigException(e.getMessage(), e); } if (queryData.getResultClass() == null) { throw new ConfigException("Sqlmap query " + dmlData.getId() + " loss result class config"); } if (dmlData.getId() == null) return null; RootTag rootTag = new RootTag(); parseSqlTag(rootTag, element, namesp); dmlData.setSqlTag(rootTag); String sql = element.getTextTrim(); if (sql != null && !"".equals(sql)) { queryData.setQueryDataType(DMLQueryDataType.Simple); queryData.setSQL(sql); } else { if (!readConstitute(element, queryData)) { if (!readSelect(element, queryData, "")) { return null; } } } AspectData aspectData = parseAspectXml(element); queryData.setAspectData(aspectData); sqlMapConfig.addDMLData(namesp + dmlData.getId(), dmlData); return dmlData; }
From source file:darks.orm.core.config.sqlmap.DMLConfigReader.java
License:Apache License
/** * Read constitute query/*from ww w . j ava 2s.co m*/ * * @param element query element * @param queryData Query data * @return If success, return true */ private boolean readConstitute(Element element, DMLQueryData queryData) { queryData.setQueryDataType(DMLQueryDataType.Constitute); Element queryElement = element.element("query"); Element cstElement = element.element("constitute"); if (queryElement == null || cstElement == null) return false; String sql = queryElement.getTextTrim(); if (sql == null || "".equals(sql)) return false; queryData.setSQL(sql); List<Element> items = cstElement.elements("item"); for (Element item : items) { String value = item.attributeValue("value"); if (value == null || "".equals(value)) continue; String exsql = item.getTextTrim(); if (exsql == null) exsql = ""; queryData.addSQL(value, exsql); } return true; }
From source file:darks.orm.core.config.sqlmap.DMLConfigReader.java
License:Apache License
/** * Read select query/*www .j av a2s .c om*/ * * @param element query element * @param queryData Query data * @param pVal Parent values * @return If success, return true */ private boolean readSelect(Element element, DMLQueryData queryData, String pVal) { queryData.setQueryDataType(DMLQueryDataType.Select); List<Element> selects = element.elements("select"); if (selects == null || selects.size() == 0) return false; for (Element sel : selects) { String value = sel.attributeValue("value"); if (value == null || "".equals(value)) continue; List<Element> chsel = sel.elements("select"); if (chsel.size() > 0) { readSelect(sel, queryData, pVal + value + "@"); } else { String sql = sel.getTextTrim(); String key = pVal + value; if (key.endsWith("@")) { key = key.substring(0, key.length() - 1); } queryData.addSQL(key, sql); } } return true; }
From source file:darks.orm.core.config.sqlmap.DMLConfigReader.java
License:Apache License
/** * Read and parse update tags//from ww w. j av a2 s. co m * * @param element Update tag * @param namesp namespace * @throws Exception */ private DMLData readUpdate(Element element, String namesp) throws Exception { if (!"".equals(namesp)) { if (!namesp.endsWith(".")) namesp += "."; } DMLData dmlData = new DMLData(); String sql = element.getTextTrim(); dmlData.setType(DMLType.Update); DMLUpdateData updateData = new DMLUpdateData(); RootTag rootTag = new RootTag(); parseSqlTag(rootTag, element, namesp); dmlData.setSqlTag(rootTag); updateData.setSql(sql); for (Iterator<Attribute> it = element.attributeIterator(); it.hasNext();) { try { Attribute at = it.next(); String name = at.getName().trim(); String value = at.getValue().trim(); if ("id".equalsIgnoreCase(name)) { dmlData.setId(value); } } catch (Exception e) { logger.error(e.getMessage(), e); } } if (dmlData.getId() == null) return null; AspectData aspectData = parseAspectXml(element); updateData.setAspectData(aspectData); dmlData.setUpdateData(updateData); sqlMapConfig.addDMLData(namesp + dmlData.getId(), dmlData); return dmlData; }
From source file:darks.orm.core.config.sqlmap.DMLConfigReader.java
License:Apache License
/** * Read and parse aspect XMLs file/* w w w . jav a 2 s .c o m*/ * * @param element Aspect tags * @return Aspect data */ private AspectData parseAspectXml(Element element) { Element aspectEl = element.element("aspect"); if (aspectEl == null) return null; AspectData aspectData = new AspectData(); boolean isNext = false; Element jythonEl = aspectEl.element("jython"); if (jythonEl != null) { aspectData.setAspectType(AspectType.JYTHON); Attribute attr = jythonEl.attribute("className"); if (attr == null) return null; aspectData.setClassName(attr.getValue().trim()); String text = jythonEl.getText(); if (text == null || "".equals(text.trim())) { String before = jythonEl.elementText("before"); String after = jythonEl.elementText("after"); if (before == null || "".equals(before.trim())) { if (after == null || "".equals(after.trim())) return null; } text = PythonBuilder.buildBody(aspectData.getClassName(), before, after); } aspectData.setContent(text); isNext = true; } Element pyfileEl = aspectEl.element("pyfile"); if (pyfileEl != null && isNext == false) { aspectData.setAspectType(AspectType.PYFILE); Attribute attr = pyfileEl.attribute("className"); if (attr == null) return null; aspectData.setClassName(attr.getValue().trim()); aspectData.setContent(pyfileEl.getTextTrim()); isNext = true; } Element javaClassEl = aspectEl.element("javaClass"); if (javaClassEl != null && isNext == false) { aspectData.setAspectType(AspectType.JAVACLASS); aspectData.setClassName(javaClassEl.getTextTrim()); isNext = true; } Element jsEl = aspectEl.element("javascript"); if (jsEl != null && isNext == false) { aspectData.setAspectType(AspectType.JAVASCRIPT); aspectData.setContent(jsEl.getTextTrim()); isNext = true; } Element jsfileEl = aspectEl.element("jsfile"); if (jsfileEl != null && isNext == false) { aspectData.setAspectType(AspectType.JSFILE); aspectData.setContent(jsfileEl.getTextTrim()); isNext = true; } if (isNext) { return aspectData; } return null; }
From source file:darks.orm.core.data.tags.impl.TextTag.java
License:Apache License
@Override public boolean parseElement(Element el) { text = el.getTextTrim(); if ("".equals(text)) { return false; }/* w w w . j a v a 2 s. c om*/ return true; }
From source file:de.ailis.wlandsuite.game.parts.ActionClassMap.java
License:Open Source License
/** * Creates and returns a new action classes map read from XML. * * @param element//from w w w . ja v a 2 s . c om * The XML element * @param mapSize * The map size * @return The action classes map */ public static ActionClassMap read(final Element element, final int mapSize) { ActionClassMap actionClassMap; String data; char c; int i; int b; // Create the new action map actionClassMap = new ActionClassMap(mapSize); // Parse the action classes data = element.getTextTrim(); i = 0; for (int y = 0; y < mapSize; y++) { for (int x = 0; x < mapSize; x++) { try { c = data.charAt(i); } catch (final StringIndexOutOfBoundsException e) { throw new GameException("Action class map is corrupt: " + (mapSize * mapSize - (y * mapSize + x)) + " bytes missing"); } if (c == '.') c = '0'; try { b = Byte.valueOf(Character.toString(c), 16); } catch (final NumberFormatException e) { throw new GameException("Illegal character in action class map at y=" + y + " x=" + x); } actionClassMap.actionClasses[y][x] = b; i++; } i++; } // Return the newly created action map return actionClassMap; }