List of usage examples for org.dom4j Element attribute
Attribute attribute(QName qName);
From source file:com.globalsight.terminology.importer.MtfReaderThread.java
License:Apache License
private void convertToSourceGrp(Element p_elem) { Element sourceGrp = p_elem.createCopy("sourceGrp"); // sourceGrp contains noteGrp, remove all non-noteGrp // children, remembering the <descrip type="source"> itself for (ListIterator lit = sourceGrp.elements().listIterator(); lit.hasNext();) { Element child = (Element) lit.next(); if (child.getName().equals("descrip")) { Element source = child.createCopy("source"); source.remove(source.attribute("type")); lit.set(source);//from w ww .j a va2s.c om } else if (!child.getName().equals("noteGrp")) { lit.remove(); } } Element parent = p_elem.getParent(); parent.content().set(parent.indexOf(p_elem), sourceGrp); }
From source file:com.globalsight.terminology.util.TBXEntryParse.java
License:Apache License
@Override public TbLanguage getTbLanguaeFromXml(TbConcept tc, Element langGrp, SessionInfo p_session) { String langLocale = langGrp.attribute("lang").getText(); String langName = EntryUtils.getLanguageName(langLocale); StringBuffer xml = new StringBuffer(); // Prepare language nodes for storage for (Iterator it = langGrp.elementIterator(); it.hasNext();) { Element elmt = (Element) it.next(); if (!elmt.getName().equals("ntig") && !elmt.getName().equals("tig")) { String tmp = elmt.asXML(); tmp = tmp.replace("\\", "\\\\"); xml.append(tmp);/* w ww . j a v a 2s .co m*/ } } String lxml = xml.toString(); TbLanguage tlan = new TbLanguage(); tlan.setTbid(tc.getTermbase().getId()); tlan.setConcept(tc); tlan.setLocal(langLocale); tlan.setName(langName); tlan.setXml(lxml); return tlan; }
From source file:com.globalsight.terminology.util.TBXEntryParse.java
License:Apache License
/** * Get TBX files entry id//w w w . j a v a 2 s . com * * @param entry * @return * @throws TermbaseException */ public String getConceptId(Entry entry) throws TermbaseException { Document dom = entry.getDom(); Element root = dom.getRootElement(); if (root.attribute("id") == null || root.attribute("id").getText().length() == 0) { return null; } else { return root.attribute("id").getText(); } }
From source file:com.gote.importexport.ExportTournamentForOpenGotha.java
License:Apache License
/** * Update a document according to Tournament state * /*w ww . j ava2 s.co m*/ * @param pDocument Document * @param pTournament Tournament */ private void updateDocument(Document pDocument, Tournament pTournament) { Element pElementTournament = pDocument.getRootElement(); Element elementGames = pElementTournament.element(TournamentOpenGothaUtil.TAG_GAMES); @SuppressWarnings("unchecked") List<Element> listOfGames = (List<Element>) elementGames.elements(TournamentOpenGothaUtil.TAG_GAME); for (Element game : listOfGames) { // Check if there is no result for the game before checking games if (game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_RESULT) != null && !TournamentOpenGothaUtil.VALUE_GAME_RESULT_UNKNOWN .equals(game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_RESULT).getValue())) { if (game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_ROUND) != null && game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_BLACK_PLAYER) != null && game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_WHITE_PLAYER) != null) { game.addAttribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_RESULT, pTournament.getGameResultWithCompleteName( Integer.parseInt(game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_ROUND) .getValue()), game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_BLACK_PLAYER).getValue(), game.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_WHITE_PLAYER) .getValue())); } else { LOGGER.log(Level.SEVERE, "Either the round number, black player name or white player name has not been found for game : " + game + ". Update impossible"); } } } }
From source file:com.gote.importexport.ImportTournamentFromOpenGotha.java
License:Apache License
/** * Init tournament rules//w ww. j a v a 2 s . co m * * @param pTournament Tournament being builded * @param pElementTournamentRulesSet Element in OpenGotha document * @return boolean, true if everything worked as expected */ public boolean initTournamentRules(Tournament pTournament, Element pElementTournamentRulesSet) { LOGGER.log(Level.INFO, "Tournament rules initialization"); boolean init = true; TournamentRules tournamentRules = new TournamentRules(); Element elementGeneralParameters = pElementTournamentRulesSet .element(TournamentOpenGothaUtil.TAG_GENERAL_PARAMETER_SET); if (elementGeneralParameters == null) { return false; } if (elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_KOMI) != null) { tournamentRules.setKomi(elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_KOMI).getValue()); } if (elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_SIZE) != null) { tournamentRules.setSize(elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_SIZE).getValue()); } if (elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_TIME_SYSTEM) != null) { tournamentRules.setTimeSystem(elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_TIME_SYSTEM).getValue()); } if (elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_BASIC_TIME) != null) { tournamentRules.setBasicTime(elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_BASIC_TIME).getValue()); } if (elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_BYOYOMI_TIME) != null) { tournamentRules.setByoYomiDuration(elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_BYOYOMI_TIME).getValue()); } if (elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_BYOYOMI_COUNT) != null) { tournamentRules.setNumberOfByoYomi(elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_BYOYOMI_COUNT).getValue()); } pTournament.setTournamentRules(tournamentRules); if (elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_NAME) != null) { pTournament.setTitle(elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_NAME).getValue()); } else { LOGGER.log(Level.WARNING, "No title found for the tournament"); } if (elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_BEGIN_DATE) != null) { pTournament.setStartDate(new DateTime(elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_BEGIN_DATE).getValue())); } else { LOGGER.log(Level.WARNING, "No start date tournament"); } if (elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_END_DATE) != null) { pTournament.setEndDate(new DateTime(elementGeneralParameters .attribute(TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_END_DATE).getValue())); } else { LOGGER.log(Level.WARNING, "No end date tournament"); } // String numberOfRounds = elementGeneralParameters.attribute( // TournamentOpenGothaUtil.ATTRIBUTE_GENERAL_PARAMETER_SET_ROUND_NUMBER).getValue(); return init; }
From source file:com.gote.importexport.ImportTournamentFromOpenGotha.java
License:Apache License
/** * Init players list// w w w . j a va 2 s . c om * * @param pTournament Tournament being builded * @param pElementPlayers Element in OpenGotha document * @return boolean, true if everything worked as expected */ public boolean initPlayers(Tournament pTournament, Element pElementPlayers) { LOGGER.log(Level.INFO, "Players initialization"); boolean init = false; @SuppressWarnings("unchecked") List<Element> listOfPlayers = (List<Element>) pElementPlayers.elements(TournamentOpenGothaUtil.TAG_PLAYER); init = (listOfPlayers != null && !listOfPlayers.isEmpty()); if (init) { List<Player> tournamentPlayers = new ArrayList<Player>(); for (Element playerElement : listOfPlayers) { Player player = new Player(); player.setPseudo(playerElement.attribute(TournamentOpenGothaUtil.ATTRIBUTE_PLAYER_NAME).getValue()); player.setFirstname( playerElement.attribute(TournamentOpenGothaUtil.ATTRIBUTE_PLAYER_FIRSTNAME).getValue()); player.setRank(playerElement.attribute(TournamentOpenGothaUtil.ATTRIBUTE_PLAYER_RANK).getValue()); tournamentPlayers.add(player); } pTournament.setParticipantsList(tournamentPlayers); } return init; }
From source file:com.gote.importexport.ImportTournamentFromOpenGotha.java
License:Apache License
/** * Init rounds and games//w w w. j ava 2 s.c o m * * @param pTournament Tournament being builded * @param pElementGames Element in OpenGotha document * @return boolean, true if everything worked as expected */ public boolean initRounds(Tournament pTournament, Element pElementGames) { LOGGER.log(Level.INFO, "Rounds initialization"); boolean init = false; @SuppressWarnings("unchecked") List<Element> listOfGames = (List<Element>) pElementGames.elements(TournamentOpenGothaUtil.TAG_GAME); init = (listOfGames != null && !listOfGames.isEmpty()); if (init) { List<Round> tournamentRounds = new ArrayList<Round>(); for (Element gameElement : listOfGames) { // Check round game number, if it exists, add it to the round if it does not exists create // the round first String roundNumberAsText = gameElement.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_ROUND) .getValue(); int roundPlacement = -1; List<Game> games = new ArrayList<Game>(); Round round = new Round(); if (roundNumberAsText != null && !roundNumberAsText.isEmpty()) { roundPlacement = getRoundPlacement(tournamentRounds, new Integer(roundNumberAsText)); } else { LOGGER.log(Level.WARNING, "No round number in configuration file. Line is : " + gameElement.toString()); } if (roundPlacement > -1) { games = tournamentRounds.get(roundPlacement).getGameList(); } else { LOGGER.log(Level.INFO, "Round " + roundNumberAsText + " is new and will be created."); round.setNumber(new Integer(roundNumberAsText)); } Game game = new Game(); Player black = pTournament.getParticipantWithCompleteName( gameElement.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_BLACK_PLAYER).getValue()); Player white = pTournament.getParticipantWithCompleteName( gameElement.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_WHITE_PLAYER).getValue()); String result = gameElement.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_RESULT).getValue(); String handicap = gameElement.attribute(TournamentOpenGothaUtil.ATTRIBUTE_GAME_HANDICAP).getValue(); game.setBlack(black); game.setWhite(white); game.setResult(result); game.setHandicap(handicap); games.add(game); if (roundPlacement < 0) { round.setGameList(games); round.setDateStart(pTournament.getStartDate()); round.setDateEnd(pTournament.getEndDate()); tournamentRounds.add(round); } } pTournament.setRounds(tournamentRounds); } return init; }
From source file:com.gote.pojo.Game.java
License:Apache License
/** * Load Game from XML/*ww w . j av a 2 s.c o m*/ * * @param pRoot Element * @param pTournament Element */ public void fromXML(Element pRoot, Tournament pTournament) { if (pRoot.attribute(TournamentGOTEUtil.ATT_GAME_BLACKPLAYER) != null) { setBlack(pTournament .getParticipantWithPseudo(pRoot.attribute(TournamentGOTEUtil.ATT_GAME_BLACKPLAYER).getValue())); } else { LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_GAME_BLACKPLAYER + " is null"); } if (pRoot.attribute(TournamentGOTEUtil.ATT_GAME_WHITEPLAYER) != null) { setWhite(pTournament .getParticipantWithPseudo(pRoot.attribute(TournamentGOTEUtil.ATT_GAME_WHITEPLAYER).getValue())); } else { LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_GAME_WHITEPLAYER + " is null"); } if (pRoot.attribute(TournamentGOTEUtil.ATT_GAME_URL) != null) { setGameUrl(pRoot.attribute(TournamentGOTEUtil.ATT_GAME_URL).getValue()); } else { LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_GAME_URL + " is null"); } if (pRoot.attribute(TournamentGOTEUtil.ATT_GAME_HANDICAP) != null) { setHandicap(pRoot.attribute(TournamentGOTEUtil.ATT_GAME_HANDICAP).getValue()); } else { LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_GAME_HANDICAP + " is null"); } if (pRoot.attribute(TournamentGOTEUtil.ATT_GAME_RESULT) != null) { setResult(pRoot.attribute(TournamentGOTEUtil.ATT_GAME_RESULT).getValue()); } else { LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_GAME_RESULT + " is null"); } if (pRoot.attribute(TournamentGOTEUtil.ATT_GAME_KOMI) != null) { setKomi(pRoot.attribute(TournamentGOTEUtil.ATT_GAME_KOMI).getValue()); } else { LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_GAME_KOMI + " is null"); } }
From source file:com.gote.pojo.Player.java
License:Apache License
/** * Load Round from XML// w w w . j a v a2 s.c o m * * @param pRoot Element */ public void fromXML(Element pRoot) { if (pRoot.attribute(TournamentGOTEUtil.ATT_PLAYER_PSEUDO) != null) { setPseudo(pRoot.attribute(TournamentGOTEUtil.ATT_PLAYER_PSEUDO).getValue()); } else { LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_PLAYER_PSEUDO + " is null"); } if (pRoot.attribute(TournamentGOTEUtil.ATT_PLAYER_RANK) != null) { setRank(pRoot.attribute(TournamentGOTEUtil.ATT_PLAYER_RANK).getValue()); } else { LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_PLAYER_RANK + " is null"); } if (pRoot.attribute(TournamentGOTEUtil.ATT_PLAYER_FIRSTNAME) != null) { setFirstname(pRoot.attribute(TournamentGOTEUtil.ATT_PLAYER_FIRSTNAME).getValue()); } else { LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_PLAYER_FIRSTNAME + " is null"); } }
From source file:com.gote.pojo.Round.java
License:Apache License
/** * Load Round from XML/* w w w . j av a2 s. c o m*/ * * @param pRoot Element * @param pTournament Tournament */ public void fromXML(Element pRoot, Tournament pTournament) { if (pRoot.attribute(TournamentGOTEUtil.ATT_ROUND_NUMBER) != null) { setNumber(Integer.parseInt(pRoot.attribute(TournamentGOTEUtil.ATT_ROUND_NUMBER).getValue())); } else { LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_ROUND_NUMBER + " is null"); } if (pRoot.attribute(TournamentGOTEUtil.ATT_ROUND_DATESTART) != null) { setDateStart(new DateTime(pRoot.attribute(TournamentGOTEUtil.ATT_ROUND_DATESTART).getValue())); } else { LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_ROUND_DATESTART + " is null"); } if (pRoot.attribute(TournamentGOTEUtil.ATT_ROUND_DATEEND) != null) { setDateEnd(new DateTime(pRoot.attribute(TournamentGOTEUtil.ATT_ROUND_DATEEND).getValue())); } else { LOGGER.log(Level.WARNING, "The attribute " + TournamentGOTEUtil.ATT_ROUND_DATEEND + " is null"); } Element elementGames = pRoot.element(TournamentGOTEUtil.TAG_GAMES); if (elementGames != null) { List<Game> games = new ArrayList<Game>(); @SuppressWarnings("unchecked") List<Element> gamesElements = elementGames.elements(TournamentGOTEUtil.TAG_GAME); if (gamesElements != null && !gamesElements.isEmpty()) { for (Element gameElement : gamesElements) { Game game = new Game(); game.fromXML(gameElement, pTournament); games.add(game); } } else { LOGGER.log(Level.WARNING, "No round has been found"); } setGameList(games); } else { LOGGER.log(Level.SEVERE, "The element " + TournamentGOTEUtil.TAG_GAMES + " is null"); } }