mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 03:52:06 +01:00
Rebase on master
This commit is contained in:
parent
a0a7f4e20c
commit
0c4fd3996c
4 changed files with 36 additions and 25 deletions
|
@ -16,6 +16,9 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.file_metadata.provider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
|
@ -28,9 +31,6 @@ import org.jivesoftware.smackx.hashes.provider.HashElementProvider;
|
|||
import org.jivesoftware.smackx.thumbnails.element.ThumbnailElement;
|
||||
import org.jivesoftware.smackx.thumbnails.provider.ThumbnailElementProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
|
||||
public class FileMetadataElementProvider extends ExtensionElementProvider<FileMetadataElement> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,20 +20,19 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.util.XmlStringBuilder;
|
||||
import org.jivesoftware.smackx.url_address_information.element.UrlDataElement;
|
||||
import org.jivesoftware.smackx.urldata.element.UrlDataElement;
|
||||
|
||||
public class SourcesElement implements NamedElement {
|
||||
|
||||
public static final String ELEMENT = "sources";
|
||||
|
||||
private final List<UrlDataElement> urlDataElements = new ArrayList<>();
|
||||
private final List<ExtensionElement> otherSourceElements = new ArrayList<>();
|
||||
private final List<NamedElement> otherSourceElements = new ArrayList<>();
|
||||
|
||||
public SourcesElement(List<UrlDataElement> urlDataElements, List<ExtensionElement> otherSourceElements) {
|
||||
public SourcesElement(List<UrlDataElement> urlDataElements, List<NamedElement> otherSourceElements) {
|
||||
this.urlDataElements.addAll(urlDataElements);
|
||||
this.otherSourceElements.addAll(otherSourceElements);
|
||||
}
|
||||
|
@ -51,7 +50,7 @@ public class SourcesElement implements NamedElement {
|
|||
return Collections.unmodifiableList(urlDataElements);
|
||||
}
|
||||
|
||||
public List<ExtensionElement> getOtherSourceElements() {
|
||||
public List<NamedElement> getOtherSourceElements() {
|
||||
return Collections.unmodifiableList(otherSourceElements);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import java.io.IOException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.ExtensionElement;
|
||||
import org.jivesoftware.smack.packet.NamedElement;
|
||||
import org.jivesoftware.smack.packet.XmlEnvironment;
|
||||
import org.jivesoftware.smack.parsing.SmackParsingException;
|
||||
import org.jivesoftware.smack.parsing.StandardExtensionElementProvider;
|
||||
|
@ -32,8 +32,9 @@ import org.jivesoftware.smackx.file_metadata.element.FileMetadataElement;
|
|||
import org.jivesoftware.smackx.file_metadata.provider.FileMetadataElementProvider;
|
||||
import org.jivesoftware.smackx.stateless_file_sharing.element.FileSharingElement;
|
||||
import org.jivesoftware.smackx.stateless_file_sharing.element.SourcesElement;
|
||||
import org.jivesoftware.smackx.url_address_information.element.UrlDataElement;
|
||||
import org.jivesoftware.smackx.url_address_information.provider.UrlDataElementProvider;
|
||||
import org.jivesoftware.smackx.urldata.element.UrlDataElement;
|
||||
import org.jivesoftware.smackx.urldata.provider.UrlDataElementProvider;
|
||||
|
||||
|
||||
public class FileSharingElementProvider extends ExtensionElementProvider<FileSharingElement> {
|
||||
|
||||
|
@ -45,14 +46,14 @@ public class FileSharingElementProvider extends ExtensionElementProvider<FileSha
|
|||
FileMetadataElement fileMetadataElement = null;
|
||||
SourcesElement sourcesElement = null;
|
||||
List<UrlDataElement> urlDataElements = new ArrayList<>();
|
||||
List<ExtensionElement> otherSourceElements = new ArrayList<>();
|
||||
List<NamedElement> otherSourceElements = new ArrayList<>();
|
||||
do {
|
||||
XmlPullParser.TagEvent event = parser.nextTag();
|
||||
String name = parser.getName();
|
||||
|
||||
if (event == XmlPullParser.TagEvent.START_ELEMENT) {
|
||||
if (name.equals(FileMetadataElement.ELEMENT)) {
|
||||
fileMetadataElement = FileMetadataElementProvider.TEST_INSTANCE.parse(parser, xmlEnvironment);
|
||||
fileMetadataElement = new FileMetadataElementProvider().parse(parser, xmlEnvironment);
|
||||
} else if (name.equals(SourcesElement.ELEMENT)) {
|
||||
int innerDepth = parser.getDepth();
|
||||
do {
|
||||
|
@ -60,9 +61,9 @@ public class FileSharingElementProvider extends ExtensionElementProvider<FileSha
|
|||
String innerName = parser.getName();
|
||||
if (innerEvent.equals(XmlPullParser.TagEvent.START_ELEMENT)) {
|
||||
if (innerName.equals(UrlDataElement.ELEMENT)) {
|
||||
urlDataElements.add(UrlDataElementProvider.INSTANCE.parse(parser));
|
||||
urlDataElements.add(new UrlDataElementProvider().parse(parser));
|
||||
} else {
|
||||
ExtensionElementProvider<?> provider = ProviderManager.getExtensionProvider(innerName, parser.getNamespace());
|
||||
ExtensionElementProvider<? extends NamedElement> provider = ProviderManager.getExtensionProvider(innerName, parser.getNamespace());
|
||||
if (provider == null) {
|
||||
provider = new StandardExtensionElementProvider();
|
||||
}
|
||||
|
|
|
@ -1,7 +1,22 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2020 Paul Schaub
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.stateless_file_sharing;
|
||||
|
||||
import static org.jivesoftware.smack.test.util.XmlAssertUtil.assertXmlSimilar;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
@ -17,7 +32,8 @@ import org.jivesoftware.smackx.hashes.element.HashElement;
|
|||
import org.jivesoftware.smackx.stateless_file_sharing.element.FileSharingElement;
|
||||
import org.jivesoftware.smackx.stateless_file_sharing.element.SourcesElement;
|
||||
import org.jivesoftware.smackx.stateless_file_sharing.provider.FileSharingElementProvider;
|
||||
import org.jivesoftware.smackx.url_address_information.element.UrlDataElement;
|
||||
import org.jivesoftware.smackx.thumbnails.element.ThumbnailElement;
|
||||
import org.jivesoftware.smackx.urldata.element.UrlDataElement;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -34,13 +50,7 @@ public class FileSharingElementTest extends SmackTestSuite {
|
|||
.addHash(new HashElement(HashManager.ALGORITHM.SHA3_256, "2XarmwTlNxDAMkvymloX3S5+VbylNrJt/l5QyPa+YoU="))
|
||||
.addHash(new HashElement(HashManager.ALGORITHM.BLAKE2B256, "2AfMGH8O7UNPTvUVAM9aK13mpCY="))
|
||||
.addDescription("Photo from the summit.")
|
||||
.addOtherChildElement(
|
||||
StandardExtensionElement.builder("thumbnail", "urn:xmpp:thumbs:1")
|
||||
.addAttribute("uri", "cid:sha1+ffd7c8d28e9c5e82afea41f97108c6b4@bob.xmpp.org")
|
||||
.addAttribute("media-type", "image/png")
|
||||
.addAttribute("width", "128")
|
||||
.addAttribute("height", "96")
|
||||
.build())
|
||||
.addThumbnail(new ThumbnailElement("cid:sha1+ffd7c8d28e9c5e82afea41f97108c6b4@bob.xmpp.org", "image/png", 128, 96))
|
||||
.build(),
|
||||
new SourcesElement(Collections.singletonList(
|
||||
new UrlDataElement(
|
||||
|
@ -61,7 +71,8 @@ public class FileSharingElementTest extends SmackTestSuite {
|
|||
" <media-type>image/jpeg</media-type>\n" +
|
||||
" <name>summit.jpg</name>\n" +
|
||||
" <size>3032449</size>\n" +
|
||||
" <dimensions>4096x2160</dimensions>\n" +
|
||||
" <width>4096</width>\n" +
|
||||
" <height>2160</height>\n" +
|
||||
" <hash xmlns='urn:xmpp:hashes:2' algo='sha3-256'>2XarmwTlNxDAMkvymloX3S5+VbylNrJt/l5QyPa+YoU=</hash>\n" +
|
||||
" <hash xmlns='urn:xmpp:hashes:2' algo='id-blake2b256'>2AfMGH8O7UNPTvUVAM9aK13mpCY=</hash>\n" +
|
||||
" <desc>Photo from the summit.</desc>\n" +
|
||||
|
|
Loading…
Reference in a new issue