1 Star 0 Fork 1.4K

hexiangyun / graphic_graphic_2d

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
diff.jsp 19.56 KB
一键复制 编辑 原始数据 按行查看 历史
hexiangyun 提交于 2022-10-18 07:03 . update
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
<%--
$Id$
CDDL HEADER START
The contents of this file are subject to the terms of the
Common Development and Distribution License (the "License").
You may not use this file except in compliance with the License.
See LICENSE.txt included in this distribution for the specific
language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each
file and include the License file at LICENSE.txt.
If applicable, add the following below this CDDL HEADER, with the
fields enclosed by brackets "[]" replaced with your own identifying
information: Portions Copyright [yyyy] [name of copyright owner]
CDDL HEADER END
Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
Portions Copyright 2011 Jens Elkner.
--%><%@page errorPage="error.jsp" import="
java.io.ByteArrayInputStream,
java.io.OutputStream,
java.io.BufferedReader,
java.io.FileNotFoundException,
java.io.InputStream,
java.io.InputStreamReader,
java.io.UnsupportedEncodingException,
java.net.URLDecoder,
java.util.ArrayList,
org.apache.commons.jrcs.diff.Chunk,
org.apache.commons.jrcs.diff.Delta,
org.apache.commons.jrcs.diff.Diff,
org.apache.commons.jrcs.diff.Revision,
org.opensolaris.opengrok.analysis.AnalyzerGuru,
org.opensolaris.opengrok.analysis.FileAnalyzer.Genre,
org.opensolaris.opengrok.web.DiffData,
org.opensolaris.opengrok.web.DiffType"
%><%!
private String getAnnotateRevision(DiffData data) {
if (data.type == DiffType.OLD || data.type == DiffType.NEW) {
String rev = data.rev[data.type == DiffType.NEW ? 1 : 0];
return "<script type=\"text/javascript\">/* <![CDATA[ */ "
+ "document.rev = function() { return " + Util.htmlize(Util.jsStringLiteral(rev))
+ "; } /* ]]> */</script>";
}
return "";
}
%>
<%
{
PageConfig cfg = PageConfig.get(request);
cfg.checkSourceRootExistence();
/**
* This block must be the first block before any other output in the
* response.
*
* If there is already any output written into the response and we
* use the same response and reset the content and the headers then we have
* a collision with the response streams and the "getOutputStream() has
* already been called" exception occurs.
*/
DiffData data = cfg.getDiffData();
request.setAttribute("diff.jsp-data", data);
if (data.type == DiffType.TEXT
&& request.getParameter("action") != null
&& request.getParameter("action").equals("download")) {
try (OutputStream o = response.getOutputStream()) {
for (int i = 0; i < data.revision.size(); i++) {
Delta d = data.revision.getDelta(i);
try (InputStream in = new ByteArrayInputStream(d.toString().getBytes("UTF-8"))) {
response.setHeader("content-disposition", "attachment; filename="
+ cfg.getResourceFile().getName() + "@" + data.rev[0]
+ "-" + data.rev[1] + ".diff");
byte[] buffer = new byte[8192];
int nr;
while ((nr = in.read(buffer)) > 0) {
o.write(buffer, 0, nr);
}
}
}
o.flush();
o.close();
return;
}
}
}
%><%@
include file="mast.jsp"
%><%
/* ---------------------- diff.jsp start --------------------- */
{
PageConfig cfg = PageConfig.get(request);
DiffData data = (DiffData) request.getAttribute("diff.jsp-data");
// the data is never null as the getDiffData always return valid object
if (data.errorMsg != null) {
%>
<div class="src">
<h3 class="error">Error:</h3>
<p><%= data.errorMsg %></p>
</div><%
} else if (data.genre == Genre.IMAGE) {
String link = request.getContextPath() + Prefix.DOWNLOAD_P
+ Util.htmlize(cfg.getPath());
%>
<div id="difftable">
<table class="image">
<thead>
<tr><th><%= data.filename %> (revision <%= data.rev[0] %>)</th>
<th><%= data.filename %> (revision <%= data.rev[1] %>)</th>
</tr>
</thead>
<tbody>
<tr><td><img src="<%= link %>?r=<%= data.rev[0] %>"/></td>
<td><img src="<%= link %>?r=<%= data.rev[1] %>"/></td>
</tr>
</tbody>
</table>
</div><%
} else if (data.genre != Genre.PLAIN && data.genre != Genre.HTML) {
String link = request.getContextPath() + Prefix.DOWNLOAD_P
+ Util.htmlize(cfg.getPath());
%>
<div id="src">Diffs for binary files cannot be displayed! Files are <a
href="<%= link %>?r=<%= data.rev[0] %>"><%=
data.filename %>(revision <%= data.rev[0] %>)</a> and <a
href="<%= link %>?r=<%= data.rev[1] %>"><%=
data.filename %>(revision <%= data.rev[1] %>)</a>.
</div><%
} else if (data.revision.size() == 0) {
%>
<%= getAnnotateRevision(data) %>
<b>No differences found!</b><%
} else {
//-------- Do THE DIFFS ------------
int ln1 = 0;
int ln2 = 0;
String rp1 = data.param[0];
String rp2 = data.param[1];
String reqURI = request.getRequestURI();
String[] file1 = data.file[0];
String[] file2 = data.file[1];
DiffType type = data.type;
boolean full = data.full;
%>
<%= getAnnotateRevision(data) %>
<div id="diffbar">
<div class="legend">
<span class="d">Deleted</span>
<span class="a">Added</span>
</div>
<div class="tabs"><%
for (DiffType t : DiffType.values()) {
if (type == t) {
%> <span class="active"><%= t.toString() %><%
if (t == DiffType.OLD) {
%> ( <%= data.rev[0] %> )<%
} else if (t == DiffType.NEW) {
%> ( <%= data.rev[1] %> )<%
}
%></span><%
} else {
%> <span><a href="<%= reqURI %>?r1=<%= rp1 %>&amp;r2=<%= rp2
%>&amp;format=<%= t.getAbbrev() %>&amp;full=<%= full ? '1' : '0'
%>"><%= t.toString() %><%
if (t == DiffType.OLD) {
%> ( <%= data.rev[0] %> )<%
} else if (t == DiffType.NEW) {
%> ( <%= data.rev[1] %> )<%
}
%></a></span><%
}
}
%></div>
<div class="ctype"><%
if (!full) {
%>
<span><a href="<%= reqURI %>?r1=<%= rp1 %>&amp;r2=<%= rp2
%>&amp;format=<%= type.getAbbrev() %>&amp;full=1">full</a></span>
<span class="active">compact</span><%
} else {
%>
<span class="active">full</span>
<span> <a href="<%= reqURI %>?r1=<%= rp1 %>&amp;r2=<%= rp2
%>&amp;format=<%= type.getAbbrev() %>&amp;full=0">compact</a></span><%
}
%><span><a href="#" id="toggle-jumper">jumper</a></span>
<span><a href="<%= reqURI %>?r1=<%= rp1 %>&amp;r2=<%= rp2 %>&amp;format=<%= DiffType.TEXT %>&amp;action=download">download diff</a></span><%
%></div>
</div>
<div id="difftable">
<div class="pre"><%
if (type == DiffType.SIDEBYSIDE || type == DiffType.UNIFIED) {
%><table class="plain"><%
if (type == DiffType.SIDEBYSIDE) {
%>
<thead><tr>
<th><%= data.filename %> (<%= data.rev[0] %>)</th>
<th><%= data.filename %> (<%= data.rev[1] %>)</th>
</tr></thead><%
}
%>
<tbody><%
}
for (int i=0; i < data.revision.size(); i++) {
Delta d = data.revision.getDelta(i);
if (type == DiffType.TEXT) {
%><%= Util.htmlize(d.toString()) %><%
} else {
Chunk c1 = d.getOriginal();
Chunk c2 = d.getRevised();
int cn1 = c1.first();
int cl1 = c1.last();
int cn2 = c2.first();
int cl2 = c2.last();
int i1 = cn1, i2 = cn2;
StringBuilder bl1 = new StringBuilder(80);
StringBuilder bl2 = new StringBuilder(80);
for (; i1 <= cl1 && i2 <= cl2; i1++, i2++) {
String[] ss = Util.diffline(
new StringBuilder(file1[i1]),
new StringBuilder(file2[i2]));
file1[i1] = ss[0];
file2[i2] = ss[1];
}
// deleted
for (; i1 <= cl1; i1++) {
bl1.setLength(0);
bl1.append("<span class=\"d\">");
Util.htmlize(file1[i1], bl1);
file1[i1] = bl1.append("</span>").toString();
}
// added
for (; i2 <= cl2; i2++) {
bl2.setLength(0);
bl2.append("<span class=\"a\">");
Util.htmlize(file2[i2], bl2);
file2[i2] = bl2.append("</span>").toString();
}
if (type == DiffType.UNIFIED) {
// UDIFF
if (cn1 > ln1 || cn2 > ln2) {
%>
<tr class="k"><td><%
if (full || (cn2 - ln2 < 20)) {
for (int j = ln2; j < cn2; j++) {
%><i><%= ++ln2 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
} else {
for (int j = ln2; j < ln2 + 8; j++) {
%><i><%= j+1 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
%><br/>--- <b><%= cn2 - ln2 - 16
%> unchanged lines hidden</b> (<a href="<%= reqURI
%>?r1=<%= rp1 %>&amp;r2=<%= rp2
%>&amp;format=<%= type.getAbbrev()
%>&amp;full=1#<%= ln2 %>">view full</a>) --- <br/><br/><%
ln2 = cn2 - 8;
for (int j = ln2; j < cn2; j++) {
%><i><%= ++ln2 %></i><%= Util.htmlize(file2[j]) %><br/><%
}
}
%></td>
</tr><%
ln1 = cn1;
}
if (cn1 <= cl1) {
%>
<tr class="chunk"><td><%
for (int j = cn1; j <= cl1 ; j++) {
%><del class="d"><%= ++ln1 %></del><%= file1[j]
%><br/><%
}
%></td>
</tr><%
}
if (cn2 <= cl2) {
%>
<tr class="k<%
if (cn1 > cl1) {
%> chunk<%
}
%>"><td><%
for (int j = cn2; j < cl2; j++) {
%><i class="a"><%= ++ln2 %></i><%= file2[j]
%><br/><%
}
%><i class="a"><%= ++ln2 %></i><%= file2[cl2] %><%
if(full) {
%><a name="<%= ln2 %>" /><%
}
%></td>
</tr><%
}
} else if (type == DiffType.SIDEBYSIDE) {
// SDIFF
if (cn1 > ln1 || cn2 > ln2) {
%>
<tr class="k"><td><%
if (full || cn2 - ln2 < 20) {
for (int j = ln1; j < cn1; j++) {
%><i><%= ++ln1 %></i><%=
Util.htmlize(file1[j]) %><br/><%
}
%></td><td><%
for (int j = ln2; j < cn2 ; j++) {
%><i><%= ++ln2 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
} else {
for (int j = ln1; j < ln1 + 8; j++) {
%><i><%= j+1 %></i><%=
Util.htmlize(file1[j]) %><br/><%
}
%><br/>--- <b><%= cn1 - ln1 - 16
%> unchanged lines hidden</b> (<a href="<%= reqURI
%>?r1=<%= rp1 %>&amp;r2=<%= rp2
%>&amp;format=<%= type.getAbbrev()
%>&amp;full=1#<%= ln2 %>">view full</a>) --- <br/><br/><%
ln1 = cn1 - 8;
for (int j = ln1; j < cn1; j++) {
%><i><%= ++ln1 %></i><%=
Util.htmlize(file1[j]) %><br/><%
}
%></td><td><%
for (int j = ln2; j < ln2 + 8; j++) {
%><i><%= j+1 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
%><br/>--- <b><%= cn2 - ln2 - 16
%> unchanged lines hidden</b> (<a href="<%= reqURI
%>?r1=<%= rp1 %>&amp;r2=<%= rp2
%>&amp;format=<%= type.getAbbrev()
%>&amp;full=1#<%= ln2 %>">view full</a>) --- <br/><br/><%
ln2 = cn2 - 8;
for (int j = ln2; j < cn2; j++) {
%><i><%= ++ln2 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
}
%></td>
</tr><%
}
%>
<tr class="k chunk"><td><%
for (int j = cn1; j <= cl1; j++) {
%><i><%= ++ln1 %></i><%= file1[j] %><br/><%
}
%></td><td><%
for (int j = cn2; j <= cl2; j++) {
%><i><%= ++ln2 %></i><a name="<%= ln2 %>"></a><%=
file2[j] %><br/><%
}
%></td>
</tr><%
// OLD
} else if (type == DiffType.OLD) {
// OLD
if (cn1 > ln1) {
if (full || cn1 - ln1 < 20) {
for (int j = ln1; j < cn1; j++) {
%><i><%= ++ln1 %></i><%=
Util.htmlize(file1[j]) %><br/><%
}
} else {
for (int j = ln1; j < ln1 + 8; j++) {
%><i><%= j+1 %></i><%=
Util.htmlize(file1[j]) %><br/><%
}
%><br/>--- <b><%= cn1 - ln1 - 16
%> unchanged lines hidden</b> (<a href="<%= reqURI
%>?r1=<%= rp1 %>&amp;r2=<%= rp2
%>&amp;format=<%= type.getAbbrev()
%>&amp;full=1#<%=ln1%>">view full</a>) --- <br/><br/><%
ln1 = cn1 - 8;
for (int j = ln1; j < cn1; j++) {
%><i><%= ++ln1 %></i><%=
Util.htmlize(file1[j]) %><br/><%
}
}
}
for (int j = cn1; j <= cl1 ; j++) {
%><i><%= ++ln1 %></i><%= file1[j] %><br/><%
}
if (full) {
%><a name="<%=ln1%>" ></a><%
}
// NEW
} else if (type == DiffType.NEW) {
if (cn2 > ln2) {
if (full || cn2 - ln2 < 20) {
for (int j = ln2; j < cn2 ; j++) {
%><i><%= ++ln2 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
} else {
for (int j = ln2; j < ln2 + 8; j++) {
%><i><%= j+1 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
%><br/>--- <b><%= cn2 - ln2 - 16
%> unchanged lines hidden</b> (<a href="<%= reqURI
%>?r1=<%= rp1 %>&amp;r2=<%= rp2
%>&amp;format=<%= type.getAbbrev()
%>&amp;full=1#<%= ln2 %>">view full</a>) --- <br/><br/><%
ln2 = cn2 - 8;
for (int j = ln2; j < cn2; j++) {
%><i><%= ++ln2 %></i><%=
Util.htmlize(file2[j]) %><br/><%
}
}
}
for (int j = cn2; j <= cl2 ; j++) {
%><i><%= ++ln2 %></i><%= file2[j] %><br/><%
}
if (full) {
%><a name="<%= ln2 %>"></a><%
}
}
} // else
} // for
// deltas done, dump the remaining
if (file1.length >= ln1) {
if (type == DiffType.SIDEBYSIDE) {
if (full || file1.length - ln1 < 20) {
%>
<tr><td><%
for (int j = ln1; j < file1.length ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file1[j]) %><br/><%
}
%></td><td><%
for (int j = ln2; j < file2.length ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file2[j]) %><br/><%
}
%></td>
</tr>
</tbody>
</table><%
} else {
%>
<tr><td><%
for (int j = ln1; j < ln1 + 8 ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file1[j]) %><br/><%
}
%><br/> --- <b><%= file1.length - ln1 - 8
%> unchanged lines hidden</b> --- </td><td><%
for (int j = ln2; j < ln2 + 8 ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file2[j]) %><br/><%
}
%><br/>--- <b><%= file1.length - ln1 - 8
%> unchanged lines hidden</b> ---</td>
</tr>
</tbody>
</table><%
}
} else if (type == DiffType.UNIFIED) {
if (full || file2.length - ln2 < 20) {
%>
<tr><td><%
for (int j = ln2; j < file2.length ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file2[j]) %><br/><%
}
%></td>
</tr>
</tbody>
</table><%
} else {
%>
<tr><td><%
for (int j = ln2; j < ln2 + 8 ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file2[j]) %><br/><%
}
%><br/>--- <b><%= file2.length - ln2 - 8
%> unchanged lines hidden</b> ---</td>
</tr>
</tbody>
</table><%
}
} else if (type == DiffType.OLD) {
if (full || file1.length - ln1 < 20) {
for (int j = ln1; j < file1.length ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file1[j]) %><br/><%
}
} else {
for (int j = ln1; j < ln1 + 8 ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file1[j]) %><br/><%
}
%><br/> --- <b><%= file1.length - ln1 - 8
%> unchanged lines hidden</b> ---<br/><%
}
} else if (type == DiffType.NEW) {
if (full || file2.length - ln2 < 20) {
for (int j = ln2; j < file2.length ; j++) {
%><i><%= j+1 %></i><%=Util.htmlize(file2[j])%><br/><%
}
} else {
for (int j = ln2; j < ln2 + 8 ; j++) {
%><i><%= j+1 %></i><%= Util.htmlize(file2[j]) %><br/><%
}
%><br/> --- <b><%= file2.length - ln2 - 8
%> unchanged lines hidden</b> ---<br/><%
}
}
}
//----DIFFS Done--------
%></div>
</div><%
}
}
/* ---------------------- diff.jsp end --------------------- */
%><%@
include file="foot.jspf"
%>
<script src="<%=request.getContextPath()%>/js/diff-0.0.1.js" type="text/javascript"></script>
1
https://gitee.com/hexiangyun/graphic_graphic_2d.git
git@gitee.com:hexiangyun/graphic_graphic_2d.git
hexiangyun
graphic_graphic_2d
graphic_graphic_2d
master

搜索帮助