use of org.structr.schema.ConfigurationProvider in project structr by structr.
the class Page method createElement.
static Element createElement(final Page page, final String tag, final boolean suppressException) {
final String elementType = StringUtils.capitalize(tag);
final App app = StructrApp.getInstance(page.getSecurityContext());
String c = Content.class.getSimpleName();
// Avoid creating an (invalid) 'Content' DOMElement
if (elementType == null || c.equals(elementType)) {
logger.warn("Blocked attempt to create a DOMElement of type {}", c);
return null;
}
try {
// final Class entityClass = Class.forName("org.structr.web.entity.html." + elementType);
final Class entityClass = Class.forName("org.structr.web.entity.html." + elementType);
if (entityClass != null) {
final ConfigurationProvider config = StructrApp.getConfiguration();
final DOMElement element = (DOMElement) app.create(entityClass, new NodeAttribute(StructrApp.key(entityClass, "tag"), tag), new NodeAttribute(StructrApp.key(entityClass, "hideOnDetail"), false), new NodeAttribute(StructrApp.key(entityClass, "hideOnIndex"), false));
element.doAdopt(page);
return element;
}
} catch (Throwable t) {
if (!suppressException) {
logger.error("Unable to instantiate element of type " + elementType, t);
}
}
return null;
}
use of org.structr.schema.ConfigurationProvider in project structr by structr.
the class CreateArchiveFunction method apply.
@Override
public Object apply(ActionContext ctx, Object caller, Object[] sources) throws FrameworkException {
if (!(sources[1] instanceof File || sources[1] instanceof Folder || sources[1] instanceof Collection || sources.length < 2)) {
logParameterError(caller, sources, ctx.isJavaScriptContext());
return usage(ctx.isJavaScriptContext());
}
final ConfigurationProvider config = StructrApp.getConfiguration();
try {
java.io.File newArchive = java.io.File.createTempFile(sources[0].toString(), "zip");
ZipArchiveOutputStream zaps = new ZipArchiveOutputStream(newArchive);
zaps.setEncoding("UTF8");
zaps.setUseLanguageEncodingFlag(true);
zaps.setCreateUnicodeExtraFields(ZipArchiveOutputStream.UnicodeExtraFieldPolicy.ALWAYS);
zaps.setFallbackToUTF8(true);
if (sources[1] instanceof File) {
File file = (File) sources[1];
addFileToZipArchive(file.getProperty(AbstractFile.name), file, zaps);
} else if (sources[1] instanceof Folder) {
Folder folder = (Folder) sources[1];
addFilesToArchive(folder.getProperty(Folder.name) + "/", folder.getFiles(), zaps);
addFoldersToArchive(folder.getProperty(Folder.name) + "/", folder.getFolders(), zaps);
} else if (sources[1] instanceof Collection) {
for (Object fileOrFolder : (Collection) sources[1]) {
if (fileOrFolder instanceof File) {
File file = (File) fileOrFolder;
addFileToZipArchive(file.getProperty(AbstractFile.name), file, zaps);
} else if (fileOrFolder instanceof Folder) {
Folder folder = (Folder) fileOrFolder;
addFilesToArchive(folder.getProperty(Folder.name) + "/", folder.getFiles(), zaps);
addFoldersToArchive(folder.getProperty(Folder.name) + "/", folder.getFolders(), zaps);
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
return usage(ctx.isJavaScriptContext());
}
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
return usage(ctx.isJavaScriptContext());
}
zaps.close();
Class archiveClass = null;
if (sources.length > 2) {
archiveClass = config.getNodeEntityClass(sources[2].toString());
}
if (archiveClass == null) {
archiveClass = org.structr.web.entity.File.class;
}
try (final FileInputStream fis = new FileInputStream(newArchive)) {
return FileHelper.createFile(ctx.getSecurityContext(), fis, "application/zip", archiveClass, sources[0].toString() + ".zip");
}
} catch (IOException e) {
logException(caller, e, sources);
}
return null;
}
use of org.structr.schema.ConfigurationProvider in project structr by structr.
the class SearchCommand method typeAndAllSupertypes.
public static Set<Class> typeAndAllSupertypes(final Class type) {
final ConfigurationProvider configuration = StructrApp.getConfiguration();
final Set<Class> allSupertypes = new LinkedHashSet<>();
Class localType = type;
while (localType != null && !localType.equals(Object.class)) {
allSupertypes.add(localType);
allSupertypes.addAll(configuration.getInterfacesForType(localType));
localType = localType.getSuperclass();
}
// remove base types
allSupertypes.removeAll(baseTypes);
return allSupertypes;
}
use of org.structr.schema.ConfigurationProvider in project structr by structr.
the class SearchCommand method getAllSubtypesAsStringSet.
public static synchronized Set<String> getAllSubtypesAsStringSet(final String type) {
Set<String> allSubtypes = subtypeMapForType.get(type);
if (allSubtypes == null) {
logger.debug("Subtype map cache miss.");
allSubtypes = new LinkedHashSet<>();
subtypeMapForType.put(type, allSubtypes);
final ConfigurationProvider configuration = StructrApp.getConfiguration();
final Map<String, Class<? extends NodeInterface>> nodeEntities = configuration.getNodeEntities();
final Map<String, Class<? extends RelationshipInterface>> relEntities = configuration.getRelationshipEntities();
// add type first (this is neccesary because two class objects of the same dynamic type node are not equal
// to each other and not assignable, if the schema node was modified in the meantime)
allSubtypes.add(type);
// scan all node entities for subtypes
for (final Map.Entry<String, Class<? extends NodeInterface>> entity : nodeEntities.entrySet()) {
final Class entityType = entity.getValue();
final Set<Class> ancestors = typeAndAllSupertypes(entityType);
for (final Class superClass : ancestors) {
final String superClasSimpleName = superClass.getSimpleName();
final String superClassFullName = superClass.getName();
if ((superClassFullName.startsWith("org.structr.") || superClassFullName.startsWith("com.structr.")) && superClasSimpleName.equals(type)) {
allSubtypes.add(entityType.getSimpleName());
}
}
}
// scan all relationship entities for subtypes
for (final Map.Entry<String, Class<? extends RelationshipInterface>> entity : relEntities.entrySet()) {
final Class entityType = entity.getValue();
final Set<Class> ancestors = typeAndAllSupertypes(entityType);
for (final Class superClass : ancestors) {
final String superClasSimpleName = superClass.getSimpleName();
final String superClassFullName = superClass.getName();
if ((superClassFullName.startsWith("org.structr.") || superClassFullName.startsWith("com.structr.")) && superClasSimpleName.equals(type)) {
allSubtypes.add(entityType.getSimpleName());
}
}
}
} else {
logger.debug("Subtype map cache hit.");
}
return Collections.unmodifiableSet(allSubtypes);
}
use of org.structr.schema.ConfigurationProvider in project structr by structr.
the class Resource method extractSearchableAttributes.
protected void extractSearchableAttributes(final SecurityContext securityContext, final Class type, final HttpServletRequest request, final Query query) throws FrameworkException {
if (type != null && request != null && !request.getParameterMap().isEmpty()) {
final boolean exactSearch = !(parseInteger(request.getParameter(JsonRestServlet.REQUEST_PARAMETER_LOOSE_SEARCH)) == 1);
final ConfigurationProvider conf = Services.getInstance().getConfigurationProvider();
final List<PropertyKey> searchKeys = new LinkedList<>();
for (final String name : request.getParameterMap().keySet()) {
final PropertyKey key = StructrApp.getConfiguration().getPropertyKeyForJSONName(type, getFirstPartOfString(name), false);
if (key != null) {
// add to list of searchable keys
searchKeys.add(key);
} else if (!JsonRestServlet.commonRequestParameters.contains(name)) {
// exclude common request parameters here (should not throw exception)
throw new FrameworkException(400, "Unknown search key " + name);
}
}
// sort list of search keys according to their desired order
// so that querying search attributes can use other attributes
// to refine their partial results.
Collections.sort(searchKeys, new PropertyKeyProcessingOrderComparator());
for (final PropertyKey key : searchKeys) {
// hand list of search attributes over to key
key.extractSearchableAttribute(securityContext, request, exactSearch, query);
}
}
}
Aggregations