summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkitfox2008-02-28 07:46:15 +0100
committerkitfox2008-02-28 07:46:15 +0100
commit9551fc304e04f5014746eb4631aadf7953b46a83 (patch)
treed82236a587003b328960914fddc9bd4b39626a2e
parentUpdated color parsing to handle rgb percentages (diff)
downloadsvg-salamander-core-9551fc304e04f5014746eb4631aadf7953b46a83.tar.gz
svg-salamander-core-9551fc304e04f5014746eb4631aadf7953b46a83.tar.xz
svg-salamander-core-9551fc304e04f5014746eb4631aadf7953b46a83.zip
Added Base64 stream codecs. Added Main-Class attribute to generated jars.
git-svn-id: https://svn.java.net/svn/svgsalamander~svn/trunk/svg-core@52 7dc7fa77-23fb-e6ad-8e2e-c86bd48ed22b
-rwxr-xr-xbuild.xml6
-rwxr-xr-xnbproject/build-impl.xml12
-rwxr-xr-xnbproject/genfiles.properties4
-rwxr-xr-xnbproject/project.properties2
-rwxr-xr-xnbproject/project.xml1
-rw-r--r--src/main/java/com/kitfox/svg/ImageSVG.java9
-rwxr-xr-xsrc/main/java/com/kitfox/svg/xml/Base64InputStream.java82
-rwxr-xr-xsrc/main/java/com/kitfox/svg/xml/Base64OutputStream.java90
-rwxr-xr-xsrc/main/java/com/kitfox/svg/xml/Base64Util.java32
-rw-r--r--src/main/java/com/kitfox/svg/xml/StyleAttribute.java2
10 files changed, 233 insertions, 7 deletions
diff --git a/build.xml b/build.xml
index 16e2b14..74bb53c 100755
--- a/build.xml
+++ b/build.xml
@@ -93,6 +93,12 @@
</target>
<target name="-post-jar">
+ <jar destfile="${dist.jar}" update="true">
+ <manifest>
+ <attribute name="Main-Class" value="com.kitfox.svg.app.SVGPlayer"/>
+ </manifest>
+ </jar>
+
<delete file="${key.location}"/>
<genkey alias="${key.user}" storepass="${key.password}" keystore="${key.location}" validity="1000" verbose="true">
<dname>
diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml
index 1bf7540..02bb0a6 100755
--- a/nbproject/build-impl.xml
+++ b/nbproject/build-impl.xml
@@ -90,6 +90,7 @@ is divided into following sections:
</condition>
<condition property="have.sources">
<or>
+ <available file="${src.www.dir}"/>
<available file="${src.dir}"/>
<available file="${src.java.dir}"/>
<available file="${src.res.dir}"/>
@@ -147,6 +148,7 @@ is divided into following sections:
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="-pre-init,-init-private,-init-libraries,-init-user,-init-project,-do-init" name="-init-check">
+ <fail unless="src.www.dir">Must set src.www.dir</fail>
<fail unless="src.dir">Must set src.dir</fail>
<fail unless="src.java.dir">Must set src.java.dir</fail>
<fail unless="src.res.dir">Must set src.res.dir</fail>
@@ -173,7 +175,7 @@ is divided into following sections:
</target>
<target name="-init-macrodef-javac">
<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
- <attribute default="${src.dir}:${src.java.dir}:${src.res.dir}:${res.dir}" name="srcdir"/>
+ <attribute default="${src.www.dir}:${src.dir}:${src.java.dir}:${src.res.dir}:${res.dir}" name="srcdir"/>
<attribute default="${build.classes.dir}" name="destdir"/>
<attribute default="${javac.classpath}" name="classpath"/>
<attribute default="${includes}" name="includes"/>
@@ -192,7 +194,7 @@ is divided into following sections:
</sequential>
</macrodef>
<macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
- <attribute default="${src.dir}:${src.java.dir}:${src.res.dir}:${res.dir}" name="srcdir"/>
+ <attribute default="${src.www.dir}:${src.dir}:${src.java.dir}:${src.res.dir}:${res.dir}" name="srcdir"/>
<attribute default="${build.classes.dir}" name="destdir"/>
<attribute default="${javac.classpath}" name="classpath"/>
<sequential>
@@ -352,6 +354,7 @@ is divided into following sections:
<target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-compile-depend" if="have.sources" name="-do-compile">
<j2seproject3:javac/>
<copy todir="${build.classes.dir}">
+ <fileset dir="${src.www.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
<fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
<fileset dir="${src.java.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
<fileset dir="${src.res.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
@@ -370,7 +373,7 @@ is divided into following sections:
<target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
<j2seproject3:force-recompile/>
- <j2seproject3:javac excludes="" includes="${javac.includes}" sourcepath="${src.dir}:${src.java.dir}:${src.res.dir}:${res.dir}"/>
+ <j2seproject3:javac excludes="" includes="${javac.includes}" sourcepath="${src.www.dir}:${src.dir}:${src.java.dir}:${src.res.dir}:${res.dir}"/>
</target>
<target name="-post-compile-single">
<!-- Empty placeholder for easier customization. -->
@@ -504,6 +507,9 @@ is divided into following sections:
<classpath>
<path path="${javac.classpath}"/>
</classpath>
+ <fileset dir="${src.www.dir}" excludes="${excludes}" includes="${includes}">
+ <filename name="**/*.java"/>
+ </fileset>
<fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
<filename name="**/*.java"/>
</fileset>
diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties
index 345b3d4..9d45de5 100755
--- a/nbproject/genfiles.properties
+++ b/nbproject/genfiles.properties
@@ -3,6 +3,6 @@ build.xml.script.CRC32=91ddbaab
build.xml.stylesheet.CRC32=be360661
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
-nbproject/build-impl.xml.data.CRC32=f852a4d9
-nbproject/build-impl.xml.script.CRC32=7235f0eb
+nbproject/build-impl.xml.data.CRC32=478066e1
+nbproject/build-impl.xml.script.CRC32=a04a2883
nbproject/build-impl.xml.stylesheet.CRC32=e327d66c
diff --git a/nbproject/project.properties b/nbproject/project.properties
index 5bb10d9..e09d66c 100755
--- a/nbproject/project.properties
+++ b/nbproject/project.properties
@@ -22,6 +22,7 @@ file.reference.ant.jar=..\\libraries\\ant.jar
file.reference.javacc.jar=..\\libraries\\javacc.jar
file.reference.main-java=src/main/java
file.reference.main-res=src/main/res
+file.reference.svgsalamander-www=../www
file.reference.test-java=src/test/java
file.reference.test-res=src/test/res
includes=**
@@ -74,5 +75,6 @@ source.encoding=UTF-8
src.dir=${file.reference.main-java}
src.java.dir=src\\gen\\java
src.res.dir=src\\gen\\res
+src.www.dir=${file.reference.svgsalamander-www}
test.res.dir=${file.reference.test-res}
test.src.dir=${file.reference.test-java}
diff --git a/nbproject/project.xml b/nbproject/project.xml
index 289b995..3253810 100755
--- a/nbproject/project.xml
+++ b/nbproject/project.xml
@@ -6,6 +6,7 @@
<name>svg-salamander-core</name>
<minimum-ant-version>1.6.5</minimum-ant-version>
<source-roots>
+ <root id="src.www.dir" name="www"/>
<root id="src.dir"/>
<root id="src.java.dir" name="Generated Source"/>
<root id="src.res.dir"/>
diff --git a/src/main/java/com/kitfox/svg/ImageSVG.java b/src/main/java/com/kitfox/svg/ImageSVG.java
index 75aaf79..6f4b301 100644
--- a/src/main/java/com/kitfox/svg/ImageSVG.java
+++ b/src/main/java/com/kitfox/svg/ImageSVG.java
@@ -80,7 +80,14 @@ public class ImageSVG extends RenderableElement
if (getPres(sty.setName("xlink:href")))
{
URI src = sty.getURIValue(getXMLBase());
- imageSrc = src.toURL();
+ try {
+ imageSrc = src.toURL();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ imageSrc = null;
+ }
}
}
catch (Exception e)
diff --git a/src/main/java/com/kitfox/svg/xml/Base64InputStream.java b/src/main/java/com/kitfox/svg/xml/Base64InputStream.java
new file mode 100755
index 0000000..3851c39
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/xml/Base64InputStream.java
@@ -0,0 +1,82 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package com.kitfox.svg.xml;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ *
+ * @author kitfox
+ */
+public class Base64InputStream extends FilterInputStream
+{
+ int buf; //Cached bytes to read
+ int bufSize; //Number of bytes waiting to be read from buffer
+ boolean drain = false; //After set, read no more chunks
+
+ public Base64InputStream(InputStream in)
+ {
+ super(in);
+ }
+
+ public int read() throws IOException
+ {
+ if (drain && bufSize == 0)
+ {
+ return -1;
+ }
+
+ if (bufSize == 0)
+ {
+ //Read next chunk into 4 byte buffer
+ int chunk = in.read();
+ if (chunk == -1)
+ {
+ drain = true;
+ return -1;
+ }
+
+ //get remaining 3 bytes
+ for (int i = 0; i < 3; ++i)
+ {
+ int value = in.read();
+ if (value == -1)
+ {
+ throw new IOException("Early termination of base64 stream");
+ }
+ chunk = (chunk << 8) | (value & 0xff);
+ }
+
+ //Check for special termination characters
+ if ((chunk & 0xffff) == (((byte)'=' << 8) | (byte)'='))
+ {
+ bufSize = 1;
+ drain = true;
+ }
+ else if ((chunk & 0xff) == (byte)'=')
+ {
+ bufSize = 2;
+ drain = true;
+ }
+ else
+ {
+ bufSize = 3;
+ }
+
+ //Fill buffer with decoded characters
+ for (int i = 0; i < bufSize + 1; ++i)
+ {
+ buf = (buf << 6) | Base64Util.decodeByte((chunk >> 24) & 0xff);
+ chunk <<= 8;
+ }
+ }
+
+ //Return nth remaing bte & decrement counter
+ return (buf >> (--bufSize * 8)) & 0xff;
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/xml/Base64OutputStream.java b/src/main/java/com/kitfox/svg/xml/Base64OutputStream.java
new file mode 100755
index 0000000..db167de
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/xml/Base64OutputStream.java
@@ -0,0 +1,90 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package com.kitfox.svg.xml;
+
+import java.io.FilterOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ *
+ * @author kitfox
+ */
+public class Base64OutputStream extends FilterOutputStream
+{
+ int buf;
+ int numBytes;
+ int numChunks;
+
+ public Base64OutputStream(OutputStream out)
+ {
+ super(out);
+ }
+
+ public void flush() throws IOException
+ {
+ out.flush();
+ }
+
+ public void close() throws IOException
+ {
+ switch (numBytes)
+ {
+ case 1:
+ buf <<= 4;
+ out.write(getBase64Byte(1));
+ out.write(getBase64Byte(0));
+ out.write('=');
+ out.write('=');
+ break;
+ case 2:
+ buf <<= 2;
+ out.write(getBase64Byte(2));
+ out.write(getBase64Byte(1));
+ out.write(getBase64Byte(0));
+ out.write('=');
+ break;
+ case 3:
+ out.write(getBase64Byte(3));
+ out.write(getBase64Byte(2));
+ out.write(getBase64Byte(1));
+ out.write(getBase64Byte(0));
+ break;
+ default:
+ assert false;
+ }
+
+ out.close();
+ }
+
+ public void write(int b) throws IOException
+ {
+ buf = (buf << 8) | (0xff & b);
+ numBytes++;
+
+ if (numBytes == 3)
+ {
+ out.write(getBase64Byte(3));
+ out.write(getBase64Byte(2));
+ out.write(getBase64Byte(1));
+ out.write(getBase64Byte(0));
+
+ numBytes = 0;
+ numChunks++;
+ if (numChunks == 16)
+ {
+// out.write('\r');
+// out.write('\n');
+ numChunks = 0;
+ }
+ }
+ }
+
+ public byte getBase64Byte(int index)
+ {
+ return Base64Util.encodeByte((buf >> (index * 6)) & 0x3f);
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/xml/Base64Util.java b/src/main/java/com/kitfox/svg/xml/Base64Util.java
new file mode 100755
index 0000000..a95b9d4
--- /dev/null
+++ b/src/main/java/com/kitfox/svg/xml/Base64Util.java
@@ -0,0 +1,32 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package com.kitfox.svg.xml;
+
+/**
+ *
+ * @author kitfox
+ */
+public class Base64Util
+{
+ static final byte[] valueToBase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".getBytes();
+ static final byte[] base64ToValue = new byte[128];
+ static {
+ for (int i = 0; i < valueToBase64.length; ++i)
+ {
+ base64ToValue[valueToBase64[i]] = (byte)i;
+ }
+ }
+
+ static public byte encodeByte(int value)
+ {
+ return valueToBase64[value];
+ }
+
+ static public byte decodeByte(int base64Char)
+ {
+ return base64ToValue[base64Char];
+ }
+}
diff --git a/src/main/java/com/kitfox/svg/xml/StyleAttribute.java b/src/main/java/com/kitfox/svg/xml/StyleAttribute.java
index 70cf71a..a3c9e63 100644
--- a/src/main/java/com/kitfox/svg/xml/StyleAttribute.java
+++ b/src/main/java/com/kitfox/svg/xml/StyleAttribute.java
@@ -226,7 +226,7 @@ public class StyleAttribute implements Serializable
{
try {
String fragment = parseURLFn();
- if (fragment == null) fragment = stringValue;
+ if (fragment == null) fragment = stringValue.replaceAll("\\s+", "");
if (fragment == null) return null;
//======================