Package org.structr.core.app

Examples of org.structr.core.app.App


          }

        } else {

          final App app = StructrApp.getInstance(securityContext);

          try {

            // Old style: Delete all incoming CONTAINS rels
            for (AbstractRelationship rel : node.getIncomingRelationships()) {

              if ("CONTAINS".equals(rel.getType())) {

                app.delete(rel);

              }

            }
View Full Code Here


      if (this.taskOrCommand != null) {

        try {

          final App app = StructrApp.getInstance(securityContext);

          if (Task.class.isAssignableFrom(taskOrCommand)) {

            Task task = (Task) taskOrCommand.newInstance();

            app.processTasks(task);

          } else if (MaintenanceCommand.class.isAssignableFrom(taskOrCommand)) {

            MaintenanceCommand cmd = (MaintenanceCommand)StructrApp.getInstance(securityContext).command(taskOrCommand);
            if (cmd.requiresEnclosingTransaction()) {

              try (final Tx tx = app.tx()) {

                cmd.execute(propertySet);
                tx.success();
              }
View Full Code Here

    }

    // No thumbnail exists, or thumbnail was too old, so let's create a new one
    logger.log(Level.FINE, "Creating thumbnail for {0}", getName());

    final App app = StructrApp.getInstance(securityContext);

    try {
      originalImage.setProperty(File.checksum, newChecksum);

      Thumbnail thumbnailData = ImageHelper.createThumbnail(originalImage, maxWidth, maxHeight, cropToFit);
      if (thumbnailData != null) {

        Integer tnWidth  = thumbnailData.getWidth();
        Integer tnHeight = thumbnailData.getHeight();
        byte[] data      = null;

        try {

          data = thumbnailData.getBytes();
          final String thumbnailName = originalImage.getName() + "_thumb_" + tnWidth + "x" + tnHeight;

          // create thumbnail node
          thumbnail = ImageHelper.createImage(securityContext, data, "image/" + Thumbnail.FORMAT, Image.class, thumbnailName, true);

        } catch (IOException ex) {

          logger.log(Level.WARNING, "Could not create thumbnail image", ex);

        }

        if (thumbnail != null && data != null) {

          // Create a thumbnail relationship
          Thumbnails thumbnailRelationship = app.create(originalImage, thumbnail, Thumbnails.class);

          // Thumbnails always have to be removed along with origin image
          thumbnailRelationship.setProperty(AbstractRelationship.cascadeDelete, Relation.SOURCE_TO_TARGET);

          // Add to cache list
View Full Code Here

  @Override
  protected void doGet(final HttpServletRequest request, final HttpServletResponse response) {

    final Authenticator auth = config.getAuthenticator();
    final SecurityContext securityContext;
    final App app;

    try {
      String path = request.getPathInfo();

      // check for registration (has its own tx because of write access
      if (checkRegistration(auth, request, response, path)) {

        return;
      }

      // isolate request authentication in a transaction
      try (final Tx tx = StructrApp.getInstance().tx()) {
        securityContext = auth.initializeAndExamineRequest(request, response);
        tx.success();
      }

      app = StructrApp.getInstance(securityContext);

      try (final Tx tx = app.tx()) {

        // Ensure access mode is frontend
        securityContext.setAccessMode(AccessMode.Frontend);

        request.setCharacterEncoding("UTF-8");

        // Important: Set character encoding before calling response.getWriter() !!, see Servlet Spec 5.4
        response.setCharacterEncoding("UTF-8");

        boolean dontCache = false;

        logger.log(Level.FINE, "Path info {0}", path);

        // don't continue on redirects
        if (response.getStatus() == 302) {
          return;
        }

        final Principal user = securityContext.getUser(false);
        if (user != null) {

          // Don't cache if a user is logged in
          dontCache = true;

        }

        final RenderContext renderContext = RenderContext.getInstance(request, response, getEffectiveLocale(request));

        renderContext.setResourceProvider(config.getResourceProvider());

        final EditMode edit = renderContext.getEditMode(user);

        DOMNode rootElement = null;
        AbstractNode dataNode = null;

        String[] uriParts = PathHelper.getParts(path);
        if ((uriParts == null) || (uriParts.length == 0)) {

          // find a visible page
          rootElement = findIndexPage(securityContext);

          logger.log(Level.FINE, "No path supplied, trying to find index page");

        } else {

          if (rootElement == null) {

            rootElement = findPage(securityContext, request, path);

          } else {
            dontCache = true;
          }
        }

        if (rootElement == null) { // No page found

          // Look for a file
          File file = findFile(securityContext, request, path);
          if (file != null) {

            streamFile(securityContext, file, request, response, edit);
            return;

          }

          // store remaining path parts in request
          Matcher matcher = threadLocalUUIDMatcher.get();
          boolean requestUriContainsUuids = false;

          for (int i = 0; i < uriParts.length; i++) {

            request.setAttribute(uriParts[i], i);
            matcher.reset(uriParts[i]);

            // set to "true" if part matches UUID pattern
            requestUriContainsUuids |= matcher.matches();

          }

          if (!requestUriContainsUuids) {

            // Try to find a data node by name
            dataNode = findFirstNodeByName(securityContext, request, path);

          } else {

            dataNode = findNodeByUuid(securityContext, PathHelper.getName(path));

          }

          if (dataNode != null && !(dataNode instanceof Linkable)) {

            // Last path part matches a data node
            // Remove last path part and try again searching for a page
            // clear possible entry points
            request.removeAttribute(POSSIBLE_ENTRY_POINTS);

            rootElement = findPage(securityContext, request, StringUtils.substringBeforeLast(path, PathHelper.PATH_SEP));

            renderContext.setDetailsDataObject(dataNode);

            // Start rendering on data node
            if (rootElement == null && dataNode instanceof DOMNode) {

              rootElement = ((DOMNode) dataNode);

            }

          }

        }

        // Still nothing found, do error handling
        if (rootElement == null) {

          // Check if security context has set an 401 status
          if (response.getStatus() == HttpServletResponse.SC_UNAUTHORIZED) {

            try {

              UiAuthenticator.writeUnauthorized(response);

            } catch (IllegalStateException ise) {
            }

          } else {

            rootElement = notFound(response, securityContext);

          }

        }

        if (rootElement == null) {
          return;
        }

        if (EditMode.WIDGET.equals(edit) || dontCache) {

          setNoCacheHeaders(response);

        }

        if (!securityContext.isVisible(rootElement)) {

          rootElement = notFound(response, securityContext);
          if (rootElement == null) {
            return;
          }

        }

        if (securityContext.isVisible(rootElement)) {

          if (!EditMode.WIDGET.equals(edit) && !dontCache && notModifiedSince(request, response, rootElement, dontCache)) {

            ServletOutputStream out = response.getOutputStream();
            out.flush();
            //response.flushBuffer();
            out.close();

          } else {

            // prepare response
            response.setCharacterEncoding("UTF-8");

            String contentType = rootElement.getProperty(Page.contentType);

            if (contentType == null) {
             
              // Default
              contentType = "text/html;charset=UTF-8";
            }
           
            if (contentType.equals("text/html")) {
              contentType = contentType.concat(";charset=UTF-8");
            }

            response.setContentType(contentType);

            response.setHeader("Strict-Transport-Security", "max-age=60");
            response.setHeader("X-Content-Type-Options", "nosniff");
            response.setHeader("X-Frame-Options", "SAMEORIGIN");
            response.setHeader("X-XSS-Protection", "1; mode=block");

            // async or not?
            boolean isAsync = HttpService.parseBoolean(Services.getBaseConfiguration().getProperty(HttpService.ASYNC), true);
            if (isAsync) {

              final AsyncContext async      = request.startAsync();
              final ServletOutputStream out = async.getResponse().getOutputStream();
              final AtomicBoolean finished  = new AtomicBoolean(false);
              final DOMNode rootNode        = rootElement;

              threadPool.submit(new Runnable() {

                @Override
                public void run() {

                  try (final Tx tx = app.tx()) {

                    //final long start = System.currentTimeMillis();

                    // render
                    rootNode.render(securityContext, renderContext, 0);
View Full Code Here

  @Override
  protected void doHead(final HttpServletRequest request, final HttpServletResponse response) {

    final Authenticator auth = config.getAuthenticator();
    final SecurityContext securityContext;
    final App app;

    try {
      String path = request.getPathInfo();

      // isolate request authentication in a transaction
      try (final Tx tx = StructrApp.getInstance().tx()) {
        securityContext = auth.initializeAndExamineRequest(request, response);
        tx.success();
      }

      app = StructrApp.getInstance(securityContext);

      try (final Tx tx = app.tx()) {

        // Ensure access mode is frontend
        securityContext.setAccessMode(AccessMode.Frontend);

        request.setCharacterEncoding("UTF-8");
View Full Code Here

    final Long port                      = (Long)properties.get("port");
    final String key                     = (String)properties.get("key");

    if (host != null && port != null && username != null && password != null && key != null) {

      final App app    = StructrApp.getInstance();
      try (final Tx tx = app.tx()) {

        // create push transmission to be filled later
        final PushTransmission tms = new PushTransmission(username, password, host, port.intValue());

        for (final SchemaNode node : app.nodeQuery(SchemaNode.class).getAsList()) {

          if (isFalseOrNull(node.getProperty(SchemaNode.isBuiltinType))) {
            tms.getExportSet().add(node);
          }
        }

        for (final SchemaRelationship rel : app.relationshipQuery(SchemaRelationship.class).getAsList()) {
          tms.getExportSet().add(rel);
        }

        // push schema
        CloudService.doRemote(tms, new WebsocketProgressListener(getWebSocket(), key));
View Full Code Here

   * @return the new ownerDocument
   * @throws FrameworkException
   */
  public static Page createNewPage(SecurityContext securityContext, String name) throws FrameworkException {

    final App app = StructrApp.getInstance(securityContext);
    final PropertyMap properties = new PropertyMap();

    properties.put(AbstractNode.name, name != null ? name : "page");
    properties.put(AbstractNode.type, Page.class.getSimpleName());
    properties.put(Page.contentType, "text/html");

    return app.create(Page.class, properties);
  }
View Full Code Here

    final String targetPage = request.getParameter(TARGET_PAGE_KEY);
    final String errorPage = request.getParameter(ERROR_PAGE_KEY);

    if (CONFIRM_REGISTRATION_PAGE.equals(path)) {

      final App app = StructrApp.getInstance();

      Result<Principal> results;
      try (final Tx tx = app.tx()) {

        results = app.nodeQuery(Principal.class).and(User.confirmationKey, key).getResult();
      }

      if (!results.isEmpty()) {

        final Principal user = results.get(0);

        try (final Tx tx = app.tx()) {

          // Clear confirmation key and set session id
          user.setProperty(User.confirmationKey, null);

          if (auth.getUserAutoLogin()){
View Full Code Here

  @Override
  public Element createElement(final String tag) throws DOMException {

    final String elementType = StringUtils.capitalize(tag);
    final App app = StructrApp.getInstance(securityContext);

    String c = Content.class.getSimpleName();

    // Avoid creating an (invalid) 'Content' DOMElement
    if (elementType == null || c.equals(elementType)) {

      logger.log(Level.WARNING, "Blocked attempt to create a DOMElement of type {0}", c);

      return null;

    }

    final Page _page = this;

    // create new content element
    DOMElement element;
    try {
      final Class entityClass = SchemaHelper.getEntityClassForRawType(elementType);
      if (entityClass != null) {

        element = (DOMElement) app.create(entityClass, new NodeAttribute(DOMElement.tag, tag));
        element.doAdopt(_page);

        return element;
      }
View Full Code Here

  }

  @Override
  public DocumentFragment createDocumentFragment() {

    final App app = StructrApp.getInstance(securityContext);

    try {

      // create new content element
      org.structr.web.entity.dom.DocumentFragment fragment = app.create(org.structr.web.entity.dom.DocumentFragment.class);

      // create relationship from ownerDocument to new text element
      ((RelationProperty<DOMNode>) Page.elements).addSingleElement(securityContext, Page.this, fragment);
      // Page.elements.createRelationship(securityContext, Page.this, fragment);
View Full Code Here

TOP

Related Classes of org.structr.core.app.App

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.