Search in sources :

Example 6 with StringProperty

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);
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) NamedNodeMap(org.w3c.dom.NamedNodeMap) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) AbstractNode(org.structr.core.entity.AbstractNode) StringProperty(org.structr.core.property.StringProperty) Image(org.structr.web.entity.Image) URI(java.net.URI) FrameworkException(org.structr.common.error.FrameworkException) OdfPackage(org.odftoolkit.odfdom.pkg.OdfPackage) OdfDocument(org.odftoolkit.odfdom.doc.OdfDocument) File(org.structr.web.entity.File)

Example 7 with StringProperty

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);
    }
}
Also used : EditMode(org.structr.web.common.RenderContext.EditMode) StringProperty(org.structr.core.property.StringProperty)

Example 8 with StringProperty

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;
}
Also used : TreeSet(java.util.TreeSet) BooleanProperty(org.structr.core.property.BooleanProperty) CustomHtmlAttributeProperty(org.structr.web.property.CustomHtmlAttributeProperty) StringProperty(org.structr.core.property.StringProperty) GraphObject(org.structr.core.GraphObject) PropertyKey(org.structr.core.property.PropertyKey)

Example 9 with StringProperty

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());
    }
}
Also used : FrameworkException(org.structr.common.error.FrameworkException) StringProperty(org.structr.core.property.StringProperty) IOException(java.io.IOException) PropertyMap(org.structr.core.property.PropertyMap) File(org.structr.web.entity.File)

Example 10 with StringProperty

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;
}
Also used : IntProperty(org.structr.core.property.IntProperty) GraphObjectMap(org.structr.core.GraphObjectMap) StringProperty(org.structr.core.property.StringProperty)

Aggregations

StringProperty (org.structr.core.property.StringProperty)53 FrameworkException (org.structr.common.error.FrameworkException)28 Tx (org.structr.core.graph.Tx)28 Test (org.junit.Test)26 PropertyKey (org.structr.core.property.PropertyKey)22 GraphObject (org.structr.core.GraphObject)14 GraphObjectMap (org.structr.core.GraphObjectMap)14 StructrTest (org.structr.common.StructrTest)11 LinkedList (java.util.LinkedList)10 NodeAttribute (org.structr.core.graph.NodeAttribute)10 SchemaNode (org.structr.core.entity.SchemaNode)9 List (java.util.List)8 AbstractNode (org.structr.core.entity.AbstractNode)7 NodeInterface (org.structr.core.graph.NodeInterface)7 StructrUiTest (org.structr.web.StructrUiTest)7 Map (java.util.Map)6 ErrorToken (org.structr.common.error.ErrorToken)6 IntProperty (org.structr.core.property.IntProperty)6 LinkedHashSet (java.util.LinkedHashSet)5 App (org.structr.core.app.App)5