本文整理汇总了Java中org.openide.xml.XMLUtil.findElement方法的典型用法代码示例。如果您正苦于以下问题:Java XMLUtil.findElement方法的具体用法?Java XMLUtil.findElement怎么用?Java XMLUtil.findElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.xml.XMLUtil
的用法示例。
在下文中一共展示了XMLUtil.findElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateKeys
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
private void updateKeys(boolean fromListener) {
Element genldata = p.getPrimaryConfigurationData();
Element viewEl = XMLUtil.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N
if (viewEl != null) {
Element itemsEl = XMLUtil.findElement(viewEl, "items", FreeformProjectType.NS_GENERAL); // NOI18N
keys = XMLUtil.findSubElements(itemsEl);
} else {
keys = Collections.<Element>emptyList();
}
if (fromListener && !synchronous) {
// #50328, #58491 - post setKeys to different thread to prevent deadlocks
RP.post(new Runnable() {
public void run() {
cs.fireChange();
}
});
} else {
cs.fireChange();
}
}
示例2: getExtraCompilationUnits
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* Find marked extra compilation units.
* Gives a map from the package root to the defining XML element.
*/
public Map<FileObject,Element> getExtraCompilationUnits() {
if (extraCompilationUnits == null) {
extraCompilationUnits = new HashMap<FileObject,Element>();
for (Element ecu : XMLUtil.findSubElements(getPrimaryConfigurationData())) {
if (ecu.getLocalName().equals("extra-compilation-unit")) { // NOI18N
Element pkgrootEl = XMLUtil.findElement(ecu, "package-root", NbModuleProject.NAMESPACE_SHARED); // NOI18N
String pkgrootS = XMLUtil.findText(pkgrootEl);
String pkgrootEval = evaluator().evaluate(pkgrootS);
FileObject pkgroot = pkgrootEval != null ? getHelper().resolveFileObject(pkgrootEval) : null;
if (pkgroot == null) {
Util.err.log(ErrorManager.WARNING, "Could not find package-root " + pkgrootEval + " for " + getCodeNameBase());
continue;
}
extraCompilationUnits.put(pkgroot, ecu);
}
}
}
return extraCompilationUnits;
}
示例3: getSupportedActions
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
public String[] getSupportedActions() {
final Element genldata = project.getPrimaryConfigurationData();
final Element actionsEl = XMLUtil.findElement(genldata, "ide-actions", FreeformProjectType.NS_GENERAL); // NOI18N
// Use a set, not a list, since when using context you can define one action several times:
final Set<String> names = new LinkedHashSet<String>();
if (actionsEl != null) {
for (Element actionEl : XMLUtil.findSubElements(actionsEl)) {
names.add(actionEl.getAttribute("name")); // NOI18N
}
// #46886: also always enable all common global actions, in case they should be selected:
names.addAll(COMMON_NON_IDE_GLOBAL_ACTIONS);
}
names.add(COMMAND_RENAME);
names.add(COMMAND_MOVE);
names.add(COMMAND_COPY);
names.add(COMMAND_DELETE);
return names.toArray(new String[names.size()]);
}
示例4: getDataFiles
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
public List<FileObject> getDataFiles() {
Element genldata = project.getPrimaryConfigurationData();
Element foldersEl = XMLUtil.findElement(genldata, "folders", FreeformProjectType.NS_GENERAL); // NOI18N
List<Element> folders = foldersEl != null ? XMLUtil.findSubElements(foldersEl) : Collections.<Element>emptyList();
List<FileObject> result = new ArrayList<FileObject>();
for (Element el : folders) {
if ("source-folder".equals(el.getLocalName()) && FreeformProjectType.NS_GENERAL.equals(el.getNamespaceURI())) { // NOI18N
addFile(el, result);
}
}
addFile(project.getProjectDirectory(), "build.xml", result); // NOI18N
return result;
}
示例5: testBrokenPrimaryConfigurationData
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* Test error recovery from malformed project.xml
* @see "#46048"
*/
public void testBrokenPrimaryConfigurationData() throws Exception {
// Make an empty, thus invalid, project.xml:
TestUtil.createFileFromContent(null, projdir, AntProjectHelper.PROJECT_XML_PATH);
AntProjectHelper.QUIETLY_SWALLOW_XML_LOAD_ERRORS = true;
Element data;
try {
data = h.getPrimaryConfigurationData(true);
} finally {
AntProjectHelper.QUIETLY_SWALLOW_XML_LOAD_ERRORS = false;
}
assertEquals("correct element name", "data", data.getLocalName());
assertEquals("correct element namespace", "urn:test:shared", data.getNamespaceURI());
Element stuff = XMLUtil.findElement(data, "shared-stuff", "urn:test:shared");
/* This now retains the former contents:
assertNull("had no stuff in it", stuff);
*/
// Make sure a subsequent save proceeds normally too:
data = XMLUtil.createDocument("whatever", "urn:test:shared", null, null).createElementNS("urn:test:shared", "data");
data.appendChild(data.getOwnerDocument().createElementNS("urn:test:shared", "details"));
h.putPrimaryConfigurationData(data, true);
pm.saveProject(p);
Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
Element root = doc.getDocumentElement();
Element type = XMLUtil.findElement(root, "type", AntProjectHelper.PROJECT_NS);
assertEquals("correct restored type", "test", XMLUtil.findText(type));
Element config = XMLUtil.findElement(root, "configuration", AntProjectHelper.PROJECT_NS);
assertNotNull("have <configuration>", config);
data = XMLUtil.findElement(config, "data", "urn:test:shared");
assertNotNull("have <data>", data);
Element details = XMLUtil.findElement(data, "details", "urn:test:shared");
assertNotNull("have <details>", details);
}
示例6: getCodeNameBase
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
public String getCodeNameBase() {
Element config = getPrimaryConfigurationData();
Element cnb = XMLUtil.findElement(config, "code-name-base", NbModuleProject.NAMESPACE_SHARED); // NOI18N
if (cnb != null) {
return XMLUtil.findText(cnb);
} else {
return null;
}
}
示例7: supportsJavadoc
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* Check whether Javadoc generation is possible.
*/
public boolean supportsJavadoc() {
if (evaluator().getProperty("module.javadoc.packages") != null) {
return true;
}
Element config = getPrimaryConfigurationData();
Element pubPkgs = XMLUtil.findElement(config, "public-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N
if (pubPkgs == null) {
// Try <friend-packages> too.
pubPkgs = XMLUtil.findElement(config, "friend-packages", NbModuleProject.NAMESPACE_SHARED); // NOI18N
}
return pubPkgs != null && !XMLUtil.findSubElements(pubPkgs).isEmpty();
}
示例8: parseData
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* Load a project.xml from a project.
* @param basedir a putative project base directory
* @return its primary configuration data (if there is an NBM project here), else null
*/
static Element parseData(File basedir) throws IOException {
File projectXml = new File(basedir, PROJECT_XML);
// #61579: tboudreau claims File.exists is much cheaper on some systems
//System.err.println("parseData: " + basedir);
if (!projectXml.exists() || !projectXml.isFile()) {
return null;
}
Document doc;
try {
xmlFilesParsed++;
timeSpentInXmlParsing -= System.currentTimeMillis();
doc = XMLUtil.parse(new InputSource(Utilities.toURI(projectXml).toString()), false, true, null, null);
timeSpentInXmlParsing += System.currentTimeMillis();
} catch (SAXException e) {
throw (IOException) new IOException(projectXml + ": " + e.toString()).initCause(e); // NOI18N
}
Element docel = doc.getDocumentElement();
Element type = XMLUtil.findElement(docel, "type", "http://www.netbeans.org/ns/project/1"); // NOI18N
if (!XMLUtil.findText(type).equals("org.netbeans.modules.apisupport.project")) { // NOI18N
return null;
}
Element cfg = XMLUtil.findElement(docel, "configuration", "http://www.netbeans.org/ns/project/1"); // NOI18N
Element data = XMLUtil.findElement(cfg, "data", NbModuleProject.NAMESPACE_SHARED); // NOI18N
if (data != null) {
return data;
} else {
data = XMLUtil.findElement(cfg, "data", NbModuleProject.NAMESPACE_SHARED_2); // NOI18N
if (data != null) {
return XMLUtil.translateXML(data, NbModuleProject.NAMESPACE_SHARED);
} else {
return null;
}
}
}
示例9: testNonstandardDependencies
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
public void testNonstandardDependencies() throws Exception { // #180717
NbModuleProject p = generateStandaloneModule("m");
Element data = p.getPrimaryConfigurationData();
Element mds = XMLUtil.findElement(data, ProjectXMLManager.MODULE_DEPENDENCIES, NbModuleProject.NAMESPACE_SHARED);
Document doc = mds.getOwnerDocument();
boolean[] Z2 = {false, true};
int i = 0;
for (boolean buildPrerequisite : Z2) {
for (boolean compileDependency : Z2) {
for (boolean runDependency : Z2) {
Element md = (Element) mds.appendChild(doc.createElementNS(NbModuleProject.NAMESPACE_SHARED, ProjectXMLManager.DEPENDENCY));
Element cnb = (Element) md.appendChild(doc.createElementNS(NbModuleProject.NAMESPACE_SHARED, ProjectXMLManager.CODE_NAME_BASE));
cnb.appendChild(doc.createTextNode("dep" + i++));
if (buildPrerequisite) {
md.appendChild(doc.createElementNS(NbModuleProject.NAMESPACE_SHARED, ProjectXMLManager.BUILD_PREREQUISITE));
}
if (compileDependency) {
md.appendChild(doc.createElementNS(NbModuleProject.NAMESPACE_SHARED, ProjectXMLManager.COMPILE_DEPENDENCY));
}
if (runDependency) {
md.appendChild(doc.createElementNS(NbModuleProject.NAMESPACE_SHARED, ProjectXMLManager.RUN_DEPENDENCY));
}
}
}
}
String orig = elementToString(mds);
p.putPrimaryConfigurationData(data);
ProjectXMLManager pxm = new ProjectXMLManager(p);
ModuleDependency extra = new ModuleDependency(new NonexistentModuleEntry(("other")), null, null, true, false);
pxm.addDependency(extra);
pxm.removeDependency("other");
mds = XMLUtil.findElement(p.getPrimaryConfigurationData(), ProjectXMLManager.MODULE_DEPENDENCIES, NbModuleProject.NAMESPACE_SHARED);
assertEquals(orig, elementToString(mds));
}
示例10: testSourceRootChanges
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
public void testSourceRootChanges() throws Exception {
FileObject top = FileUtil.toFileObject(copyFolder(FileUtil.toFile(egdirFO.getFileObject("extsrcroot"))));
FreeformProject extsrcroot_ = (FreeformProject) ProjectManager.getDefault().findProject(top.getFileObject("proj"));
Sources s = ProjectUtils.getSources(extsrcroot_);
SourceGroup[] groups = s.getSourceGroups("java");
assertEquals("one Java group", 1, groups.length);
assertEquals("right root folder", top.getFileObject("src"), groups[0].getRootFolder());
TestCL l = new TestCL();
s.addChangeListener(l);
Element data = extsrcroot_.getPrimaryConfigurationData();
Element folders = XMLUtil.findElement(data, "folders", FreeformProjectType.NS_GENERAL);
assertNotNull("have <folders>", folders);
List<Element> sourceFolders = XMLUtil.findSubElements(folders);
assertEquals("have 2 <source-folder>s", 2, sourceFolders.size());
Element sourceFolder = sourceFolders.get(1);
Element location = XMLUtil.findElement(sourceFolder, "location", FreeformProjectType.NS_GENERAL);
assertNotNull("have <location>", location);
NodeList nl = location.getChildNodes();
assertEquals("one child (text)", 1, nl.getLength());
location.removeChild(nl.item(0));
location.appendChild(location.getOwnerDocument().createTextNode("../src2"));
extsrcroot_.putPrimaryConfigurationData(data);
assertEquals("got a change in Sources", 1, l.changeCount());
groups = s.getSourceGroups("java");
assertEquals("one Java group", 1, groups.length);
assertEquals("right root folder", top.getFileObject("src2"), groups[0].getRootFolder());
}
示例11: getValue
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
public Object getValue(String key) {
if (key.equals(Action.NAME)) {
Element labelEl = XMLUtil.findElement(actionEl, "label", FreeformProjectType.NS_GENERAL); // NOI18N
return XMLUtil.findText(labelEl);
} else {
return super.getValue(key);
}
}
示例12: testGetPrimaryConfigurationData
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* Test that it is possible to retrieve the main data from project.xml and private.xml.
* @throws Exception if anything unexpected happens
*/
public void testGetPrimaryConfigurationData() throws Exception {
assertNotNull("Had helper in lookup", h);
Element data = h.getPrimaryConfigurationData(true);
assertEquals("correct element name", "data", data.getLocalName());
assertEquals("correct element namespace", "urn:test:shared", data.getNamespaceURI());
Element stuff = XMLUtil.findElement(data, "shared-stuff", "urn:test:shared");
assertNotNull("had nested stuff in it", stuff);
data = h.getPrimaryConfigurationData(false);
assertEquals("correct element name", "data", data.getLocalName());
assertEquals("correct element namespace", "urn:test:private", data.getNamespaceURI());
stuff = XMLUtil.findElement(data, "private-stuff", "urn:test:private");
assertNotNull("had nested stuff in it", stuff);
}
示例13: testPutPrimaryConfigurationData
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* Test that writing changes to project.xml and private.xml works.
* @throws Exception if anything unexpected happens
*/
public void testPutPrimaryConfigurationData() throws Exception {
h.addAntProjectListener(l);
Element data = h.getPrimaryConfigurationData(true);
assertNotNull("<shared-stuff/> is there to start", XMLUtil.findElement(data, "shared-stuff", "urn:test:shared"));
assertTrue("project is not initially modified", !pm.isModified(p));
assertEquals("gPCD fires no events", 0, l.events().length);
assertNotNull("config data has an owner document", data.getOwnerDocument());
Element nue = data.getOwnerDocument().createElementNS("urn:test:shared", "misc");
data.appendChild(nue);
assertTrue("project is not modified after uncommitted change", !pm.isModified(p));
assertEquals("no events fired after uncommitted change", 0, l.events().length);
assertEquals("after uncommitted change gPCD does not yet have new <misc/>", null, XMLUtil.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared"));
h.putPrimaryConfigurationData(data, true);
assertTrue("project is modified after committed change", pm.isModified(p));
AntProjectEvent[] evs = l.events();
assertEquals("putPCD fires one event", 1, evs.length);
assertEquals("correct helper", h, evs[0].getHelper());
assertEquals("correct path", AntProjectHelper.PROJECT_XML_PATH, evs[0].getPath());
assertTrue("expected change", evs[0].isExpected());
nue = XMLUtil.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared");
assertNotNull("after committed change gPCD has new <misc/>", nue);
assertEquals("new element name is correct", "misc", nue.getLocalName());
assertEquals("new element namespace is correct", "urn:test:shared", nue.getNamespaceURI());
Document doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
Element configuration = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
assertNotNull("still has <configuration> on disk", configuration);
data = XMLUtil.findElement(configuration, "data", "urn:test:shared");
assertNotNull("still has <data> on disk", data);
nue = XMLUtil.findElement(data, "misc", "urn:test:shared");
assertEquals("<misc/> not yet on disk", null, nue);
pm.saveProject(p);
assertTrue("project is not modified after save", !pm.isModified(p));
assertEquals("saving changes fires no new events", 0, l.events().length);
nue = XMLUtil.findElement(h.getPrimaryConfigurationData(true), "misc", "urn:test:shared");
assertNotNull("after save gPCD still has new <misc/>", nue);
doc = AntBasedTestUtil.slurpXml(h, AntProjectHelper.PROJECT_XML_PATH);
configuration = XMLUtil.findElement(doc.getDocumentElement(), "configuration", AntProjectHelper.PROJECT_NS);
assertNotNull("still has <configuration> on disk", configuration);
data = XMLUtil.findElement(configuration, "data", "urn:test:shared");
assertNotNull("still has <data> on disk", data);
nue = XMLUtil.findElement(data, "misc", "urn:test:shared");
assertNotNull("<misc/> now on disk", nue);
// #42147: changes made on disk should result in firing of an AntProjectEvent
ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
public Void run() throws Exception {
TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/project-modified.xml"), projdir, AntProjectHelper.PROJECT_XML_PATH);
return null;
}
});
evs = l.events();
assertEquals("writing project.xml on disk fires one event", 1, evs.length);
assertEquals("correct helper", h, evs[0].getHelper());
assertEquals("correct path", AntProjectHelper.PROJECT_XML_PATH, evs[0].getPath());
assertFalse("unexpected change", evs[0].isExpected());
assertEquals("correct new display name", "Some New Name", ProjectUtils.getInformation(p).getDisplayName());
data = h.getPrimaryConfigurationData(true);
Element stuff = XMLUtil.findElement(data, "other-shared-stuff", "urn:test:shared");
assertNotNull("have <other-shared-stuff/> now", stuff);
AuxiliaryConfiguration aux = p.getLookup().lookup(AuxiliaryConfiguration.class);
data = aux.getConfigurationFragment("data", "urn:test:shared-aux", true);
assertNotNull("have aux <data>", data);
stuff = XMLUtil.findElement(data, "other-aux-shared-stuff", "urn:test:shared-aux");
assertNotNull("have <other-aux-shared-stuff/> now", stuff);
// XXX try private.xml too
// XXX try modifying both XML files, or different parts of the same, and saving in a batch
// XXX try storing unmodified XML fragments and see what happens
// XXX try storing a fresh Element not returned from getPrimaryConfigurationData
}
示例14: looksLikeGitChangeLog
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* @return false if the item does not look like a Git changelog, true
* otherwise.
*/
private boolean looksLikeGitChangeLog(Element itemXML) {
Element idE = XMLUtil.findElement(itemXML, "id", null); //NOI18N
return idE != null
&& XMLUtil.findText(idE).matches("[0-9a-f]{40}"); //NOI18N
}
示例15: getCustomContextMenuActions
import org.openide.xml.XMLUtil; //导入方法依赖的package包/类
/**
* Read custom context menu actions from project.
* @param helper AntProjectHelper instance
* @return list of CustomTarget instances
*/
public static List<CustomTarget> getCustomContextMenuActions(AntProjectHelper helper) {
//assert ProjectManager.mutex().isReadAccess() || ProjectManager.mutex().isWriteAccess();
List<CustomTarget> list = new ArrayList<CustomTarget>();
Element genldata = Util.getPrimaryConfigurationData(helper);
Element viewEl = XMLUtil.findElement(genldata, "view", FreeformProjectType.NS_GENERAL); // NOI18N
if (viewEl == null) {
return list;
}
Element contextMenuEl = XMLUtil.findElement(viewEl, "context-menu", FreeformProjectType.NS_GENERAL); // NOI18N
if (contextMenuEl == null) {
return list;
}
for (Element actionEl : XMLUtil.findSubElements(contextMenuEl)) {
if (!actionEl.getLocalName().equals("action")) { // NOI18N
continue;
}
CustomTarget ct = new CustomTarget();
List<String> targetNames = new ArrayList<String>();
EditableProperties props = new EditableProperties(false);
for (Element subEl : XMLUtil.findSubElements(actionEl)) {
if (subEl.getLocalName().equals("target")) { // NOI18N
targetNames.add(XMLUtil.findText(subEl));
continue;
}
if (subEl.getLocalName().equals("script")) { // NOI18N
ct.script = XMLUtil.findText(subEl);
continue;
}
if (subEl.getLocalName().equals("label")) { // NOI18N
ct.label = XMLUtil.findText(subEl);
continue;
}
if (subEl.getLocalName().equals("property")) { // NOI18N
readProperty(subEl, props);
continue;
}
}
ct.targets = targetNames;
if (props.keySet().size() > 0) {
ct.properties = props;
}
list.add(ct);
}
return list;
}