19 package org.turro.elephant.web.context;
22 import java.nio.file.Path;
23 import java.util.Date;
24 import java.util.List;
25 import org.turro.string.ObjectString;
26 import org.turro.string.Strings;
27 import org.turro.action.Contacts;
28 import org.turro.plugin.contacts.IContact;
36 private static final String
37 RESOURCE_EXT =
"\\.(jsp|html|htm|txt|zul|zhtml)$",
38 EDITABLE_EXT =
"\\.(wiki)$",
39 LOCALE =
"((?:_[a-zA-Z]{2})?(?:_[a-zA-Z]{2})?(?:_[a-zA-Z]{2})?)",
40 BASE =
"^([^\\.\\_]+)",
41 MODIFIED =
"\\.([0-9]+)",
42 AUTHOR =
"\\.([^\\.\\_]+)",
43 RESOURCE = BASE + LOCALE + RESOURCE_EXT,
44 RESOURCE_GLOBAL = BASE + RESOURCE_EXT,
45 EDITABLE = BASE + MODIFIED + AUTHOR + LOCALE + EDITABLE_EXT;
47 private String base, locale, extension, author, modified;
48 private Date modifiedDate;
81 return Strings.isBlank(base);
85 return !
isEmpty() && Strings.isBlank(modified);
89 return !
isEmpty() && !Strings.isBlank(modified);
93 return base + locale +
".html";
97 return base +
"." + modified +
"." + contact.
getId() + locale +
".wiki";
101 return Path.of(folder.toString(),
nameAsEditable(contact)).toFile();
114 if(Strings.isBlank(base)) {
115 wrp.base =
"000" + ObjectString.formatObject(
new Date(),
116 ObjectString.COMPRESSED_DATE_PATTERN,
false);
120 wrp.modified = ObjectString.formatObject(
new Date(),
121 ObjectString.COMPRESSED_DATE_PATTERN,
false);
122 wrp.author = contact.
getId();
124 wrp.extension =
"wiki";
128 private void matchFile(File file) {
129 if(file ==
null)
return;
130 String fileName = file.getName();
131 if(fileName.matches(RESOURCE)) {
132 List<String> parts = Strings.extractAllGroups(fileName, RESOURCE);
133 if(parts.size() == 3) {
135 locale = parts.get(1);
136 extension = parts.get(2);
138 }
else if(fileName.matches(RESOURCE_GLOBAL)) {
139 List<String> parts = Strings.extractAllGroups(fileName, RESOURCE_GLOBAL);
140 if(parts.size() == 2) {
143 extension = parts.get(1);
145 }
else if(fileName.matches(EDITABLE)) {
146 List<String> parts = Strings.extractAllGroups(fileName, EDITABLE);
147 if(parts.size() == 5) {
149 modified = parts.get(1);
150 author = parts.get(2);
151 locale = parts.get(3);
152 extension = parts.get(4);
153 modifiedDate = (Date) ObjectString.parseString(modified,
154 ObjectString.COMPRESSED_DATE_PATTERN, Date.class,
false);
File getEditableFile(Path folder, IContact contact)
String nameAsEditable(IContact contact)
static WebResourceParts editable(IContact contact, String base, String locale)
WebResourceParts(File file)
File getResourceFile(Path folder)