Debian Codegraph @

netx/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageExtendedImpl.java

raw
1 /* Copyright (C) 2013 Red Hat, Inc.
2
3 This file is part of IcedTea.
4
5 IcedTea is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 2.
8
9 IcedTea is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with IcedTea; see the file COPYING. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301 USA.
18
19 Linking this library statically or dynamically with other modules is
20 making a combined work based on this library. Thus, the terms and
21 conditions of the GNU General Public License cover the whole
22 combination.
23
24 As a special exception, the copyright holders of this library give you
25 permission to link this library with independent modules to produce an
26 executable, regardless of the license terms of these independent
27 modules, and to copy and distribute the resulting executable under
28 terms of your choice, provided that you also meet, for each linked
29 independent module, the terms and conditions of the license of that
30 module. An independent module is a module which is not derived from
31 or based on this library. If you modify this library, you may extend
32 this exception to your version of the library, but you are not
33 obligated to do so. If you do not wish to do so, delete this
34 exception statement from your version.
35 */
36 package net.sourceforge.jnlp.security.appletextendedsecurity.impl;
37
38 import java.io.File;
39 import java.io.IOException;
40 import java.util.Date;
41 import net.sourceforge.jnlp.security.appletextendedsecurity.UnsignedAppletActionEntry;
42 import net.sourceforge.jnlp.security.appletextendedsecurity.UrlRegEx;
43 import net.sourceforge.jnlp.security.dialogs.remember.AppletSecurityActions;
44 import net.sourceforge.jnlp.security.dialogs.remember.ExecuteAppletAction;
45 import net.sourceforge.jnlp.util.lockingfile.StorageIoException;
46
47 public class UnsignedAppletActionStorageExtendedImpl extends UnsignedAppletActionStorageImpl {
48
49 public UnsignedAppletActionStorageExtendedImpl(String location) {
50 this(new File(location));
51 }
52
53 public UnsignedAppletActionStorageExtendedImpl(File location) {
54 super(location);
55 }
56
57 /**
58 *
59 * @return always fresh copy loaded from disc
60 */
61 public UnsignedAppletActionEntry[] toArray() {
62 lock();
63 try {
64 readContents();
65 return items.toArray(new UnsignedAppletActionEntry[items.size()]);
66 } catch (IOException e) {
67 throw new StorageIoException(e);
68 } finally {
69 unlock();
70 }
71 }
72
73 public void clear() {
74 doLocked(new Runnable() {
75 @Override
76 public void run() {
77 try {
78 items.clear();
79 writeContents();
80 } catch (IOException e) {
81 throw new StorageIoException(e);
82 }
83 }
84 });
85 }
86
87 public void removeByBehaviour(final ExecuteAppletAction unsignedAppletAction) {
88 doLocked(new Runnable() {
89 @Override
90 public void run() {
91 try {
92 readContents();
93 for (int i = 0; i < items.size(); i++) {
94 UnsignedAppletActionEntry unsignedAppletActionEntry = items.get(i);
95 AppletSecurityActions actions = unsignedAppletActionEntry.getAppletSecurityActions();
96 for (int j = 0; j < actions.getRealCount(); j++) {
97 // ExecuteAppletAction action = actions.getAction(j);
98 // if (action == unsignedAppletAction) {
99 // items.remove(i);
100 // i--;
101 // break; //actions loop
102 // }
103 }
104 }
105 writeContents();
106 } catch (IOException e) {
107 throw new StorageIoException(e);
108 }
109 }
110 });
111 }
112
113 private void swap(final int i, final int ii) {
114 doLocked(new Runnable() {
115 public void run() {
116 try {
117 readContents();
118 UnsignedAppletActionEntry backup = items.get(i);
119 items.set(i, items.get(ii));
120 items.set(ii, backup);
121 writeContents();
122 } catch (IOException e) {
123 throw new StorageIoException(e);
124 }
125 }
126 });
127
128 }
129
130 public int moveUp(int selectedRow) {
131 if (selectedRow <= 0) {
132 return selectedRow;
133 }
134 swap(selectedRow, selectedRow - 1);
135 return selectedRow-1;
136 }
137
138 public int moveDown(int selectedRow) {
139 if (selectedRow >= items.size() - 1) {
140 return selectedRow;
141 }
142 swap(selectedRow, selectedRow + 1);
143 return selectedRow+1;
144 }
145
146 public void remove(final int item) {
147 doLocked(new Runnable() {
148 public void run() {
149 try {
150 readContents();
151 items.remove(item);
152 writeContents();
153 } catch (IOException ex) {
154 throw new StorageIoException(ex);
155 }
156 }
157 });
158 }
159
160 public void modify(final UnsignedAppletActionEntry source, final int columnIndex, final Object aValue) {
161 Runnable r = new Runnable() {
162 @Override
163 public void run() {
164
165 try {
166 if (!items.contains(source)) {
167 throw new StorageIoException("Item to be modified not found in storage");
168 }
169
170 if (columnIndex == 0) {
171 source.getAppletSecurityActions().refresh((String) aValue);
172 }
173 if (columnIndex == 1) {
174 source.setTimeStamp((Date) aValue);
175 }
176 if (columnIndex == 2) {
177 source.setDocumentBase(UrlRegEx.exact((String) aValue));
178 }
179 if (columnIndex == 3) {
180 source.setCodeBase(UrlRegEx.exact((String) aValue));
181 }
182 if (columnIndex == 4) {
183 source.setArchives(UnsignedAppletActionEntry.createArchivesList((String) aValue));
184 }
185
186 writeContents();
187 } catch (IOException ex) {
188 throw new StorageIoException(ex);
189 }
190 }
191 };
192 doLocked(r);
193
194 }
195
196 @Override
197 public synchronized void writeContentsLocked() throws IOException {
198 super.writeContentsLocked();
199 }
200 }