Search in sources :

Example 26 with SAXBuilder

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);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) CoreException(org.eclipse.core.runtime.CoreException) ExportRootElement(org.jcryptool.crypto.flexiprovider.operations.xml.ExportRootElement) InputStream(java.io.InputStream) IFileStore(org.eclipse.core.filesystem.IFileStore) IOException(java.io.IOException) Document(org.jdom.Document) IOperationChangedListener(org.jcryptool.crypto.flexiprovider.operations.ui.listeners.IOperationChangedListener) JDOMException(org.jdom.JDOMException) IFlexiProviderOperation(org.jcryptool.crypto.flexiprovider.descriptors.IFlexiProviderOperation)

Example 27 with SAXBuilder

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);
    }
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) MouseEvent(org.eclipse.swt.events.MouseEvent) FolderNode(org.jcryptool.crypto.flexiprovider.algorithms.ui.views.nodes.FolderNode) AlgorithmNode(org.jcryptool.crypto.flexiprovider.algorithms.ui.views.nodes.AlgorithmNode) Hashtable(java.util.Hashtable) Element(org.jdom.Element) MouseAdapter(org.eclipse.swt.events.MouseAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) Document(org.jdom.Document) JDOMException(org.jdom.JDOMException) AbstractHandler(org.eclipse.core.commands.AbstractHandler) URL(java.net.URL) CategoryNode(org.jcryptool.crypto.flexiprovider.algorithms.ui.views.nodes.CategoryNode) ITreeNode(org.jcryptool.crypto.flexiprovider.ui.nodes.ITreeNode) ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 28 with SAXBuilder

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;
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) Document(org.jdom.Document) Namespace(org.jdom.Namespace)

Example 29 with SAXBuilder

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();
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Properties(java.util.Properties) Document(org.jdom.Document) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 30 with SAXBuilder

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);
}
Also used : ConfigPlugin(org.wildfly.extras.config.ConfigPlugin) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) SAXBuilder(org.jdom.input.SAXBuilder) WildFlyCamelConfigPlugin(org.wildfly.extension.camel.config.WildFlyCamelConfigPlugin) Element(org.jdom.Element) Document(org.jdom.Document) URL(java.net.URL) ConfigContext(org.wildfly.extras.config.ConfigContext) Test(org.junit.Test)

Aggregations

SAXBuilder (org.jdom.input.SAXBuilder)145 Document (org.jdom.Document)109 Element (org.jdom.Element)84 IOException (java.io.IOException)60 JDOMException (org.jdom.JDOMException)50 StringReader (java.io.StringReader)35 InputStream (java.io.InputStream)29 File (java.io.File)18 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)13 ArrayList (java.util.ArrayList)12 XPath (org.jdom.xpath.XPath)11 HttpMethod (org.apache.commons.httpclient.HttpMethod)10 XMLOutputter (org.jdom.output.XMLOutputter)10 URL (java.net.URL)9 List (java.util.List)8 GoraException (org.apache.gora.util.GoraException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 FileInputStream (java.io.FileInputStream)7 Namespace (org.jdom.Namespace)6 StringWriter (java.io.StringWriter)5