Java Code Examples for org.jdom.Element#addContent()

The following examples show how to use org.jdom.Element#addContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsoleHistoryController.java    From consulo with Apache License 2.0 6 votes vote down vote up
private Element saveHistoryElement() {
  Element rootElement = new Element("console-history");
  rootElement.setAttribute("version", "1");
  rootElement.setAttribute("id", myId);
  for (String s : getModel().getEntries()) {
    Element historyEntryElement = new Element("history-element");
    historyEntryElement.setText(s);
    rootElement.addContent(historyEntryElement);
  }

  String current = myContent;
  if (StringUtil.isNotEmpty(current)) {
    rootElement.addContent(new Element("console-content").setText(current));
  }
  return rootElement;
}
 
Example 2
Source File: PathMacrosCollectorTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testCollectMacros() {
  Element root = new Element("root");
  root.addContent(new Text("$MACro1$ some text $macro2$ other text $MACRo3$"));
  root.addContent(new Text("$macro4$ some text"));
  root.addContent(new Text("some text$macro5$"));
  root.addContent(new Text("file:$mac_ro6$"));
  root.addContent(new Text("jar://$macr.o7$ "));
  root.addContent(new Text("$mac-ro8$ "));
  root.addContent(new Text("$$$ "));
  root.addContent(new Text("$c:\\a\\b\\c$ "));
  root.addContent(new Text("$Revision 1.23$"));

  final Set<String> macros = PathMacrosService.getInstance().getMacroNames(root, null, new PathMacrosImpl());

  assertEquals(5, macros.size());
  assertTrue(macros.contains("MACro1"));
  assertTrue(macros.contains("macro4"));
  assertTrue(macros.contains("mac_ro6"));
  assertTrue(macros.contains("macr.o7"));
  assertTrue(macros.contains("mac-ro8"));
}
 
Example 3
Source File: OldLanguageFactory.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private static Element getRegistersElement(Language lang) {

		Register[] registers = lang.getRegisters();
		Register contextReg = lang.getContextBaseRegister();
		Element registersElement = new Element("registers");
		if (contextReg != null) {
			Element ctxElement = getRegisterElement(contextReg);
			int contextBitLength = contextReg.getBitLength();
			for (Register bitReg : contextReg.getChildRegisters()) {
				Element fieldElement = new Element("field");
				fieldElement.setAttribute("name", bitReg.getName());
				int fieldBitLength = bitReg.getBitLength();
				int lsb = bitReg.getLeastSignificatBitInBaseRegister();
				int msb = lsb + fieldBitLength - 1;

				// Transpose bit numbering to agree with Sleigh context bit numbering
				lsb = contextBitLength - msb - 1;
				msb = lsb + fieldBitLength - 1;

				fieldElement.setAttribute("range", lsb + "," + msb);
				ctxElement.addContent(fieldElement);
			}
			registersElement.addContent(ctxElement);
		}
		for (Register reg : registers) {
			if (!reg.getBaseRegister().isProcessorContext()) {
				Element regElement = getRegisterElement(reg);
				registersElement.addContent(regElement);
			}
		}
		return registersElement;
	}
 
Example 4
Source File: JDOMExternalizer.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Saves a pack of strings to some attribute. I.e: [tag attr="value"]
 * @param parent parent element (where to add newly created tags)
 * @param nodeName node name (tag, in our example)
 * @param attrName attribute name (attr, in our example)
 * @param values a pack of values to add
 * @see #loadStringsList(org.jdom.Element, String, String)
 */
public static void saveStringsList(@Nonnull final Element parent,
                                   @Nonnull final String nodeName,
                                   @Nonnull final String attrName,
                                   @Nonnull final String... values) {
  for (final String value : values) {
    final Element node = new Element(nodeName);
    node.setAttribute(attrName, value);
    parent.addContent(node);
  }
}
 
Example 5
Source File: AntigenicPlotter.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Element generateTraceElement(String[] labels, double[][][] points, int[] order) {
    Element traceElement = new Element("Folder");
    Element nameElement = new Element("name");
    String name = "points";

    nameElement.addContent(name);
    traceElement.addContent(nameElement);

    for (int i = 0; i < points.length; i++)  {
        for (int j = 0; j < points[i].length; j++)  {
            Element placemarkElement = new Element("Placemark");

            placemarkElement.addContent(generateTraceData(labels[order[j]], j, i));


            Element pointElement = new Element("Point");
            Element coordinates = new Element("coordinates");
            coordinates.addContent(points[i][order[j]][1]+","+points[i][order[j]][0]+",0");
            pointElement.addContent(coordinates);
            placemarkElement.addContent(pointElement);

            traceElement.addContent(placemarkElement);

        }

    }
    return traceElement;
}
 
