use of org.structr.core.property.StringProperty in project structr by structr.
the class ODFExporter method exportImage.
public static void exportImage(final ODFExporter thisNode, final String uuid) {
final File output = thisNode.getResultDocument();
try {
final App app = StructrApp.getInstance();
final Image result = app.nodeQuery(Image.class).and(GraphObject.id, uuid).getFirst();
String imageName = result.getProperty(new StringProperty("name"));
String contentType = result.getProperty(new StringProperty("contentType"));
String templateImagePath = null;
OdfDocument doc = OdfDocument.loadDocument(output.getFileOnDisk().getAbsolutePath());
NodeList nodes = doc.getContentRoot().getElementsByTagName(ODF_IMAGE_PARENT_NAME);
for (int i = 0; i < nodes.getLength(); i++) {
Node currentNode = nodes.item(i);
NamedNodeMap attrs = currentNode.getAttributes();
Node fieldName = attrs.getNamedItem(ODF_IMAGE_ATTRIBUTE_PARENT_IMAGE_NAME);
if (fieldName != null && fieldName.getTextContent().equals(imageName)) {
NamedNodeMap childAttrs = currentNode.getFirstChild().getAttributes();
Node filePath = childAttrs.getNamedItem(ODF_IMAGE_ATTRIBUTE_FILE_PATH);
templateImagePath = filePath.getTextContent();
filePath.setTextContent(ODF_IMAGE_DIRECTORY + imageName);
}
}
OdfPackage pkg = doc.getPackage();
if (templateImagePath != null && templateImagePath.length() > 0) {
pkg.remove(templateImagePath);
}
pkg.insert(new URI(result.getFileOnDisk().getAbsolutePath()), ODF_IMAGE_DIRECTORY + imageName, contentType);
pkg.save(output.getFileOnDisk().getAbsolutePath());
pkg.close();
doc.close();
} catch (Exception e) {
logger.error("Error while exporting image to document", e);
}
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class DOMElement method renderStructrAppLib.
static void renderStructrAppLib(final DOMElement thisElement, final AsyncBuffer out, final SecurityContext securityContext, final RenderContext renderContext, final int depth) throws FrameworkException {
EditMode editMode = renderContext.getEditMode(securityContext.getUser(false));
if (!(EditMode.DEPLOYMENT.equals(editMode) || EditMode.RAW.equals(editMode) || EditMode.WIDGET.equals(editMode)) && !renderContext.appLibRendered() && thisElement.getProperty(new StringProperty(STRUCTR_ACTION_PROPERTY)) != null) {
out.append("<!--").append(DOMNode.indent(depth, renderContext)).append("--><script>if (!window.jQuery) { document.write('<script src=\"/structr/js/lib/jquery-1.11.1.min.js\"><\\/script>'); }</script><!--").append(DOMNode.indent(depth, renderContext)).append("--><script>if (!window.jQuery.ui) { document.write('<script src=\"/structr/js/lib/jquery-ui-1.11.0.custom.min.js\"><\\/script>'); }</script><!--").append(DOMNode.indent(depth, renderContext)).append("--><script>if (!window.jQuery.ui.timepicker) { document.write('<script src=\"/structr/js/lib/jquery-ui-timepicker-addon.min.js\"><\\/script>'); }</script><!--").append(DOMNode.indent(depth, renderContext)).append("--><script>if (!window.StructrApp) { document.write('<script src=\"/structr/js/structr-app.js\"><\\/script>'); }</script><!--").append(DOMNode.indent(depth, renderContext)).append("--><script>if (!window.moment) { document.write('<script src=\"/structr/js/lib/moment.min.js\"><\\/script>'); }</script><!--").append(DOMNode.indent(depth, renderContext)).append("--><link rel=\"stylesheet\" type=\"text/css\" href=\"/structr/css/lib/jquery-ui-1.10.3.custom.min.css\">");
renderContext.setAppLibRendered(true);
}
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class DOMNode method getDataPropertyKeys.
static Set<PropertyKey> getDataPropertyKeys(final DOMNode thisNode) {
final Set<PropertyKey> customProperties = new TreeSet<>();
final org.structr.api.graph.Node dbNode = thisNode.getNode();
final Iterable<String> props = dbNode.getPropertyKeys();
for (final String key : props) {
PropertyKey propertyKey = StructrApp.getConfiguration().getPropertyKeyForJSONName(thisNode.getClass(), key, false);
if (propertyKey == null) {
// support arbitrary data-* attributes
propertyKey = new StringProperty(key);
}
if (key.startsWith("data-")) {
if (propertyKey != null && propertyKey instanceof BooleanProperty && dbNode.hasProperty(key)) {
final Object defaultValue = propertyKey.defaultValue();
final Object nodeValue = dbNode.getProperty(key);
// don't export boolean false values (which is the default)
if (nodeValue != null && Boolean.FALSE.equals(nodeValue) && (defaultValue == null || nodeValue.equals(defaultValue))) {
continue;
}
}
customProperties.add(propertyKey);
} else if (key.startsWith(CustomHtmlAttributeProperty.CUSTOM_HTML_ATTRIBUTE_PREFIX)) {
final CustomHtmlAttributeProperty customProp = new CustomHtmlAttributeProperty(propertyKey);
customProperties.add(customProp);
}
}
return customProperties;
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class CopyFileContentsFunction method apply.
@Override
public Object apply(final ActionContext ctx, final Object caller, Object[] sources) throws FrameworkException {
if (arrayHasMinLengthAndAllElementsNotNull(sources, 2)) {
final Object toCopy = sources[0];
final Object toBeReplaced = sources[1];
if (toCopy instanceof File && toBeReplaced instanceof File) {
File nodeToCopy = (File) toCopy;
File nodeToBeReplaced = (File) toBeReplaced;
try {
java.io.File fileToCopy = nodeToCopy.getFileOnDisk();
if (!fileToCopy.exists()) {
logger.warn("Error: Given source file does not exist. Parameters: {}", getParametersAsString(sources));
return "Error: Given source file does not exist.";
}
java.io.File fileToBeReplaced = nodeToBeReplaced.getFileOnDisk();
if (!fileToBeReplaced.exists()) {
// Call afterCreation method to ensure that the file is properly initialized.
nodeToBeReplaced.afterCreation(nodeToBeReplaced.getSecurityContext());
}
Files.copy(fileToCopy, fileToBeReplaced);
final PropertyKey<Integer> versionKey = StructrApp.key(File.class, "version");
final PropertyKey<Long> checksumKey = StructrApp.key(File.class, "checksum");
final PropertyKey<Long> sizeKey = StructrApp.key(File.class, "size");
final PropertyMap changedProperties = new PropertyMap();
changedProperties.put(checksumKey, FileHelper.getChecksum(fileToBeReplaced));
changedProperties.put(versionKey, 0);
changedProperties.put(new StringProperty("contentType"), nodeToCopy.getProperty(new StringProperty("contentType")));
long fileSize = FileHelper.getSize(fileToBeReplaced);
if (fileSize > 0) {
changedProperties.put(sizeKey, fileSize);
}
nodeToBeReplaced.unlockSystemPropertiesOnce();
nodeToBeReplaced.setProperties(nodeToBeReplaced.getSecurityContext(), changedProperties);
return nodeToBeReplaced;
} catch (IOException | FrameworkException ex) {
logger.error("Error: Could not copy file due to exception.", ex);
return "Error: Could not copy file due to exception.";
}
} else {
logger.warn("Error: entities are not instances of File. Parameters: {}", getParametersAsString(sources));
return "Error: entities are not nodes.";
}
} else {
logParameterError(caller, sources, ctx.isJavaScriptContext());
return usage(ctx.isJavaScriptContext());
}
}
use of org.structr.core.property.StringProperty in project structr by structr.
the class UiFunction method headFromUrl.
protected GraphObjectMap headFromUrl(final ActionContext ctx, final String requestUrl, final String username, final String password) throws IOException, FrameworkException {
final Map<String, String> headers = HttpHelper.head(requestUrl, password, username, ctx.getHeaders());
final GraphObjectMap response = new GraphObjectMap();
response.setProperty(new IntProperty("status"), headers.get("status"));
headers.remove("status");
final GraphObjectMap map = new GraphObjectMap();
for (final Entry<String, String> entry : headers.entrySet()) {
map.put(new StringProperty(entry.getKey()), entry.getValue());
}
return map;
}
Aggregations