MCPcopy Create free account
hub / github.com/ArtifexSoftware/mupdf / openDocument

Method openDocument

platform/java/example/ViewerCore.java:55–112  ·  view source on GitHub ↗
(final OnException onException)

Source from the content-addressed store, hash-verified

53 }
54
55 public void openDocument(final OnException onException) {
56 worker.add(new Worker.Task() {
57 Document doc = null;
58 String acceleratorPath = null;
59 boolean needsPassword = false;
60 protected String getAcceleratorPath(String documentPath) {
61 try {
62 String accelerator = new File(documentPath).
63 getCanonicalFile().
64 getPath().
65 replace(File.separatorChar, '%').
66 replace('\\', '%').
67 replace('/', '%').
68 replace(':', '%') + ".accel";
69 String tmpdir = System.getProperty("java.io.tmpdir");
70 return new File(tmpdir, accelerator).getCanonicalFile().getPath();
71 } catch (Exception e) {
72 return null;
73 }
74 }
75 protected boolean acceleratorValid(String documentPath, String acceleratorPath) {
76 try {
77 long documentModified = new File(documentPath).lastModified();
78 long acceleratorModified = new File(acceleratorPath).lastModified();
79 return acceleratorModified != 0 && acceleratorModified > documentModified;
80 } catch (Exception e) {
81 return false;
82 }
83 }
84 public void work() {
85 String acceleratorPath = getAcceleratorPath(documentPath);
86 if (!acceleratorValid(documentPath, acceleratorPath))
87 acceleratorPath = null;
88 if (acceleratorPath != null)
89 doc = Document.openDocument(documentPath, acceleratorPath);
90 else
91 doc = Document.openDocument(documentPath);
92 needsPassword = doc.needsPassword();
93 }
94 public void run() {
95 ViewerCore.this.doc = doc;
96 ViewerCore.this.acceleratorPath = acceleratorPath;
97 if (needsPassword) {
98 String password = callback.askPassword();
99 if (password != null)
100 checkPassword(password, onException);
101 }
102 else
103 loadDocument(onException);
104 }
105 public void exception(Throwable t) {
106 ViewerCore.this.acceleratorPath = null;
107 ViewerCore.this.doc = null;
108 if (onException != null)
109 onException.run(t);
110 }
111 });
112 }

Callers 2

reloadDocumentMethod · 0.95
ViewerMethod · 0.45

Calls 1

addMethod · 0.45

Tested by

no test coverage detected