private ArrayList<Element> serializeFields( Field[] fields, Object object, Document doc) // serializes the fields { Class currentClass = object.getClass(); ArrayList<Element> elements = new ArrayList<Element>(); for (Field f : fields) { try { if (!f.getType().isPrimitive()) // Field not primitive, is a reference to another object { } else // field is primitive { Element newField = new Element("field"); newField.setAttribute("name", f.getName()); newField.setAttribute("declaringclass", f.getDeclaringClass().getName()); Element newValue = new Element("value"); newValue.addContent(f.get(object).toString()); newField.addContent(newValue); elements.add(newField); } } catch (Exception e) { e.printStackTrace(); } } return elements; }
public Element handleShortAddressVal(Element type, long cv, String name, String comment) { Element r = new Element("int"); r.setAttribute("origin", "" + (4278190080L + cv)); r.addContent(new Element("name").addContent(name)); if (comment != null && !comment.equals("")) r.addContent(new Element("description").addContent(comment)); return r; }
public Element getSettingsXml() { Element e = new Element(COLUMN_TAG); // e.setAttribute("index",Integer.toString(index)); e.addContent(new Element(COLUMN_TYPE_TAG).setText(type)); if (type.compareToIgnoreCase(IGNORE_COLUMN_TYPE) != 0) { e.addContent(templateValue.getMetadataXml()); } return e; }
private Element mkFounderXML(String name, String address, String PeerID) { Element founder = new Element("founder"); Element founderName = new Element("name").setText(name); Element founderAddress = new Element("email").setText(address); Element founderPeerID = new Element("peerid").setText(PeerID); founder.addContent(founderName); founder.addContent(founderAddress); founder.addContent(founderPeerID); return founder; }
public void addVariables(Element inRoot) throws org.jdom2.DataConversionException { Element vs = inRoot.getChild("decoder").getChild("variables"); Element segment = new Element("segment"); segment.setAttribute("space", "253"); root.addContent(segment); Iterator it = vs.getDescendants(); while (it.hasNext()) { Object o = it.next(); if (o instanceof Element) { Element e = (Element) o; if (e.getName().equals("variable")) { // get common attributes String comment = e.getAttributeValue("comment"); for (Object oc : e.getChildren("comment")) { Element ec = (Element) oc; if (ec.getAttributeValue("lang", "xml").equals("")) comment = ec.getText(); } String name = e.getAttributeValue("label"); if (name.equals("")) name = e.getAttributeValue("item"); for (Object on : e.getChildren("label")) { Element en = (Element) on; if (en.getAttributeValue("lang", "xml").equals("")) name = en.getText(); } long cv = e.getAttribute("CV").getIntValue(); // find subtype and process Element type; type = e.getChild("decVal"); if (type != null) { segment.addContent(handleDecVal(type, cv, name, comment, e.getAttributeValue("mask"))); continue; } type = e.getChild("enumVal"); if (type != null) { segment.addContent(handleEnumVal(type, cv, name, comment, e.getAttributeValue("mask"))); continue; } type = e.getChild("shortAddressVal"); if (type != null) { segment.addContent(handleShortAddressVal(type, cv, name, comment)); continue; } type = e.getChild("longAddressVal"); if (type != null) { segment.addContent(handleLongAddressVal(type, cv, name, comment)); continue; } } } } }
private Element mkUserInfoXML(String name, String address, String PeerID, String status) { Element user = new Element("user"); Element userName = new Element("name").setText(name); Element userAddress = new Element("email").setText(address); Element userPeerID = new Element("peerid").setText(PeerID); Element userStatus = new Element("status").setText(status); user.addContent(userName); user.addContent(userAddress); user.addContent(userPeerID); user.addContent(userStatus); return user; }
public HelpDataManager() { super(); Table = super.CreateElement("Table"); TableData = super.CreateElement("TableData"); Rows = super.CreateElement("Rows"); super.Root = Table; super.getDocment().setRootElement(Root); TableData.addContent(Rows); Table.addContent(TableData); }
public Document serialize(Object object, Document doc) { Class c = object.getClass(); Integer id = getID(object); map.put(object, id); String mapSize = Integer.toString(map.size()); // creating serialization objects Element objectElement = new Element("object"); objectElement.setAttribute(new Attribute("class", c.getName())); objectElement.setAttribute(new Attribute("id", mapSize)); doc.getRootElement().addContent(objectElement); if (!c.isArray()) // class is not an array { Field[] fields = c.getDeclaredFields(); ArrayList<Element> fieldXML = serializeFields(fields, object, doc); for (int i = 0; i < fieldXML.size(); i++) { objectElement.addContent(fieldXML.get(i)); } } else // class is an array { Object array = object; objectElement.setAttribute(new Attribute("length", Integer.toString(Array.getLength(array)))); if (c.getComponentType().isPrimitive()) // class is array of primitives { for (int i = 0; i < Array.getLength(array); i++) { Element value = new Element("value"); value.setText(Array.get(c, i).toString()); objectElement.addContent(value); } } else // class is array of references { for (int j = 0; j < Array.getLength(array); j++) { Element ref = new Element("reference"); id = getID(Array.get(c, j)); if (id != -1) { ref.setText(Integer.toString(id)); } } for (int k = 0; k < Array.getLength(array); k++) { serialize(Array.get(array, k), doc); } } } if (currentElement == 0) { referenceID = 0; } return doc; }
public void buildXML() { Element root = new Element("ChannelInfo"); doc = new org.jdom.Document(root); // costructring descriptor Element desc = new Element("desc"); Element name = (new Element("name")).setText(getName()); Element topicitem = (new Element("topic")).setText(getTopic()); Element pipeUri = (new Element("pipeID")).setText(getPipeUri()); desc.addContent(name); desc.addContent(pipeUri); desc.addContent(topicitem); desc.addContent(mkTimeStampXML()); desc.addContent(mkFounderXML(founderName, founderAddress, founderPeerID)); root.addContent(desc); // end descriptor Element userList = new Element("userlist"); Set<Entry<String, UserInfo>> entrySet = chUsers.entrySet(); for (Entry<String, UserInfo> e : entrySet) { UserInfo val = e.getValue(); String s = new Integer(val.getStatus()).toString(); Element user = mkUserInfoXML(val.getName(), val.getAddress(), val.getPeerID(), s); userList.addContent(user); } root.addContent(userList); }
public Element handleDecVal(Element type, long cv, String name, String comment, String mask) { Element r; if (mask != null && !mask.equals("")) { r = new Element("bit"); r.setAttribute("size", "8"); r.setAttribute("mask", maskToInt(mask)); } else { r = new Element("int"); } r.setAttribute("origin", "" + (4278190080L + cv)); r.addContent(new Element("name").addContent(name)); if (comment != null && !comment.equals("")) r.addContent(new Element("description").addContent(comment)); return r; }
public Element getLookupElement() { Element e = new Element("lookup"); if (saveErrors.size() != 0) { saveErrors.clear(); } ObjEntityView view = objEntityViewField.getObjEntityView(); DataView dataView = view.getDataView(); String fieldPath = "<b>" + dataView.getName() + "." + view.getName() + "." + objEntityViewField.getName() + "</b><br>"; if (lookupObjEntityView != null) { e.setAttribute(new Attribute("obj-entity-view-name", lookupObjEntityView.getName())); } else { e.setAttribute(new Attribute("obj-entity-view-name", "")); saveErrors.add(fieldPath + "lookup hasn't attribute \"obj-entity-view-name\"<br><br>"); } if (lookupField != null) { e.setAttribute(new Attribute("field-name", lookupField.getName())); } else { e.setAttribute(new Attribute("field-name", "")); saveErrors.add(fieldPath + "lookup hasn't attribute \"field-name\"<br><br>"); } e.addContent(""); return e; }
public void fillDOMElement(Element element) { element.setAttribute("name", getLabel()); element.setAttribute("id", getId()); for (Object obj : getChildren()) { if (obj instanceof IDataSets) { Element dataset = new Element(IDataSets.class.getName()); element.addContent(dataset); for (Object dataobj : ((IDataSets) obj).getChildren()) { if (dataobj instanceof IDataContent) { CodeFragment code = ((IDataContent) dataobj).getCode(); dataset.addContent(code); } } } } }
public String createTable() { Element root = new Element("table"); root.setAttribute("border", "0"); Document doc = new Document(root); Element thead = new Element("thead"); Element th = new Element("th"); th.addContent("A header"); th.setAttribute("class", "aka_header_border"); thead.addContent(th); Element th2 = new Element("th"); th2.addContent("Another header"); th2.setAttribute("class", "aka_header_border"); thead.addContent(th2); root.addContent(thead); Element tr1 = new Element("tr"); Element td1 = new Element("td"); td1.setAttribute("valign", "top"); td1.setAttribute("class", "cellBorders"); td1.setText("cell contents"); tr1.addContent(td1); root.addContent(tr1); XMLOutputter outp = new XMLOutputter(); Format format = Format.getPrettyFormat(); format.setOmitDeclaration(true); outp.setFormat(format); Writer writer = new StringWriter(); try { outp.output(doc, writer); } catch (IOException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } return writer.toString(); }
// 参数是一个数据行的属性列表 // 列表中的元素是2维字符串数组,一个属性名,一个属性值 public void addDataRow(Vector v) { Element Row; Row = super.CreateElement("Row"); for (int i = 0; i < v.size(); i++) { String[] attr = (String[]) v.elementAt(i); Row.setAttribute(attr[0], attr[1]); } Rows.addContent(Row); }
// TODO : to be tested ! @Override public JdomRepresentation addAll(String nodeName, String listName, List<Object> values) { Element list = new Element(listName); for (Object o : values) { Element e = new Element(nodeName); e.setText(o.toString()); list.addContent(e); } this.document.getRootElement().addContent(list); return this; }
/** * This is the preferred way for creating a Representation via a customized Resource serialization * * @param rootName * @param serialization */ public JdomRepresentation(String rootName, CoupleList<String, Object> serialization) { Element root = new Element(rootName); for (Couple<String, Object> couple : serialization) { Element elt = new Element(couple.getLeft()); if (couple.getRight() == null) { elt.setText(this.getEmptyValue()); } else { elt.setText(couple.getRight().toString()); } root.addContent(elt); } this.document = new Document(root); }
/** * sauvegarde une voiture dans un fichier xml temporaire listvoitures.xml * * @param pvoiture est l'objet course recuperée depuis l'ihm */ public static void saveVoituresinTempFile(Voiture pvoiture) { SAXBuilder sxb = new SAXBuilder(); Document document; try { document = sxb.build(new File(xmlTempPathListVoitures)); Element racine = document.getRootElement(); // racine.removeChildren("voiture"); Element newVoitureElement = new Element("voiture"); newVoitureElement.setAttribute( "numeroVoiture", pvoiture.getNumeroVoiture_() != null ? pvoiture.getNumeroVoiture_() : ""); newVoitureElement.setAttribute( "couleur", pvoiture.getCouleur_() != null ? pvoiture.getCouleur_() : ""); Element nombreDeTours = new Element("nombreDeTours"); Element tempsEstimeTour = new Element("tempsEstimeTour"); Element voitureActive = new Element("voitureActive"); Element quantiteMoyenneEssenceParTour = new Element("quantiteMoyenneEssenceParTour"); Element nombreToursEffectues = new Element("nombreToursEffectues"); Element nombreToursDepuisDernierRelais = new Element("nombreToursDepuisDernierRelais"); Element numeroRelaisEnCours = new Element("numeroRelaisEnCours"); Element heurePrevueProchainPassage = new Element("heurePrevueProchainPassage"); newVoitureElement.addContent(nombreDeTours); newVoitureElement.addContent(tempsEstimeTour); newVoitureElement.addContent(voitureActive); newVoitureElement.addContent(quantiteMoyenneEssenceParTour); newVoitureElement.addContent(nombreToursEffectues); newVoitureElement.addContent(nombreToursDepuisDernierRelais); newVoitureElement.addContent(numeroRelaisEnCours); newVoitureElement.addContent(heurePrevueProchainPassage); racine.addContent(newVoitureElement); enregistre(document, xmlTempPathListVoitures); } catch (Exception e) { e.getMessage(); } }
public String createXml(String videoid) throws SQLException { // TODO Auto-generated method stub Element rootElement = new Element("popcorn"); // Document document = new Document(rootElement); Element timeline = new Element("timeline"); rootElement.addContent(timeline); Element resources = new Element("resources"); timeline.addContent(resources); String row = ""; // String xml = ""; PreparedStatement preparedStatement = mysqlCon.prepareStatement( "SELECT DISTINCT `row` FROM `IKSvideotag`.`metadata` WHERE `idvideo`=?"); preparedStatement.setString(1, videoid); ResultSet resultSet = preparedStatement.executeQuery(); // writeResultSet(resultSet); while (resultSet.next()) { row = resultSet.getString("row"); PreparedStatement getdata = mysqlCon.prepareStatement( "SELECT `IKSvideotag`.`metadata`.*, `IKSvideotag`.`plugin`.`name` FROM `IKSvideotag`.`metadata`, `IKSvideotag`.`plugin` WHERE (`IKSvideotag`.`metadata`.`row` = ? AND `IKSvideotag`.`plugin`.`idplugin` = `IKSvideotag`.`metadata`.`idplugin`)"); getdata.setString(1, row); ResultSet dataSet = getdata.executeQuery(); Element pluginElement = null; while (dataSet.next()) { if (pluginElement == null) pluginElement = new Element(dataSet.getString("name")); pluginElement.setAttribute(dataSet.getString("tagname"), dataSet.getString("tagvalue")); } resources.addContent(pluginElement); pluginElement = null; } resultSet.close(); preparedStatement.close(); XMLOutputter outputter = new XMLOutputter(); return outputter.outputString(rootElement); }
public Document getDoc() { Element root = new Element("isotime"); Document doc = new Document(root); // un noeud game Element node1 = new Element("time"); node1.setAttribute("beginTime", String.valueOf(beginTime)); // Actualisation of acctualTime node1.setAttribute("day", String.valueOf(getDay())); node1.setAttribute("hour", String.valueOf(getHour())); node1.setAttribute("min", String.valueOf(getMin())); node1.setAttribute("sec", String.valueOf(getSec())); root.addContent(node1); return doc; }
public static void saveCourseCreerToXml(Evenement event) { Element elementEvent = JDomOperations.getElementActuel_(); Element listCourses = elementEvent.getChild("listcourses"); Iterator itListCoursesInEvent = event.getIteratorCollectionEssaiCourse_(); while (itListCoursesInEvent.hasNext()) { EssaiOrCourse course = (EssaiOrCourse) itListCoursesInEvent.next(); Element elementCourse = new Element("course"); elementCourse.setAttribute(new Attribute("nomEssaiOrCourse", course.getNomEssaiOrCourse_())); elementCourse.setAttribute( new Attribute("typeEssaiOrCourse", course.getTypeEssaiOrCourse_().toString())); listCourses.addContent(elementCourse); } JDomOperations.enregistre(elementEvent.getDocument(), xmlDefaultPath); }
public void addDefaultCVs() { Element segment = new Element("segment"); segment.setAttribute("origin", "4278190081"); // 255.0.0.1 segment.setAttribute("space", "253"); Element group = new Element("group"); group.setAttribute("replication", "256"); group.addContent(new Element("name").addContent("CVs")); group.addContent(new Element("description").addContent("Raw CV access")); group.addContent(new Element("repname").addContent("CV")); segment.addContent(group); Element intElement = new Element("int"); intElement.setAttribute("size", "1"); intElement.addContent(new Element("min").addContent("0")); intElement.addContent(new Element("max").addContent("255")); group.addContent(intElement); root.addContent(segment); }
/** * 新增循环节点 * @param cycNode 循环节点 * @return */ public Element addCycNode(Element cycNode) { Element node=cycNode; Element child=null; Element newNode=null; Element tmpNode=null; String sName=""; if(cycNode==null) return newNode; newNode=new Element(node.getName()); node.getParent().addContent(newNode); List cList=node.getChildren(); for(int i=0;i<cList.size();i++) { child=(Element)cList.get(i); sName=child.getName(); sName=sName.trim(); tmpNode=new Element(sName); newNode.addContent(tmpNode); } return newNode; }
public void addHeader(Element inRoot) { Element id = new Element("identification"); String mfg = inRoot.getChild("decoder").getChild("family").getAttributeValue("mfg"); id.addContent(new Element("manufacturer").addContent(mfg)); String name = inRoot.getChild("decoder").getChild("family").getAttributeValue("name"); id.addContent(new Element("model").addContent(name)); id.addContent(new Element("hardwareVersion")); id.addContent(new Element("softwareVersion")); // add models in map, if any Element map = new Element("map"); for (Object o : inRoot.getChild("decoder").getChild("family").getChildren("model")) { Element e = (Element) o; Element relation = new Element("relation"); relation.addContent(new Element("property").addContent("Model")); relation.addContent(new Element("value").addContent(e.getAttributeValue("model"))); map.addContent(relation); } id.addContent(map); root.addContent(id); }
public Element handleEnumVal(Element type, long cv, String name, String comment, String mask) throws org.jdom2.DataConversionException { Element r; if (mask != null && !mask.equals("")) { r = new Element("bit"); r.setAttribute("size", "8"); r.setAttribute("mask", maskToInt(mask)); } else { r = new Element("int"); } r.setAttribute("origin", "" + (4278190080L + cv)); r.addContent(new Element("name").addContent(name)); if (comment != null && !comment.equals("")) r.addContent(new Element("description").addContent(comment)); Element map = new Element("map"); int counter = 0; r.addContent(map); for (Object c : type.getChildren("enumChoice")) { Element choice = (Element) c; if (choice.getAttribute("value") != null) { counter = choice.getAttribute("value").getIntValue(); } String cname = choice.getAttributeValue("choice"); for (Object oc : choice.getChildren("choice")) { Element ec = (Element) oc; if (ec.getAttributeValue("lang", "xml").equals("")) cname = ec.getText(); } Element relation = new Element("relation"); map.addContent(relation); relation.addContent(new Element("property").addContent("" + counter)); relation.addContent(new Element("value").addContent(cname)); counter++; } return r; }
public void addCommonCDI() { Element segment = new Element("segment"); segment.setAttribute("space", "253"); segment.setAttribute("origin", "256"); segment.addContent(new Element("name").addContent("DCC Controls")); segment.addContent(new Element("description").addContent("DCC-specific control items")); root.addContent(segment); Element i; Element map; Element relation; i = new Element("int"); i.addContent(new Element("name").addContent("Programming Mode")); map = new Element("map"); i.addContent(map); relation = new Element("relation"); map.addContent(relation); relation.addContent(new Element("property").addContent("1")); relation.addContent(new Element("value").addContent("Register Mode")); relation = new Element("relation"); map.addContent(relation); relation.addContent(new Element("property").addContent("2")); relation.addContent(new Element("value").addContent("Paged Mode")); relation = new Element("relation"); map.addContent(relation); relation.addContent(new Element("property").addContent("4")); relation.addContent(new Element("value").addContent("Direct Bit Mode")); relation = new Element("relation"); map.addContent(relation); relation.addContent(new Element("property").addContent("5")); relation.addContent(new Element("value").addContent("Direct Byte Mode")); segment.addContent(i); i = new Element("int"); i.setAttribute("size", "2"); i.addContent(new Element("name").addContent("DCC Address")); segment.addContent(i); i = new Element("int"); i.addContent(new Element("name").addContent("Speed Steps")); segment.addContent(i); i = new Element("int"); i.addContent(new Element("name").addContent("Single Index CV Address")); segment.addContent(i); i = new Element("int"); i.setAttribute("size", "2"); i.addContent(new Element("name").addContent("Double Index CV Addresses")); segment.addContent(i); }
/** * sauvegarde une course dans un fichier xml temporaire listcourses.xml * * @param pcourse est l'objet course recuperée depuis l'ihm */ public static void saveCoursesinTempFile(EssaiOrCourse pcourse) { SAXBuilder sxb = new SAXBuilder(); Document document; try { document = sxb.build(new File(xmlTempPathListCourses)); Element racine = document.getRootElement(); // racine.removeChildren("course"); Element newCourseElement = new Element("course"); newCourseElement.setAttribute( "nomEssaiOrCourse", pcourse.getNomEssaiOrCourse_() != null ? pcourse.getNomEssaiOrCourse_() : ""); newCourseElement.setAttribute( "typeEssaiOrCourse", pcourse.getTypeEssaiOrCourse_() != null ? pcourse.getTypeEssaiOrCourse_().toString() : ""); Element departAutomatique = new Element("departAutomatique"); Element typeDeFin = new Element("typeDeFin"); Element heureDebut = new Element("heureDebut"); Element heureFin = new Element("heureFin"); Element nbToursMax = new Element("nbToursMax"); Element dureeMaxPilotage = new Element("dureeMaxPilotage"); Element dureeConsecutiveMaxPilotage = new Element("dureeConsecutiveMaxPilotage"); Element commentaire = new Element("commentaire"); departAutomatique.setText(pcourse.isDepartAutomatique_() ? "true" : "false"); typeDeFin.setText(pcourse.getTypeDeFin_() != null ? pcourse.getTypeDeFin_().toString() : ""); heureDebut.setText( pcourse.getHeureDebut_() != null ? pcourse.getHeureDebut_().toString() : ""); heureFin.setText(pcourse.getHeureFin_() != null ? pcourse.getHeureFin_().toString() : ""); nbToursMax.setText( pcourse.getNbToursMax_() >= 0 ? String.valueOf(pcourse.getNbToursMax_()) : ""); dureeMaxPilotage.setText( pcourse.getDureeMaxPilotage_() >= 0 ? String.valueOf(pcourse.getDureeMaxPilotage_()) : ""); dureeConsecutiveMaxPilotage.setText( pcourse.getDureeConsecutiveMaxPilotage_() >= 0 ? String.valueOf(pcourse.getDureeConsecutiveMaxPilotage_()) : ""); commentaire.setText(pcourse.getCommentaire_() != null ? pcourse.getCommentaire_() : ""); newCourseElement.addContent(departAutomatique); newCourseElement.addContent(typeDeFin); newCourseElement.addContent(heureDebut); newCourseElement.addContent(heureFin); newCourseElement.addContent(nbToursMax); newCourseElement.addContent(dureeMaxPilotage); newCourseElement.addContent(dureeConsecutiveMaxPilotage); newCourseElement.addContent(commentaire); racine.addContent(newCourseElement); enregistre(document, xmlTempPathListCourses); } catch (Exception e) { e.getMessage(); } }
public void writeXML(Element e) { Element ne = new Element("char"); ne.setAttribute("char", "" + key); e.addContent(ne); }
public void addAcdiElement() { root.addContent(new Element("acdi")); }
/* public boolean typedNew(KeyEvent e,NewBinding.EvBindStatus status) { return false; } */ public void writeXML(Element e) { Element ne = new Element("keycode"); ne.setAttribute("keyCode", "" + keyCode); ne.setAttribute("modifier", "" + modifierEx); e.addContent(ne); }
public void writeXML(Element e) { Element ne = new Element("jinput"); ne.setAttribute("ident", ident); ne.setAttribute("value", "" + value); e.addContent(ne); }