本文整理汇总了Java中com.intellij.openapi.util.JDOMUtil类的典型用法代码示例。如果您正苦于以下问题:Java JDOMUtil类的具体用法?Java JDOMUtil怎么用?Java JDOMUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JDOMUtil类属于com.intellij.openapi.util包,在下文中一共展示了JDOMUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doTest
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
private void doTest(int version) throws IOException, JDOMException, StudySerializationUtils.StudyUnrecognizedFormatException {
final String name = PlatformTestUtil.getTestName(this.name.getMethodName(), true);
final Path before = getTestDataPath().resolve(name + ".xml");
final Path after = getTestDataPath().resolve(name + ".after.xml");
Element element = JdomKt.loadElement(before);
Element converted = element;
switch (version) {
case 1:
converted = StudySerializationUtils.Xml.convertToSecondVersion(element);
break;
case 3:
converted = StudySerializationUtils.Xml.convertToForthVersion(element);
break;
case 4:
converted = StudySerializationUtils.Xml.convertToFifthVersion(element);
break;
}
assertTrue(JDOMUtil.areElementsEqual(converted, JdomKt.loadElement(after)));
}
示例2: reloadConfiguration
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
private synchronized void reloadConfiguration() throws JDOMException, IOException {
LOG.info("Loading configuration file: " + configFile);
Document document = JDOMUtil.loadDocument(configFile.toFile());
Element root = document.getRootElement();
TelegramSettings newSettings = new TelegramSettings();
newSettings.setBotToken(unscramble(root.getAttributeValue(BOT_TOKEN_ATTR)));
newSettings.setPaused(Boolean.parseBoolean(root.getAttributeValue(PAUSE_ATTR)));
newSettings.setUseProxy(Boolean.parseBoolean(root.getAttributeValue(USE_PROXY_ATTR)));
newSettings.setProxyServer(root.getAttributeValue(PROXY_SERVER_ATTR));
newSettings.setProxyPort(restoreInteger(root.getAttributeValue(PROXY_PORT_ATTR)));
newSettings.setProxyUsername(root.getAttributeValue(PROXY_PASSWORD_ATTR));
newSettings.setProxyPassword(unscramble(root.getAttributeValue(PROXY_PASSWORD_ATTR)));
settings = newSettings;
botManager.reloadIfNeeded(settings);
}
示例3: readPreSignUrlMapping
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
@NotNull
public static Map<String, URL> readPreSignUrlMapping(String data) throws IOException {
Document document;
try {
document = JDOMUtil.loadDocument(data);
} catch (JDOMException e) {
return Collections.emptyMap();
}
Element rootElement = document.getRootElement();
if(!rootElement.getName().equals(S3_PRESIGN_URL_MAPPING)) return Collections.emptyMap();
final Map<String, URL> result = new HashMap<String, URL>();
for(Object mapEntryElement : rootElement.getChildren(S3_PRESIGN_URL_MAP_ENTRY)){
Element mapEntryElementCasted = (Element) mapEntryElement;
String s3ObjectKey = mapEntryElementCasted.getChild(S3_OBJECT_KEY).getValue();
String preSignUrlString = mapEntryElementCasted.getChild(PRE_SIGN_URL).getValue();
result.put(s3ObjectKey, new URL(preSignUrlString));
}
return result;
}
示例4: writePreSignUrlMapping
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
@NotNull
public static String writePreSignUrlMapping(@NotNull Map<String, URL> data) throws IOException {
Element rootElement = new Element(S3_PRESIGN_URL_MAPPING);
for (String s3ObjectKey : data.keySet()){
URL preSignUrl = data.get(s3ObjectKey);
Element mapEntry = new Element(S3_PRESIGN_URL_MAP_ENTRY);
Element preSignUrlElement = new Element(PRE_SIGN_URL);
preSignUrlElement.addContent(preSignUrl.toString());
mapEntry.addContent(preSignUrlElement);
Element s3ObjectKeyElement = new Element(S3_OBJECT_KEY);
s3ObjectKeyElement.addContent(s3ObjectKey);
mapEntry.addContent(s3ObjectKeyElement);
rootElement.addContent(mapEntry);
}
return JDOMUtil.writeDocument(new Document(rootElement), System.getProperty("line.separator"));
}
示例5: saveUserArchetypes
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
private void saveUserArchetypes() {
Element root = new Element(ELEMENT_ARCHETYPES);
for (MavenArchetype each : myUserArchetypes) {
Element childElement = new Element(ELEMENT_ARCHETYPE);
childElement.setAttribute(ELEMENT_GROUP_ID, each.groupId);
childElement.setAttribute(ELEMENT_ARTIFACT_ID, each.artifactId);
childElement.setAttribute(ELEMENT_VERSION, each.version);
if (each.repository != null) {
childElement.setAttribute(ELEMENT_REPOSITORY, each.repository);
}
if (each.description != null) {
childElement.setAttribute(ELEMENT_DESCRIPTION, each.description);
}
root.addContent(childElement);
}
try {
File file = getUserArchetypesFile();
file.getParentFile().mkdirs();
JDOMUtil.writeDocument(new Document(root), file, "\n");
}
catch (IOException e) {
MavenLog.LOG.warn(e);
}
}
示例6: checkModule
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
static void checkModule(String path, Module module) throws IOException, JDOMException, ConversionException {
final File classpathFile1 = new File(path, EclipseXml.DOT_CLASSPATH_EXT);
if (!classpathFile1.exists()) return;
String fileText1 = FileUtil.loadFile(classpathFile1).replaceAll("\\$ROOT\\$", module.getProject().getBaseDir().getPath());
if (!SystemInfo.isWindows) {
fileText1 = fileText1.replaceAll(EclipseXml.FILE_PROTOCOL + "/", EclipseXml.FILE_PROTOCOL);
}
Element classpathElement1 = JDOMUtil.loadDocument(fileText1).getRootElement();
ModuleRootModel model = ModuleRootManager.getInstance(module);
Element resultClasspathElement = new EclipseClasspathWriter().writeClasspath(classpathElement1, model);
String resulted = new String(JDOMUtil.printDocument(new Document(resultClasspathElement), "\n"));
assertTrue(resulted.replaceAll(StringUtil.escapeToRegexp(module.getProject().getBaseDir().getPath()), "\\$ROOT\\$"),
JDOMUtil.areElementsEqual(classpathElement1, resultClasspathElement));
}
示例7: tryLoadRootElement
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
private static Element tryLoadRootElement(File file) throws IOException, JDOMException {
for (int i = 0; i < MAX_ATTEMPTS - 1; i++) {
try {
return JDOMUtil.loadDocument(file).getRootElement();
}
catch (Exception e) {
LOG.info("Loading attempt #" + i + " failed", e);
}
//most likely configuration file is being written by IDE so we'll wait a little
try {
//noinspection BusyWait
Thread.sleep(300);
}
catch (InterruptedException ignored) { }
}
return JDOMUtil.loadDocument(file).getRootElement();
}
示例8: loadExtension
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
@Override
public void loadExtension(@NotNull JpsProject project, @NotNull Element componentTag) {
String projectEncoding = null;
Map<String, String> urlToEncoding = new HashMap<String, String>();
for (Element fileTag : JDOMUtil.getChildren(componentTag, "file")) {
String url = fileTag.getAttributeValue("url");
String encoding = fileTag.getAttributeValue("charset");
if (url.equals("PROJECT")) {
projectEncoding = encoding;
}
else {
urlToEncoding.put(url, encoding);
}
}
JpsEncodingConfigurationService.getInstance().setEncodingConfiguration(project, projectEncoding, urlToEncoding);
}
示例9: loadData
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
private PsiTestData loadData(String dataName) throws Exception {
PsiTestData data = createData();
Element documentElement = JDOMUtil.load(new File(myDataRoot + "/" + "data.xml"));
final List nodes = documentElement.getChildren("data");
for (Object node1 : nodes) {
Element node = (Element)node1;
String value = node.getAttributeValue("name");
if (value.equals(dataName)) {
DefaultJDOMExternalizer.readExternal(data, node);
data.loadText(myDataRoot);
return data;
}
}
throw new IllegalArgumentException("Cannot find data chunk '" + dataName + "'");
}
示例10: loadContext
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
private synchronized boolean loadContext(String zipPostfix, String entryName) {
JBZipFile archive = null;
try {
archive = getTasksArchive(zipPostfix);
JBZipEntry entry = archive.getEntry(StringUtil.startsWithChar(entryName, '/') ? entryName : "/" + entryName);
if (entry != null) {
byte[] bytes = entry.getData();
Document document = JDOMUtil.loadDocument(new String(bytes));
Element rootElement = document.getRootElement();
loadContext(rootElement);
return true;
}
}
catch (Exception e) {
LOG.error(e);
}
finally {
closeArchive(archive);
}
return false;
}
示例11: saveMaps
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
public void saveMaps() throws IOException{
File dir = getMapDirectory();
if (dir == null) {
return;
}
File[] files = getMapFiles();
@NonNls String[] filePaths = new String[myMaps.size()];
Document[] documents = new Document[myMaps.size()];
UniqueNameGenerator namesProvider = new UniqueNameGenerator();
for(int i = 0; i < myMaps.size(); i++){
MigrationMap map = myMaps.get(i);
filePaths[i] = dir + File.separator + namesProvider.generateUniqueName(FileUtil.sanitizeFileName(map.getName(), false)) + ".xml";
documents[i] = saveMap(map);
}
JDOMUtil.updateFileSet(files, filePaths, documents, CodeStyleSettingsManager.getSettings(null).getLineSeparator());
}
示例12: doTest
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
private static void doTest(final String dirName) throws Exception {
InspectionProfileImpl.INIT_INSPECTIONS = true;
try {
final String relativePath = "/inspection/converter/";
final File projectFile = new File(JavaTestUtil.getJavaTestDataPath() + relativePath + dirName + "/options.ipr");
for (Element element : JDOMUtil.loadDocument(projectFile).getRootElement().getChildren("component")) {
if (Comparing.strEqual(element.getAttributeValue("name"), "InspectionProjectProfileManager")) {
final InspectionProjectProfileManager profileManager = InspectionProjectProfileManager.getInstance(getProject());
profileManager.loadState(element);
Element configElement = profileManager.getState();
final File file = new File(JavaTestUtil.getJavaTestDataPath() + relativePath + dirName + "/options.after.xml");
PlatformTestUtil.assertElementsEqual(JDOMUtil.loadDocument(file).getRootElement(), configElement);
break;
}
}
}
finally {
InspectionProfileImpl.INIT_INSPECTIONS = false;
}
}
示例13: testReloadProfileWithUnknownScopes
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
public void testReloadProfileWithUnknownScopes() throws Exception {
final Element element = JDOMUtil.loadDocument("<inspections version=\"1.0\">\n" +
" <option name=\"myName\" value=\"" + PROFILE + "\" />\n" +
" <inspection_tool class=\"ArgNamesErrorsInspection\" enabled=\"true\" level=\"ERROR\" enabled_by_default=\"false\" />\n" +
" <inspection_tool class=\"ArgNamesWarningsInspection\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\" />\n" +
" <inspection_tool class=\"AroundAdviceStyleInspection\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\" />\n" +
" <inspection_tool class=\"DeclareParentsInspection\" enabled=\"true\" level=\"ERROR\" enabled_by_default=\"false\" />\n" +
/*" <inspection_tool class=\"ManifestDomInspection\" enabled=\"true\" level=\"ERROR\" enabled_by_default=\"false\" />\n" +*/
" <inspection_tool class=\"MissingAspectjAutoproxyInspection\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"false\" />\n" +
" <inspection_tool class=\"UNUSED_IMPORT\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"true\">\n" +
" <scope name=\"Unknown scope name\" level=\"WARNING\" enabled=\"true\" />\n" +
" </inspection_tool>\n" +
"</inspections>").getRootElement();
final InspectionProfileImpl profile = createProfile();
profile.readExternal(element);
final ModifiableModel model = profile.getModifiableModel();
model.commit();
final Element copy = new Element("inspections");
profile.writeExternal(copy);
assertElementsEqual(element, copy);
}
示例14: testPreserveCompatibility
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
public void testPreserveCompatibility() throws Exception {
InspectionProfileImpl foo = new InspectionProfileImpl("foo", InspectionToolRegistrar.getInstance(), InspectionProjectProfileManager.getInstance(getProject()));
String test = "<profile version=\"1.0\" is_locked=\"false\">\n" +
" <option name=\"myName\" value=\"idea.default\" />\n" +
" <option name=\"myLocal\" value=\"false\" />\n" +
" <inspection_tool class=\"AbstractMethodCallInConstructor\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"true\" />\n" +
" <inspection_tool class=\"AssignmentToForLoopParameter\" enabled=\"true\" level=\"WARNING\" enabled_by_default=\"true\">\n" +
" <option name=\"m_checkForeachParameters\" value=\"false\" />\n" +
" </inspection_tool>\n" +
"</profile>";
foo.readExternal(JDOMUtil.loadDocument(test).getRootElement());
foo.initInspectionTools(getProject());
Element serialized = new Element("profile");
foo.writeExternal(serialized);
assertEquals(test, JDOMUtil.writeElement(serialized));
}
示例15: doTest
import com.intellij.openapi.util.JDOMUtil; //导入依赖的package包/类
private static void doTest(String type, String fqName, String expectedFQName) throws Exception {
final Element entryPoints = setUpEntryPoint(type, fqName);
final HashMap<String, SmartRefElementPointer> persistentEntryPoints = new HashMap<String, SmartRefElementPointer>();
EntryPointsManagerBase.convert(entryPoints, persistentEntryPoints);
final Element testElement = new Element("comp");
EntryPointsManagerBase.writeExternal(testElement, persistentEntryPoints, new JDOMExternalizableStringList());
final Element expectedEntryPoints = setUpEntryPoint(type, expectedFQName);
expectedEntryPoints.setAttribute("version", "2.0");
final Element expected = new Element("comp");
expected.addContent(expectedEntryPoints);
assertTrue(JDOMUtil.areElementsEqual(testElement, expected));
}