HeaderElement.java

  1. /**
  2.  *
  3.  * Copyright 2020 Paul Schaub
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.urldata.http.element;

  18. import org.jivesoftware.smack.packet.XmlEnvironment;
  19. import org.jivesoftware.smack.util.EqualsUtil;
  20. import org.jivesoftware.smack.util.HashCode;
  21. import org.jivesoftware.smack.util.XmlStringBuilder;

  22. public class HeaderElement extends NameValuePairElement {

  23.     public static final String ELEMENT = "header";
  24.     public static final String PREFIX = "http";

  25.     public HeaderElement(String name, String value) {
  26.         super(name, value);
  27.     }

  28.     @Override
  29.     public XmlStringBuilder toXML(XmlEnvironment xmlEnvironment) {
  30.         return addCommonXml(new XmlStringBuilder(this))
  31.                 .closeEmptyElement();
  32.     }

  33.     @Override
  34.     public String getElementName() {
  35.         return PREFIX + ':' + ELEMENT;
  36.     }

  37.     @Override
  38.     public int hashCode() {
  39.         return HashCode.builder()
  40.                 .append(getElementName())
  41.                 .append(getName())
  42.                 .append(getValue())
  43.                 .build();
  44.     }

  45.     @Override
  46.     public boolean equals(Object obj) {
  47.         return EqualsUtil.equals(this, obj, (equalsBuilder, other) ->
  48.                 equalsBuilder
  49.                         .append(getElementName(), other.getElementName())
  50.                         .append(getName(), other.getName())
  51.                         .append(getValue(), other.getValue()));
  52.     }
  53. }