add support parsing swf-metadata to swfparser

flash supports metadata tag in swf file with metadata in xmp (xml) format.
parse some common data to include it in the head section of the html string
of converttohtml.
pull/41/merge
reger 9 years ago
parent 11b1587067
commit 06e5cd6164

Binary file not shown.

@ -52,5 +52,11 @@
<version>1.5</version> <version>1.5</version>
<type>jar</type> <type>jar</type>
</dependency> </dependency>
<dependency>
<groupId>com.adobe.xmp</groupId>
<artifactId>xmpcore</artifactId>
<version>5.1.2</version>
<type>jar</type>
</dependency>
</dependencies> </dependencies>
</project> </project>

@ -1,5 +1,10 @@
package pt.tumba.parser.swf; package pt.tumba.parser.swf;
import com.adobe.xmp.XMPConst;
import com.adobe.xmp.XMPException;
import com.adobe.xmp.XMPMeta;
import com.adobe.xmp.XMPMetaFactory;
import com.adobe.xmp.properties.XMPProperty;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -34,15 +39,9 @@ public class SWF2HTML extends SWFTagTypesImpl {
} }
/**
* Description of the Field
*/
protected Map fontCodes = new HashMap(); protected Map fontCodes = new HashMap();
protected String headerstr ="";
/** protected PrintWriter output; // body of html output (containing all text)
* Description of the Field
*/
protected PrintWriter output;
//private HTMLParser aux; //private HTMLParser aux;
@ -159,6 +158,65 @@ public class SWF2HTML extends SWFTagTypesImpl {
return new TextDumper(); return new TextDumper();
} }
/**
* Parse and interprete Metadata string (xmp rdf format) and create a
* html header tags for the html output
*
* @param xml Metadata
* @throws IOException
*/
@Override
public void tagMetaData(String xml) throws IOException {
try {
XMPMeta xmpmeta = XMPMetaFactory.parseFromString(xml);
XMPProperty xp = xmpmeta.getProperty(XMPConst.NS_DC, "title");
if (xp != null) {
headerstr = "<title>" + xp.getValue() + "</title>";
}
xp = xmpmeta.getProperty(XMPConst.NS_DC, "creator");
if (xp != null) {
headerstr += "<meta name=\"author\" content=\"" + xp.getValue() + "\">";
}
xp = xmpmeta.getProperty(XMPConst.NS_DC, "description");
if (xp != null) {
headerstr += "<meta name=\"description\" content=\"" + xp.getValue() + "\">";
}
xp = xmpmeta.getProperty(XMPConst.NS_DC, "subject");
if (xp != null) {
headerstr += "<meta name=\"keywords\" content=\"" + xp.getValue() + "\">";
}
// get a date (modified , created)
xp = xmpmeta.getProperty(XMPConst.NS_XMP, "ModifyDate");
if (xp != null) {
headerstr += "<meta name=\"date\" content=\"" + xp.getValue() + "\">";
} else {
xp = xmpmeta.getProperty(XMPConst.NS_XMP, "CreateDate");
if (xp != null) {
headerstr += "<meta name=\"date\" content=\"" + xp.getValue() + "\">";
} else {
xp = xmpmeta.getProperty(XMPConst.NS_DC, "date");
if (xp != null) {
headerstr += "<meta name=\"date\" content=\"" + xp.getValue() + "\">";
}
}
}
xp = xmpmeta.getProperty(XMPConst.NS_XMP, "CreatorTool");
if (xp != null) {
headerstr += "<meta name=\"generator\" content=\"" + xp.getValue() + "\">";
}
xp = xmpmeta.getProperty(XMPConst.NS_DC, "publisher");
if (xp != null) {
headerstr += "<meta name=\"publisher\" content=\"" + xp.getValue() + "\">";
}
} catch (XMPException ex) { }
}
/** /**
* Description of the Class * Description of the Class
@ -167,13 +225,8 @@ public class SWF2HTML extends SWFTagTypesImpl {
*@created 15 de Setembro de 2002 *@created 15 de Setembro de 2002
*/ */
public class TextDumper implements SWFText { public class TextDumper implements SWFText {
/**
* Description of the Field
*/
protected Integer fontId; protected Integer fontId;
/**
* Description of the Field
*/
protected boolean firstY = true; protected boolean firstY = true;
@ -285,23 +338,26 @@ public class SWF2HTML extends SWFTagTypesImpl {
/** /**
* Arguments are: 0. Name of input SWF * Parses swf input and extracts text and wrap it as html
* *
*@param in Description of the Parameter * @param in SWF inputstream
*@return Description of the Return Value * @return html of text in swf
*@exception Exception Description of the Exception * @exception Exception Description of the Exception
*/ */
public String convertSWFToHTML(InputStream in) throws Exception { public String convertSWFToHTML(InputStream in) throws Exception {
StringWriter out1 = new StringWriter(); StringWriter out1 = new StringWriter();
output = new PrintWriter(out1); output = new PrintWriter(out1);
output.println("<html><body>");
TagParser parser = new TagParser(this); TagParser parser = new TagParser(this);
SWFReader reader = new SWFReader(parser, in); SWFReader reader = new SWFReader(parser, in);
reader.readFile(); reader.readFile();
in.close(); in.close();
output.println("</body></html>");
sizeCount = reader.size; sizeCount = reader.size;
return out1.toString(); // generate html output string
final String ret = "<html>"
+ (headerstr.isEmpty() ? "<body>" : "<header>" + headerstr + "</header><body>")
+ out1.toString()
+ "</body></html>";
return ret;
} }

@ -425,4 +425,14 @@ public interface SWFTagTypes extends SWFSpriteTagTypes {
*@exception IOException Description of the Exception *@exception IOException Description of the Exception
*/ */
public void tagGeneratorFont(byte[] data) throws IOException; public void tagGeneratorFont(byte[] data) throws IOException;
/**
* Metadata such as title in xml format
* The format of the metadata is RDF that is compliant with Adobes
* Extensible Metadata Platform (XMP) specification.
*
* @param data xml data as string
* @throws IOException
*/
public void tagMetaData(String data) throws IOException;
} }

@ -881,4 +881,20 @@ public class SWFTagTypesImpl implements SWFTagTypes {
colors, imageData); colors, imageData);
} }
} }
/**
* SWFTagTypes METADATA
* Metadata such as title in xml format
* The format of the metadata is RDF that is compliant with Adobes
* Extensible Metadata Platform (XMP) specification.
*
* @param data xml data as string
* @throws IOException
*/
@Override
public void tagMetaData (String xml) throws IOException {
if (tags != null) {
tags.tagMetaData(xml);
}
}
} }

@ -200,11 +200,14 @@ public class TagParser implements SWFTags, SWFConstants {
parseDefineBits(in); parseDefineBits(in);
break; break;
case TAG_JPEGTABLES: case TAG_JPEGTABLES:
//parseDefineJPEGTables(in); // TODO: content length=0 (in==null) occurs for unknown reason - find out! if (in != null) parseDefineJPEGTables(in); // TODO: content length=0 (in==null) occurs for unknown reason - find out!
break; break;
case TAG_DEFINEBITSJPEG3: case TAG_DEFINEBITSJPEG3:
parseDefineBitsJPEG3(in); parseDefineBitsJPEG3(in);
break; break;
case TAG_METADATA:
if (in != null) parseMetaData(in);
break;
default: default:
//--Unknown Tag Type //--Unknown Tag Type
tagtypes.tag(tagType, longTag, contents); tagtypes.tag(tagType, longTag, contents);
@ -366,6 +369,15 @@ public class TagParser implements SWFTags, SWFConstants {
tagtypes.tagDefineBitsJPEG3(id, imageData, alphaData); tagtypes.tagDefineBitsJPEG3(id, imageData, alphaData);
} }
/**
* parse METADATA tag (TAG_METADATA = 77)
* @param in
* @throws IOException
*/
protected void parseMetaData(InStream in) throws IOException {
String xmlMetaData = in.readString();
tagtypes.tagMetaData(xmlMetaData);
}
/** /**
* Description of the Method * Description of the Method

@ -1203,6 +1203,12 @@ public class TagWriter implements SWFTagTypes, SWFConstants {
} }
@Override
public void tagMetaData (String xml) throws IOException {
startTag(TAG_METADATA, true);
out.writeString(xml);
completeTag();
}
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
/** /**

Loading…
Cancel
Save