001: /*
002: * $Id: ImportAssets.java,v 1.2 2002/02/15 23:44:27 skavish Exp $
003: *
004: * ==========================================================================
005: *
006: * The JGenerator Software License, Version 1.0
007: *
008: * Copyright (c) 2000 Dmitry Skavish (skavish@usa.net). All rights reserved.
009: * Copyright (c) 2007
010: *
011: * Redistribution and use in source and binary forms, with or without
012: * modification, are permitted provided that the following conditions are met:
013: *
014: * 1. Redistributions of source code must retain the above copyright
015: * notice, this list of conditions and the following disclaimer.
016: *
017: * 2. Redistributions in binary form must reproduce the above copyright
018: * notice, this list of conditions and the following disclaimer in
019: * the documentation and/or other materials provided with the
020: * distribution.
021: *
022: * 3. The end-user documentation included with the redistribution, if
023: * any, must include the following acknowlegement:
024: * "This product includes software developed by Dmitry Skavish
025: * (skavish@usa.net, http://www.flashgap.com/)."
026: * Alternately, this acknowlegement may appear in the software itself,
027: * if and wherever such third-party acknowlegements normally appear.
028: *
029: * 4. The name "The JGenerator" must not be used to endorse or promote
030: * products derived from this software without prior written permission.
031: * For written permission, please contact skavish@usa.net.
032: *
033: * 5. Products derived from this software may not be called "The JGenerator"
034: * nor may "The JGenerator" appear in their names without prior written
035: * permission of Dmitry Skavish.
036: *
037: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
038: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
039: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
040: * DISCLAIMED. IN NO EVENT SHALL DMITRY SKAVISH OR THE OTHER
041: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
042: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
043: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
044: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
045: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
046: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
047: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
048: * SUCH DAMAGE.
049: *
050: */
051:
052: package org.openlaszlo.iv.flash.api;
053:
054: import java.io.PrintStream;
055: import org.openlaszlo.iv.flash.parser.*;
056: import org.openlaszlo.iv.flash.util.*;
057: import org.openlaszlo.iv.flash.commands.*;
058: import org.openlaszlo.iv.flash.context.Context;
059:
060: /**
061: * The ImportAssets tag imports assets from another swf file as a linked asset.
062: * <P>
063: * "Client" swf files can import assets like fonts that are stored in "server"
064: * swfs (that are ideally cached on an end user's local system).
065: * The importing swf file references the exporting swf file with a URL.
066: * The URL needs to include the asset identifier string.
067: * Imported assets are resolved and stored in a ScriptThread's SCharacter dictionary.
068: * <BR>
069: * Note that the URL can be absolute or relative. If it's relative, it's resolved
070: * relative to the location of the importing swf file.
071: *
072: * @author Dmitry Skavish
073: * @see ExportAssets
074: * @see ImportedDef
075: */
076: public class ImportAssets extends FlashObject {
077:
078: private String url; // the url of the exporting swf file
079: private IVVector defs = new IVVector(); // imported definitions references (ImportedDef)
080: private IVVector names = new IVVector(); // imported definitions names
081:
082: public ImportAssets() {
083: }
084:
085: public int getTag() {
086: return Tag.IMPORTASSETS;
087: }
088:
089: public void setUrl(String url) {
090: this .url = url;
091: }
092:
093: public void addAsset(String name, FlashDef def) {
094: names.addElement(name);
095: defs.addElement(def);
096: }
097:
098: public static ImportAssets parse(Parser p) {
099: ImportAssets o = new ImportAssets();
100: o.url = p.getString();
101: int num = p.getUWord();
102: o.defs = new IVVector(num);
103: o.names = new IVVector(num);
104: for (int i = 0; i < num; i++) {
105: int tagID = p.getUWord();
106: ImportedDef idef = new ImportedDef();
107: idef.setID(tagID);
108: p.addDef(idef);
109: String name = p.getString();
110: o.defs.addElement(idef);
111: o.names.addElement(name);
112: }
113: return o;
114: }
115:
116: // we should not collect defs here, it has to be done by other objects
117: /* public void collectDeps( DepsCollector dc ) {
118: }*/
119:
120: /* protected void collectFonts( FontsCollector fc ) {
121: }*/
122:
123: public void write(FlashOutput fob) {
124: int tagPos = fob.getPos();
125: fob.skip(6);
126:
127: fob.writeStringZ(url);
128: fob.writeWord(defs.size());
129: for (int i = 0; i < defs.size(); i++) {
130: FlashDef def = (FlashDef) defs.elementAt(i);
131: String name = (String) names.elementAt(i);
132: fob.writeDefID(def);
133: fob.writeStringZ(name);
134: }
135:
136: fob.writeLongTagAt(getTag(), fob.getPos() - tagPos - 6, tagPos);
137: }
138:
139: public void printContent(PrintStream out, String indent) {
140: out.println(indent + "ImportAssets: url=" + url);
141: for (int i = 0; i < defs.size(); i++) {
142: FlashDef def = (FlashDef) defs.elementAt(i);
143: String name = (String) names.elementAt(i);
144: out.println(indent + " name=" + name + ", defID="
145: + def.getID());
146: }
147:
148: }
149:
150: protected boolean _isConstant() {
151: if (Util.hasVar(url))
152: return false;
153: for (int i = 0; i < names.size(); i++) {
154: String name = (String) names.elementAt(i);
155: if (Util.hasVar(name))
156: return false;
157: }
158: return true;
159: }
160:
161: public void apply(Context context) {
162: url = context.apply(url);
163: for (int i = 0; i < names.size(); i++) {
164: String name = (String) names.elementAt(i);
165: name = context.apply(name);
166: names.setElementAt(name, i);
167: }
168: }
169:
170: protected FlashItem copyInto(FlashItem item, ScriptCopier copier) {
171: super .copyInto(item, copier);
172: ((ImportAssets) item).url = url;
173: ((ImportAssets) item).defs = defs.getCopy(copier);
174: ((ImportAssets) item).names = (IVVector) names.clone();
175: return item;
176: }
177:
178: public FlashItem getCopy(ScriptCopier copier) {
179: return copyInto(new ImportAssets(), copier);
180: }
181: }
|