Search in sources :

Example 46 with SAXReader

use of org.dom4j.io.SAXReader in project Spark by igniterealtime.

the class PluginViewer method getPluginList.

public Collection<PublicPlugin> getPluginList(InputStream response) {
    final List<PublicPlugin> pluginList = new ArrayList<>();
    SAXReader saxReader = new SAXReader();
    Document pluginXML = null;
    try {
        pluginXML = saxReader.read(response);
    } catch (DocumentException e) {
        Log.error(e);
    }
    List<? extends Node> plugins = pluginXML.selectNodes("/plugins/plugin");
    for (Node plugin1 : plugins) {
        PublicPlugin publicPlugin = new PublicPlugin();
        String clazz;
        String name = null;
        try {
            Element plugin = (Element) plugin1;
            try {
                String version = plugin.selectSingleNode("minSparkVersion").getText();
                if (!isGreaterOrEqual(JiveInfo.getVersion(), version)) {
                    Log.error("Unable to load plugin " + name + " due to min version incompatibility.");
                    continue;
                }
            } catch (Exception e) {
                Log.error("Unable to load plugin " + name + " due to no minSparkVersion.");
                continue;
            }
            name = plugin.selectSingleNode("name").getText();
            clazz = plugin.selectSingleNode("class").getText();
            publicPlugin.setPluginClass(clazz);
            publicPlugin.setName(name);
            try {
                String version = plugin.selectSingleNode("version").getText();
                publicPlugin.setVersion(version);
                String author = plugin.selectSingleNode("author").getText();
                publicPlugin.setAuthor(author);
                Node emailNode = plugin.selectSingleNode("email");
                if (emailNode != null) {
                    publicPlugin.setEmail(emailNode.getText());
                }
                Node descriptionNode = plugin.selectSingleNode("description");
                if (descriptionNode != null) {
                    publicPlugin.setDescription(descriptionNode.getText());
                }
                Node homePageNode = plugin.selectSingleNode("homePage");
                if (homePageNode != null) {
                    publicPlugin.setHomePage(homePageNode.getText());
                }
                Node downloadNode = plugin.selectSingleNode("downloadURL");
                if (downloadNode != null) {
                    String downloadURL = downloadNode.getText();
                    publicPlugin.setDownloadURL(downloadURL);
                }
                Node changeLogNode = plugin.selectSingleNode("changeLog");
                if (changeLogNode != null) {
                    publicPlugin.setChangeLogURL(changeLogNode.getText());
                }
                Node readMeNode = plugin.selectSingleNode("readme");
                if (readMeNode != null) {
                    publicPlugin.setReadMeURL(readMeNode.getText());
                }
                Node smallIcon = plugin.selectSingleNode("smallIcon");
                if (smallIcon != null) {
                    publicPlugin.setSmallIconAvailable(true);
                }
                Node largeIcon = plugin.selectSingleNode("largeIcon");
                if (largeIcon != null) {
                    publicPlugin.setLargeIconAvailable(true);
                }
            } catch (Exception e) {
                Log.error("Error retrieving PluginInformation from xml.", e);
            }
            pluginList.add(publicPlugin);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return pluginList;
}
Also used : SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) Node(org.dom4j.Node) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) PublicPlugin(org.jivesoftware.spark.plugin.PublicPlugin) Document(org.dom4j.Document) DocumentException(org.dom4j.DocumentException)

Example 47 with SAXReader

use of org.dom4j.io.SAXReader in project Spark by igniterealtime.

the class PluginManager method loadInternalPlugins.

/**
 * Loads an internal plugin.
 *
 * @param reader the inputstreamreader for an internal plugin.
 */
