All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpedal.objects.javascript.jsobjects.JSDoc Maven / Gradle / Ivy

There is a newer version: 7.15.25
Show newest version
/*
 * ===========================================
 * Java Pdf Extraction Decoding Access Library
 * ===========================================
 *
 * Project Info:  http://www.idrsolutions.com
 * Help section for developers at http://www.idrsolutions.com/support/
 *
 * (C) Copyright 1997-2017 IDRsolutions and Contributors.
 *
 * This file is part of JPedal/JPDF2HTML5
 *
 @LICENSE@
 *
 * ---------------
 * JSDoc.java
 * ---------------
 */
package org.jpedal.objects.javascript.jsobjects;

import java.util.HashMap;
import java.util.List;

import org.jpedal.objects.acroforms.AcroRenderer;
import org.jpedal.objects.acroforms.ReturnValues;
import org.jpedal.objects.raw.FormObject;
import org.jpedal.objects.raw.PdfDictionary;


public class JSDoc {
    //	public boolean external = true;
    private AcroRenderer acroRenderer;
    private HashMap nameTofields = new HashMap();
    private HashMap refTofields = new HashMap();

    //public Object ADBE = null;

    public JSDoc() {
    }

    public void setAcroRenderer(final AcroRenderer acro) {
        acroRenderer = acro;
        if (acro != null) {
            loadFormObjects();
        }
    }

    // TODO: add call to loadFormObjects() to GenericParser in a way that its called after the acrorender/GUIData has loaded the FormObjects
    public void loadFormObjects() {
        if (acroRenderer == null) {
            throw new RuntimeException("No acrorender object set for Doc object.");
        }
        final List obs = acroRenderer.getCompData().getFormComponents(null, ReturnValues.FORMOBJECTS_FROM_REF, -1);
//		System.out.println("obs=" + obs);
//		System.out.println("size=" + obs.size());
        for (final FormObject formObject : obs) {
            final JSField field = new JSField(formObject);
            refTofields.put(formObject.getObjectRefAsString(), field);
            nameTofields.put(formObject.getTextStreamValue(PdfDictionary.T), field);
        }
    }

    public JSField getField(final String name) {
//		System.out.println("Called getField(" + name + ");");

        // check if there are field objects in the map
        if (nameTofields.size() <= 0) {
            loadFormObjects();
        }
        if (nameTofields.containsKey(name)) {
            return nameTofields.get(name);
        }
        return null;
    }

    public JSField getFieldByRef(final String ref) {
//		System.out.println("Called getFieldByRef(" + ref + ");");
        // check if there are field objects in the map
        if (refTofields.size() <= 0) {
            loadFormObjects();
        }
        if (refTofields.containsKey(ref)) {
            return refTofields.get(ref);
        }
        return null;
    }

    public void flush() {
        nameTofields = new HashMap();
        refTofields = new HashMap();
    }

    public FormObject[] getFormObjects() {
        final FormObject[] formObjects = new FormObject[refTofields.size()];
        int i = 0;
        for (final String S : refTofields.keySet()) {
            formObjects[i] = refTofields.get(S).target;
            i++;
        }
        return formObjects;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy