Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Support for XEP-0447: Stateless File Sharing #450

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

vanitasvitae
Copy link
Member

This PR adds initial support (elements and providers) for XEP-0447: Stateless File Sharing

Depends on (and contains) #448 and #449

@Flowdalic Flowdalic added the Needs rebasing All or some commits need to be squashed label Dec 16, 2023
@Flowdalic
Copy link
Member

Needs rebasing now that #448 and #449 are merged. Please also note that a package name was changed (it's now o.j.smackx.uridata).

@vanitasvitae
Copy link
Member Author

I rebased.

Why is StandardExtensionElement no longer extending ExtensionElement btw?
I changed the item type of some lists to NamedElement instead, which is not ideal, but allows me to put StandardExtensionElement instances into it during tests.

Copy link
Member

@Flowdalic Flowdalic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, thanks!

Please also add the XEP entries into the table at smack-java8-full/src/main/java/org/jivesoftware/smackx/package-info.java

Why is StandardExtensionElement no longer extending ExtensionElement btw?

Because ExtensionElement has become a marker interface where all implementing classes must have a static final QNAME field. This invariant is checked by Smack's test suite.

I changed the item type of some lists to NamedElement instead, which is not ideal, but allows me to put StandardExtensionElement instances into it during tests.

I think NamedElement is ideal, as the element is not qualified by an different namespace than its enclosing element.


public class FileSharingElementProvider extends ExtensionElementProvider<FileSharingElement> {

public static final FileSharingElementProvider INSTANCE = new FileSharingElementProvider();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only used by test code, hence it should be declared in the test class.


if (event == XmlPullParser.TagEvent.START_ELEMENT) {
if (name.equals(FileMetadataElement.ELEMENT)) {
fileMetadataElement = new FileMetadataElementProvider().parse(parser, xmlEnvironment);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid the allocation cost, we should create FileMetadataElementProvider.INSTANCE.

List<UrlDataElement> urlDataElements = new ArrayList<>();
List<NamedElement> otherSourceElements = new ArrayList<>();
do {
XmlPullParser.TagEvent event = parser.nextTag();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nextTag() may throw if the parser is before CHARACTERS, please implement the provider using the idiomatic pattern for providers.

@Override
public int hashCode() {
return HashCode.builder()
.append(getElementName())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to mix in the constant element name here? This can probably be implemented as return date.hashCode().

@Override
public boolean equals(Object obj) {
return EqualsUtil.equals(this, obj, (equalsBuilder, other) ->
equalsBuilder.append(getElementName(), other.getElementName())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
equalsBuilder.append(getElementName(), other.getElementName())

As above, I believe it is sufficient to compare the dates of the elements

default:
// Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
break;
case START_ELEMENT:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "just" seems to fix the indentation, which I would keep for now in its broken state and probably fix at some point later.

@Override
public int hashCode() {
return HashCode.builder()
.append(getElementName())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.append(getElementName())

public boolean equals(Object obj) {
return EqualsUtil.equals(this, obj, (equalsBuilder, other) ->
equalsBuilder
.append(getElementName(), other.getElementName())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.append(getElementName(), other.getElementName())

public int hashCode() {
return HashCode.builder()
.append(getElementName())
.append(getNamespace())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.append(getNamespace())

return EqualsUtil.equals(this, obj, (equalsBuilder, other) ->
equalsBuilder
.append(getElementName(), other.getElementName())
.append(getNamespace(), other.getNamespace())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.append(getNamespace(), other.getNamespace())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs rebasing All or some commits need to be squashed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants