mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-16 07:51:08 +01:00
SMACK-541 Fix of XHTMLExtensionProvider on Android
This fixes issue there on android in XHTMLExtension bodys contained "null" instead of actual xhtml tags This happened due to difference in XPP implementation in KXmlPullParser (on Android) MXParser (in other cases) This fix replaces usage of getText method of XPP with restoration of xhtml tags using XPP api.
This commit is contained in:
parent
585e20e93e
commit
06f88674ee
4 changed files with 168 additions and 47 deletions
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2014 Vyacheslav Blinov
|
||||
*
|
||||
* 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.xhtmlim.provider;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smackx.xhtmlim.packet.XHTMLExtension;
|
||||
import org.junit.Test;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
|
||||
public class XHTMLExtensionProviderTest {
|
||||
public static final String XHTML_EXTENSION_SAMPLE_RESOURCE_NAME = "xhtml.xml";
|
||||
|
||||
@Test
|
||||
public void parsesWell() throws IOException, XmlPullParserException {
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(getClass().getResourceAsStream(XHTML_EXTENSION_SAMPLE_RESOURCE_NAME), "UTF-8");
|
||||
parser.next();
|
||||
|
||||
XHTMLExtensionProvider provider = new XHTMLExtensionProvider();
|
||||
PacketExtension extension = provider.parseExtension(parser);
|
||||
|
||||
assertThat(extension, is(instanceOf(XHTMLExtension.class)));
|
||||
XHTMLExtension attachmentsInfo = (XHTMLExtension) extension;
|
||||
|
||||
assertEquals(sampleXhtml(), attachmentsInfo.getBodies().next());
|
||||
}
|
||||
|
||||
private String sampleXhtml() {
|
||||
return "<body xmlns='http://www.w3.org/1999/xhtml'>" +
|
||||
"<span style='color: rgb(0, 0, 0); font-family: sans-serif, 'trebuchet ms'" +
|
||||
", 'lucida grande', 'lucida sans unicode', arial, helvetica, " +
|
||||
"sans-serif; font-weight: 600; line-height: 18px;'>Generic family<br/>AnotherLine</span></body>";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue