Package org.apache.fop.afp.parser

Examples of org.apache.fop.afp.parser.UnparsedStructuredField


        File outputFile = renderFile(ua, "nops.fo", "");

        InputStream in = new java.io.FileInputStream(outputFile);
        try {
            MODCAParser parser = new MODCAParser(in);
            UnparsedStructuredField field = skipTo(parser, 0xD3A8A8); //Begin Document

            //NOP in fo:declarations
            field = parser.readNextStructuredField();
            assertEquals(0xD3EEEE, field.getSfTypeID());
            assertEquals("fo:declarations", getNopText(field));

            field = parser.readNextStructuredField();
            assertEquals(0xD3A8AD, field.getSfTypeID()); //Begin Named Page Group

            //NOPs in fo:page-sequence
            field = parser.readNextStructuredField();
            assertEquals(0xD3EEEE, field.getSfTypeID());
            assertEquals("fo:page-sequence: start", getNopText(field));
            field = parser.readNextStructuredField();
            assertEquals(0xD3EEEE, field.getSfTypeID());
            assertEquals("fo:page-sequence: end", getNopText(field));

            field = parser.readNextStructuredField();
            assertEquals(0xD3A8AF, field.getSfTypeID()); //Begin Page

            field = skipTo(parser, 0xD3A9C9); //End Active Environment Group
            field = parser.readNextStructuredField();
            assertEquals(0xD3EEEE, field.getSfTypeID());
            assertEquals("fo:simple-page-master: first", getNopText(field));

            field = skipTo(parser, 0xD3A9C9); //End Active Environment Group
            field = parser.readNextStructuredField();
            assertEquals(0xD3EEEE, field.getSfTypeID());
            assertEquals("fo:simple-page-master: rest", getNopText(field));
        } finally {
            IOUtils.closeQuietly(in);
        }

        int counter = 0;
        in = new java.io.FileInputStream(outputFile);
        try {
            MODCAParser parser = new MODCAParser(in);
            while (true) {
                UnparsedStructuredField field = parser.readNextStructuredField();
                if (field == null) {
                    break;
                }
                if (field.getSfTypeID() == 0xD3EEEE) {
                    counter++;
                }
            }
        } finally {
            IOUtils.closeQuietly(in);
View Full Code Here


        String text = new String(data, AFPConstants.EBCIDIC_ENCODING);
        return text;
    }

    private UnparsedStructuredField skipTo(MODCAParser parser, int typeID) throws IOException {
        UnparsedStructuredField field = null;
        do {
            field = parser.readNextStructuredField();
            if (field.getSfTypeID() == typeID) {
                return field;
            }
        } while (field != null);
        fail("Structured field not found: " + Integer.toHexString(typeID));
        return null;
View Full Code Here

     * @return the next structured field or null when there are no more
     */
    public static byte[] getNext(byte[] identifier, InputStream inputStream) throws IOException {
        MODCAParser parser = new MODCAParser(inputStream);
        while (true) {
            UnparsedStructuredField field = parser.readNextStructuredField();
            if (field == null) {
                return null;
            }
            if (field.getSfClassCode() == identifier[0]
                    && field.getSfTypeCode() == identifier[1]
                    && field.getSfCategoryCode() == identifier[2]) {
                return field.getCompleteFieldAsBytes();
            }
        }
    }
View Full Code Here

     */
    public static void copyResourceFile(final InputStream in, OutputStream out)
                throws IOException {
        MODCAParser parser = new MODCAParser(in);
        while (true) {
            UnparsedStructuredField field = parser.readNextStructuredField();
            if (field == null) {
                break;
            }
            out.write(MODCAParser.CARRIAGE_CONTROL_CHAR);
            field.writeTo(out);
        }
    }
View Full Code Here

            final InputStream in, final OutputStream out) throws IOException {
        final MODCAParser parser = new MODCAParser(in);
        Collection<String> resourceNames = new java.util.HashSet<String>();

        //Find matching "Begin" field
        final UnparsedStructuredField fieldBegin;
        while (true) {
            final UnparsedStructuredField field = parser.readNextStructuredField();

            if (field == null) {
                throw new IOException("Requested resource '" + name
                        + "' not found. Encountered resource names: " + resourceNames);
            }

            if (field.getSfTypeCode() != TYPE_CODE_BEGIN) { //0xA8=Begin
                continue; //Not a "Begin" field
            }
            final String resourceName = getResourceName(field);

            resourceNames.add(resourceName);
View Full Code Here

    private static void copyNamedStructuredFields(final String name,
            UnparsedStructuredField fieldBegin, MODCAParser parser,
            OutputStream out) throws IOException {

        UnparsedStructuredField field = fieldBegin;

        while (true) {
            if (field == null) {
                throw new IOException("Ending structured field not found for resource " + name);
            }
            out.write(MODCAParser.CARRIAGE_CONTROL_CHAR);
            field.writeTo(out);

            if (field.getSfTypeCode() == TYPE_CODE_END
                    && fieldBegin.getSfCategoryCode() == field.getSfCategoryCode()
                    && name.equals(getResourceName(field))) {
                break;
            }
            field = parser.readNextStructuredField();
        }
View Full Code Here

    public void extract(File file, File targetDir) throws IOException {
        InputStream in = new java.io.FileInputStream(file);
        try {
            MODCAParser parser = new MODCAParser(in);
            ByteArrayOutputStream baout = new ByteArrayOutputStream();
            UnparsedStructuredField strucField;
            while ((strucField = parser.readNextStructuredField()) != null) {
                if (strucField.getSfTypeID() == 0xD3EE89) {
                    byte[] sfData = strucField.getData();
                    println(strucField.toString());
                    HexDump.dump(sfData, 0, printStream, 0);
                    baout.write(sfData);
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.fop.afp.parser.UnparsedStructuredField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.