Package com.multysite.entity.admin

Examples of com.multysite.entity.admin.ApplicationTemplate


  private static final Logger log = Logger.getLogger(TestServlet.class
      .getName());

  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    ApplicationTemplate template = (ApplicationTemplate) req
        .getAttribute("template");
    try {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();

      ZipOutputStream zos = new ZipOutputStream(baos);
      zos.putNextEntry(new ZipEntry("home.php"));
      zos.write(template.getHome().getBytes());

      zos.putNextEntry(new ZipEntry("category.php"));
      zos.write(template.getCategory().getBytes());

      zos.putNextEntry(new ZipEntry("tag.php"));
      zos.write(template.getTag().getBytes());

      zos.putNextEntry(new ZipEntry("search.php"));
      zos.write(template.getSearch().getBytes());

      zos.putNextEntry(new ZipEntry("style.css"));
      zos.write(template.getCss().getBytes());

      zos.putNextEntry(new ZipEntry("javascript.js"));
      zos.write(template.getJs().getBytes());

      zos.closeEntry();
      zos.flush();

      baos.flush();
      zos.close();
      baos.close();

      byte[] zip = baos.toByteArray();

      ServletOutputStream sos = resp.getOutputStream();
      resp.setContentType("application/zip");
      resp.setHeader("Content-Disposition",
          "attachment; filename=\"template_" + template.getId()
              + ".ZIP\"");

      sos.write(zip);
      sos.flush();
    } catch (Exception e) {
View Full Code Here


  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    try {
      ApplicationTemplate template = (ApplicationTemplate) req
          .getAttribute("template");
      ApplicationConfig config = (ApplicationConfig) req
          .getAttribute("config");
      log.warning("--------do post from test servlet---------");
      BlobstoreService blobService = BlobstoreServiceFactory
          .getBlobstoreService();
      byte b[] = null;
      try {

        Map<String, List<BlobKey>> blobs = blobService.getUploads(req);
        List<BlobKey> blobKeys = blobs.get("template");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        if (blobKeys != null && blobKeys.size() > 0) {
          for (BlobKey blobKey : blobKeys) {
            b = blobService.fetchData(blobKey, 0, 20);
            if (b.length > 0) {
              FileService fileService = FileServiceFactory
                  .getFileService();
              AppEngineFile file = fileService
                  .getBlobFile(blobKey);
              FileReadChannel readChannel = fileService
                  .openReadChannel(file, false);
              InputStream is = Channels
                  .newInputStream(readChannel);
              int nRead;
              byte[] buffer = new byte[10240];
              while ((nRead = is.read(buffer, 0, buffer.length)) != -1) {
                bos.write(buffer, 0, nRead);
              }
              bos.flush();
            }
          }
          ByteArrayInputStream bais = new ByteArrayInputStream(
              bos.toByteArray());
          ZipInputStream zis = new ZipInputStream(bais);
          ZipEntry entry;
          InputStreamReader isr = new InputStreamReader(zis);

          while ((entry = zis.getNextEntry()) != null) {
            log.warning("-----------------size " + entry.getSize());

            char[] buffer = new char[10240];
            StringBuilder strTemp = new StringBuilder();
            int length;
            while ((length = isr.read(buffer, 0, buffer.length)) != -1) {
              strTemp.append(buffer, 0, length);
            }

            if (entry.toString().contains("home.php")) {
              template.setHome(strTemp.toString());
              log.warning("--------home ok---------");
            } else if (entry.toString().contains("category.php")) {
              template.setCategory(strTemp.toString());
              log.warning("--------category ok---------");
            } else if (entry.toString().contains("tag.php")) {
              template.setTag(strTemp.toString());
              log.warning("--------tag ok---------");
            } else if (entry.toString().contains("search.php")) {
              template.setSearch(strTemp.toString());
              log.warning("--------search ok---------");
            } else if (entry.toString().contains("style.css")) {
              template.setCss(strTemp.toString());
              log.warning("--------css ok---------");
            } else if (entry.toString().contains("javascript.js")) {
              template.setJs(strTemp.toString());
              log.warning("--------js ok---------");
            } else {
              log.warning("--------not ok---------"
                  + entry.toString());
            }
View Full Code Here

  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    try {
      System.out.println("Current NS : " + NamespaceManager.get());
      req.setCharacterEncoding("utf-8");
      ApplicationTemplate template = (ApplicationTemplate) req
          .getAttribute("template");
      ApplicationConfig config = (ApplicationConfig) req
          .getAttribute("config");
      if (template != null && config != null) {
        /*
         * get detail content
         */
        String[] splitted = req.getRequestURI().split("/");
        if (splitted.length == 3) {
          String keyword = splitted[2];
          keyword = URLDecoder.decode(keyword, "UTF-8");
          int page = 1;
          try {
            page = Integer.parseInt((String) req
                .getParameter("page"));
          } catch (Exception e) {
            page = 1;
          }
          log.warning("----------Key-------" + keyword);
          NewsSearchModel model = new NewsSearchModel();
          model.setPage(page);
          model.search(keyword);

          CompiledScript compiledscript = CompileScriptEngine
              .getCompileScript(config.getApplicationId(),
                  "search", template.getSearch());

          Bindings bind = compiledscript.getEngine().getBindings(
              ScriptContext.ENGINE_SCOPE);
          bind.put("title_for_layout", config.getTitle());
          bind.put("description_for_layout", config.getDescription());
          bind.put("keyword_for_layout", config.getKeyword());
          bind.put("css_for_layout", template.getCss());
          bind.put("js_for_layout", template.getJs());

          CategoryModel cateModel = new CategoryModel();
          cateModel.prepareAll();
          TagModel tagModel = new TagModel();
          tagModel.prepareList();
View Full Code Here

         */
        String ns = obj.getId();
        /*
         * site template, add default template
         */
        ApplicationTemplate template = new ApplicationTemplate();
        template.setId(IdUniqueHelper.getId());
        template.setHome(Utils.getContentPhp(
            "/templates/classic/home.php", getServletContext()));
        template.setCategory(Utils.getContentPhp(
            "/templates/classic/category.php", getServletContext()));
        template.setDetail(Utils.getContentPhp(
            "/templates/classic/detail.php", getServletContext()));
        template.setTag(Utils.getContentPhp(
            "/templates/classic/tag.php", getServletContext()));
        template.setSearch(Utils.getContentPhp(
            "/templates/classic/search.php", getServletContext()));
        template.setCss(Utils
            .getContentPhp("/templates/classic/css/style.css",
                getServletContext()));
        template.setJs(Utils.getContentPhp(
            "/templates/classic/js/multysite.js",
            getServletContext()));
        ApplicationTemplateModel.insert(ns, template);

        /*
         * site config
         */
        ApplicationConfig config = new ApplicationConfig();
        config.setApplicationId(obj.getId());
        config.setTitle(obj.getTitle() + " Title");
        config.setDescription(obj.getTitle() + " Description");
        config.setKeyword(obj.getId());
        config.setTemplateId(template.getId());
        config.setStatus(1);
        ApplicationConfigModel.insert(ns, config);

        resp.setContentType("text/html");
        resp.getWriter().println(
View Full Code Here

  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    try {
      req.setCharacterEncoding("utf-8");
      ApplicationTemplate template = (ApplicationTemplate) req
          .getAttribute("template");
      ApplicationConfig config = (ApplicationConfig) req
          .getAttribute("config");
      if (template != null && config != null) {
        NewsModel model = new NewsModel();
View Full Code Here

  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    try {
      System.out.println("Current NS : " + NamespaceManager.get());
      req.setCharacterEncoding("utf-8");
      ApplicationTemplate template = (ApplicationTemplate) req
          .getAttribute("template");
      ApplicationConfig config = (ApplicationConfig) req
          .getAttribute("config");
      if (template != null && config != null) {
        /*
         * get detail content
         */
        String[] splitted = req.getRequestURI().split("/");
        if (splitted.length == 3) {
          String tagAlias = splitted[2];
          tagAlias = URLDecoder.decode(tagAlias, "UTF-8");
          Tag obj = TagModel.getById(tagAlias);
          if (obj != null) {
            int limit = 10;
            int page = 1;
            try {
              page = Integer.parseInt((String) req
                  .getParameter("page"));
            } catch (Exception e) {
              page = 1;
            }
            CompiledScript compiledscript = CompileScriptEngine
                .getCompileScript(config.getApplicationId(),
                    "tag", template.getTag());

            Bindings bind = compiledscript.getEngine().getBindings(
                ScriptContext.ENGINE_SCOPE);
            bind.put("title_for_layout", config.getTitle());
            bind.put("description_for_layout",
                config.getDescription());
            bind.put("keyword_for_layout", config.getKeyword());
            bind.put("css_for_layout", template.getCss());
            bind.put("js_for_layout", template.getJs());

            CategoryModel cateModel = new CategoryModel();
            cateModel.prepareAll();
            TagModel tagModel = new TagModel();
            tagModel.prepareList();
View Full Code Here

  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    try {
      if (!NamespaceManager.get().equals(Setting.getGeneralNamespace())) {
        req.setCharacterEncoding("utf-8");
        ApplicationTemplate template = (ApplicationTemplate) req
            .getAttribute("template");
        ApplicationConfig config = (ApplicationConfig) req
            .getAttribute("config");
        if (template != null && config != null) {
          int page = 1;
          try {
            page = Integer.parseInt((String) req
                .getParameter("page"));
          } catch (Exception e) {
            page = 1;
          }
          NewsModel model = new NewsModel();
          model.setPage(page);
          model.prepareList();
          CategoryModel cateModel = new CategoryModel();
          cateModel.prepareAll();
          TagModel tagModel = new TagModel();
          tagModel.prepareList();

          CompiledScript compiledscript = CompileScriptEngine
              .getCompileScript(config.getApplicationId(),
                  "home", template.getHome());
          if (compiledscript != null) {
            Bindings bind = compiledscript.getEngine().getBindings(
                ScriptContext.ENGINE_SCOPE);
            bind.put("title_for_layout", config.getTitle());
            bind.put("description_for_layout",
                config.getDescription());
            bind.put("keyword_for_layout", config.getKeyword());
            bind.put("css_for_layout", template.getCss());
            bind.put("js_for_layout", template.getJs());

            bind.put("recent_view",
                RecentViewHelper.getRecentView());
            bind.put("list_tag", tagModel.getListResult());
            bind.put("list_category", cateModel.getListResult());
View Full Code Here

  private static TreeMap<String, String> treeCache = new TreeMap<String, String>();

  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    try {
      ApplicationTemplate template = (ApplicationTemplate) req
          .getAttribute("template");
      ApplicationConfig config = (ApplicationConfig) req
          .getAttribute("config");
      if (template != null && config != null) {
        /*
         * get detail content
         */
        String alias = req.getRequestURI().replace("/", "")
            .replace(".html", "");
        alias = URLDecoder.decode(alias, "UTF-8");
        if (treeCache.containsKey(alias)) {
          log.warning("-------detail cached -----");
          resp.getWriter().print(treeCache.get(alias));
        } else {
          log.warning("-------detail no cache -----");
          News obj = NewsModel.getById(alias);
          if (obj != null) {
            CategoryModel cateModel = new CategoryModel();
            cateModel.prepareAll();
            TagModel tagModel = new TagModel();
            tagModel.prepareList();
            CompiledScript compiledscript = CompileScriptEngine
                .getCompileScript(config.getApplicationId(),
                    "detail", template.getDetail());

            Bindings bind = compiledscript.getEngine().getBindings(
                ScriptContext.ENGINE_SCOPE);
            bind.put("title_for_layout", config.getTitle());
            bind.put("description_for_layout",
                config.getDescription());
            bind.put("keyword_for_layout", config.getKeyword());
            bind.put("css_for_layout", template.getCss());
            bind.put("js_for_layout", template.getJs());

            RecentViewHelper.addRecentView(obj);
            bind.put("recent_view",
                RecentViewHelper.getRecentView());
            bind.put("list_tag", tagModel.getListResult());
View Full Code Here

  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    try {
      req.setCharacterEncoding("utf-8");
      ApplicationTemplate template = (ApplicationTemplate) req
          .getAttribute("template");
      ApplicationConfig config = (ApplicationConfig) req
          .getAttribute("config");
      if (template != null && config != null) {
        NewsModel model = new NewsModel();
View Full Code Here

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    String ns = NamespaceManager.get();
    ApplicationConfig config = ApplicationConfigModel.getById(ns, ns);
    ApplicationTemplate template = ApplicationTemplateModel.getById(ns,
        config.getTemplateId());
    String action = req.getParameter("action");
    String value = req.getParameter("pageValue");
    if (action != null && action.equals("homePage")) {
      template.setHome(value);
    } else if (action != null && action.equals("detailPage")) {
      template.setDetail(value);
    } else if (action != null && action.equals("tagPage")) {
      template.setTag(value);
    } else if (action != null && action.equals("categoryPage")) {
      template.setCategory(value);
    } else if (action != null && action.equals("cssFile")) {
      template.setCss(value);
    } else if (action != null && action.equals("jsFile")) {
      template.setJs(value);
    } else if (action != null && action.equals("searchPage")) {
      template.setSearch(value);
    }
    ApplicationTemplateModel.insert(ns, template);
  }
View Full Code Here

TOP

Related Classes of com.multysite.entity.admin.ApplicationTemplate

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.