use of org.jdom.Element in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoRunConfigurationTestCase method doTestProducedConfigurations.
protected void doTestProducedConfigurations(@Nullable PsiElement context) {
assertNotNull(context);
ConfigurationContext configurationContext = new ConfigurationContext(context);
List<ConfigurationFromContext> configurationAndSettings = configurationContext.getConfigurationsFromContext();
Element configurationsElement = new Element("configurations");
if (configurationAndSettings != null) {
for (ConfigurationFromContext setting : configurationAndSettings) {
try {
RunConfiguration configuration = setting.getConfiguration();
Element configurationElement = new Element("configurations");
configurationElement.setAttribute("name", configuration.getName());
configurationElement.setAttribute("class", configuration.getClass().getSimpleName());
configuration.writeExternal(configurationElement);
configurationsElement.addContent(configurationElement);
} catch (WriteExternalException e) {
throw new RuntimeException(e);
}
}
}
assertSameLinesWithFile(getTestDataPath() + "/" + getTestName(true) + ".xml", JDOMUtil.writeElement(configurationsElement));
}
use of org.jdom.Element in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoBuildTagsSettingsConverterProvider method createConverter.
@NotNull
@Override
public ProjectConverter createConverter(@NotNull ConversionContext context) {
return new ProjectConverter() {
private GoBuildTargetSettings newSettings;
@NotNull
private File getGoBuildFlagsFile() {
return new File(context.getSettingsBaseDir(), "goBuildFlags.xml");
}
@Nullable
@Override
public ConversionProcessor<ProjectSettings> createProjectFileConverter() {
return new ConversionProcessor<ProjectSettings>() {
@Override
public boolean isConversionNeeded(@NotNull ProjectSettings settings) {
Element oldSettings = JDomSerializationUtil.findComponent(settings.getRootElement(), "GoBuildFlags");
return oldSettings != null;
}
@Override
public void process(@NotNull ProjectSettings settings) throws CannotConvertException {
Element oldSettings = JDomSerializationUtil.findComponent(settings.getRootElement(), "GoBuildFlags");
if (oldSettings != null) {
newSettings = XmlSerializer.deserialize(oldSettings, GoBuildTargetSettings.class);
oldSettings.detach();
}
}
};
}
@Override
public Collection<File> getAdditionalAffectedFiles() {
return Collections.singletonList(getGoBuildFlagsFile());
}
@Override
public boolean isConversionNeeded() {
return getGoBuildFlagsFile().exists();
}
@Override
public void preProcessingFinished() throws CannotConvertException {
File oldSettingsFile = getGoBuildFlagsFile();
if (oldSettingsFile.exists()) {
Element oldSettingsRoot = JDomConvertingUtil.loadDocument(oldSettingsFile).getRootElement();
Element buildFlagsSettings = JDomSerializationUtil.findComponent(oldSettingsRoot, "GoBuildFlags");
if (buildFlagsSettings != null) {
newSettings = XmlSerializer.deserialize(buildFlagsSettings, GoBuildTargetSettings.class);
buildFlagsSettings.detach();
//noinspection ResultOfMethodCallIgnored
oldSettingsFile.delete();
}
}
}
@Nullable
@Override
public ConversionProcessor<ModuleSettings> createModuleFileConverter() {
return new ConversionProcessor<ModuleSettings>() {
@Override
public boolean isConversionNeeded(@NotNull ModuleSettings settings) {
return getGoBuildFlagsFile().exists();
}
@Override
public void process(@NotNull ModuleSettings settings) throws CannotConvertException {
Element rootElement = settings.getRootElement();
Element goComponent = JDomSerializationUtil.findOrCreateComponentElement(rootElement, GoConstants.GO_MODULE_SESTTINGS_SERVICE_NAME);
Element buildTags = XmlSerializer.serialize(newSettings);
Element existingBuildTags = goComponent.getChild(buildTags.getName());
if (existingBuildTags != null) {
existingBuildTags.detach();
}
goComponent.addContent(buildTags);
}
};
}
};
}
use of org.jdom.Element in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoProjectModelConverterProvider method addProjectDirToLibraries.
private static void addProjectDirToLibraries(@NotNull File file, @NotNull Element rootElement) throws CannotConvertException {
GoProjectLibrariesService librariesService = new GoProjectLibrariesService();
librariesService.setLibraryRootUrls("file://$PROJECT_DIR$");
Element componentElement = JDomSerializationUtil.findOrCreateComponentElement(rootElement, GoConstants.GO_LIBRARIES_SERVICE_NAME);
XmlSerializer.serializeInto(librariesService.getState(), componentElement);
saveFile(file, rootElement, "Cannot save libraries settings");
}
use of org.jdom.Element in project nhin-d by DirectProject.
the class HumanReadableTextAssembler method assembleHtmlBody.
/**
* This method will assemble html bounce message
*
* @return bounce html message
* @throws IOException
*/
protected String assembleHtmlBody(List<Address> rejectedRecipients, String errorMessage) throws IOException {
List<UnescapedText> lstToUnescape = new ArrayList<UnescapedText>();
Element html = new Element("html");
Element body = new Element("body");
html.addContent(body);
{
Element p = new Element("p");
body.addContent(p);
UnescapedText text = new UnescapedText(bounceHeader);
lstToUnescape.add(text);
p.addContent(text);
}
{
Element p = new Element("p");
body.addContent(p);
p.setText(this.recipientsTitle);
Element ul = new Element("ul");
p.addContent(ul);
for (Address address : rejectedRecipients) {
Element li = new Element("li");
ul.addContent(li);
li.addContent(address.toString());
}
}
{
Element p = new Element("p");
body.addContent(p);
p.setText(this.errorMessageTitle);
Element br = new Element("br");
p.addContent(br);
if ((errorMessage != null) && errorMessage.length() > 0) {
p.addContent(errorMessage);
} else {
UnescapedText text = new UnescapedText(this.errorMessageDefault);
lstToUnescape.add(text);
p.addContent(text);
}
}
{
Element p = new Element("p");
body.addContent(p);
UnescapedText text = new UnescapedText(bounceFooter);
lstToUnescape.add(text);
p.addContent(text);
}
Document document = new Document(html);
String randomStr;
{
// Determine which string indicator can be used to indicate that a
// string should not be escaped.
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
XMLOutputter outputter = new NoEscapeXMLOutputter(Format.getPrettyFormat());
outputter.output(document, byteArrayOutputStream);
String htmlString = new String(byteArrayOutputStream.toByteArray());
randomStr = getUniqueString();
while (htmlString.indexOf(randomStr) > -1) {
randomStr = getUniqueString();
}
}
String htmlString;
{
for (UnescapedText unescapedText : lstToUnescape) {
unescapedText.setUnescapedIndicator(randomStr);
}
XMLOutputter outputter = new UnescapedAwareXMLOutputter(Format.getPrettyFormat(), randomStr);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
outputter.output(document, byteArrayOutputStream);
htmlString = new String(byteArrayOutputStream.toByteArray());
}
return htmlString;
}
use of org.jdom.Element in project symmetric-ds by JumpMind.
the class AbstractXmlPublisherExtensionPoint method toXmlElement.
protected void toXmlElement(DataEventType dml, Element xml, String catalogName, String schemaName, String tableName, String[] columnNames, String[] data, String[] keyNames, String[] keys) {
Element row = new Element("row");
xml.addContent(row);
if (StringUtils.isNotBlank(catalogName)) {
row.setAttribute("catalog", catalogName);
}
if (StringUtils.isNotBlank(schemaName)) {
row.setAttribute("schema", schemaName);
}
row.setAttribute("entity", tableName);
row.setAttribute("dml", dml.getCode());
String[] colNames = null;
if (data == null) {
colNames = keyNames;
data = keys;
} else {
colNames = columnNames;
}
for (int i = 0; i < data.length; i++) {
String col = colNames[i];
Element dataElement = new Element("data");
row.addContent(dataElement);
dataElement.setAttribute("key", col);
if (data[i] != null) {
dataElement.setText(replaceInvalidChars(data[i]));
} else {
dataElement.setAttribute("nil", "true", getXmlNamespace());
}
}
}
Aggregations