Example 6
Source File: RecordElement.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public RecordElement asExporter(XChangeExporter c, Konsultation k){
	asExporter(c);
	
	setAttribute(ATTR_DATE, new TimeTool(k.getDatum()).toString(TimeTool.DATE_ISO));
	Kontakt kMandant = k.getMandant();
	if (kMandant == null) {
		setAttribute(ATTR_RESPONSIBLE, "unknown");
	} else {
		ContactElement cMandant = c.addContact(kMandant);
		setAttribute(ATTR_RESPONSIBLE, cMandant.getID());
	}
	setAttribute(ATTR_ID, XMLTool.idToXMLID(k.getId()));
	c.getContainer().addChoice(this, k.getLabel(), k);
	VersionedResource vr = k.getEintrag();
	ResourceItem entry = vr.getVersion(vr.getHeadVersion());
	if (entry != null) {
		setAttribute(ATTR_AUTHOR, entry.remark);
		
		Samdas samdas = new Samdas(k.getEintrag().getHead());
		Record record = samdas.getRecord();
		if (record != null) {
			String st = record.getText();
			if (st != null) {
				Element eText = new Element(ELEMENT_TEXT, getContainer().getNamespace());
				eText.addContent(XMLTool.getValidXMLString(st));
				getElement().addContent(eText);
				List<XRef> xrefs = record.getXrefs();
				for (XRef xref : xrefs) {
					MarkupElement me = new MarkupElement().asExporter(c, xref);
					add(me);
				}
			}
		}
	}
	c.getContainer().addMapping(this, k);
	return this;
}
 
Example 7
Source File: PersistentFileSetManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Element getState() {
  final Element root = new Element("root");
  for (VirtualFile vf : getSortedFiles()) {
    final Element vfElement = new Element(FILE_ELEMENT);
    final Attribute filePathAttr = new Attribute(PATH_ATTR, VfsUtilCore.pathToUrl(vf.getPath()));
    vfElement.setAttribute(filePathAttr);
    root.addContent(vfElement);
  }
  return root;
}
 
Example 8
Source File: AntigenicPlotter.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
private Element generateContourData(String label, int point, double hpd) {
        Element data = new Element("ExtendedData");
        Element schemaData = new Element("SchemaData");
        schemaData.setAttribute("schemaUrl", "HPD_Schema");
        schemaData.addContent(new Element("SimpleData").setAttribute("name", "Label").addContent(label));
//        Label l = new Label(label);
//        schemaData.addContent(new Element("SimpleData").setAttribute("name", "Year").addContent(Integer.toString(l.year)));
        schemaData.addContent(new Element("SimpleData").setAttribute("name", "Point").addContent(Integer.toString(point)));
        if (hpd > 0) {
            schemaData.addContent(new Element("SimpleData").setAttribute("name", "HPD").addContent(Double.toString(hpd)));
        }
        data.addContent(schemaData);
        return data;
    }
 
Example 9
Source File: MessageNotifierConfigDOM.java    From entando-components with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create an xml containing the notifier configuration.
 * @param config The jpmail configuration.
 * @return The xml containing the configuration.
 * @throws ApsSystemException In case of errors.
 */
public String createConfigXml(Map<String, MessageTypeNotifierConfig> config) throws ApsSystemException {
	Element root = new Element(ROOT);
	for (MessageTypeNotifierConfig messageTypeConfig : config.values()) {
		Element configElement = this.createConfigElement(messageTypeConfig);
		root.addContent(configElement);
	}
	Document doc = new Document(root);
	String xml = new XMLOutputter().outputString(doc);
	return xml;
}
 
Example 10
Source File: LibraryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void writeExternal(Element rootElement) {
  checkDisposed();

  Element element = new Element(ELEMENT);
  if (myName != null) {
    element.setAttribute(LIBRARY_NAME_ATTR, myName);
  }
  if (myKind != null) {
    element.setAttribute(LIBRARY_TYPE_ATTR, myKind.getKindId());
    LOG.assertTrue(myProperties != null, "Properties is 'null' in library with kind " + myKind);
    final Object state = myProperties.getState();
    if (state != null) {
      final Element propertiesElement = XmlSerializer.serialize(state);
      if (propertiesElement != null) {
        element.addContent(propertiesElement.setName(PROPERTIES_ELEMENT));
      }
    }
  }
  for (OrderRootType rootType : OrderRootType.getSortedRootTypes()) {
    VirtualFilePointerContainer roots = myRoots.get(rootType);
    if (roots == null || roots.isEmpty()) {
      continue;
    }

    final Element rootTypeElement = new Element(rootType.name());
    if (roots != null) {
      roots.writeExternal(rootTypeElement, ROOT_PATH_ELEMENT, false);
    }
    element.addContent(rootTypeElement);
  }
  if (myExcludedRoots != null && !myExcludedRoots.isEmpty()) {
    Element excluded = new Element(EXCLUDED_ROOTS_TAG);
    myExcludedRoots.writeExternal(excluded, ROOT_PATH_ELEMENT, false);
    element.addContent(excluded);
  }
  writeJarDirectories(element);
  rootElement.addContent(element);
}
 
Example 11
Source File: DuplocatorHashCallback.java    From consulo with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"HardCodedStringLiteral"})
private static void writeFragments(final List<? extends PsiFragment> psiFragments, Element duplicateElement, Project project, final boolean shouldWriteOffsets) {
  final PathMacroManager macroManager = PathMacroManager.getInstance(project);
  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);

  for (PsiFragment fragment : psiFragments) {
    final PsiFile psiFile = fragment.getFile();
    final VirtualFile virtualFile = psiFile != null ? psiFile.getVirtualFile() : null;
    if (virtualFile != null) {
      Element fragmentElement = new Element("fragment");
      fragmentElement.setAttribute("file", macroManager.collapsePath(virtualFile.getUrl()));
      if (shouldWriteOffsets) {
        final Document document = documentManager.getDocument(psiFile);
        LOG.assertTrue(document != null);
        int startOffset = fragment.getStartOffset();
        final int line = document.getLineNumber(startOffset);
        fragmentElement.setAttribute("line", String.valueOf(line));
        final int lineStartOffset = document.getLineStartOffset(line);
        if (StringUtil.isEmptyOrSpaces(document.getText().substring(lineStartOffset, startOffset))) {
          startOffset = lineStartOffset;
        }
        fragmentElement.setAttribute("start", String.valueOf(startOffset));
        fragmentElement.setAttribute("end", String.valueOf(fragment.getEndOffset()));
        if (fragment.containsMultipleFragments()) {
          final int[][] offsets = fragment.getOffsets();
          for (int[] offset : offsets) {
            Element offsetElement = new Element("offset");
            offsetElement.setAttribute("start", String.valueOf(offset[0]));
            offsetElement.setAttribute("end", String.valueOf(offset[1]));
            fragmentElement.addContent(offsetElement);
          }
        }
      }
      duplicateElement.addContent(fragmentElement);
    }
  }
}
 
Example 12
Source File: ChangelistConflictTracker.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void saveState(Element to) {
  for (Map.Entry<String,Conflict> entry : myConflicts.entrySet()) {
    Element fileElement = new Element("file");
    fileElement.setAttribute("path", entry.getKey());
    fileElement.setAttribute("ignored", Boolean.toString(entry.getValue().ignored));
    to.addContent(fileElement);
  }
  XmlSerializer.serializeInto(myOptions, to);
}
 
Example 13
Source File: SaveStateTest.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Test
public void testXML() {
	Element elem1 = new Element("ELEM_1");
	Element elem2 = new Element("ELEM_2");
	elem1.setAttribute("NAME", "VALUE");
	elem1.addContent(elem2);
	ss.putXmlElement("XML", elem1);
	Element elem3 = ss.getXmlElement("XML");
	Element elem4 = (Element) elem3.getChildren().get(0);
	assertEquals(elem1, elem3);
	assertEquals(elem1.getName(), elem3.getName());
	assertEquals(elem2, elem4);
	assertEquals(elem2.getName(), elem4.getName());
}
 
Example 14
Source File: ExternalizablePropertyContainer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void writeValue(Element dataElement, List<T> value) {
  for (T item : value) {
    if (item == null) {
      dataElement.addContent(new Element(NULL_ELEMENT));
    }
    else {
      Element element = new Element(myItemTagName);
      myItemExternalizer.writeValue(element, item);
      dataElement.addContent(element);
    }
  }
}
 
