List of usage examples for org.jdom2 Element setText
public Element setText(final String text)
From source file:de.huberlin.german.korpling.laudatioteitool.SplitTEI.java
License:Apache License
private TEIValidator.Errors extractMainCorpusHeader(Document doc) throws LaudatioException, IOException, SAXException { TEIValidator validator = corpusSchemeURL == null ? new TEICorpusValidator() : new FromURLValidator(corpusSchemeURL); Element corpusHeader = doc.getRootElement().getChild("teiHeader", null); if (corpusHeader != null) { File corpusDir = new File(outputDirectory, "CorpusHeader"); if (!corpusDir.exists() && !corpusDir.mkdir()) { throw new LaudatioException( messages.getString("COULD NOT CREATE DIRECTORY") + corpusDir.getAbsolutePath()); }/*from w w w . j a v a 2s. co m*/ // create the subtree for the global corpus header Namespace teiNS = Namespace.getNamespace("http://www.tei-c.org/ns/1.0"); Element newRootForCorpus = new Element("TEI", teiNS); newRootForCorpus.addContent(corpusHeader.clone()); Document corpusDoc = new Document(newRootForCorpus); if (corpusSchemeURL == null) { corpusDoc.addContent(0, new ProcessingInstruction("xml-model", "href=\"" + TEICorpusValidator.DEFAULT_SCHEME_URL + "\"")); } else { corpusDoc.addContent(0, new ProcessingInstruction("xml-model", "href=\"" + corpusSchemeURL + "\"")); } // we need to append an empty "text" element after the header Element text = new Element("text", teiNS); text.setText(""); newRootForCorpus.addContent(text); // we work with the copy from now corpusHeader = newRootForCorpus.getChild("teiHeader", null); Preconditions.checkNotNull(corpusHeader, messages.getString("ERROR NO CORPUS TITLE GIVEN")); Preconditions.checkState("CorpusHeader".equals(corpusHeader.getAttributeValue("type"))); Preconditions.checkNotNull(corpusHeader.getChild("fileDesc", null), messages.getString("ERROR NO CORPUS TITLE GIVEN")); Preconditions.checkNotNull(corpusHeader.getChild("fileDesc", null).getChild("titleStmt", null), messages.getString("ERROR NO CORPUS TITLE GIVEN")); String title = corpusHeader.getChild("fileDesc", null).getChild("titleStmt", null) .getChildTextNormalize("title", null); Preconditions.checkNotNull(title, messages.getString("ERROR NO CORPUS TITLE GIVEN")); // save the file with the title as file name File outputFile = new File(corpusDir, title + ".xml"); XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); xmlOut.output(corpusDoc, new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")); log.info(messages.getString("WRITTEN CORPUS HEADER"), outputFile.getPath()); validator.validate(outputFile); } return validator.getErrors(); }
From source file:de.huberlin.german.korpling.laudatioteitool.SplitTEI.java
License:Apache License
private TEIValidator.Errors extractDocumentHeaders(Document doc) throws LaudatioException, IOException, SAXException { TEIValidator validator = documentSchemeURL == null ? new TEIDocumentValidator() : new FromURLValidator(documentSchemeURL); File documentDir = new File(outputDirectory, "DocumentHeader"); if (!documentDir.exists() && !documentDir.mkdir()) { throw new LaudatioException( messages.getString("COULD NOT CREATE DIRECTORY") + documentDir.getAbsolutePath()); }//from w ww. j av a 2 s . c o m Element documentRoot = Preconditions.checkNotNull(doc.getRootElement().getChild("teiCorpus", null)); for (Element docHeader : documentRoot.getChildren("teiHeader", null)) { Preconditions.checkState("DocumentHeader".equals(docHeader.getAttributeValue("type"))); // create the subtree for the global corpus header Namespace teiNS = Namespace.getNamespace("http://www.tei-c.org/ns/1.0"); Element tei = new Element("TEI", teiNS); tei.addContent(docHeader.clone()); Document newDoc = new Document(tei); if (documentSchemeURL == null) { newDoc.addContent(0, new ProcessingInstruction("xml-model", "href=\"" + TEIDocumentValidator.DEFAULT_SCHEME_URL + "\"")); } else { newDoc.addContent(0, new ProcessingInstruction("xml-model", "href=\"" + documentSchemeURL + "\"")); } // we need to append an empty "text" element after the header Element text = new Element("text", teiNS); text.setText(""); tei.addContent(text); Element fileDesc = Preconditions .checkNotNull(tei.getChild("teiHeader", null).getChild("fileDesc", null)); String outName = UUID.randomUUID().toString(); String id = fileDesc.getAttributeValue("id", Namespace.XML_NAMESPACE); if (id != null) { outName = id; } else { Element titleStmt = Preconditions.checkNotNull(fileDesc.getChild("titleStmt", null)); String title = titleStmt.getChildText("title", null); if (title != null) { outName = title; } } File outputFile = new File(documentDir, outName + ".xml"); XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); xmlOut.output(newDoc, new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")); log.info(messages.getString("WRITTEN DOCUMENT HEADER"), outputFile.getPath()); validator.validate(outputFile); } return validator.getErrors(); }
From source file:de.huberlin.german.korpling.laudatioteitool.SplitTEI.java
License:Apache License
private TEIValidator.Errors extractPreparationSteps(Document doc) throws LaudatioException, IOException, SAXException { TEIValidator validator = preparationSchemeURL == null ? new TEIPreparationValidator() : new FromURLValidator(preparationSchemeURL); Multiset<String> knownPreparationTitles = HashMultiset.create(); File documentDir = new File(outputDirectory, "PreparationHeader"); if (!documentDir.exists() && !documentDir.mkdir()) { throw new LaudatioException( messages.getString("COULD NOT CREATE DIRECTORY") + documentDir.getAbsolutePath()); }//ww w .j a va2 s. c o m Preconditions.checkNotNull(doc.getRootElement().getChild("teiCorpus", null)); Element preparationRoot = Preconditions .checkNotNull(doc.getRootElement().getChild("teiCorpus", null).getChild("teiCorpus", null)); for (Element preparationHeader : preparationRoot.getChildren("teiHeader", null)) { Preconditions.checkState("PreparationHeader".equals(preparationHeader.getAttributeValue("type"))); // create the subtree for the global corpus header Namespace teiNS = Namespace.getNamespace("http://www.tei-c.org/ns/1.0"); Element tei = new Element("TEI", teiNS); tei.addContent(preparationHeader.clone()); Document newDoc = new Document(tei); if (preparationSchemeURL == null) { newDoc.addContent(0, new ProcessingInstruction("xml-model", "href=\"" + TEIPreparationValidator.DEFAULT_SCHEME_URL + "\"")); } else { newDoc.addContent(0, new ProcessingInstruction("xml-model", "href=\"" + preparationSchemeURL + "\"")); } // we need to append an empty "text" element after the header Element text = new Element("text", teiNS); text.setText(""); tei.addContent(text); Element fileDesc = Preconditions .checkNotNull(tei.getChild("teiHeader", null).getChild("fileDesc", null)); String outName = UUID.randomUUID().toString(); Element titleStmt = Preconditions.checkNotNull(fileDesc.getChild("titleStmt", null)); Element title = Preconditions.checkNotNull(titleStmt.getChild("title", null)); String corresp = title.getAttributeValue("corresp"); if (corresp != null) { if (knownPreparationTitles.contains(corresp)) { knownPreparationTitles.add(corresp); outName = corresp + "_" + knownPreparationTitles.count(corresp); log.warn(messages.getString("MORE THAN ONE PREPARATION HEADER"), corresp); } else { outName = corresp; knownPreparationTitles.add(corresp); } } File outputFile = new File(documentDir, outName + ".xml"); XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); xmlOut.output(newDoc, new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8")); log.info(messages.getString("WRITTEN PREPARATION HEADER"), outputFile.getPath()); validator.validate(outputFile); } return validator.getErrors(); }
From source file:de.ing_poetter.binview.variables.IntegerVariable.java
License:Open Source License
@Override protected Element[] getExtraConfiguration() { final Element[] res = new Element[2]; final Element signEle = new Element(SIGNED_ELEMENT_NAME); signEle.setText("" + signed); res[0] = signEle;//from www . j av a 2 s .co m final Element descrEle = new Element(VALUE_PRESENTATION_ELEMENT_NAME); descrEle.setText(valuePresenation); res[1] = descrEle; return res; }
From source file:de.ing_poetter.binview.variables.Variable.java
License:Open Source License
public Element save() { final Element res = new Element(getTypeName()); // Name/* w w w . jav a 2 s. com*/ final Element nameEle = new Element("Name"); nameEle.setText(Name); res.addContent(nameEle); // Number of Bits final Element numBitsEle = new Element("numberOfBits"); numBitsEle.setText("" + numBits); res.addContent(numBitsEle); // Extra Configuration final Element[] extra = getExtraConfiguration(); for (int i = 0; i < extra.length; i++) { res.addContent(extra[i]); } return res; }
From source file:de.intranda.goobi.plugins.sru.SRUHelper.java
License:Open Source License
public static Node parseHaabResult(GbvMarcSruImport opac, String catalogue, String schema, String searchField, String searchValue, String resultString, String packing, String version, boolean ignoreAnchor) throws IOException, JDOMException, ParserConfigurationException { SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING); builder.setFeature("http://xml.org/sax/features/validation", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); Document doc = builder.build(new StringReader(resultString), "utf-8"); Element record = getRecordWithoutSruHeader(doc); if (record == null) { opac.setHitcount(0);/*from w w w. j a va 2s. co m*/ return null; } opac.setHitcount(1); boolean isPeriodical = false; boolean isManuscript = false; boolean isCartographic = false; boolean isMultiVolume = false; boolean isFSet = false; String anchorPpn = null; String otherAnchorPpn = null; String otherAnchorEpn = null; String otherPpn = null; String currentEpn = null; String otherEpn = null; boolean foundMultipleEpns = false; // generate an answer document DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); org.w3c.dom.Document answer = docBuilder.newDocument(); org.w3c.dom.Element collection = answer.createElement("collection"); answer.appendChild(collection); boolean shelfmarkFound = false; List<Element> data = record.getChildren(); for (Element el : data) { if (el.getName().equalsIgnoreCase("leader")) { String value = el.getText(); if (value.length() < 24) { value = "00000" + value; } char c6 = value.toCharArray()[6]; char c7 = value.toCharArray()[7]; char c19 = value.toCharArray()[19]; if (c6 == 'a' && (c7 == 's' || c7 == 'd')) { isPeriodical = true; } else if (c6 == 't') { isManuscript = true; } else if (c6 == 'e') { isCartographic = true; } if (c19 == 'b' || c19 == 'c') { isFSet = true; } } if (el.getName().equalsIgnoreCase("datafield")) { String tag = el.getAttributeValue("tag"); List<Element> subfields = el.getChildren(); boolean isCurrentEpn = false; for (Element sub : subfields) { String code = sub.getAttributeValue("code"); // anchor identifier if (tag.equals("773") && code.equals("w")) { if (ignoreAnchor) { sub.setText(""); } else if (isFSet || isPeriodical) { isMultiVolume = true; anchorPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } } else if (tag.equals("800") && code.equals("w")) { isMultiVolume = true; anchorPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else if (isManuscript && tag.equals("810") && code.equals("w")) { isMultiVolume = true; anchorPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else if (tag.equals("830") && code.equals("w")) { if (isCartographic || (isFSet && anchorPpn == null)) { isMultiVolume = true; anchorPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } } else if (tag.equals("776") && code.equals("w")) { if (otherPpn == null) { // found first/only occurrence otherPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else { otherPpn = null; foundMultipleEpns = true; } } else if (tag.equals("954")) { if (code.equals("b")) { if (searchField.equals("pica.epn")) { // remove wrong epns currentEpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); isCurrentEpn = true; if (!searchValue.trim().equals(currentEpn)) { sub.setAttribute("code", "invalid"); for (Element exemplarData : subfields) { if (exemplarData.getAttributeValue("code").equals("d")) { exemplarData.setAttribute("code", "invalid"); } } } } else { if (currentEpn == null) { isCurrentEpn = true; currentEpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else { foundMultipleEpns = true; } } } else if (code.equals("d")) { if (!shelfmarkFound && isCurrentEpn) { shelfmarkFound = true; } else { sub.setAttribute("code", "invalid"); } } } } } } // search for pica.zdb for periodca // get digital epn from digital ppn record if (otherPpn != null) { String otherResult = SRUHelper.search(catalogue, schema, isPeriodical ? "pica.zdb" : "pica.ppn", otherPpn, packing, version); Document otherDocument = new SAXBuilder().build(new StringReader(otherResult), "utf-8"); if (otherDocument != null) { Element otherRecord = getRecordWithoutSruHeader(otherDocument); if (otherRecord == null) { Helper.setFehlerMeldung("import_OtherEPNNotFound"); } else { List<Element> controlList = otherRecord.getChildren("controlfield", MARC); for (Element field : controlList) { if (field.getAttributeValue("tag").equals("001")) { otherPpn = field.getText(); } } List<Element> fieldList = otherRecord.getChildren("datafield", MARC); for (Element field : fieldList) { String tag = field.getAttributeValue("tag"); List<Element> subfields = field.getChildren(); for (Element sub : subfields) { String code = sub.getAttributeValue("code"); // anchor identifier if (tag.equals("773") && code.equals("w")) { otherAnchorPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else if (tag.equals("800") && code.equals("w")) { otherAnchorPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else if (isManuscript && tag.equals("810") && code.equals("w")) { otherAnchorPpn = sub.getText().replaceAll("\\(.+\\)", ""); } else if (isCartographic && tag.equals("830") && code.equals("w")) { otherAnchorPpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else if (tag.equals("954") && code.equals("b")) { if (otherEpn == null) { otherEpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else { foundMultipleEpns = true; otherEpn = null; } } } } } if (otherPpn != null) { Element datafield = new Element("datafield", MARC); datafield.setAttribute("tag", "ppnDigital"); datafield.setAttribute("ind1", ""); datafield.setAttribute("ind2", ""); Element subfield = new Element("subfield", MARC); subfield.setAttribute("code", "a"); subfield.setText(otherPpn); datafield.addContent(subfield); data.add(datafield); } if (otherEpn != null && !foundMultipleEpns) { Element datafield = new Element("datafield", MARC); datafield.setAttribute("tag", "epnDigital"); datafield.setAttribute("ind1", ""); datafield.setAttribute("ind2", ""); Element subfield = new Element("subfield", MARC); subfield.setAttribute("code", "a"); subfield.setText(otherEpn); datafield.addContent(subfield); data.add(datafield); } } } org.w3c.dom.Element marcRecord = getRecord(answer, data, opac); if (isMultiVolume) { // get anchor record String anchorResult = SRUHelper.search(catalogue, schema, "pica.ppn", anchorPpn, packing, version); Document anchorDoc = new SAXBuilder().build(new StringReader(anchorResult), "utf-8"); Element anchorRecord = getRecordWithoutSruHeader(anchorDoc); if (anchorRecord != null) { List<Element> anchorData = anchorRecord.getChildren(); // get EPN/PPN digital for anchor String otherAnchorResult = SRUHelper.search(catalogue, schema, isPeriodical ? "pica.zdb" : "pica.ppn", otherAnchorPpn, packing, version); Document otherAnchorDoc = new SAXBuilder().build(new StringReader(otherAnchorResult), "utf-8"); Element otherAnchorRecord = getRecordWithoutSruHeader(otherAnchorDoc); if (otherAnchorRecord == null) { Helper.setFehlerMeldung("import_OtherEPNNotFound"); } else { List<Element> controlList = otherAnchorRecord.getChildren("controlfield", MARC); for (Element field : controlList) { if (field.getAttributeValue("tag").equals("001")) { otherAnchorPpn = field.getText(); } } List<Element> fieldList = otherAnchorRecord.getChildren("datafield", MARC); for (Element field : fieldList) { if (field.getAttributeValue("tag").equals("954")) { List<Element> subfields = field.getChildren(); for (Element sub : subfields) { String code = sub.getAttributeValue("code"); if (code.equals("b")) { if (otherAnchorEpn == null) { otherAnchorEpn = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); ; } else { foundMultipleEpns = true; } } } } } if (otherAnchorPpn != null) { Element datafield = new Element("datafield", MARC); datafield.setAttribute("tag", "ppnDigital"); datafield.setAttribute("ind1", ""); datafield.setAttribute("ind2", ""); Element subfield = new Element("subfield", MARC); subfield.setAttribute("code", "a"); subfield.setText(otherAnchorPpn); datafield.addContent(subfield); anchorData.add(datafield); } if (otherAnchorEpn != null && !foundMultipleEpns) { Element datafield = new Element("datafield", MARC); datafield.setAttribute("tag", "epnDigital"); datafield.setAttribute("ind1", ""); datafield.setAttribute("ind2", ""); Element subfield = new Element("subfield", MARC); subfield.setAttribute("code", "a"); subfield.setText(otherAnchorEpn); datafield.addContent(subfield); anchorData.add(datafield); } } org.w3c.dom.Element anchorMarcRecord = getRecord(answer, anchorData, opac); collection.appendChild(anchorMarcRecord); } } if (foundMultipleEpns) { Helper.setFehlerMeldung("import_foundMultipleEPNs"); } collection.appendChild(marcRecord); return answer.getDocumentElement(); }
From source file:de.intranda.goobi.plugins.sru.SRUHelper.java
License:Open Source License
public static Node parseGbvResult(GbvMarcSruImport opac, String catalogue, String schema, String searchField, String resultString, String packing, String version) throws IOException, JDOMException, ParserConfigurationException { // removed validation against external dtd SAXBuilder builder = new SAXBuilder(XMLReaders.NONVALIDATING); builder.setFeature("http://xml.org/sax/features/validation", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); Document doc = builder.build(new StringReader(resultString), "utf-8"); // srw:searchRetrieveResponse Element record = getRecordWithoutSruHeader(doc); if (record == null) { opac.setHitcount(0);/* w ww . j a va2 s . c om*/ return null; } else { opac.setHitcount(1); // generate an answer document DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = dbfac.newDocumentBuilder(); org.w3c.dom.Document answer = docBuilder.newDocument(); org.w3c.dom.Element collection = answer.createElement("collection"); answer.appendChild(collection); boolean isMultiVolume = false; boolean isPeriodical = false; boolean isManuscript = false; boolean isCartographic = false; String anchorIdentifier = ""; List<Element> data = record.getChildren(); for (Element el : data) { if (el.getName().equalsIgnoreCase("leader")) { String value = el.getText(); if (value.length() < 24) { value = "00000" + value; } char c6 = value.toCharArray()[6]; char c7 = value.toCharArray()[7]; char c19 = value.toCharArray()[19]; if (c6 == 'a' && (c7 == 's' || c7 == 'd')) { isPeriodical = true; } else if (c6 == 't') { isManuscript = true; } else if (c6 == 'e') { isCartographic = true; } if (c19 == 'b' || c19 == 'c') { isMultiVolume = true; } } if (el.getName().equalsIgnoreCase("datafield")) { String tag = el.getAttributeValue("tag"); List<Element> subfields = el.getChildren(); for (Element sub : subfields) { String code = sub.getAttributeValue("code"); // anchor identifier if (tag.equals("773") && code.equals("w")) { if (!isMultiVolume && !isPeriodical) { sub.setText(""); } else { anchorIdentifier = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } } else if (tag.equals("800") && code.equals("w") && isMultiVolume) { anchorIdentifier = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else if (isManuscript && tag.equals("810") && code.equals("w")) { isMultiVolume = true; anchorIdentifier = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } else if (tag.equals("830") && code.equals("w")) { if (isCartographic || (isMultiVolume && anchorIdentifier == null)) { anchorIdentifier = sub.getText().replaceAll("\\(.+\\)", "").replace("KXP", ""); } } } } } org.w3c.dom.Element marcRecord = getRecord(answer, data, opac); if (isMultiVolume) { String anchorResult = SRUHelper.search(catalogue, schema, searchField, anchorIdentifier, packing, version); Document anchorDoc = new SAXBuilder().build(new StringReader(anchorResult), "utf-8"); Element anchorRecord = getRecordWithoutSruHeader(anchorDoc); if (anchorRecord != null) { List<Element> anchorData = anchorRecord.getChildren(); org.w3c.dom.Element anchorMarcRecord = getRecord(answer, anchorData, opac); collection.appendChild(anchorMarcRecord); } } collection.appendChild(marcRecord); return answer.getDocumentElement(); } }
From source file:de.knewcleus.openradar.gui.flightplan.FpXml_1_0.java
License:Open Source License
public static Element createXml(FlightPlanData fp) { /*/* ww w . ja v a 2 s.c o m*/ * <header> <flight>unique number of flightplan</flight> <callsign>callsign of aiplane</callsign> * <owner>callsign of owning ATC</owner> <handover>optional callsign of next ATC</handover> * <squawk>assignedSquawk</squawk> <assignedAlt>XML decimal</assignedAlt> * <status>filed,active,closed,expired</status> </header> <data> <type>VFR/IFR</type> <aircraft>ICAO of * aircraft</aircraft> <trueAirspeed>travel air speed of aircraft</trueAirspeed> <departure>departure * airport</departure> <departureTime>XML date+time</departureTime> <cruisingAlt>XML decimal</cruisingAlt> * <route>comma separated list of navaid codes</route> <destination>destination airport</destination> * <alternateDest>comma separated alternative destination airports</alternateDest> * <estFlightTime>hours:minutes</estFlightTime> <fuelTime>hours:minutes</fuelTime> <pilot>Name of Pilot</pilot> * <sob>number of souls on board</sob> <remarks></remarks> </data> */ GuiRadarContact contact = fp.getContact(); Element eFlightPlan = new Element("flightplan"); try { eFlightPlan.setAttribute("version", "1.0"); // header Element eFpHeader = new Element("header"); eFlightPlan.addContent(eFpHeader); Element eFlight = new Element("flight"); if (fp.getFlightCode() != null) { eFlight.setText(fp.getFlightCode()); } eFpHeader.addContent(eFlight); Element eCallsign = new Element("callsign"); if (fp.getCallsign() != null) { eCallsign.setText(fp.getCallsign()); } eFpHeader.addContent(eCallsign); Element eOwner = new Element("owner"); if (fp.getOwner() != null) { eOwner.setText(fp.getOwner()); } eFpHeader.addContent(eOwner); Element eHandover = new Element("handover"); if (fp.getHandover() != null) { eHandover.setText(fp.getHandover()); } eFpHeader.addContent(eHandover); Element eSquawk = new Element("squawk"); if (fp.getSquawk() != null) { eSquawk.setText(fp.getSquawk()); } eFpHeader.addContent(eSquawk); Element eAssignedRunway = new Element("assignedRunway"); if (fp.getAssignedRunway() != null) { eAssignedRunway.setText(fp.getAssignedRunway()); } eFpHeader.addContent(eAssignedRunway); Element eAssignedAlt = new Element("assignedAlt"); if (fp.getAssignedAltitude() != null) { eAssignedAlt.setText(fp.getAssignedAltitude()); } eFpHeader.addContent(eAssignedAlt); Element eAssignedRoute = new Element("assignedRoute"); if (fp.getAssignedRoute() != null) { eAssignedRoute.setText(fp.getAssignedRoute()); } eFpHeader.addContent(eAssignedRoute); Element eState = new Element("status"); if (fp.getFpStatus() != null) { eState.setText(fp.getFpStatus().toString()); } eFpHeader.addContent(eState); Element eFgCom = new Element("fgcom"); eFgCom.setText(contact.hasFgComSupport() ? "true" : "false"); eFpHeader.addContent(eFgCom); Element eFlags = new Element("flags"); if (fp.getFlags() != null) { eFlags.setText(fp.getFlags()); } eFpHeader.addContent(eFlags); // data Element eFpData = new Element("data"); eFlightPlan.addContent(eFpData); Element eType = new Element("type"); if (fp.getType() != null) { eType.setText(fp.getType()); } eFpData.addContent(eType); Element eAircraft = new Element("aircraft"); if (fp.getAircraft() != null) { eAircraft.setText(fp.getAircraft()); } eFpData.addContent(eAircraft); Element eTrueAirspeed = new Element("trueAirspeed"); if (fp.getTrueAirspeed() != null) { eTrueAirspeed.setText(fp.getTrueAirspeed()); } eFpData.addContent(eTrueAirspeed); Element eDeparture = new Element("departure"); if (fp.getDepartureAirport() != null) { eDeparture.setText(fp.getDepartureAirport()); } eFpData.addContent(eDeparture); Element eDepartureTime = new Element("departureTime"); if (fp.getDeparture() != null) { eDepartureTime.setText(fp.getDeparture()); } eFpData.addContent(eDepartureTime); Element eCruisingAlt = new Element("cruisingAlt"); if (fp.getCruisingAltitude() != null) { eCruisingAlt.setText(fp.getCruisingAltitude()); } eFpData.addContent(eCruisingAlt); Element eRoute = new Element("route"); if (fp.getRoute() != null) { eRoute.setText(fp.getRoute()); } eFpData.addContent(eRoute); Element eDestination = new Element("destination"); if (fp.getDestinationAirport() != null) { eDestination.setText(fp.getDestinationAirport()); } eFpData.addContent(eDestination); Element eAlternateDest = new Element("alternateDest"); if (fp.getAlternativeDestinationAirports() != null) { eAlternateDest.setText(fp.getAlternativeDestinationAirports()); } eFpData.addContent(eAlternateDest); Element eEstFlightTime = new Element("estFlightTime"); if (fp.getEstimatedFlightTime() != null) { eEstFlightTime.setText(fp.getEstimatedFlightTime()); } eFpData.addContent(eEstFlightTime); Element eFuelTime = new Element("fuelTime"); if (fp.getEstimatedFuelTime() != null) { eFuelTime.setText(fp.getEstimatedFuelTime()); } eFpData.addContent(eFuelTime); Element ePilot = new Element("pilot"); if (fp.getPilotName() != null) { ePilot.setText(fp.getPilotName()); } eFpData.addContent(ePilot); Element eSoulsOnBoard = new Element("soulsOnBoard"); eSoulsOnBoard.setText("" + fp.getSoulsOnBoard()); eFpData.addContent(eSoulsOnBoard); Element eRemarks = new Element("remarks"); if (fp.getRemarks() != null) { eRemarks.setText(fp.getRemarks()); } eFpData.addContent(eRemarks); } catch (Exception e) { log.error("Problem to create XML for flightplan " + fp.getFlightCode(), e); eFlightPlan = null; } return eFlightPlan; }
From source file:de.relaunch64.popelganda.database.CustomScripts.java
License:Open Source License
/** * Adds a new script.//from w ww . j a va2s. co m * * @param name the name of the new script * @param content the content of the new script * @return {@code true} if script was successfully added. */ public boolean addScript(String name, String content) { // check for valid values if (null == name || name.isEmpty() || null == content || content.isEmpty()) return false; // check if element exists int pos = findScript(name); // script already exists, so update if (pos != -1) { // retrieve element Element el = retrieveElement(pos); // change content if (el != null) { el.setText(content); } else { return false; } } // script does not exist, so add else { // create new element Element el = new Element(ELEMENT_SCRIPT); // add attribute el.setAttribute(ATTR_NAME, name); // add content el.setText(content); // add to document scriptFile.getRootElement().addContent(el); } return true; }
From source file:de.relaunch64.popelganda.database.Settings.java
License:Open Source License
/** * This method creates all the settings-child-elements, but only, if they don't * already exist. We do this because when loading older settings-xml-document-structures, * we might have new elements that would not be initialised. but now we can call this * method after loading the xml-document, and create elements and default values for all * new elements. This ensures compatibility to older/news settings-file-versions. *//*from w ww. ja va2s.c o m*/ private void fillElements() { root = settingsFile.getRootElement(); for (int cnt = 0; cnt < recentDocCount; cnt++) { // create field-identifier String fi = SETTING_RECENT_DOC + String.valueOf(cnt + 1); // retrieve content if (null == root.getChild(fi)) { // create a filepath-element Element el = new Element(fi); el.setText(""); // and add it to the document root.addContent(el); } } if (null == root.getChild(SETTING_REOPEN_FILES)) { // create element for font Element el = new Element(SETTING_REOPEN_FILES); root.addContent(el); } if (null == root.getChild(SETTING_MAINFONT)) { // create element for font Element el = new Element(SETTING_MAINFONT); root.addContent(el); el.setText(Font.MONOSPACED); el.setAttribute("size", "12"); } if (null == root.getChild(SETTING_LAST_USED_PATH)) { // create element Element el = new Element(SETTING_LAST_USED_PATH); el.setText(""); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_ANTIALIAS)) { // create element Element el = new Element(SETTING_ANTIALIAS); el.setText(AntiAlias.SUBPIXEL); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_SIDEBAR_ISHIDDEN)) { // create element Element el = new Element(SETTING_SIDEBAR_ISHIDDEN); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_USE_NOTABS)) { // create element Element el = new Element(SETTING_USE_NOTABS); el.setText("0"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_FINDBYTYPE)) { // create element Element el = new Element(SETTING_FINDBYTYPE); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_WAITFORPROCESS)) { // create element Element el = new Element(SETTING_WAITFORPROCESS); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_CODE_FOLDING)) { // create element Element el = new Element(SETTING_CODE_FOLDING); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_CF_BRACES)) { // create element Element el = new Element(SETTING_CF_BRACES); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_CF_DIRECTIVES)) { // create element Element el = new Element(SETTING_CF_DIRECTIVES); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_CF_LABELS)) { // create element Element el = new Element(SETTING_CF_LABELS); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_CF_MANUAL)) { // create element Element el = new Element(SETTING_CF_MANUAL); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_CF_STRUCTS)) { // create element Element el = new Element(SETTING_CF_STRUCTS); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_CF_SECTIONS)) { // create element Element el = new Element(SETTING_CF_SECTIONS); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_SCALE_FONT)) { // create element Element el = new Element(SETTING_SCALE_FONT); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_CHECKUPDATES)) { // create element Element el = new Element(SETTING_CHECKUPDATES); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_FINDFIELDFOCUS)) { // create element Element el = new Element(SETTING_FINDFIELDFOCUS); el.setText("0"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_ALT_ASM_MODE)) { // create element Element el = new Element(SETTING_ALT_ASM_MODE); el.setText("0"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_SHOW_LINEHIGLIGHT)) { // create element Element el = new Element(SETTING_SHOW_LINEHIGLIGHT); el.setText("0"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_SHOW_BUFFERSIZE)) { // create element Element el = new Element(SETTING_SHOW_BUFFERSIZE); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_SHOW_EXT_IN_TAB)) { // create element Element el = new Element(SETTING_SHOW_EXT_IN_TAB); el.setText("0"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_SHOW_CLOSEBUTTON)) { // create element Element el = new Element(SETTING_SHOW_CLOSEBUTTON); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_SHOW_TOOLBAR)) { // create element Element el = new Element(SETTING_SHOW_TOOLBAR); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_SHOW_TOOLBARTEXT)) { // create element Element el = new Element(SETTING_SHOW_TOOLBARTEXT); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_SUGGEST_SORT_CASE)) { // create element Element el = new Element(SETTING_SUGGEST_SORT_CASE); el.setText("0"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_REOPEN_FILES_ON_STARTUP)) { // create element Element el = new Element(SETTING_REOPEN_FILES_ON_STARTUP); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_SAVEONCOMPILE)) { // create element Element el = new Element(SETTING_SAVEONCOMPILE); el.setText("1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_NIMBUS_ON_OSX)) { // create element Element el = new Element(SETTING_NIMBUS_ON_OSX); el.setText("0"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_USE_SCROLL_TABS)) { // create element Element el = new Element(SETTING_USE_SCROLL_TABS); el.setText("0"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_PREF_ASM)) { // create element Element el = new Element(SETTING_PREF_ASM); el.setText(String.valueOf(Assemblers.ASM_KICKASSEMBLER.getID())); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_SIDEBAR_SORT)) { // create element Element el = new Element(SETTING_SIDEBAR_SORT); el.setText(String.valueOf(SORT_CASE)); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_SYNTAX_SCHEME)) { // create element Element el = new Element(SETTING_SYNTAX_SCHEME); el.setText(String.valueOf(ColorSchemes.SCHEME_DEFAULT)); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_LAST_SCRIPT)) { // create element Element el = new Element(SETTING_LAST_SCRIPT); el.setText("0"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_LOGSPLITLAYOUT)) { // create a filepath-element Element el = new Element(SETTING_LOGSPLITLAYOUT); el.setText(String.valueOf(JSplitPane.HORIZONTAL_SPLIT)); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_TABWIDTH)) { // create a filepath-element Element el = new Element(SETTING_TABWIDTH); el.setText("4"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_LISTGOTOINDEX)) { // create a filepath-element Element el = new Element(SETTING_LISTGOTOINDEX); el.setText("-1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_DIVIDER_LOCATION)) { // create a filepath-element Element el = new Element(SETTING_DIVIDER_LOCATION); el.setText("-1"); // and add it to the document root.addContent(el); } if (null == root.getChild(SETTING_LINE_NUMBER_ALIGNMENT)) { // create a filepath-element Element el = new Element(SETTING_LINE_NUMBER_ALIGNMENT); el.setText(String.valueOf(Gutter.RIGHT)); // and add it to the document root.addContent(el); } }