-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if a file contains a file link.
- Loading branch information
1 parent
5e33645
commit 8f7a2b7
Showing
11 changed files
with
185 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.adobe.epubcheck.ctc; | ||
|
||
import com.adobe.epubcheck.api.EPUBLocation; | ||
import com.adobe.epubcheck.api.Report; | ||
import com.adobe.epubcheck.messages.MessageId; | ||
import com.adobe.epubcheck.util.EPUBVersion; | ||
|
||
import java.io.*; | ||
import java.util.Scanner; | ||
import java.util.Vector; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.zip.ZipFile; | ||
|
||
public class FileLinkSearch extends TextSearch { | ||
private static final Pattern fileLinkPattern = Pattern.compile("href=[\"']file://"); | ||
|
||
public FileLinkSearch(EPUBVersion version, ZipFile zip, Report report) | ||
{ | ||
super(version, zip, report); | ||
} | ||
|
||
@Override | ||
Vector<String> Search(String entry) | ||
{ | ||
String fileName = new File(zip.getName()).getName(); | ||
InputStream is = null; | ||
BufferedReader br = null; | ||
try | ||
{ | ||
is = getInputStream(entry); | ||
br = new BufferedReader(new InputStreamReader(is)); | ||
|
||
int lineCounter = 1; | ||
String line; | ||
while ((line = br.readLine()) != null) | ||
{ | ||
Matcher matcher = fileLinkPattern.matcher(line); | ||
int position = 0; | ||
while (matcher.find(position)) | ||
{ | ||
int contextStart = Math.max(0, matcher.start() - 20); | ||
int contextEnd = Math.min(contextStart + 40, line.length() - 1); | ||
String context = line.substring(contextStart, contextEnd); | ||
|
||
report.message(MessageId.HTM_053, EPUBLocation.create(entry, lineCounter, matcher.start(), context.trim()), context.trim()); | ||
position = matcher.end(); | ||
} | ||
lineCounter++; | ||
} | ||
} | ||
catch (FileNotFoundException e1) | ||
{ | ||
report.message(MessageId.RSC_001, EPUBLocation.create(fileName), entry); | ||
} | ||
catch (IOException e1) | ||
{ | ||
report.message(MessageId.PKG_008, EPUBLocation.create(fileName), entry); | ||
} | ||
catch (Exception e) | ||
{ | ||
e.printStackTrace(); | ||
report.message(MessageId.RSC_005, EPUBLocation.create(entry), e.getMessage()); | ||
} | ||
finally | ||
{ | ||
silentlyClose(br); | ||
silentlyClose(is); | ||
} | ||
return new Vector<String>(); | ||
} | ||
|
||
private void silentlyClose(Closeable c) { | ||
try | ||
{ | ||
c.close(); | ||
} | ||
catch (IOException ignored) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.adobe.epubcheck.ctc; | ||
|
||
import com.adobe.epubcheck.api.Report; | ||
import com.adobe.epubcheck.ocf.EncryptionFilter; | ||
import com.adobe.epubcheck.util.EPUBVersion; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Hashtable; | ||
import java.util.Vector; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipFile; | ||
|
||
abstract class TextSearch { | ||
private final Hashtable<String, EncryptionFilter> enc; | ||
final ZipFile zip; | ||
final Report report; | ||
final EPUBVersion version; | ||
|
||
|
||
public TextSearch(EPUBVersion version, ZipFile zip, Report report) | ||
{ | ||
this.zip = zip; | ||
this.enc = new Hashtable<String, EncryptionFilter>(); | ||
this.report = report; | ||
this.version = version; | ||
} | ||
|
||
InputStream getInputStream(String name) throws IOException | ||
{ | ||
ZipEntry entry = zip.getEntry(name); | ||
if (entry == null) | ||
{ | ||
return null; | ||
} | ||
InputStream in = zip.getInputStream(entry); | ||
EncryptionFilter filter = enc.get(name); | ||
if (filter == null) | ||
{ | ||
return in; | ||
} | ||
if (filter.canDecrypt()) | ||
{ | ||
return filter.decrypt(in); | ||
} | ||
return null; | ||
} | ||
|
||
abstract Vector<String> Search(String entry); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.