List of usage examples for org.dom4j Element addElement
Element addElement(String name);
Element
node with the given name to this branch and returns a reference to the new node. From source file:com.gote.pojo.Round.java
License:Apache License
/** * Transform Round to XML format//from ww w. ja va 2 s . c om * * @param pRoot "Rounds" element * @see TournamentGOTEUtil */ public void toXML(Element pRoot) { // Create round element Element round = pRoot.addElement(TournamentGOTEUtil.TAG_ROUND); // Add its attributes round.addAttribute(TournamentGOTEUtil.ATT_ROUND_NUMBER, new Integer(getNumber()).toString()); round.addAttribute(TournamentGOTEUtil.ATT_ROUND_DATESTART, getDateStart().toString()); round.addAttribute(TournamentGOTEUtil.ATT_ROUND_DATEEND, getDateEnd().toString()); // Add Games list Element games = round.addElement(TournamentGOTEUtil.TAG_GAMES); for (Game game : getGameList()) { game.toXML(games); } }
From source file:com.gote.pojo.Tournament.java
License:Apache License
/** * Transform Tournament in a formatted XML * /*from w ww . j a v a 2 s. c o m*/ * @return XML to write as a String */ public String toXML() { // Create document Document doc = DocumentHelper.createDocument(); // Create tournament element Element root = doc.addElement(TournamentGOTEUtil.TAG_TOURNAMENT); // Add attributes root.addAttribute(TournamentGOTEUtil.ATT_TOURNAMENT_NAME, getTitle()); root.addAttribute(TournamentGOTEUtil.ATT_TOURNAMENT_SERVER, getServerType()); root.addAttribute(TournamentGOTEUtil.ATT_TOURNAMENT_DATESTART, getStartDate().toString()); root.addAttribute(TournamentGOTEUtil.ATT_TOURNAMENT_DATEEND, getEndDate().toString()); // Add rules getTournamentRules().toXML(root); // Add players Element players = root.addElement(TournamentGOTEUtil.TAG_PLAYERS); for (Player player : getParticipantsList()) { player.toXML(players); } // Add rounds Element rounds = root.addElement(TournamentGOTEUtil.TAG_ROUNDS); for (Round round : getRounds()) { round.toXML(rounds); } StringWriter out = new StringWriter(1024); XMLWriter writer; try { writer = new XMLWriter(OutputFormat.createPrettyPrint()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } writer.setWriter(out); try { writer.write(doc); } catch (IOException e) { e.printStackTrace(); } // Return the friendly XML return out.toString(); }
From source file:com.gote.pojo.TournamentRules.java
License:Apache License
/** * Transform rules to xml// www . jav a 2s.c o m * * @param pRoot element "Tournaments" * @see TournamentGOTEUtil */ public void toXML(Element pRoot) { // Create tournament rules element Element rules = pRoot.addElement(TournamentGOTEUtil.TAG_RULES); // Add attributes rules.addAttribute(TournamentGOTEUtil.ATT_RULES_TAG, getTag()); rules.addAttribute(TournamentGOTEUtil.ATT_RULES_KOMI, getKomi()); rules.addAttribute(TournamentGOTEUtil.ATT_RULES_SIZE, getSize()); rules.addAttribute(TournamentGOTEUtil.ATT_RULES_TIMESYSTEM, getTimeSystem()); rules.addAttribute(TournamentGOTEUtil.ATT_RULES_BASICTIME, getBasicTime()); rules.addAttribute(TournamentGOTEUtil.ATT_RULES_BYODURATION, getByoYomiDuration()); rules.addAttribute(TournamentGOTEUtil.ATT_RULES_BYOPERIODS, getNumberOfByoYomi()); }
From source file:com.gst.mix.service.XBRLBuilder.java
License:Apache License
Element addTaxonomy(final Element rootElement, final MixTaxonomyData taxonomy, final BigDecimal value) { // throw an error is start / endate is null if (this.startDate == null || this.endDate == null) { throw new XBRLMappingInvalidException("start date and end date should not be null"); }/*from w w w . ja va 2 s.com*/ final String prefix = taxonomy.getNamespace(); String qname = taxonomy.getName(); if (prefix != null && (!prefix.isEmpty())) { final NamespaceData ns = this.readNamespaceService.retrieveNamespaceByPrefix(prefix); if (ns != null) { this.root.addNamespace(prefix, ns.url()); } qname = prefix + ":" + taxonomy.getName(); } final Element xmlElement = rootElement.addElement(qname); final String dimension = taxonomy.getDimension(); final SimpleDateFormat timeFormat = new SimpleDateFormat("MM_dd_yyyy"); ContextData context = null; if (dimension != null) { final String[] dims = dimension.split(":"); if (dims.length == 2) { context = new ContextData(dims[0], dims[1], taxonomy.getType()); if (this.contextMap.containsKey(context)) { } else { } } } if (context == null) { context = new ContextData(null, null, taxonomy.getType()); } if (!this.contextMap.containsKey(context)) { final String startDateStr = timeFormat.format(this.startDate); final String endDateStr = timeFormat.format(this.endDate); final String contextRefID = (context.getPeriodType() == 0) ? ("As_Of_" + endDateStr + (this.instantScenarioCounter++)) : ("Duration_" + startDateStr + "_To_" + endDateStr + (this.durationScenarioCounter++)); this.contextMap.put(context, contextRefID); } xmlElement.addAttribute("contextRef", this.contextMap.get(context)); xmlElement.addAttribute("unitRef", getUnitRef(taxonomy)); xmlElement.addAttribute("decimals", getNumberOfDecimalPlaces(value).toString()); // add the child xmlElement.addText(value.toPlainString()); return xmlElement; }
From source file:com.gst.mix.service.XBRLBuilder.java
License:Apache License
/** * Adds the generic number unit//w w w . ja v a2 s .co m */ void addNumberUnit() { final Element numerUnit = this.root.addElement("unit"); numerUnit.addAttribute("id", UNITID_PURE); final Element measure = numerUnit.addElement("measure"); measure.addText("xbrli:pure"); }
From source file:com.gst.mix.service.XBRLBuilder.java
License:Apache License
/** * Adds the currency unit to the document * /*from ww w . j a va 2 s .co m*/ * @param currencyCode */ public void addCurrencyUnit(final String currencyCode) { final Element currencyUnitElement = this.root.addElement("unit"); currencyUnitElement.addAttribute("id", UNITID_CUR); final Element measure = currencyUnitElement.addElement("measure"); measure.addText("iso4217:" + currencyCode); }
From source file:com.gst.mix.service.XBRLBuilder.java
License:Apache License
public void addContexts() { final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); for (final Entry<ContextData, String> entry : this.contextMap.entrySet()) { final ContextData context = entry.getKey(); final Element contextElement = this.root.addElement("context"); contextElement.addAttribute("id", entry.getValue()); contextElement.addElement("entity").addElement("identifier").addAttribute("scheme", SCHEME_URL) .addText(IDENTIFIER);//w ww . j ava 2 s . co m final Element periodElement = contextElement.addElement("period"); if (context.getPeriodType() == 0) { periodElement.addElement("instant").addText(format.format(this.endDate)); } else { periodElement.addElement("startDate").addText(format.format(this.startDate)); periodElement.addElement("endDate").addText(format.format(this.endDate)); } final String dimension = context.getDimension(); final String dimType = context.getDimensionType(); if (dimType != null && dimension != null) { contextElement.addElement("scenario").addElement("explicitMember") .addAttribute("dimension", dimType).addText(dimension); } } }
From source file:com.hand.hemp.push.server.xmpp.push.NotificationManager.java
License:Open Source License
/** * Creates a new notification IQ and returns it. * * @param apiKey/*from w ww .j a v a 2 s. c om*/ * @param title * @param message * @param uri * @return */ private IQ createNotificationIQ(String apiKey, String title, String message, String uri) { Random random = new Random(); String id = Integer.toHexString(random.nextInt()); // String id = String.valueOf(System.currentTimeMillis()); Element notification = DocumentHelper.createElement(QName.get("notification", NOTIFICATION_NAMESPACE)); notification.addElement("id").setText(id); notification.addElement("apiKey").setText(apiKey); if (title == null) { title = " "; } notification.addElement("title").setText(title); notification.addElement("message").setText(message); if (uri == null) { uri = " "; } notification.addElement("uri").setText(uri); IQ iq = new IQ(); iq.setType(IQ.Type.set); iq.setChildElement(notification); return iq; }
From source file:com.haulmont.bali.util.Dom4j.java
License:Apache License
public static void storeMap(Element parentElement, Map<String, String> map) { if (map == null) { return;/*from w w w. j a va 2s . co m*/ } Element mapElem = parentElement.addElement("map"); for (Map.Entry<String, String> entry : map.entrySet()) { Element entryElem = mapElem.addElement("entry"); entryElem.addAttribute("key", entry.getKey()); Element valueElem = entryElem.addElement("value"); if (entry.getValue() != null) { String value = StringEscapeUtils.escapeXml(entry.getValue()); valueElem.setText(value); } } }
From source file:com.haulmont.cuba.core.entity.ScheduledTask.java
License:Apache License
public void updateMethodParameters(List<MethodParameterInfo> params) { Document doc = DocumentHelper.createDocument(); Element paramsEl = doc.addElement("params"); for (MethodParameterInfo param : params) { Element paramEl = paramsEl.addElement("param"); paramEl.addAttribute("type", param.getType().getName()); paramEl.addAttribute("name", param.getName()); paramEl.setText(param.getValue() != null ? param.getValue().toString() : ""); }//from ww w . ja v a 2s. c om setMethodParamsXml(Dom4j.writeDocument(doc, true)); }