Skip to content

Commit

Permalink
Rebase on master
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Dec 27, 2023
1 parent a0a7f4e commit 0c4fd39
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,9 +31,6 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,19 @@
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);
}
Expand All @@ -51,7 +50,7 @@ public List<UrlDataElement> getUrlDataElements() {
return Collections.unmodifiableList(urlDataElements);
}

public List<ExtensionElement> getOtherSourceElements() {
public List<NamedElement> getOtherSourceElements() {
return Collections.unmodifiableList(otherSourceElements);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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;
Expand All @@ -32,8 +32,9 @@
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> {

Expand All @@ -45,24 +46,24 @@ public FileSharingElement parse(XmlPullParser parser, int initialDepth, XmlEnvir
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 {
XmlPullParser.TagEvent innerEvent = parser.nextTag();
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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,7 +32,8 @@
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;

Expand All @@ -34,13 +50,7 @@ public void simpleElementTest() throws XmlPullParserException, IOException, Smac
.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:[email protected]")
.addAttribute("media-type", "image/png")
.addAttribute("width", "128")
.addAttribute("height", "96")
.build())
.addThumbnail(new ThumbnailElement("cid:[email protected]", "image/png", 128, 96))
.build(),
new SourcesElement(Collections.singletonList(
new UrlDataElement(
Expand All @@ -61,7 +71,8 @@ public void simpleElementTest() throws XmlPullParserException, IOException, Smac
" <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" +
Expand Down

0 comments on commit 0c4fd39

Please sign in to comment.