Lines 22-27
Link Here
|
22 |
import java.lang.ref.WeakReference; |
22 |
import java.lang.ref.WeakReference; |
23 |
import java.util.ArrayList; |
23 |
import java.util.ArrayList; |
24 |
import java.util.HashMap; |
24 |
import java.util.HashMap; |
|
|
25 |
import java.util.HashSet; |
25 |
import java.util.Hashtable; |
26 |
import java.util.Hashtable; |
26 |
import java.util.Iterator; |
27 |
import java.util.Iterator; |
27 |
import java.util.List; |
28 |
import java.util.List; |
Lines 563-599
Link Here
|
563 |
} |
564 |
} |
564 |
|
565 |
|
565 |
protected String getContents(IPath filePath) { |
566 |
protected String getContents(IPath filePath) { |
566 |
StringBuffer s = new StringBuffer(); |
567 |
|
|
|
568 |
StringBuffer s = null; |
567 |
IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath); |
569 |
IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath); |
|
|
570 |
|
568 |
if (iFile != null && iFile.exists()) { |
571 |
if (iFile != null && iFile.exists()) { |
569 |
String charset = detectCharset(iFile); |
572 |
Object o = getIncludedFilesCache().get(filePath); |
570 |
InputStream contents = null; |
573 |
if(o != null){ |
571 |
try { |
574 |
if(o instanceof IncludedFilesEntry){ |
572 |
contents = iFile.getContents(); |
575 |
IncludedFilesEntry entry = (IncludedFilesEntry) o; |
573 |
Reader reader = new InputStreamReader(contents, charset); |
576 |
if(iFile.getModificationStamp() == entry.modificationStamp){ |
574 |
char[] readBuffer = new char[2048]; |
577 |
s = entry.document; |
575 |
int n = reader.read(readBuffer); |
578 |
entry.referenceCount++; |
576 |
while (n > 0) { |
579 |
}//else will be taken care of if(s == null) |
577 |
s.append(readBuffer, 0, n); |
580 |
} else if(o instanceof WeakReference){ |
578 |
n = reader.read(readBuffer); |
581 |
IncludedFilesEntry entry = (IncludedFilesEntry) ((WeakReference) o).get(); |
|
|
582 |
if(entry != null){ |
583 |
if(iFile.getModificationStamp() == entry.modificationStamp){ |
584 |
s = entry.document; |
585 |
entry.referenceCount = 1; |
586 |
getIncludedFilesCache().put(filePath, entry); |
587 |
}//else will be taken care of if(s == null) |
588 |
} |
579 |
} |
589 |
} |
580 |
} |
590 |
} |
581 |
catch (Exception e) { |
591 |
if(s == null){ |
582 |
if (Debug.debugStructuredDocument) |
592 |
s = new StringBuffer(); |
583 |
Logger.log(Logger.WARNING, "An exception occured while scanning " + filePath, e); //$NON-NLS-1$ |
593 |
String charset = detectCharset(iFile); |
584 |
} |
594 |
InputStream contents = null; |
585 |
finally { |
|
|
586 |
try { |
595 |
try { |
587 |
if (contents != null) { |
596 |
contents = iFile.getContents(); |
588 |
contents.close(); |
597 |
Reader reader = new InputStreamReader(contents, charset); |
|
|
598 |
char[] readBuffer = new char[2048]; |
599 |
int n = reader.read(readBuffer); |
600 |
while (n > 0) { |
601 |
s.append(readBuffer, 0, n); |
602 |
n = reader.read(readBuffer); |
589 |
} |
603 |
} |
590 |
} |
604 |
} |
591 |
catch (Exception e) { |
605 |
catch (Exception e) { |
592 |
// nothing to do |
606 |
if (Debug.debugStructuredDocument) |
|
|
607 |
Logger.log(Logger.WARNING, "An exception occured while scanning " + filePath, e); //$NON-NLS-1$ |
608 |
} |
609 |
finally { |
610 |
try { |
611 |
if (contents != null) { |
612 |
contents.close(); |
613 |
} |
614 |
} |
615 |
catch (Exception e) { |
616 |
// nothing to do |
617 |
} |
593 |
} |
618 |
} |
|
|
619 |
IncludedFilesEntry entry = new IncludedFilesEntry(); |
620 |
entry.document = s; |
621 |
entry.referenceCount = 1; |
622 |
entry.modificationStamp = iFile.getModificationStamp(); |
623 |
getIncludedFilesCache().put(filePath, entry); |
624 |
|
594 |
} |
625 |
} |
|
|
626 |
getIncludedDocumentsKeys().add(filePath); |
595 |
} |
627 |
} |
596 |
else { |
628 |
else { |
|
|
629 |
s = new StringBuffer(); |
597 |
int c = 0; |
630 |
int c = 0; |
598 |
int length = 0; |
631 |
int length = 0; |
599 |
int count = 0; |
632 |
int count = 0; |
Lines 696-701
Link Here
|
696 |
CMDocument document; |
729 |
CMDocument document; |
697 |
int referenceCount; |
730 |
int referenceCount; |
698 |
} |
731 |
} |
|
|
732 |
|
733 |
static class IncludedFilesEntry { |
734 |
StringBuffer document; |
735 |
int referenceCount; |
736 |
long modificationStamp; |
737 |
} |
699 |
|
738 |
|
700 |
private static class TLDCMDocumentDescriptor { |
739 |
private static class TLDCMDocumentDescriptor { |
701 |
Object cacheKey; |
740 |
Object cacheKey; |
Lines 718-723
Link Here
|
718 |
protected static List bannedPrefixes = null; |
757 |
protected static List bannedPrefixes = null; |
719 |
|
758 |
|
720 |
private static Hashtable fCache = null; |
759 |
private static Hashtable fCache = null; |
|
|
760 |
|
761 |
private static Hashtable fIncludedFilesCache = null; |
762 |
|
721 |
static final String XMLNS = "xmlns:"; //$NON-NLS-1$ |
763 |
static final String XMLNS = "xmlns:"; //$NON-NLS-1$ |
722 |
|
764 |
|
723 |
static final int XMLNS_LENGTH = XMLNS.length(); |
765 |
static final int XMLNS_LENGTH = XMLNS.length(); |
Lines 746-751
Link Here
|
746 |
return fCache; |
788 |
return fCache; |
747 |
} |
789 |
} |
748 |
|
790 |
|
|
|
791 |
/** |
792 |
* Gets all of the known included documents. |
793 |
* |
794 |
* @return Returns a Hashtable of either IncludedFileEntrys or WeakReferences |
795 |
* to StringBuffers |
796 |
*/ |
797 |
public static Hashtable getIncludedFilesCache() { |
798 |
if (fIncludedFilesCache == null) { |
799 |
fIncludedFilesCache = new Hashtable(); |
800 |
} |
801 |
return fIncludedFilesCache; |
802 |
} |
803 |
|
749 |
|
804 |
|
750 |
public static Object getUniqueIdentifier(ITaglibRecord reference) { |
805 |
public static Object getUniqueIdentifier(ITaglibRecord reference) { |
751 |
Object identifier = null; |
806 |
Object identifier = null; |
Lines 786-791
Link Here
|
786 |
*/ |
841 |
*/ |
787 |
private Hashtable fDocuments = null; |
842 |
private Hashtable fDocuments = null; |
788 |
|
843 |
|
|
|
844 |
/** |
845 |
* The locally-know list of included documents keys |
846 |
*/ |
847 |
private HashSet fIncludedDocuments = null; |
848 |
|
789 |
// timestamp cache to prevent excessive reparsing |
849 |
// timestamp cache to prevent excessive reparsing |
790 |
// of included files |
850 |
// of included files |
791 |
// IPath (filepath) > Long (modification stamp) |
851 |
// IPath (filepath) > Long (modification stamp) |
Lines 820-825
Link Here
|
820 |
} |
880 |
} |
821 |
} |
881 |
} |
822 |
} |
882 |
} |
|
|
883 |
|
884 |
for (Iterator iter = getIncludedDocumentsKeys().iterator(); iter.hasNext();) { |
885 |
Object key = iter.next(); |
886 |
synchronized (getIncludedFilesCache()) { |
887 |
Object o = getIncludedFilesCache().get(key); |
888 |
if (o instanceof IncludedFilesEntry) { |
889 |
IncludedFilesEntry entry = (IncludedFilesEntry) o; |
890 |
entry.referenceCount--; |
891 |
if (entry.referenceCount <= 0) { |
892 |
getIncludedFilesCache().put(key, new WeakReference(entry)); |
893 |
} |
894 |
} |
895 |
} |
896 |
} |
823 |
} |
897 |
} |
824 |
|
898 |
|
825 |
/** |
899 |
/** |
Lines 1003-1008
Link Here
|
1003 |
} |
1077 |
} |
1004 |
|
1078 |
|
1005 |
/** |
1079 |
/** |
|
|
1080 |
* Gets the documents. |
1081 |
* |
1082 |
* @return Returns a java.util.Hashtable |
1083 |
*/ |
1084 |
public HashSet getIncludedDocumentsKeys() { |
1085 |
if (fIncludedDocuments == null) |
1086 |
fIncludedDocuments = new HashSet(); |
1087 |
return fIncludedDocuments; |
1088 |
} |
1089 |
|
1090 |
/** |
1006 |
* Return the CMDocument at the tagdir (cached) |
1091 |
* Return the CMDocument at the tagdir (cached) |
1007 |
*/ |
1092 |
*/ |
1008 |
protected CMDocument getImplicitCMDocument(String tagdir) { |
1093 |
protected CMDocument getImplicitCMDocument(String tagdir) { |