Search in sources :

Example 11 with SAXBuilder

use of org.jdom.input.SAXBuilder in project libresonic by Libresonic.

the class LyricsService method parseSearchResult.

private LyricsInfo parseSearchResult(String xml) throws Exception {
    SAXBuilder builder = new SAXBuilder();
    Document document = builder.build(new StringReader(xml));
    Element root = document.getRootElement();
    Namespace ns = root.getNamespace();
    String lyric = StringUtils.trimToNull(root.getChildText("Lyric", ns));
    String song = root.getChildText("LyricSong", ns);
    String artist = root.getChildText("LyricArtist", ns);
    return new LyricsInfo(lyric, artist, song);
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) StringReader(java.io.StringReader) Document(org.jdom.Document) Namespace(org.jdom.Namespace)

Example 12 with SAXBuilder

use of org.jdom.input.SAXBuilder in project libresonic by Libresonic.

the class PodcastService method doRefreshChannel.

@SuppressWarnings({ "unchecked" })
private void doRefreshChannel(PodcastChannel channel, boolean downloadEpisodes) {
    InputStream in = null;
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        channel.setStatus(PodcastStatus.DOWNLOADING);
        channel.setErrorMessage(null);
        podcastDao.updateChannel(channel);
        RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(// 2 minutes
        2 * 60 * 1000).setSocketTimeout(// 10 minutes
        10 * 60 * 1000).build();
        HttpGet method = new HttpGet(channel.getUrl());
        method.setConfig(requestConfig);
        try (CloseableHttpResponse response = client.execute(method)) {
            in = response.getEntity().getContent();
            Document document = new SAXBuilder().build(in);
            Element channelElement = document.getRootElement().getChild("channel");
            channel.setTitle(StringUtil.removeMarkup(channelElement.getChildTextTrim("title")));
            channel.setDescription(StringUtil.removeMarkup(channelElement.getChildTextTrim("description")));
            channel.setImageUrl(getChannelImageUrl(channelElement));
            channel.setStatus(PodcastStatus.COMPLETED);
            channel.setErrorMessage(null);
            podcastDao.updateChannel(channel);
            downloadImage(channel);
            refreshEpisodes(channel, channelElement.getChildren("item"));
        }
    } catch (Exception x) {
        LOG.warn("Failed to get/parse RSS file for Podcast channel " + channel.getUrl(), x);
        channel.setStatus(PodcastStatus.ERROR);
        channel.setErrorMessage(getErrorMessage(x));
        podcastDao.updateChannel(channel);
    } finally {
        IOUtils.closeQuietly(in);
    }
    if (downloadEpisodes) {
        for (final PodcastEpisode episode : getEpisodes(channel.getId())) {
            if (episode.getStatus() == PodcastStatus.NEW && episode.getUrl() != null) {
                downloadEpisode(episode);
            }
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) RequestConfig(org.apache.http.client.config.RequestConfig) SAXBuilder(org.jdom.input.SAXBuilder) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) Element(org.jdom.Element) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) Document(org.jdom.Document) PodcastEpisode(org.libresonic.player.domain.PodcastEpisode)

Example 13 with SAXBuilder

use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.

the class GuiTestBase method cleanUpProjectForImport.

protected void cleanUpProjectForImport(@NotNull File projectPath) {
    File dotIdeaFolderPath = new File(projectPath, Project.DIRECTORY_STORE_FOLDER);
    if (dotIdeaFolderPath.isDirectory()) {
        File modulesXmlFilePath = new File(dotIdeaFolderPath, "modules.xml");
        if (modulesXmlFilePath.isFile()) {
            SAXBuilder saxBuilder = new SAXBuilder();
            try {
                Document document = saxBuilder.build(modulesXmlFilePath);
                XPath xpath = XPath.newInstance("//*[@fileurl]");
                //noinspection unchecked
                List<Element> modules = xpath.selectNodes(document);
                int urlPrefixSize = "file://$PROJECT_DIR$/".length();
                for (Element module : modules) {
                    String fileUrl = module.getAttributeValue("fileurl");
                    if (!StringUtil.isEmpty(fileUrl)) {
                        String relativePath = toSystemDependentName(fileUrl.substring(urlPrefixSize));
                        File imlFilePath = new File(projectPath, relativePath);
                        if (imlFilePath.isFile()) {
                            delete(imlFilePath);
                        }
                        // It is likely that each module has a "build" folder. Delete it as well.
                        File buildFilePath = new File(imlFilePath.getParentFile(), "build");
                        if (buildFilePath.isDirectory()) {
                            delete(buildFilePath);
                        }
                    }
                }
            } catch (Throwable ignored) {
            // if something goes wrong, just ignore. Most likely it won't affect project import in any way.
            }
        }
        delete(dotIdeaFolderPath);
    }
}
Also used : XPath(org.jdom.xpath.XPath) SAXBuilder(org.jdom.input.SAXBuilder) Element(org.jdom.Element) Document(org.jdom.Document) VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtil.findFileByIoFile(com.intellij.openapi.vfs.VfsUtil.findFileByIoFile) File(java.io.File)

Example 14 with SAXBuilder

use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.

the class JDOMUtil method getSaxBuilder.

private static SAXBuilder getSaxBuilder() {
    SoftReference<SAXBuilder> reference = ourSaxBuilder.get();
    SAXBuilder saxBuilder = com.intellij.reference.SoftReference.dereference(reference);
    if (saxBuilder == null) {
        saxBuilder = new SAXBuilder() {

            @Override
            protected void configureParser(XMLReader parser, SAXHandler contentHandler) throws JDOMException {
                super.configureParser(parser, contentHandler);
                try {
                    parser.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
                } catch (Exception ignore) {
                }
            }
        };
        saxBuilder.setEntityResolver(new EntityResolver() {

            @Override
            @NotNull
            public InputSource resolveEntity(String publicId, String systemId) {
                return new InputSource(new CharArrayReader(ArrayUtil.EMPTY_CHAR_ARRAY));
            }
        });
        ourSaxBuilder.set(new SoftReference<SAXBuilder>(saxBuilder));
    }
    return saxBuilder;
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) InputSource(org.xml.sax.InputSource) SAXHandler(org.jdom.input.SAXHandler) EntityResolver(org.xml.sax.EntityResolver) NotNull(org.jetbrains.annotations.NotNull) XMLReader(org.xml.sax.XMLReader)

Example 15 with SAXBuilder

use of org.jdom.input.SAXBuilder in project intellij-community by JetBrains.

the class ModelGen method loadXml.

public static Element loadXml(File configXml) throws Exception {
    SAXBuilder saxBuilder = new SAXBuilder();
    saxBuilder.setEntityResolver(new EntityResolver() {

        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            return new InputSource(new CharArrayReader(new char[0]));
        }
    });
    final Document document = saxBuilder.build(configXml);
    return document.getRootElement();
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) InputSource(org.xml.sax.InputSource) XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource) CharArrayReader(java.io.CharArrayReader) XMLEntityResolver(org.apache.xerces.xni.parser.XMLEntityResolver) EntityResolver(org.xml.sax.EntityResolver) IOException(java.io.IOException) Document(org.jdom.Document) SAXException(org.xml.sax.SAXException)

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