use of org.jdom.input.SAXBuilder in project core by jcryptool.
the class OperationsManager method importOperation.
public void importOperation(String fileName) {
try {
// $NON-NLS-1$
LogUtil.logInfo("1");
IFileStore store = EFS.getStore(URIUtil.toURI(fileName));
// $NON-NLS-1$
LogUtil.logInfo("2");
InputStream is = store.openInputStream(SWT.NONE, null);
// $NON-NLS-1$
LogUtil.logInfo("3");
SAXBuilder sax = new SAXBuilder();
// $NON-NLS-1$
LogUtil.logInfo("4");
Document doc = sax.build(is);
// $NON-NLS-1$
LogUtil.logInfo("5");
is.close();
// $NON-NLS-1$
LogUtil.logInfo("6");
ExportRootElement root = new ExportRootElement(doc.getRootElement());
// $NON-NLS-1$
LogUtil.logInfo("7");
IFlexiProviderOperation importEntry = root.getEntryNode();
// $NON-NLS-1$
LogUtil.logInfo("8");
newOperations.put(importEntry.getTimestamp(), importEntry);
// $NON-NLS-1$
LogUtil.logInfo("9");
Iterator<IOperationChangedListener> it = listeners.iterator();
while (it.hasNext()) {
it.next().addOperation();
}
// $NON-NLS-1$
LogUtil.logInfo("10");
} catch (CoreException e) {
LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "CoreException while importing an operation", e, true);
} catch (JDOMException e) {
LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "JDOMException while importing an operation", e, true);
} catch (IOException e) {
LogUtil.logError(FlexiProviderOperationsPlugin.PLUGIN_ID, "IOException while importing an operation", e, false);
}
}
use of org.jdom.input.SAXBuilder in project core by jcryptool.
the class FlexiProviderAlgorithmsView method hookActions.
/**
* Adds an listener, which will provide the context help for a selected algorithm. If for a child is no context help
* available, it will use the parents context help
*/
@SuppressWarnings("unchecked")
private void hookActions(String xmlfile) {
doubleClickHandler = new AbstractHandler() {
public Object execute(ExecutionEvent event) {
ISelection selection = viewer.getSelection();
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof CategoryNode || obj instanceof FolderNode) {
if (viewer.getTree().getSelection()[0].getExpanded()) {
viewer.collapseToLevel(obj, 1);
} else {
viewer.expandToLevel(obj, 1);
}
} else if (obj instanceof AlgorithmNode) {
AlgorithmsManager.getInstance().algorithmCalled(((AlgorithmNode) obj).getAlgorithm());
}
return (null);
}
};
URL xmlFile = FlexiProviderAlgorithmsPlugin.getDefault().getBundle().getEntry(xmlfile);
SAXBuilder builder = new SAXBuilder();
// Build a lookup table for the names defined in xml/help_algorithmis.xml
// to the according context id (in $nl$/contexts_algorithms.xml)
final Hashtable<String, String> contextIdLookup = new Hashtable<String, String>();
try {
Document doc = builder.build(xmlFile);
Element root = doc.getRootElement();
List<Element> helpEntries = root.getChildren("helpentry");
for (Element helpEntry : helpEntries) {
String mainname = helpEntry.getAttributeValue("mainname");
String contextid = helpEntry.getAttributeValue("contextid");
contextIdLookup.put(mainname, contextid);
Element aliasesRoot = helpEntry.getChild("aliases");
if (aliasesRoot != null) {
List<Element> aliases = aliasesRoot.getChildren("alias");
for (Element alias : aliases) {
contextIdLookup.put(alias.getValue(), contextid);
}
}
}
viewer.getControl().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(final MouseEvent e) {
if (e.button == 1) {
// only left button double clicks
try {
// run assigned action
doubleClickHandler.execute(null);
} catch (ExecutionException ex) {
LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, ex);
}
}
}
@Override
public void mouseDown(final MouseEvent event) {
IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
Object obj = ((IStructuredSelection) selection).getFirstElement();
if (obj instanceof ITreeNode) {
ITreeNode node = (ITreeNode) obj;
// display help of parent entry if no context help is available
do {
String name = node.toString();
if (contextIdLookup.containsKey(name)) {
String contextId = FlexiProviderAlgorithmsPlugin.PLUGIN_ID + "." + contextIdLookup.get(name);
PlatformUI.getWorkbench().getHelpSystem().displayHelp(contextId);
break;
}
node = node.getParent();
} while (node != null);
viewer.getControl().setFocus();
viewer.setSelection(selection);
}
}
});
} catch (JDOMException e) {
LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, e);
} catch (IOException e) {
LogUtil.logError(FlexiProviderAlgorithmsPlugin.PLUGIN_ID, e);
}
}
use of org.jdom.input.SAXBuilder in project fabric8 by jboss-fuse.
the class StandaloneInstaller method updateAriesBlueprintCompatibility.
public int updateAriesBlueprintCompatibility() throws Exception {
Namespace NS = Namespace.getNamespace("http://karaf.apache.org/xmlns/features/v1.2.0");
File xmlFile = new File(karafBase, "system/org/apache/karaf/assemblies/features/standard/2.4.0.redhat-620133/standard-2.4.0.redhat-620133-features.xml");
if (!xmlFile.exists()) {
LOG.error("File not found: " + xmlFile);
return 0;
}
SAXBuilder builder = new SAXBuilder();
Document doc = (Document) builder.build(xmlFile);
Element rootNode = doc.getRootElement();
for (Element feature : findChildrenWith(rootNode, "feature", "name", "aries-blueprint", NS)) {
// Is it not installed?
String compatBundle = "mvn:org.apache.aries.blueprint/org.apache.aries.blueprint.core.compatibility/1.0.0";
if (findChildrenWithText(feature, "bundle", compatBundle, NS).isEmpty()) {
Element bundle = new Element("bundle", NS).setText(compatBundle);
bundle.setAttribute("start-level", "20");
feature.addContent(bundle);
XMLOutputter xmlOutput = new XMLOutputter();
xmlOutput.setFormat(Format.getRawFormat());
xmlOutput.output(doc, new FileWriter(xmlFile));
LOG.info("Updated: " + xmlFile);
return 1;
}
}
return 0;
}
use of org.jdom.input.SAXBuilder in project wildfly-camel by wildfly-extras.
the class VersionsValidatorTest method getRootNode.
private Element getRootNode(String pomKey) throws IOException, JDOMException {
Properties props = new Properties();
try (InputStream input = new FileInputStream("target/pom-paths.txt")) {
props.load(input);
}
String pomPath = props.getProperty(pomKey);
File xmlFile = new File(pomPath);
SAXBuilder builder = new SAXBuilder();
Document document = (Document) builder.build(xmlFile);
return document.getRootElement();
}
use of org.jdom.input.SAXBuilder in project wildfly-camel by wildfly-extras.
the class StandaloneConfigTest method testStandaloneConfig.
@Test
public void testStandaloneConfig() throws Exception {
URL resurl = StandaloneConfigTest.class.getResource("/standalone.xml");
SAXBuilder jdom = new SAXBuilder();
Document doc = jdom.build(resurl);
ConfigPlugin plugin = new WildFlyCamelConfigPlugin();
ConfigContext context = ConfigSupport.createContext(null, Paths.get(resurl.toURI()), doc);
plugin.applyStandaloneConfigChange(context, true);
// Verify extension
assertElementWithAttributeValueNotNull(doc.getRootElement(), "extension", "module", "org.wildfly.extension.camel", NS_DOMAINS);
// Verify system-properties
Element element = ConfigSupport.findChildElement(doc.getRootElement(), "system-properties", NS_DOMAINS);
Assert.assertNotNull("system-properties not null", element);
assertElementWithAttributeValueNotNull(element, "property", "name", "hawtio.realm", NS_DOMAINS);
assertElementWithAttributeValueNotNull(element, "property", "name", "ee8.preview.mode", NS_DOMAINS);
// Verify camel
List<Element> profiles = ConfigSupport.findProfileElements(doc, NS_DOMAINS);
Assert.assertEquals("One profile", 1, profiles.size());
assertElementNotNull(profiles.get(0), "subsystem", NS_CAMEL);
// Verify hawtio-domain
assertElementWithAttributeValueNotNull(doc.getRootElement(), "security-domain", "name", "hawtio-domain", NS_SECURITY);
// outputDocumentContent(doc, System.out);
}
Aggregations