Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/main/java/nl/pvanassen/bplist/converter/ConvertToXml.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,37 @@ private static XMLGregorianCalendar fromDate(Date date) {
xmlgc.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
return xmlgc;
}

public static void dig(PrintWriter out, XMLElement xml, int indent){
if(xml == null){
System.out.println("Something's wrong with the pblist input");
return;
}
String name = xml.getName();
// get all attribute
indent(out, indent);
out.print("<" + name);
Iterator<String> attributeNames = xml.enumerateAttributeNames();
while(attributeNames.hasNext()){
String attributeName = attributeNames.next();
out.print(" " + attributeName + "=\"" + xml.getStringAttribute(attributeName) + "\"");
}
out.print(">\n");
Iterator<XMLElement> children = xml.iterateChildren();
if(!children.hasNext()){
indent(out, indent);
out.print(xml.getContent() + "\n");
}
while(children.hasNext()){
XMLElement child = children.next();
dig(out, child, indent + 1);
}
indent(out, indent);
out.print("</" + name + ">\n");
}
private static void indent(PrintWriter out, int indent){
for(int i = 0;i < indent;i++){
out.print("\t");
}
}
}
25 changes: 24 additions & 1 deletion src/test/java/nl/pvanassen/bplist/BinaryPListParserTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package nl.pvanassen.bplist;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.util.List;
import java.util.Scanner;

import nl.pvanassen.bplist.converter.ConvertToXml;
import nl.pvanassen.bplist.ext.nanoxml.XMLElement;
Expand All @@ -21,6 +25,22 @@ private void test(String baseName) throws IOException {
assertEquals(FileHelper.getContent(baseName + ".result"), xmlElement.getChildren().get(0).toString());
}

private void testPrettyPrint(String baseName) throws IOException {
List<BPListElement<?>> elements = elementParser.parseObjectTable(FileHelper.getFile(baseName + ".bplist"));
XMLElement xmlElement = convetToXml.convertToXml(elements);
assertNotNull(xmlElement);
ByteArrayOutputStream outputBufferBOS = new ByteArrayOutputStream();
PrintWriter outputBufferPW = new PrintWriter(outputBufferBOS);
convetToXml.dig(outputBufferPW, xmlElement, 0);
outputBufferPW.close();
String output = "";
Scanner outputBufferScanner = new Scanner(new ByteArrayInputStream(outputBufferBOS.toByteArray()));
while(outputBufferScanner.hasNextLine()){
output += outputBufferScanner.nextLine() + "\n";
}
assertEquals(FileHelper.getContent(baseName + ".resultPrettyPrint"), output);
}

@Test
public void testAirplay() throws IOException {
test("airplay");
Expand Down Expand Up @@ -48,5 +68,8 @@ public void testUID() throws IOException {
public void testUTF16() throws IOException {
test("utf16");
}

@Test
public void testAirplayPrettyPrint() throws IOException {
testPrettyPrint("airplay");
}
}
84 changes: 84 additions & 0 deletions src/test/resources/airplay.resultPrettyPrint
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<plist version="1.0">
<dict>
<key>
duration
</key>
<real>
5555.0495
</real>
<key>
loadedTimeRanges
</key>
<array>
<dict>
<key>
duration
</key>
<real>
5555.0495
</real>
<key>
start
</key>
<real>
0.0
</real>
</dict>
</array>
<key>
seekableTimeRanges
</key>
<array>
<dict>
<key>
duration
</key>
<real>
5555.0495
</real>
<key>
start
</key>
<real>
0.0
</real>
</dict>
</array>
<key>
playbackBufferFull
</key>
<boolean>
false
</boolean>
<key>
readyToPlay
</key>
<boolean>
true
</boolean>
<key>
rate
</key>
<real>
1.0
</real>
<key>
playbackLikelyToKeepUp
</key>
<boolean>
true
</boolean>
<key>
playbackBufferEmpty
</key>
<boolean>
true
</boolean>
<key>
position
</key>
<real>
4.626998904
</real>
</dict>
</plist>