Example 15
Source File: TravelAccountTypeExporter.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Override
public void export(Class<?> dataObjectClass, List<? extends Object> dataObjects, String exportFormat,
        OutputStream outputStream) throws IOException, ExportNotSupportedException {
    Document document = new Document(new Element("travelAccountTypes"));

    for (Object dataObject : dataObjects) {
        Element travelAccountTypeElement = new Element("travelAccountType");
        TravelAccountType travelAccountType = (TravelAccountType) dataObject;

        Element accountTypeCodeElement = new Element("accountTypeCode");
        accountTypeCodeElement.setText(travelAccountType.getAccountTypeCode());
        travelAccountTypeElement.addContent(accountTypeCodeElement);

        Element nameElement = new Element("name");
        nameElement.setText(travelAccountType.getName());
        travelAccountTypeElement.addContent(nameElement);

        Element activeElement = new Element("active");
        activeElement.setText(Boolean.toString(travelAccountType.isActive()));
        travelAccountTypeElement.addContent(activeElement);

        document.getRootElement().addContent(travelAccountTypeElement);
    }

    XMLOutputter outputer = new XMLOutputter(Format.getPrettyFormat());
    try {
        outputer.output(document, outputStream);
    } catch (IOException e) {
        throw new RuntimeException("Could not write XML data export.", e);
    }
}
 
Example 16
Source File: UnknownFeaturesCollector.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Element getState() {
  if (myIgnoredUnknownExtensions.isEmpty()) return null;

  final Element ignored = new Element("ignored");
  for (UnknownExtension feature : myIgnoredUnknownExtensions) {
    final Element option = new Element("option");
    option.setAttribute(FEATURE_ID, feature.getExtensionKey());
    option.setAttribute(IMPLEMENTATION_NAME, feature.getValue());
    ignored.addContent(option);
  }
  return ignored;
}
 
Example 17
Source File: PageExtraConfigDOM.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void fillDocument(Document doc, PageMetadata page) {
	Set<String> extraGroups = page.getExtraGroups();
	Element useExtraTitlesElement = new Element(USE_EXTRA_TITLES_ELEMENT_NAME);
	useExtraTitlesElement.setText(String.valueOf(page.isUseExtraTitles()));
	doc.getRootElement().addContent(useExtraTitlesElement);
	if (null != extraGroups && extraGroups.size() > 0) {
		Element extraGroupsElement = new Element(EXTRA_GROUPS_ELEMENT_NAME);
		doc.getRootElement().addContent(extraGroupsElement);
		Iterator<String> iterator = extraGroups.iterator();
		while (iterator.hasNext()) {
			String group = iterator.next();
			Element extraGroupElement = new Element(EXTRA_GROUP_ELEMENT_NAME);
			extraGroupElement.setAttribute(EXTRA_GROUP_NAME_ATTRIBUTE, group);
			extraGroupsElement.addContent(extraGroupElement);
		}
	}
	String charset = page.getCharset();
	if (null != charset && charset.trim().length() > 0) {
		Element charsetElement = new Element(CHARSET_ELEMENT_NAME);
		charsetElement.setText(charset);
		doc.getRootElement().addContent(charsetElement);
	}
	String mimeType = page.getMimeType();
	if (null != mimeType && mimeType.trim().length() > 0) {
		Element mimeTypeElement = new Element(MIMETYPE_ELEMENT_NAME);
		mimeTypeElement.setText(mimeType);
		doc.getRootElement().addContent(mimeTypeElement);
	}
}
 
Example 18
Source File: IndependentColorProvider.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void savePluginColors(SaveState saveState) {
	// store off global colors for vertices
	Element colorsElement = new Element(VERTEX_COLORS);
	for (Color color : recentColorCache) {
		Element element = new Element("COLOR");
		element.setAttribute("RGB", Integer.toString(color.getRGB()));
		colorsElement.addContent(element);
	}
	saveState.putXmlElement(VERTEX_COLORS, colorsElement);
}
 
Example 19
Source File: Interrogative.java    From nadia with Apache License 2.0 4 votes vote down vote up
protected void addRel(Element parent_node, String name, Element child_node){
	Element rel=new Element("rel");
	rel.setAttribute(new Attribute("name", name));
	rel.addContent(child_node);
	parent_node.addContent(rel);
}
 
Example 20
Source File: FieldRange.java    From ghidra with Apache License 2.0 4 votes vote down vote up
public Element getElement() {
	Element element = new Element("RANGE");
	element.addContent(start.getElement("START"));
	element.addContent(end.getElement("END"));
	return element;
}