private void loadInternalPlugins(InputStreamReader reader) {
    SAXReader saxReader = new SAXReader();
    Document pluginXML = null;
    try {
        pluginXML = saxReader.read(reader);
    } catch (DocumentException e) {
        Log.error(e);
    }
    List<Element> plugins = pluginXML.selectNodes("/plugins/plugin");
    for (final Element plugin : plugins) {
        EventQueue.invokeLater(() -> {
            String clazz = null;
            String name;
            try {
                name = plugin.selectSingleNode("name").getText();
                clazz = plugin.selectSingleNode("class").getText();
                Plugin pluginClass1 = (Plugin) Class.forName(clazz).newInstance();
                Log.debug(name + " has been loaded. Internal plugin.");
                registerPlugin(pluginClass1);
            } catch (Throwable ex) {
                Log.error("Unable to load plugin " + clazz + ".", ex);
            }
        });
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) Element(org.dom4j.Element) Document(org.dom4j.Document) PublicPlugin(org.jivesoftware.spark.plugin.PublicPlugin) Plugin(org.jivesoftware.spark.plugin.Plugin)

Example 48 with SAXReader

use of org.dom4j.io.SAXReader in project Spark by igniterealtime.

the class PluginManager method hasDependencies.

private boolean hasDependencies(File pluginFile) {
    SAXReader saxReader = new SAXReader();
    try {
        final Document pluginXML = saxReader.read(pluginFile);
        final List dependencies = pluginXML.selectNodes("plugin/depends/plugin");
        return dependencies != null && dependencies.size() > 0;
    } catch (DocumentException e) {
        Log.error("Unable to read plugin dependencies from " + pluginFile, e);
        return false;
    }
}
Also used : SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Document(org.dom4j.Document)

Example 49 with SAXReader

use of org.dom4j.io.SAXReader in project sic by belluccifranco.

the class AfipServiceImpl method getFEAuth.

@Override
public FEAuthRequest getFEAuth(String afipNombreServicio, Empresa empresa) {
    FEAuthRequest feAuthRequest = new FEAuthRequest();
    String loginTicketResponse = "";
    byte[] p12file = configuracionDelSistemaService.getConfiguracionDelSistemaPorEmpresa(empresa).getCertificadoAfip();
    if (p12file.length == 0) {
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_cds_certificado_vacio"));
    }
    String p12signer = configuracionDelSistemaService.getConfiguracionDelSistemaPorEmpresa(empresa).getFirmanteCertificadoAfip();
    String p12pass = configuracionDelSistemaService.getConfiguracionDelSistemaPorEmpresa(empresa).getPasswordCertificadoAfip();
    // siempre devuelve por 12hs
    long ticketTime = 3600000L;
    byte[] loginTicketRequest_xml_cms = afipWebServiceSOAPClient.crearCMS(p12file, p12pass, p12signer, afipNombreServicio, ticketTime);
    LoginCms loginCms = new LoginCms();
    loginCms.setIn0(Base64.getEncoder().encodeToString(loginTicketRequest_xml_cms));
    try {
        loginTicketResponse = afipWebServiceSOAPClient.loginCMS(loginCms);
    } catch (WebServiceClientException ex) {
        LOGGER.error(ex.getMessage());
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_token_wsaa_error"));
    }
    try {
        Reader tokenReader = new StringReader(loginTicketResponse);
        Document tokenDoc = new SAXReader(false).read(tokenReader);
        feAuthRequest.setToken(tokenDoc.valueOf("/loginTicketResponse/credentials/token"));
        feAuthRequest.setSign(tokenDoc.valueOf("/loginTicketResponse/credentials/sign"));
        feAuthRequest.setCuit(empresa.getCuip());
    } catch (DocumentException ex) {
        LOGGER.error(ex.getMessage());
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_error_procesando_xml"));
    }
    return feAuthRequest;
}
Also used : FEAuthRequest(afip.wsfe.wsdl.FEAuthRequest) BusinessServiceException(sic.service.BusinessServiceException) WebServiceClientException(org.springframework.ws.client.WebServiceClientException) SAXReader(org.dom4j.io.SAXReader) DocumentException(org.dom4j.DocumentException) StringReader(java.io.StringReader) SAXReader(org.dom4j.io.SAXReader) Reader(java.io.Reader) StringReader(java.io.StringReader) LoginCms(afip.wsaa.wsdl.LoginCms) Document(org.dom4j.Document)

Example 50 with SAXReader

use of org.dom4j.io.SAXReader in project eclipse-cs by checkstyle.

the class ProjectConfigurationFactory method getProjectConfiguration.

private static IProjectConfiguration getProjectConfiguration(InputStream in, IProject project) throws DocumentException, CheckstylePluginException {
    SAXReader reader = new SAXReader();
    Document document = reader.read(in);
    Element root = document.getRootElement();
    String version = root.attributeValue(XMLTags.FORMAT_VERSION_TAG);
    if (!SUPPORTED_VERSIONS.contains(version)) {
        throw new CheckstylePluginException(NLS.bind(Messages.errorUnknownFileFormat, version));
    }
    boolean useSimpleConfig = Boolean.valueOf(root.attributeValue(XMLTags.SIMPLE_CONFIG_TAG)).booleanValue();
    boolean syncFormatter = Boolean.valueOf(root.attributeValue(XMLTags.SYNC_FORMATTER_TAG)).booleanValue();
    List<ICheckConfiguration> checkConfigs = getLocalCheckConfigs(root, project);
    List<FileSet> fileSets = getFileSets(root, checkConfigs);
    List<IFilter> filters = getFilters(root);
    return new ProjectConfiguration(project, checkConfigs, fileSets, filters, useSimpleConfig, syncFormatter);
}
Also used : ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) SAXReader(org.dom4j.io.SAXReader) Element(org.dom4j.Element) Document(org.dom4j.Document) IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException)

Aggregations

SAXReader (org.dom4j.io.SAXReader)322 Document (org.dom4j.Document)256 Element (org.dom4j.Element)195 StringReader (java.io.StringReader)120 DocumentException (org.dom4j.DocumentException)74 Test (org.junit.jupiter.api.Test)74 File (java.io.File)54 List (java.util.List)49 IOException (java.io.IOException)48 InputStream (java.io.InputStream)48 ArrayList (java.util.ArrayList)47 Node (org.dom4j.Node)28 FileInputStream (java.io.FileInputStream)25 HashMap (java.util.HashMap)24 XMLWriter (org.dom4j.io.XMLWriter)22 ByteArrayInputStream (java.io.ByteArrayInputStream)20 URL (java.net.URL)18 OutputFormat (org.dom4j.io.OutputFormat)18 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)17 Test (org.junit.Test)14