aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/area
diff options
context:
space:
mode:
authorAdrian Cumiskey <acumiskey@apache.org>2008-04-25 13:12:30 +0000
committerAdrian Cumiskey <acumiskey@apache.org>2008-04-25 13:12:30 +0000
commit7a70e99012aece4d8c53121d11b454b43e432994 (patch)
treeac6599271ede68ae0848815176fc1b949c6c84f8 /src/java/org/apache/fop/area
parent25a8131ea662070fddd811a77c9de352dea3b050 (diff)
downloadxmlgraphics-fop-7a70e99012aece4d8c53121d11b454b43e432994.tar.gz
xmlgraphics-fop-7a70e99012aece4d8c53121d11b454b43e432994.zip
Merged revisions 651575 via svnmerge from
https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk ........ r651575 | adelmelle | 2008-04-25 12:27:19 +0100 (Fri, 25 Apr 2008) | 3 lines Bugzilla 44634: Added partial implementation for show-destination. Only works for PDF output, when the PDF is opened in a standalone viewer, and for links that point to destinations in another PDF document. ........ git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AFPGOCAResources@651599 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/area')
-rw-r--r--src/java/org/apache/fop/area/AreaTreeParser.java4
-rw-r--r--src/java/org/apache/fop/area/Trait.java192
2 files changed, 80 insertions, 116 deletions
diff --git a/src/java/org/apache/fop/area/AreaTreeParser.java b/src/java/org/apache/fop/area/AreaTreeParser.java
index 19edd3d5e..d48221c0a 100644
--- a/src/java/org/apache/fop/area/AreaTreeParser.java
+++ b/src/java/org/apache/fop/area/AreaTreeParser.java
@@ -1018,7 +1018,7 @@ public class AreaTreeParser {
Trait.IS_REFERENCE_AREA, Trait.IS_VIEWPORT_AREA};
private void setTraits(Attributes attributes, Area area, Object[] traitSubset) {
- for (int i = 0, c = traitSubset.length; i < c; i++) {
+ for (int i = traitSubset.length; --i >= 0;) {
Object trait = traitSubset[i];
String traitName = Trait.getTraitName(trait);
String value = attributes.getValue(traitName);
@@ -1044,6 +1044,8 @@ public class AreaTreeParser {
}
} else if (cl == InternalLink.class) {
area.addTrait(trait, new InternalLink(value));
+ } else if (cl == Trait.ExternalLink.class) {
+ area.addTrait(trait, Trait.ExternalLink.makeFromTraitValue(value));
} else if (cl == Background.class) {
Background bkg = new Background();
try {
diff --git a/src/java/org/apache/fop/area/Trait.java b/src/java/org/apache/fop/area/Trait.java
index 98bed098c..9599d8833 100644
--- a/src/java/org/apache/fop/area/Trait.java
+++ b/src/java/org/apache/fop/area/Trait.java
@@ -194,7 +194,7 @@ public class Trait implements Serializable {
public static final Integer OVERLINE_COLOR = new Integer(35);
/** Trait for color of linethrough decorations when rendering inline parent. */
public static final Integer LINETHROUGH_COLOR = new Integer(36);
-
+
/** Maximum value used by trait keys */
public static final int MAX_TRAIT_KEY = 36;
@@ -226,7 +226,7 @@ public class Trait implements Serializable {
// Create a hashmap mapping trait code to name for external representation
//put(ID_LINK, new TraitInfo("id-link", String.class));
put(INTERNAL_LINK, new TraitInfo("internal-link", InternalLink.class));
- put(EXTERNAL_LINK, new TraitInfo("external-link", String.class));
+ put(EXTERNAL_LINK, new TraitInfo("external-link", ExternalLink.class));
put(FONT, new TraitInfo("font", FontTriplet.class));
put(FONT_SIZE, new TraitInfo("font-size", Integer.class));
put(COLOR, new TraitInfo("color", Color.class));
@@ -277,7 +277,7 @@ public class Trait implements Serializable {
new TraitInfo("is-reference-area", Boolean.class));
put(IS_VIEWPORT_AREA,
new TraitInfo("is-viewport-area", Boolean.class));
-
+
}
/**
@@ -291,25 +291,6 @@ public class Trait implements Serializable {
}
/**
- * Get the trait code for a trait name.
- *
- * @param sTraitName the name of the trait to find
- * @return the trait code object
- */
- /*
- public static Object getTraitCode(String sTraitName) {
- Iterator iter = TRAIT_INFO.entrySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- TraitInfo ti = (TraitInfo) entry.getValue();
- if (ti != null && ti.getName().equals(sTraitName)) {
- return entry.getKey();
- }
- }
- return null;
- }*/
-
- /**
* Get the data storage class for the trait.
*
* @param traitCode the trait code to lookup
@@ -320,99 +301,6 @@ public class Trait implements Serializable {
}
/**
- * The type of trait for an area.
- */
- private Object propType;
-
- /**
- * The data value of the trait.
- */
- private Object data;
-
- /**
- * Create a new empty trait.
- */
- public Trait() {
- this.propType = null;
- this.data = null;
- }
-
- /**
- * Create a trait with the value and type.
- *
- * @param propType the type of trait
- * @param data the data value
- */
- public Trait(Object propType, Object data) {
- this.propType = propType;
- this.data = data;
- }
-
- /**
- * Returns the trait data value.
- * @return the trait data value
- */
- public Object getData() {
- return this.data;
- }
-
- /**
- * Returns the property type.
- * @return the property type
- */
- public Object getPropType() {
- return this.propType;
- }
-
- /**
- * Return the string for debugging.
- * {@inheritDoc}
- */
- public String toString() {
- return data.toString();
- }
-
- /**
- * Make a trait value.
- *
- * @param oCode trait code
- * @param sTraitValue trait value as String
- * @return the trait value as object
- */
- /*
- public static Object makeTraitValue(Object oCode, String sTraitValue) {
- // Get the code from the name
- // See what type of object it is
- // Convert string value to an object of that type
- Class tclass = getTraitClass(oCode);
- if (tclass == null) {
- return null;
- }
- if (tclass.equals(String.class)) {
- return sTraitValue;
- }
- if (tclass.equals(Integer.class)) {
- return new Integer(sTraitValue);
- }
- // See if the class has a constructor from string or can read from a string
- try {
- Object o = tclass.newInstance();
- //return o.fromString(sTraitValue);
- } catch (IllegalAccessException e1) {
- log.error("Can't create instance of "
- + tclass.getName());
- return null;
- } catch (InstantiationException e2) {
- log.error("Can't create instance of "
- + tclass.getName());
- return null;
- }
-
-
- return null;
- }*/
-
- /**
* Class for internal link traits.
* Stores PageViewport key and producer ID
*/
@@ -548,6 +436,80 @@ public class Trait implements Serializable {
}
/**
+ * External Link trait structure
+ */
+ public static class ExternalLink implements Serializable {
+
+ private String destination;
+ private boolean newWindow;
+
+ /**
+ * Constructs an ExternalLink object with the given destination
+ *
+ * @param destination target of the link
+ * @param newWindow true if the target should be opened in a new window
+ */
+ public ExternalLink(String destination, boolean newWindow) {
+ this.destination = destination;
+ this.newWindow = newWindow;
+ }
+
+ /**
+ * Create an <code>ExternalLink</code> from a trait value/attribute value in the
+ * area tree
+ * @param traitValue the value to use (should match the result of {@link #toString()}
+ * @return an <code>ExternalLink</code> instance corresponding to the given value
+ */
+ protected static ExternalLink makeFromTraitValue(String traitValue) {
+ if (traitValue.indexOf(ExternalLink.class.getName()) == -1
+ || traitValue.indexOf("dest=") == -1) {
+ throw new IllegalArgumentException(
+ "Malformed trait value for Trait.ExternalLink: " + traitValue);
+ }
+ int startIndex = traitValue.indexOf("dest=") + 5;
+ int endIndex = traitValue.indexOf(',', startIndex);
+ if (endIndex == -1) {
+ endIndex = traitValue.indexOf(']');
+ }
+ String dest = traitValue.substring(startIndex, endIndex);
+ startIndex = traitValue.indexOf("newWindow=", endIndex) + 10;
+ endIndex = traitValue.indexOf(']', startIndex);
+ boolean newWindow = Boolean.parseBoolean(
+ traitValue.substring(startIndex, endIndex));
+ return new ExternalLink(dest, newWindow);
+ }
+
+ /**
+ * Get the target/destination of the link
+ * @return the destination of the link
+ */
+ public String getDestination() {
+ return this.destination;
+ }
+
+ /**
+ * Check if the target has to be displayed in a new window
+ * @return <code>true</code> if the target has to be displayed in a new window
+ */
+ public boolean newWindow() {
+ return this.newWindow;
+ }
+
+ /**
+ * Return a String representation of the object.
+ * @return a <code>String</code> of the form
+ * "org.apache.fop.area.Trait.ExternalLink[dest=someURL,newWindow=false]"
+ */
+ public String toString() {
+ StringBuffer sb = new StringBuffer(64);
+ sb.append(super.toString());
+ sb.append("[dest=").append(this.destination);
+ sb.append(",newWindow=").append(newWindow).append("]");
+ return sb.toString();
+ }
+ }
+
+ /**
* Background trait structure.
* Used for storing back trait information which are related.
*/