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

The following examples show how to use org.jdom.Element#setAttribute() . 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: LafManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public Element getState() {
  Element element = new Element("state");
  if (myCurrentLaf != null) {
    String className = myCurrentLaf.getClassName();
    if (className != null) {
      Element child = new Element(ELEMENT_LAF);
      child.setAttribute(ATTRIBUTE_CLASS_NAME, className);
      element.addContent(child);
    }
  }

  if(!myLocalizeManager.isDefaultLocale()) {
    Element localeElement = new Element(ELEMENT_LOCALE);
    element.addContent(localeElement);

    localeElement.setText(myLocalizeManager.getLocale().toString());
  }
  return element;
}
 
Example 2
Source File: TextAttribute.java    From entando-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Add the elements, related to the texts inserted in the attribute, needed
 * in order to prepare the element to finally insert in the XML of the
 * entity.
 *
 * @param attributeElement The element to complete.
 */
protected void addTextElements(Element attributeElement) {
    if (null == this.getTextMap()) {
        return;
    }
    Iterator<String> langIter = this.getTextMap().keySet().iterator();
    while (langIter.hasNext()) {
        String currentLangCode = langIter.next();
        String text = this.getTextMap().get(currentLangCode);
        if (null != text && text.trim().length() > 0 && currentLangCode != null) {
            Element textElement = new Element("text");
            textElement.setAttribute("lang", currentLangCode);
            textElement.setText(text.trim());
            attributeElement.addContent(textElement);
        }
    }
}
 
Example 3
Source File: AbbreviationManagerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public Element getState() {
  final Element actions = new Element("actions");
  final Element abbreviations = new Element("abbreviations");
  actions.addContent(abbreviations);
  for (String key : myActionId2Abbreviations.keySet()) {
    final LinkedHashSet<String> abbrs = myActionId2Abbreviations.get(key);
    final LinkedHashSet<String> pluginAbbrs = myPluginsActionId2Abbreviations.get(key);
    if (abbrs == pluginAbbrs || (abbrs != null && abbrs.equals(pluginAbbrs))) {
      continue;
    }
    if (abbrs != null) {
      final Element action = new Element("action");
      action.setAttribute("id", key);
      abbreviations.addContent(action);
      for (String abbr : abbrs) {
        final Element abbreviation = new Element("abbreviation");
        abbreviation.setAttribute("name", abbr);
        action.addContent(abbreviation);
      }
    }
  }

  return actions;
}
 
Example 4
Source File: StateSplitterEx.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected static void mergeStateInto(@Nonnull Element target, @Nonnull Element subState, @Nonnull String subStateName) {
  if (subState.getName().equals(subStateName)) {
    target.addContent(subState);
  }
  else {
    for (Iterator<Element> iterator = subState.getChildren().iterator(); iterator.hasNext(); ) {
      Element configuration = iterator.next();
      iterator.remove();
      target.addContent(configuration);
    }
    for (Iterator<Attribute> iterator = subState.getAttributes().iterator(); iterator.hasNext(); ) {
      Attribute attribute = iterator.next();
      iterator.remove();
      target.setAttribute(attribute);
    }
  }
}
 
Example 5
Source File: TodoAttributes.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void writeExternal(Element element) throws WriteExternalException {
  String icon;
  if (myIcon == AllIcons.General.TodoDefault) {
    icon = ICON_DEFAULT;
  }
  else if (myIcon == AllIcons.General.TodoQuestion) {
    icon = ICON_QUESTION;
  }
  else if (myIcon == AllIcons.General.TodoImportant) {
    icon = ICON_IMPORTANT;
  }
  else {
    throw new WriteExternalException("");
  }
  element.setAttribute(ATTRIBUTE_ICON, icon);
  myTextAttributes.writeExternal(element);

  // default color setting
  element.setAttribute(USE_CUSTOM_COLORS_ATT, Boolean.toString(shouldUseCustomTodoColor()));
}
 
