Search in sources :

Example 21 with Element

use of org.jdom.Element in project symmetric-ds by JumpMind.

the class XmlPublisherDatabaseWriterFilter method beforeWrite.

public boolean beforeWrite(DataContext context, Table table, CsvData data) {
    if (tableNamesToPublishAsGroup == null || tableNamesToPublishAsGroup.contains(table.getName())) {
        String[] rowData = data.getParsedData(CsvData.ROW_DATA);
        if (data.getDataEventType() == DataEventType.DELETE) {
            rowData = data.getParsedData(CsvData.OLD_DATA);
        }
        Element xml = getXmlFromCache(context, context.getBatch().getBinaryEncoding(), table.getColumnNames(), rowData, table.getPrimaryKeyColumnNames(), data.getParsedData(CsvData.PK_DATA));
        if (xml != null) {
            toXmlElement(data.getDataEventType(), xml, table.getCatalog(), table.getSchema(), table.getName(), table.getColumnNames(), rowData, table.getPrimaryKeyColumnNames(), data.getParsedData(CsvData.PK_DATA));
        }
    }
    return loadDataInTargetDatabase;
}
Also used : Element(org.jdom.Element)

Example 22 with Element

use of org.jdom.Element in project symmetric-ds by JumpMind.

the class XmlPublisherDataRouter method routeToNodes.

public Set<String> routeToNodes(SimpleRouterContext context, DataMetaData dataMetaData, Set<Node> nodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter) {
    Data data = dataMetaData.getData();
    if (tableNamesToPublishAsGroup == null || tableNamesToPublishAsGroup.contains(data.getTableName())) {
        String[] rowData = data.getParsedData(CsvData.ROW_DATA);
        if (data.getDataEventType() == DataEventType.DELETE) {
            rowData = data.getParsedData(CsvData.OLD_DATA);
        }
        TriggerHistory triggerHistory = dataMetaData.getTriggerHistory();
        Element xml = getXmlFromCache(context, engine.getSymmetricDialect().getBinaryEncoding(), triggerHistory.getParsedColumnNames(), rowData, triggerHistory.getParsedPkColumnNames(), data.toParsedPkData());
        if (xml != null) {
            toXmlElement(data.getDataEventType(), xml, triggerHistory.getSourceCatalogName(), triggerHistory.getSourceSchemaName(), data.getTableName(), triggerHistory.getParsedColumnNames(), rowData, triggerHistory.getParsedPkColumnNames(), data.toParsedPkData());
        }
    } else if (log.isDebugEnabled()) {
        log.debug("'{}' not in list to publish", data.getTableName());
    }
    return Collections.emptySet();
}
Also used : Element(org.jdom.Element) CsvData(org.jumpmind.symmetric.io.data.CsvData)

Example 23 with Element

use of org.jdom.Element in project symmetric-ds by JumpMind.

the class AbstractXmlPublisherExtensionPoint method finalizeXmlAndPublish.

protected void finalizeXmlAndPublish(Context context) {
    Map<String, Element> contextCache = getXmlCache(context);
    Collection<Element> buffers = contextCache.values();
    for (Iterator<Element> iterator = buffers.iterator(); iterator.hasNext(); ) {
        String xml = new XMLOutputter(xmlFormat).outputString(new Document(iterator.next()));
        log.debug("Sending XML to IPublisher: {}", xml);
        iterator.remove();
        long ts = System.currentTimeMillis();
        publisher.publish(context, xml.toString());
        amountOfTimeToPublishMessagesSinceLastPrintTime += (System.currentTimeMillis() - ts);
        numberOfMessagesPublishedSinceLastPrintTime++;
    }
    if ((System.currentTimeMillis() - lastStatisticsPrintTime) > timeBetweenStatisticsPrintTime) {
        synchronized (this) {
            if ((System.currentTimeMillis() - lastStatisticsPrintTime) > timeBetweenStatisticsPrintTime) {
                log.info(name + " published " + numberOfMessagesPublishedSinceLastPrintTime + " messages in the last " + (System.currentTimeMillis() - lastStatisticsPrintTime) / 1000 + " seconds.  Spent " + (amountOfTimeToPublishMessagesSinceLastPrintTime / numberOfMessagesPublishedSinceLastPrintTime) + "ms of publishing time per message");
                lastStatisticsPrintTime = System.currentTimeMillis();
                numberOfMessagesPublishedSinceLastPrintTime = 0;
                amountOfTimeToPublishMessagesSinceLastPrintTime = 0;
            }
        }
    }
}
Also used : XMLOutputter(org.jdom.output.XMLOutputter) Element(org.jdom.Element) Document(org.jdom.Document)

Example 24 with Element

use of org.jdom.Element 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 25 with Element

use of org.jdom.Element 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)

Aggregations

Element (org.jdom.Element)1236 NotNull (org.jetbrains.annotations.NotNull)103 Nullable (org.jetbrains.annotations.Nullable)98 IOException (java.io.IOException)81 ArrayList (java.util.ArrayList)76 List (java.util.List)70 VirtualFile (com.intellij.openapi.vfs.VirtualFile)67 Document (org.jdom.Document)67 File (java.io.File)64 JDOMException (org.jdom.JDOMException)53 PsiElement (com.intellij.psi.PsiElement)44 SAXBuilder (org.jdom.input.SAXBuilder)40 Attribute (org.jdom.Attribute)32 Iterator (java.util.Iterator)31 InvalidDataException (com.intellij.openapi.util.InvalidDataException)30 WriteExternalException (com.intellij.openapi.util.WriteExternalException)30 THashMap (gnu.trove.THashMap)30 XMLOutputter (org.jdom.output.XMLOutputter)27 JpsElement (org.jetbrains.jps.model.JpsElement)24 NonNls (org.jetbrains.annotations.NonNls)22