001
014
015 package com.liferay.portal.xsl;
016
017 import com.liferay.portal.kernel.io.unsync.UnsyncStringReader;
018 import com.liferay.portal.kernel.template.TemplateResource;
019 import com.liferay.portal.kernel.util.HashUtil;
020 import com.liferay.portal.kernel.util.Validator;
021
022 import java.io.IOException;
023 import java.io.ObjectInput;
024 import java.io.ObjectOutput;
025 import java.io.Reader;
026
027
030 public class XSLTemplateResource implements TemplateResource {
031
032
036 public XSLTemplateResource() {
037 }
038
039 public XSLTemplateResource(
040 String templateId, String xsl, XSLURIResolver xslURIResolver,
041 String xml) {
042
043 if (Validator.isNull(templateId)) {
044 throw new IllegalArgumentException("Template ID is null");
045 }
046
047 if (Validator.isNull(xsl)) {
048 throw new IllegalArgumentException("XSL is null");
049 }
050
051 if (Validator.isNull(xml)) {
052 throw new IllegalArgumentException("XML is null");
053 }
054
055 _templateId = templateId;
056 _xsl = xsl;
057 _xslURIResolver = xslURIResolver;
058 _xml = xml;
059 }
060
061 @Override
062 public boolean equals(Object obj) {
063 if (this == obj) {
064 return true;
065 }
066
067 if (!(obj instanceof XSLTemplateResource)) {
068 return false;
069 }
070
071 XSLTemplateResource xslTemplateResource = (XSLTemplateResource)obj;
072
073 if (_templateId.equals(xslTemplateResource._templateId) &&
074 _xsl.equals(xslTemplateResource._xsl) &&
075 Validator.equals(
076 _xslURIResolver, xslTemplateResource._xslURIResolver) &&
077 _xml.equals(xslTemplateResource._xml)) {
078
079 return true;
080 }
081
082 return false;
083 }
084
085 public long getLastModified() {
086 return _lastModified;
087 }
088
089 public Reader getReader() {
090 return new UnsyncStringReader(_xsl);
091 }
092
093 public String getTemplateId() {
094 return _templateId;
095 }
096
097 public Reader getXMLReader() {
098 return new UnsyncStringReader(_xml);
099 }
100
101 public XSLURIResolver getXSLURIResolver() {
102 return _xslURIResolver;
103 }
104
105 @Override
106 public int hashCode() {
107 int hashCode = HashUtil.hash(0, _templateId);
108
109 hashCode = HashUtil.hash(hashCode, _xsl);
110 hashCode = HashUtil.hash(hashCode, _xslURIResolver);
111 hashCode = HashUtil.hash(hashCode, _xml);
112
113 return hashCode;
114 }
115
116 public void readExternal(ObjectInput objectInput)
117 throws ClassNotFoundException, IOException {
118
119 _templateId = objectInput.readUTF();
120 _lastModified = objectInput.readLong();
121 _xsl = objectInput.readUTF();
122 _xslURIResolver = (XSLURIResolver)objectInput.readObject();
123 _xml = objectInput.readUTF();
124 }
125
126 public void writeExternal(ObjectOutput objectOutput) throws IOException {
127 objectOutput.writeUTF(_templateId);
128 objectOutput.writeLong(_lastModified);
129 objectOutput.writeUTF(_xsl);
130 objectOutput.writeObject(_xslURIResolver);
131 objectOutput.writeUTF(_xml);
132 }
133
134 private long _lastModified = System.currentTimeMillis();
135 private String _templateId;
136 private String _xml;
137 private String _xsl;
138 private XSLURIResolver _xslURIResolver;
139
140 }