Example 6
Source File: StepConfigsDOM.java    From entando-components with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Element createStepElement(Step step) throws ApsSystemException {
	Element element = new Element(STEP_ELEM);
	try {
		//element.setAttribute(STEP_ORDER_ATTR, String.valueOf(step.getOrder()));
		//element.setAttribute(STEP_TYPE_ATTR, step.getType().toString());
		element.setAttribute(STEP_CODE_ATTR, step.getCode());
		element.setAttribute(STEP_BUILT_GUI, String.valueOf(step.isBuiltGui()));
		if(StringUtils.isNotBlank(step.getOgnlExpression())){
			element.setAttribute(STEP_OGNL_EXPRESSION_ATTR, step.getOgnlExpression());
		}
		List<String> attributes = step.getAttributeOrder();
		for (int i = 0; i < attributes.size(); i++) {
			String name = attributes.get(i);
			Step.AttributeConfig attributeConfig = step.getAttributeConfigs().get(name);
			Element attributeConfigElement = new Element(ATTRIBUTE_ELEM);
			attributeConfigElement.setAttribute(ATTRIBUTE_NAME_ATTR, attributeConfig.getName());
			attributeConfigElement.setAttribute(ATTRIBUTE_VIEW_ATTR, String.valueOf(attributeConfig.isView()));
			element.addContent(attributeConfigElement);
		}
	} catch (Throwable t) {
		_logger.error("Error creating steb element", t);
		throw new ApsSystemException("Error creating step element", t);
	}
	return element;
}
 
Example 7
Source File: PathMacrosCollectorTest.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void testWithRecursiveFilter() throws Exception {
  Element root = new Element("root");
  final Element configuration = new Element("configuration");
  configuration.setAttribute("value", "some text$macro5$fdsjfhdskjfsd$MACRO$");
  root.addContent(configuration);

  final Set<String> macros = PathMacrosCollectorImpl.getMacroNames(root, new PathMacroFilter() {
                                                                  @Override
                                                                  public boolean recursePathMacros(Attribute attribute) {
                                                                    return "value".equals(attribute.getName());
                                                                  }
                                                                }, new PathMacrosImpl());

  assertEquals(2, macros.size());
  assertTrue(macros.contains("macro5"));
  assertTrue(macros.contains("MACRO"));
}
 
Example 8
Source File: ProjectLevelVcsManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
void writeDirectoryMappings(@Nonnull Element element) {
  if (myProject.isDefault()) {
    element.setAttribute(ATTRIBUTE_DEFAULT_PROJECT, Boolean.TRUE.toString());
  }
  for (VcsDirectoryMapping mapping : getDirectoryMappings()) {
    VcsRootSettings rootSettings = mapping.getRootSettings();
    if (rootSettings == null && StringUtil.isEmpty(mapping.getDirectory()) && StringUtil.isEmpty(mapping.getVcs())) {
      continue;
    }

    Element child = new Element(ELEMENT_MAPPING);
    child.setAttribute(ATTRIBUTE_DIRECTORY, mapping.getDirectory());
    child.setAttribute(ATTRIBUTE_VCS, mapping.getVcs());
    if (rootSettings != null) {
      Element rootSettingsElement = new Element(ELEMENT_ROOT_SETTINGS);
      rootSettingsElement.setAttribute(ATTRIBUTE_CLASS, rootSettings.getClass().getName());
      try {
        rootSettings.writeExternal(rootSettingsElement);
        child.addContent(rootSettingsElement);
      }
      catch (WriteExternalException e) {
        // don't add element
      }
    }
    element.addContent(child);
  }
}
 
Example 9
Source File: SystemInstallationReport.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String toXml() {
    Document doc = new Document();
    Element rootElement = new Element(ROOT_ELEMENT);
    Status status = Status.OK;
    for (ComponentInstallationReport componentReport : this.getReports()) {
        if (!componentReport.getStatus().equals(Status.OK)
                && !componentReport.getStatus().equals(Status.UNINSTALLED)) {
            status = componentReport.getStatus();
            break;
        }
    }
    rootElement.setAttribute(STATUS_ATTRIBUTE, status.toString());

    Element creationElement = new Element(CREATION_ELEMENT);
    creationElement.setText(DateConverter.getFormattedDate(this.getCreation(), DATE_FORMAT));
    rootElement.addContent(creationElement);

    Element lastUpdateElement = new Element(LAST_UPDATE_ELEMENT);
    lastUpdateElement.setText(DateConverter.getFormattedDate(this.getLastUpdate(), DATE_FORMAT));
    rootElement.addContent(lastUpdateElement);

    Element componentsElement = new Element(COMPONENTS_ELEMENT);
    rootElement.addContent(componentsElement);
    for (int i = 0; i < this.getReports().size(); i++) {
        ComponentInstallationReport singleReport = this.getReports().get(i);
        Element componentElement = singleReport.toJdomElement();
        componentsElement.addContent(componentElement);
    }
    doc.setRootElement(rootElement);
    XMLOutputter out = new XMLOutputter();
    Format format = Format.getPrettyFormat();
    format.setIndent("\t");
    out.setFormat(format);
    return out.outputString(doc);
}
 
