1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /* $Id$ */
19 
20 package org.apache.fop.pdf;
21 
22 import java.io.IOException;
23 import java.io.OutputStream;
24 
25 public class PDFSetOCGStateAction extends PDFNavigatorAction {
26 
27     public abstract static class Resolver {
28         private boolean resolved;
29         private PDFSetOCGStateAction action;
30         private Object extension;
Resolver(PDFSetOCGStateAction action, Object extension)31         public Resolver(PDFSetOCGStateAction action, Object extension) {
32             this.action = action;
33             this.extension = extension;
34         }
getAction()35         public PDFSetOCGStateAction getAction() {
36             return action;
37         }
getExtension()38         public Object getExtension() {
39             return extension;
40         }
resolve()41         public void resolve() {
42             if (!resolved) {
43                 performResolution();
44                 resolved = true;
45             }
46         }
performResolution()47         protected void performResolution() {
48         }
49     }
50 
51     private Resolver resolver;
52 
PDFSetOCGStateAction(String id)53     public PDFSetOCGStateAction(String id) {
54         super(id);
55         put("Type", new PDFName("Action"));
56         put("S", new PDFName("SetOCGState"));
57     }
58 
59     @Override
output(OutputStream stream)60     public int output(OutputStream stream) throws IOException {
61         if (resolver != null) {
62             resolver.resolve();
63         }
64         return super.output(stream);
65     }
66 
setResolver(Resolver resolver)67     public void setResolver(Resolver resolver) {
68         this.resolver = resolver;
69     }
70 
populate(Object state, Object preserveRB, Object nextAction)71     public void populate(Object state, Object preserveRB, Object nextAction) {
72         if (state != null) {
73             put("State", state);
74         }
75         if (preserveRB != null) {
76             put("PreserveRB", preserveRB);
77         }
78         if (nextAction != null) {
79             put("Next", nextAction);
80         }
81     }
82 }
83