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;
}
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();
}
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;
}
}
}
}
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);
}
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);
}
}
}
}
Aggregations