Example 10
Source File: DiffManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Element getState() {
  Element state = new Element("state");
  myProperties.writeExternal(state);
  if (myComparisonPolicy != ComparisonPolicy.DEFAULT) {
    state.setAttribute(COMPARISON_POLICY_ATTR_NAME, myComparisonPolicy.getName());
  }
  if (myHighlightMode != HighlightMode.BY_WORD) {
    state.setAttribute(HIGHLIGHT_MODE_ATTR_NAME, myHighlightMode.name());
  }
  return state;
}
 
Example 11
Source File: ModuleManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
public void getState0(Element element) {
  final Element modulesElement = new Element(ELEMENT_MODULES);
  final Module[] modules = getModules();

  for (Module module : modules) {
    Element moduleElement = new Element(ELEMENT_MODULE);
    String name = module.getName();
    final String[] moduleGroupPath = getModuleGroupPath(module);
    if (moduleGroupPath != null) {
      name = StringUtil.join(moduleGroupPath, MODULE_GROUP_SEPARATOR) + MODULE_GROUP_SEPARATOR + name;
    }
    moduleElement.setAttribute(ATTRIBUTE_NAME, name);
    String moduleDirUrl = module.getModuleDirUrl();
    if (moduleDirUrl != null) {
      moduleElement.setAttribute(ATTRIBUTE_DIRURL, moduleDirUrl);
    }

    final ModuleRootManagerImpl moduleRootManager = (ModuleRootManagerImpl)ModuleRootManager.getInstance(module);
    moduleRootManager.saveState(moduleElement);

    collapseOrExpandMacros(module, moduleElement, true);

    modulesElement.addContent(moduleElement);
  }

  for (ModuleLoadItem failedModulePath : new ArrayList<>(myFailedModulePaths)) {
    final Element clone = failedModulePath.getElement().clone();
    modulesElement.addContent(clone);
  }

  element.addContent(modulesElement);
}
 
Example 12
Source File: ContextRegisterInfo.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
 * Converts this object into XML
 * 
 * @return new jdom Element
 */
public Element toXml() {

	Element e = new Element(XML_ELEMENT_NAME);
	e.setAttribute("contextRegister", contextRegister);
	if (value != null) {
		e.setAttribute("value", value.toString());
	}

	return e;
}
 
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: BookmarkManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void writeExternal(Element element) {
  List<Bookmark> reversed = new ArrayList<Bookmark>(myBookmarks);
  Collections.reverse(reversed);

  for (Bookmark bookmark : reversed) {
    if (!bookmark.isValid()) continue;
    Element bookmarkElement = new Element("bookmark");

    bookmarkElement.setAttribute("url", bookmark.getFile().getUrl());

    String description = bookmark.getNotEmptyDescription();
    if (description != null) {
      bookmarkElement.setAttribute("description", description);
    }

    int line = bookmark.getLine();
    if (line >= 0) {
      bookmarkElement.setAttribute("line", String.valueOf(line));
    }

    char mnemonic = bookmark.getMnemonic();
    if (mnemonic != 0) {
      bookmarkElement.setAttribute("mnemonic", String.valueOf(mnemonic));
    }

    element.addContent(bookmarkElement);
  }
}
 
Example 15
Source File: ElementIO.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void addOption(@NotNull Element element, @NotNull String name, @Nullable String value) {
  if (value == null) return;

  final Element child = new Element("option");
  child.setAttribute("name", name);
  child.setAttribute("value", value);
  element.addContent(child);
}
 
Example 16
Source File: MantisService.java    From ezScrum with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void reopenStatusToAssigned(long issueID, String name,
		String bugNote, Date reopenDate) {
	IIssue issue = getIssue(issueID);
	int oldStatus = issue.getStatusValue();

	// String updateQuery = "UPDATE `mantis_bug_table` SET `status` = '"
	// + ITSEnum.ASSIGNED_STATUS + "', `resolution` = '"
	// + ITSEnum.OPEN_RESOLUTION
	// + "' WHERE `mantis_bug_table`.`id` =" + issueID;

	IQueryValueSet valueSet = new MySQLQuerySet();
	valueSet.addTableName("mantis_bug_table");
	valueSet.addInsertValue("summary", name);
	valueSet.addInsertValue("status",
			Integer.toString(ITSEnum.ASSIGNED_STATUS));
	valueSet.addInsertValue("resolution",
			Integer.toString(ITSEnum.OPEN_RESOLUTION));
	valueSet.addEqualCondition("id", Long.toString(issueID));
	String query = valueSet.getUpdateQuery();

	getControl().execute(query);
	// 新增歷史記錄,還有一個resolution的history,因為不是很重要,就暫時沒加入
	HistoryObject statusHistory = new HistoryObject(
			issue.getIssueID(), 
			issue.getIssueType(), 
			HistoryObject.TYPE_STATUS,
			String.valueOf(oldStatus),
			String.valueOf(ITSEnum.ASSIGNED_STATUS),
			reopenDate.getTime());
	statusHistory.save();
	if (bugNote != null && !bugNote.equals("")) {
		Element history = new Element(ScrumEnum.HISTORY_TAG);
		history.setAttribute(ScrumEnum.ID_HISTORY_ATTR,
				DateUtil.format(new Date(), DateUtil._16DIGIT_DATE_TIME_2));

		Element notesElem = new Element(ScrumEnum.NOTES);
		notesElem.setText(bugNote);
		history.addContent(notesElem);

		if (history.getChildren().size() > 0) {
			issue.addTagValue(history);
			// 最後將修改的結果更新至DB
			updateBugNote(issue);
		}
	}

}
 
