LinkInfoStorageImpl.java
27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.commons.jcr.JcrUtil
* com.day.text.Text
* javax.jcr.Item
* javax.jcr.Node
* javax.jcr.NodeIterator
* javax.jcr.PathNotFoundException
* javax.jcr.Property
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.Value
* javax.jcr.Workspace
* javax.jcr.observation.EventIterator
* javax.jcr.observation.EventListener
* javax.jcr.observation.ObservationManager
* org.apache.felix.scr.annotations.Activate
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Deactivate
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.commons.osgi.PropertiesUtil
* org.apache.sling.discovery.InstanceDescription
* org.apache.sling.discovery.TopologyEvent
* org.apache.sling.discovery.TopologyEvent$Type
* org.apache.sling.discovery.TopologyEventListener
* org.apache.sling.discovery.TopologyView
* org.apache.sling.jcr.api.SlingRepository
* org.osgi.service.component.ComponentContext
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.rewriter.linkchecker.impl;
import com.day.cq.commons.jcr.JcrUtil;
import com.day.cq.rewriter.linkchecker.LinkInfo;
import com.day.cq.rewriter.linkchecker.LinkInfoStorage;
import com.day.text.Text;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.jcr.Item;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.Workspace;
import javax.jcr.observation.EventIterator;
import javax.jcr.observation.EventListener;
import javax.jcr.observation.ObservationManager;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.commons.osgi.PropertiesUtil;
import org.apache.sling.discovery.InstanceDescription;
import org.apache.sling.discovery.TopologyEvent;
import org.apache.sling.discovery.TopologyEventListener;
import org.apache.sling.discovery.TopologyView;
import org.apache.sling.jcr.api.SlingRepository;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(label="%storageservice.name", description="%storageservice.description", metatype=1)
@Service(value={LinkInfoStorage.class, Runnable.class, TopologyEventListener.class})
@Properties(value={@org.apache.felix.scr.annotations.Property(name="scheduler.period", longValue={5}, propertyPrivate=1), @org.apache.felix.scr.annotations.Property(name="scheduler.concurrent", boolValue={0}, propertyPrivate=1)})
public class LinkInfoStorageImpl
implements LinkInfoStorage,
Runnable,
EventListener,
TopologyEventListener {
private static final long LAST_ACCESS_ACCURACY = 600000;
private static final boolean SAVE_EXTERNAL_REFERENCES_DEFAULT = true;
private static final Logger logger = LoggerFactory.getLogger(LinkInfoStorageImpl.class);
private static final String PN_LAST_ACCESSED = "lastAccessed";
private static final String PN_LAST_CHECKED = "lastChecked";
private static final String PN_LAST_AVAILABLE = "lastAvailable";
private static final String PN_LAST_STATUS = "lastStatus";
private static final String PN_VALID = "valid";
private static final String PN_REFERENCED_BY = "referencedBy";
private static final String LINKSTORAGE_SERVICE = "linkstorage-service";
private static final int MAX_LINKS_PER_HOST_DEFAULT = 500;
private static final String LINKCHECKER_RESOURCETYPE = "cq/linkchecker/components/linkchecker";
@org.apache.felix.scr.annotations.Property(value={"/var/linkchecker"}, propertyPrivate=1)
private static final String REPOSITORY_PATH = "service.repository_path";
@org.apache.felix.scr.annotations.Property(intValue={500})
private static final String MAX_LINKS_PER_HOST = "service.max_links_per_host";
@org.apache.felix.scr.annotations.Property(boolValue={1})
private static final String SAVE_EXTERNAL_LINK_REFERENCES = "service.save_external_link_references";
private Boolean isMasterInstance = Boolean.FALSE;
protected String storageRootPath;
protected int maxLinksPerHost;
protected Session readSession;
protected Session writeSession;
protected boolean saveExternalReferences;
private final Map<String, Entry> infos = new HashMap<String, Entry>();
private final Map<String, HostInfo> hostInfos = new HashMap<String, HostInfo>();
private final ReadWriteLock lock = new ReentrantReadWriteLock();
private final Lock writeBackLock = new ReentrantLock();
@Reference
private SlingRepository repository = null;
@Activate
protected void activate(ComponentContext context) throws RepositoryException {
Dictionary props = context.getProperties();
this.infos.clear();
this.writeSession = this.repository.loginService("linkstorage-service", null);
this.storageRootPath = (String)props.get("service.repository_path");
this.maxLinksPerHost = PropertiesUtil.toInteger(props.get("service.max_links_per_host"), (int)500);
this.saveExternalReferences = PropertiesUtil.toBoolean(props.get("service.save_external_link_references"), (boolean)true);
this.init();
this.upgradeStorage();
this.fillCache();
this.writeSession.getWorkspace().getObservationManager().addEventListener((EventListener)this, 19, this.storageRootPath, true, null, null, true);
logger.debug("LinkInfoStorage service activated");
}
private void upgradeStorage() {
try {
Node root = this.getStorageRoot(this.writeSession);
if (root != null) {
NodeIterator iter = root.getNodes();
while (iter.hasNext()) {
Node node = (Node)iter.next();
if (!node.hasProperty("url")) continue;
String url = node.getProperty("url").getString();
logger.debug("Converting legacy link info for {}", (Object)url);
LinkInfo info = LinkInfoStorageImpl.createInfo(node, url, this.saveExternalReferences);
Entry e = new Entry(info);
if (e.hostname != null) {
HostInfo hInfo = this.hostInfos.get(e.hostname);
if (hInfo == null) {
hInfo = new HostInfo();
this.hostInfos.put(e.hostname, hInfo);
}
if (hInfo.numLinks == this.maxLinksPerHost) {
logger.warn("External links for host {} has reached the maximum number of [ {} ] configured per host.", (Object)e.hostname, (Object)this.maxLinksPerHost);
logger.warn("You can change maximum allowed links configuration by updating the [ {} ] service parameter for {}", (Object)"service.max_links_per_host", (Object)LinkInfoStorage.class.getName());
} else {
hInfo.numLinks++;
e.modified = true;
this.infos.put(e.relPath, e);
}
}
node.remove();
}
if (!this.infos.isEmpty()) {
logger.debug("Saving {} removed nodes....", (Object)this.infos.size());
root.getSession().save();
logger.debug("Saving converted link infos.");
this.sync();
logger.debug("Upgrade done.");
}
}
}
catch (RepositoryException e) {
logger.error("Error during upgrade link checker information: " + e.getMessage(), (Throwable)e);
}
}
protected void init() throws RepositoryException {
try {
Node storageRoot = this.writeSession.getNode(this.storageRootPath);
if (!storageRoot.hasProperty("sling:resourceType") || !"cq/linkchecker/components/linkchecker".equals(storageRoot.getProperty("sling:resourceType").getString())) {
storageRoot.setProperty("sling:resourceType", "cq/linkchecker/components/linkchecker");
}
if (this.writeSession.hasPendingChanges()) {
this.writeSession.save();
}
}
catch (PathNotFoundException e) {
logger.error("Error getting the default node var/linkchecker. Please make sure it exists");
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Deactivate
protected void deactivate() {
block8 : {
this.writeBackLock.lock();
try {
if (this.writeSession == null) break block8;
try {
this.writeSession.getWorkspace().getObservationManager().removeEventListener((EventListener)this);
}
catch (RepositoryException e) {
// empty catch block
}
this.writeSession.logout();
this.writeSession = null;
}
finally {
this.writeBackLock.unlock();
}
}
this.lock.writeLock().lock();
try {
this.infos.clear();
}
finally {
this.lock.writeLock().unlock();
}
logger.debug("LinkInfoStorage service shut down");
}
public void handleTopologyEvent(TopologyEvent event) {
if (event.getType() == TopologyEvent.Type.TOPOLOGY_CHANGED || event.getType() == TopologyEvent.Type.TOPOLOGY_INIT) {
this.isMasterInstance = event.getNewView().getLocalInstance().isLeader();
} else if (event.getType() == TopologyEvent.Type.TOPOLOGY_CHANGING) {
this.isMasterInstance = false;
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public String[] getLinks() {
ArrayList<String> links;
links = new ArrayList<String>();
this.lock.readLock().lock();
try {
for (Entry e : this.infos.values()) {
if (e.info == null) continue;
links.add(e.info.getUrl());
}
}
finally {
this.lock.readLock().unlock();
}
Collections.sort(links);
return links.toArray(new String[links.size()]);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public LinkInfo getLinkInfo(String url) {
this.lock.readLock().lock();
try {
Entry e = this.infos.get(url);
LinkInfo linkInfo = e == null || e.info == null ? null : new LinkInfo(e.info){
@Override
public String[] getReferrer() {
return LinkInfoStorageImpl.this.saveExternalReferences ? super.getReferrer() : new String[]{};
}
};
return linkInfo;
}
finally {
this.lock.readLock().unlock();
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public void putLinkInfo(LinkInfo info) {
info = new LinkInfo(info);
String key = info.getUrl();
this.lock.writeLock().lock();
try {
Entry e = this.infos.get(key);
if (e == null || e.info == null) {
e = new Entry(info);
if (e.hostname == null) {
return;
}
HostInfo hostInfo = this.hostInfos.get(e.hostname);
if (hostInfo == null) {
hostInfo = new HostInfo();
this.hostInfos.put(e.hostname, hostInfo);
}
if (hostInfo.numLinks == this.maxLinksPerHost) {
logger.warn("External links for host {} has reached the maximum number of [ {} ] configured per host.", (Object)e.hostname, (Object)this.maxLinksPerHost);
logger.warn("You can change maximum allowed links configuration by updating the [ {} ] service parameter for {}", (Object)"service.max_links_per_host", (Object)LinkInfoStorage.class.getName());
return;
}
hostInfo.numLinks++;
e.modified = true;
this.infos.put(key, e);
} else if (!e.info.isSame(info)) {
e.info = info;
e.modified = true;
} else {
long t2;
long t1 = e.info.getLastAccessed() == null ? 0 : e.info.getLastAccessed().getTimeInMillis();
long l = t2 = info.getLastAccessed() == null ? 0 : info.getLastAccessed().getTimeInMillis();
if (t2 - t1 > 600000) {
e.info = info;
e.modified = true;
}
}
}
finally {
this.lock.writeLock().unlock();
}
}
@Override
public void deleteLinkInfo(LinkInfo info) {
if (info == null) {
throw new IllegalArgumentException("LinkInfo must not be null.");
}
this.deleteLinkInfo(info.getUrl());
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public void deleteLinkInfo(String url) {
this.lock.writeLock().lock();
try {
Entry e = this.infos.get(url);
if (e != null) {
e.info = null;
HostInfo hInfo = this.hostInfos.get(e.hostname);
if (hInfo != null) {
hInfo.numLinks--;
}
}
}
finally {
this.lock.writeLock().unlock();
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public void sync() {
this.writeBackLock.lock();
try {
this.writeBack();
}
finally {
this.writeBackLock.unlock();
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public void run() {
if (!this.isMasterInstance.booleanValue()) {
return;
}
try {
if (this.writeBackLock.tryLock()) {
try {
this.writeBack();
}
finally {
this.writeBackLock.unlock();
}
}
}
catch (Throwable t) {
logger.error("Unhandled Throwable in " + this.getClass().getSimpleName(), t);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void writeBack() {
HashMap<String, LinkInfo> toUpdate;
HashSet<String> toDelete;
if (this.writeSession == null) {
return;
}
toDelete = new HashSet<String>();
toUpdate = new HashMap<String, LinkInfo>();
this.lock.writeLock().lock();
try {
Iterator<Map.Entry<String, Entry>> iter = this.infos.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<String, Entry> e = iter.next();
Entry entry = e.getValue();
if (entry.info == null) {
toDelete.add(entry.relPath);
iter.remove();
continue;
}
if (!entry.modified) continue;
toUpdate.put(entry.relPath, entry.info);
entry.modified = false;
}
}
finally {
this.lock.writeLock().unlock();
}
if (toDelete.isEmpty() && toUpdate.isEmpty()) {
logger.debug("no link infos modified or deleted.");
return;
}
Node root = this.getStorageRoot(this.writeSession);
if (root == null) {
try {
this.init();
root = this.getStorageRoot(this.writeSession);
}
catch (RepositoryException e) {
logger.error("error during re-initialization of storage root.", (Throwable)e);
}
if (root == null) {
return;
}
}
int retries = 3;
while (retries-- > 0) {
try {
for (String name : toDelete) {
if (!root.hasNode(name)) continue;
logger.debug("deleting {}", (Object)name);
root.getNode(name).remove();
}
for (Map.Entry e : toUpdate.entrySet()) {
String[] segments;
Node node = root;
for (String name2 : segments = Text.explode((String)((String)e.getKey()), (int)47)) {
node = node.hasNode(name2) ? node.getNode(name2) : node.addNode(name2);
}
logger.debug("updating {}", e.getKey());
this.writeInfo((LinkInfo)e.getValue(), node);
}
this.writeSession.save();
logger.debug("Updated {} and deleted {} link infos.", (Object)toUpdate.size(), (Object)toDelete.size());
return;
}
catch (RepositoryException e) {
logger.error("Error during writeback of link infos.", (Throwable)e);
try {
this.writeSession.refresh(false);
}
catch (RepositoryException e) {
logger.error("Error during refresh. aborting.", (Throwable)e);
return;
}
if (retries <= 0) continue;
logger.error("Retrying writeback in 100ms...");
try {
Thread.sleep(100);
}
catch (InterruptedException e1) {}
continue;
}
}
logger.error("Unrecoverable error during write back. try restarting the service.");
}
public void onEvent(EventIterator eventIterator) {
logger.debug("Modification below {} detected. reloading cache.", (Object)this.storageRootPath);
Thread bgThread = new Thread(new Runnable(){
@Override
public void run() {
long now = System.currentTimeMillis();
int numLinks = LinkInfoStorageImpl.this.fillCache();
logger.info("Reloaded {} external links in {}ms", (Object)numLinks, (Object)(System.currentTimeMillis() - now));
}
}, "LinkInfoStorage Loader");
bgThread.setDaemon(true);
bgThread.start();
}
private Node getStorageRoot(Session session) {
try {
if (!session.itemExists(this.storageRootPath)) {
return null;
}
return (Node)session.getItem(this.storageRootPath);
}
catch (Exception e) {
logger.error("error while retrieving linkchecker storage root. try restarting the service.", (Throwable)e);
return null;
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private int fillCache() {
try {
this.readSession = this.repository.loginService("linkstorage-service", null);
HashMap<String, Entry> links = new HashMap<String, Entry>();
HashMap<String, HostInfo> hInfos = new HashMap<String, HostInfo>();
Node root = this.getStorageRoot(this.readSession);
if (root != null) {
NodeIterator iter = root.getNodes();
while (iter.hasNext()) {
Node node = (Node)iter.next();
LinkInfoStorageImpl.loadProtocols(links, hInfos, node.getName() + ":/", node, this.saveExternalReferences);
}
}
this.lock.writeLock().lock();
try {
this.infos.clear();
this.infos.putAll(links);
this.hostInfos.clear();
this.hostInfos.putAll(hInfos);
int iter = links.size();
this.lock.writeLock().unlock();
return iter;
}
catch (Throwable var6_8) {
try {
this.lock.writeLock().unlock();
throw var6_8;
}
catch (RepositoryException e) {
logger.error("Error while retrieving the link infos.", (Throwable)e);
}
}
}
finally {
if (this.readSession != null) {
this.readSession.logout();
}
}
return -1;
}
private static void loadProtocols(Map<String, Entry> links, Map<String, HostInfo> hostInfos, String parentUrl, Node parent, boolean getReferences) throws RepositoryException {
NodeIterator iter = parent.getNodes();
while (iter.hasNext()) {
Node node = (Node)iter.next();
String host = JcrUtil.unescapeIllegalJcrChars((String)node.getName());
HostInfo hostInfo = new HostInfo();
hostInfos.put(host, hostInfo);
String url = parentUrl + "/" + host;
String relPath = parent.getName() + "/" + node.getName();
LinkInfoStorageImpl.loadInfos(links, url, node, relPath, hostInfo, getReferences);
}
}
private static void loadInfos(Map<String, Entry> links, String parentUrl, Node parent, String parentPath, HostInfo hostInfo, boolean getReferences) throws RepositoryException {
if (parent.hasProperty("lastAccessed")) {
LinkInfo info = LinkInfoStorageImpl.createInfo(parent, parentUrl, getReferences);
Entry e = new Entry(parentPath, info);
links.put(parentUrl, e);
hostInfo.numLinks++;
}
NodeIterator iter = parent.getNodes();
while (iter.hasNext()) {
Node node = (Node)iter.next();
String urlSegment = JcrUtil.unescapeIllegalJcrChars((String)node.getName());
if (urlSegment.equals("/")) {
urlSegment = "";
}
String url = parentUrl + "/" + urlSegment;
String relPath = parentPath + "/" + node.getName();
LinkInfoStorageImpl.loadInfos(links, url, node, relPath, hostInfo, getReferences);
}
}
private void writeInfo(LinkInfo info, Node node) throws RepositoryException {
node.setProperty("lastAccessed", info.getLastAccessed());
node.setProperty("lastChecked", info.getLastChecked());
node.setProperty("lastAvailable", info.getLastAvailable());
node.setProperty("lastStatus", (long)info.getLastStatus());
node.setProperty("valid", info.isValid());
String[] referrer = info.getReferrer();
if (this.saveExternalReferences) {
if (referrer == null || referrer.length == 0) {
try {
Property p = node.getProperty("referencedBy");
if (p != null) {
p.remove();
}
}
catch (Exception ignore) {}
} else {
node.setProperty("referencedBy", referrer);
}
}
}
private static LinkInfo createInfo(Node node, String url, boolean getReferences) throws RepositoryException {
LinkInfo info = new LinkInfo(url);
if (node.hasProperty("lastAccessed")) {
info.setLastAccessed(node.getProperty("lastAccessed").getDate());
}
if (node.hasProperty("lastChecked")) {
info.setLastChecked(node.getProperty("lastChecked").getDate());
}
if (node.hasProperty("lastAvailable")) {
info.setLastAvailable(node.getProperty("lastAvailable").getDate());
}
if (node.hasProperty("valid")) {
info.setValid(node.getProperty("valid").getBoolean());
}
if (node.hasProperty("lastStatus")) {
info.setLastStatus((int)node.getProperty("lastStatus").getLong());
}
if (getReferences && node.hasProperty("referencedBy")) {
for (Value v : node.getProperty("referencedBy").getValues()) {
info.addReferrer(v.getString());
}
}
return info;
}
protected void bindRepository(SlingRepository slingRepository) {
this.repository = slingRepository;
}
protected void unbindRepository(SlingRepository slingRepository) {
if (this.repository == slingRepository) {
this.repository = null;
}
}
private static class HostInfo {
private int numLinks;
private HostInfo() {
}
}
protected static class Entry {
private String hostname;
private String relPath;
private LinkInfo info;
private boolean modified;
protected Entry(LinkInfo info) {
this.info = info;
try {
String[] segments;
URI uri = new URI(info.getUrl());
this.hostname = uri.getHost();
if (uri.getPort() >= 0) {
this.hostname = this.hostname + ":" + uri.getPort();
}
StringBuilder path = new StringBuilder();
String scheme = uri.getScheme();
if (scheme != null && scheme.length() > 0) {
path.append(JcrUtil.escapeIllegalJcrChars((String)scheme));
}
String schemeSpecific = uri.getSchemeSpecificPart();
for (String s : segments = Text.explode((String)schemeSpecific, (int)47)) {
path.append('/').append(JcrUtil.escapeIllegalJcrChars((String)s));
}
if (schemeSpecific.endsWith("/")) {
path.append("/").append(JcrUtil.escapeIllegalJcrChars((String)"/"));
}
this.relPath = path.toString();
}
catch (URISyntaxException e) {
// empty catch block
}
}
private Entry(String relPath, LinkInfo info) {
this.relPath = relPath;
this.info = info;
}
protected String getHostname() {
return this.hostname;
}
protected String getRelPath() {
return this.relPath;
}
}
}