Example 17
Source File: DefaultInspectionToolPresentation.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void exportResults(@Nonnull final CommonProblemDescriptor[] descriptors, @Nonnull RefEntity refEntity, @Nonnull Element parentNode) {
  for (CommonProblemDescriptor descriptor : descriptors) {
    @NonNls final String template = descriptor.getDescriptionTemplate();
    int line = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor)descriptor).getLineNumber() : -1;
    final PsiElement psiElement = descriptor instanceof ProblemDescriptor ? ((ProblemDescriptor)descriptor).getPsiElement() : null;
    @NonNls String problemText = StringUtil.replace(StringUtil.replace(template, "#ref", psiElement != null ? ProblemDescriptorUtil
            .extractHighlightedText(descriptor, psiElement) : ""), " #loc ", " ");

    Element element = refEntity.getRefManager().export(refEntity, parentNode, line);
    if (element == null) return;
    @NonNls Element problemClassElement = new Element(InspectionsBundle.message("inspection.export.results.problem.element.tag"));
    problemClassElement.addContent(myToolWrapper.getDisplayName());
    if (refEntity instanceof RefElement){
      final RefElement refElement = (RefElement)refEntity;
      final HighlightSeverity severity = getSeverity(refElement);
      ProblemHighlightType problemHighlightType = descriptor instanceof ProblemDescriptor
                                                  ? ((ProblemDescriptor)descriptor).getHighlightType()
                                                  : ProblemHighlightType.GENERIC_ERROR_OR_WARNING;
      final String attributeKey = getTextAttributeKey(refElement.getRefManager().getProject(), severity, problemHighlightType);
      problemClassElement.setAttribute("severity", severity.myName);
      problemClassElement.setAttribute("attribute_key", attributeKey);
    }
    element.addContent(problemClassElement);
    if (myToolWrapper instanceof GlobalInspectionToolWrapper) {
      final GlobalInspectionTool globalInspectionTool = ((GlobalInspectionToolWrapper)myToolWrapper).getTool();
      final QuickFix[] fixes = descriptor.getFixes();
      if (fixes != null) {
        @NonNls Element hintsElement = new Element("hints");
        for (QuickFix fix : fixes) {
          final String hint = globalInspectionTool.getHint(fix);
          if (hint != null) {
            @NonNls Element hintElement = new Element("hint");
            hintElement.setAttribute("value", hint);
            hintsElement.addContent(hintElement);
          }
        }
        element.addContent(hintsElement);
      }
    }
    try {
      Element descriptionElement = new Element(InspectionsBundle.message("inspection.export.results.description.tag"));
      descriptionElement.addContent(problemText);
      element.addContent(descriptionElement);
    }
    catch (IllegalDataException e) {
      //noinspection HardCodedStringLiteral,UseOfSystemOutOrSystemErr
      System.out.println("Cannot save results for " + refEntity.getName() + ", inspection which caused problem: " + myToolWrapper.getShortName());
    }
  }
}
 
Example 18
Source File: TestFieldsTest.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void addOption(Element elt, String name, String value) {
  final Element child = new Element("option");
  child.setAttribute("name", name);
  child.setAttribute("value", value);
  elt.addContent(child);
}
 
Example 19
Source File: TestSearchScope.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void writeExternal(final Element element) throws WriteExternalException {
  String name = WHOLE_PROJECT_NAE;
  if (myScope == SINGLE_MODULE) name = SINGLE_MODULE_NAME;
  else if (myScope == MODULE_WITH_DEPENDENCIES) name = MODULE_WITH_DEPENDENCIES_NAME;
  element.setAttribute(DEFAULT_NAME, name);
}
 
Example 20
Source File: XMLBasedSQSInfo.java    From TeamCity.SonarQubePlugin with Apache License 2.0 4 votes vote down vote up
private void addAttribute(Element serverElement, String key, String value) {
    if (!Util.isEmpty(value)) {
        serverElement.setAttribute(key, value);
    }
}