예제 #1
0
파일: Dialect.java 프로젝트: netvisao/nuxeo
 /** Creates a {@code Dialect} by connecting to the datasource to check what database is used. */
 public static Dialect createDialect(
     Connection connection, RepositoryDescriptor repositoryDescriptor) {
   DatabaseMetaData metadata;
   String databaseName;
   try {
     metadata = connection.getMetaData();
     databaseName = metadata.getDatabaseProductName();
   } catch (SQLException e) {
     throw new NuxeoException(e);
   }
   if (databaseName.contains("/")) {
     // DB2/LINUX, DB2/DARWIN, etc.
     databaseName = databaseName.substring(0, databaseName.indexOf('/'));
   }
   String dialectClassName = Framework.getProperty(DIALECT_CLASS);
   if (dialectClassName == null) {
     dialectClassName = Framework.getProperty(DIALECT_CLASS + '.' + databaseName.replace(" ", ""));
   }
   Class<? extends Dialect> dialectClass;
   if (dialectClassName == null) {
     dialectClass = DIALECTS.get(databaseName);
     if (dialectClass == null) {
       throw new NuxeoException("Unsupported database: " + databaseName);
     }
   } else {
     Class<?> klass;
     try {
       ClassLoader cl = Thread.currentThread().getContextClassLoader();
       klass = cl.loadClass(dialectClassName);
     } catch (ClassNotFoundException e) {
       throw new NuxeoException(e);
     }
     if (!Dialect.class.isAssignableFrom(klass)) {
       throw new NuxeoException("Not a Dialect: " + dialectClassName);
     }
     dialectClass = (Class<? extends Dialect>) klass;
   }
   Constructor<? extends Dialect> ctor;
   try {
     ctor = dialectClass.getConstructor(DatabaseMetaData.class, RepositoryDescriptor.class);
   } catch (ReflectiveOperationException e) {
     throw new NuxeoException("Bad constructor signature for: " + dialectClassName, e);
   }
   Dialect dialect;
   try {
     dialect = ctor.newInstance(metadata, repositoryDescriptor);
   } catch (InvocationTargetException e) {
     Throwable t = e.getTargetException();
     if (t instanceof NuxeoException) {
       throw (NuxeoException) t;
     } else {
       throw new NuxeoException(t);
     }
   } catch (ReflectiveOperationException e) {
     throw new NuxeoException("Cannot construct dialect: " + dialectClassName, e);
   }
   return dialect;
 }
예제 #2
0
  @Override
  public File getBundleFile(Bundle bundle) {
    File file;
    String location = bundle.getLocation();
    String vendor = Framework.getProperty(Constants.FRAMEWORK_VENDOR);
    String name = bundle.getSymbolicName();

    if ("Eclipse".equals(vendor)) { // equinox framework
      log.debug("getBundleFile (Eclipse): " + name + "->" + location);
      return getEclipseBundleFileUsingReflection(bundle);
    } else if (location.startsWith("file:")) { // nuxeo osgi adapter
      try {
        file = FileUtils.urlToFile(location);
      } catch (MalformedURLException e) {
        log.error(
            "getBundleFile: Unable to create " + " for bundle: " + name + " as URI: " + location);
        return null;
      }
    } else { // may be a file path - this happens when using
      // JarFileBundle (for ex. in nxshell)
      file = new File(location);
    }
    if (file != null && file.exists()) {
      log.debug("getBundleFile: " + name + " bound to file: " + file);
      return file;
    } else {
      log.debug("getBundleFile: " + name + " cannot bind to nonexistent file: " + file);
      return null;
    }
  }
예제 #3
0
  /**
   * Called by the theme negotiation module.
   *
   * @return the local theme associated to the current space (workspace, section, ...) as a
   *     'theme/page' string. Return null otherwise.
   */
  public String getOutcome(Object context) {
    Boolean useOldThemeConf =
        Boolean.valueOf(Framework.getProperty(LocalThemeConfig.OLD_THEME_CONFIGURATION_PROPERTY));
    if (Boolean.FALSE.equals(useOldThemeConf)) {
      return null;
    }

    DocumentModel currentSuperSpace = (DocumentModel) Component.getInstance("currentSuperSpace");
    if (currentSuperSpace == null) {
      return null;
    }

    // Get the placeful local theme configuration for the current
    // workspace.
    LocalThemeConfig localThemeConfig = LocalThemeHelper.getLocalThemeConfig(currentSuperSpace);
    if (localThemeConfig == null) {
      return null;
    }

    // Extract the page path
    String path = localThemeConfig.computePagePath();
    if (path == null) {
      return null;
    }

    // Look up the page
    PageElement page = Manager.getThemeManager().getPageByPath(path);
    if (page != null) {
      return path;
    }
    return null;
  }
예제 #4
0
 /**
  * Internet Explorer file downloads over SSL do not work with certain HTTP cache control headers
  *
  * <p>See http://support.microsoft.com/kb/323308/
  *
  * <p>What is not mentioned in the above Knowledge Base is that "Pragma: no-cache" also breaks
  * download in MSIE over SSL
  */
 private static void addCacheControlHeaders(
     HttpServletRequest request, HttpServletResponse response) {
   String userAgent = request.getHeader("User-Agent");
   boolean secure = request.isSecure();
   if (!secure) {
     String nvh = request.getHeader(VH_HEADER);
     if (nvh == null) {
       nvh = Framework.getProperty(VH_PARAM);
     }
     if (nvh != null) {
       secure = nvh.startsWith("https");
     }
   }
   log.debug("User-Agent: " + userAgent);
   log.debug("secure: " + secure);
   if (userAgent.contains("MSIE") && (secure || forceNoCacheOnMSIE())) {
     log.debug("Setting \"Cache-Control: max-age=15, must-revalidate\"");
     response.setHeader("Cache-Control", "max-age=15, must-revalidate");
   } else {
     log.debug("Setting \"Cache-Control: private\" and \"Pragma: no-cache\"");
     response.setHeader("Cache-Control", "private, must-revalidate");
     response.setHeader("Pragma", "no-cache");
     response.setDateHeader("Expires", 0);
   }
 }
 /**
  * Returns the layout to use for local configuration, to handle migration to a flavor model
  *
  * @since 5.5
  * @return
  */
 public String getConfigurationLayout() {
   Boolean useOldThemeConf =
       Boolean.valueOf(Framework.getProperty(LocalThemeConfig.OLD_THEME_CONFIGURATION_PROPERTY));
   if (Boolean.TRUE.equals(useOldThemeConf)) {
     return "old_theme_configuration";
   }
   return "theme_configuration";
 }
 /**
  * to complete with '/'
  *
  * @param module of webengine
  * @param ctx the webContext
  * @return
  */
 public static String getSkinPathPrefix(Module module, WebContext ctx) {
   if (Framework.getProperty(SKIN_PATH_PREFIX_KEY) != null) {
     return module.getSkinPathPrefix();
   }
   String webenginePath = ctx.getRequest().getHeader(NUXEO_WEBENGINE_BASE_PATH);
   if (webenginePath == null) {
     return module.getSkinPathPrefix();
   } else {
     return ctx.getBasePath() + "/" + module.getName() + "/skin";
   }
 }
예제 #7
0
파일: Dialect.java 프로젝트: netvisao/nuxeo
 /**
  * Gets the SQL descending sort direction with option to sort nulls last. Use to unify database
  * behavior.
  *
  * @return DESC or DESC NULLS LAST depending on dialects.
  */
 public String getDescending() {
   if (descending == null) {
     if (needsNullsLastOnDescSort()
         && Boolean.parseBoolean(Framework.getProperty(NULLS_LAST_ON_DESC_PROP, "true"))) {
       descending = " DESC NULLS LAST";
     } else {
       descending = " DESC";
     }
   }
   return descending;
 }
  @BeforeClass
  public static void initialize() {
    AbstractCloudBinaryManager bm = new AzureBinaryManager();
    PARAMETERS.forEach(
        s -> {
          properties.put(s, Framework.getProperty(bm.getSystemPropertyName(s)));
        });

    // Ensure mandatory parameters are set
    PARAMETERS.forEach(
        s -> {
          assumeFalse(isBlank(properties.get(s)));
        });
  }
 protected long getDefaultMaxPageSize() {
   long res = DEFAULT_MAX_PAGE_SIZE;
   if (Framework.isInitialized()) {
     String maxPageSize = Framework.getProperty(DEFAULT_MAX_PAGE_SIZE_RUNTIME_PROP);
     if (!StringUtils.isBlank(maxPageSize)) {
       try {
         res = Long.parseLong(maxPageSize.trim());
       } catch (NumberFormatException e) {
         log.warn(
             String.format(
                 "Invalid max page size defined for property "
                     + "\"%s\": %s (waiting for a long value)",
                 DEFAULT_MAX_PAGE_SIZE_RUNTIME_PROP, maxPageSize));
       }
     }
   }
   return res;
 }
  @Override
  public void activate(ComponentContext context) throws Exception {
    super.activate(context);
    ctx = context;
    String webDir = Framework.getProperty("org.nuxeo.ecm.web.root");
    File root = null;
    if (webDir != null) {
      root = new File(webDir);
    } else {
      root = new File(Framework.getRuntime().getHome(), "web");
    }
    root = root.getCanonicalFile();
    log.info("Using web root: " + root);
    if (!new File(root, "default").exists()) {
      try {
        root.mkdirs();
        // runtime predeployment is not supporting conditional unziping so we do the predeployment
        // here:
        deployWebDir(context.getRuntimeContext().getBundle(), root);
      } catch (Exception e) { // delete incomplete files
        FileUtils.deleteTree(root);
        throw e;
      }
    }
    // register contrib managers
    registerContributionManager(APPLICATION_XP, new ContributionManager(this));
    registerContributionManager(WEB_OBJ_XP, new ContributionManager(this));

    // load message bundle
    notifier = new FileChangeNotifier();
    notifier.start();
    notifier.addListener(this);

    engine = new DefaultWebEngine(root, notifier);
    deployer = new ConfigurationDeployer(notifier);
    deployer.addConfigurationChangedListener(this);
  }
 /**
  * Loads default properties.
  *
  * <p>Used for backward compatibility when adding new mandatory properties
  */
 protected void loadDefaultConfig() {
   String varName = "org.nuxeo.ecm.contextPath";
   if (Framework.getProperty(varName) == null) {
     properties.setProperty(varName, "/nuxeo");
   }
 }
예제 #12
0
  @Override
  public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
    rendererParamsNotNull(context, component);

    if (!shouldEncode(component)) {
      return;
    }

    UIMessages messages = (UIMessages) component;
    ResponseWriter writer = context.getResponseWriter();
    assert (writer != null);

    // String clientId = ((UIMessages) component).getFor();
    String clientId = null; // PENDING - "for" is actually gone now
    // if no clientId was included
    if (clientId == null) {
      // and the author explicitly only wants global messages
      if (messages.isGlobalOnly()) {
        // make it so only global messages get displayed.
        clientId = "";
      }
    }

    // "for" attribute optional for Messages
    Iterator messageIter = getMessageIter(context, clientId, component);

    assert (messageIter != null);

    if (!messageIter.hasNext()) {
      return;
    }

    boolean showSummary = messages.isShowSummary();
    boolean showDetail = messages.isShowDetail();

    while (messageIter.hasNext()) {
      FacesMessage curMessage = (FacesMessage) messageIter.next();

      // make sure we have a non-null value for summary and
      // detail.
      String summary = (null != (summary = curMessage.getSummary())) ? summary : "";
      // Default to summary if we have no detail
      String detail = (null != (detail = curMessage.getDetail())) ? detail : summary;

      String severityStyleClass = null;
      String errorType = "default";
      long timeout = 5;
      if (curMessage.getSeverity() == FacesMessage.SEVERITY_INFO) {
        severityStyleClass = (String) component.getAttributes().get("infoClass");
        errorType = "info";
      } else if (curMessage.getSeverity() == FacesMessage.SEVERITY_WARN) {
        severityStyleClass = (String) component.getAttributes().get("warnClass");
        errorType = "warn";
      } else if (curMessage.getSeverity() == FacesMessage.SEVERITY_ERROR) {
        severityStyleClass = (String) component.getAttributes().get("errorClass");
        errorType = "error";
        timeout = 0;
      } else if (curMessage.getSeverity() == FacesMessage.SEVERITY_FATAL) {
        severityStyleClass = (String) component.getAttributes().get("fatalClass");
        errorType = "fatal";
        timeout = 0;
      }

      if (Framework.getProperty("org.nuxeo.ecm.tester.name") != null) {
        timeout = 0;
      }

      writer.startElement("script", messages);
      writer.writeAttribute("type", "text/javascript", null);

      String scriptContent =
          "jQuery(document).ready(function() {\n"
              + "  jQuery.ambiance({\n"
              + "    "
              + "message: \"%s\",\n"
              + "    title: \"%s\",\n"
              + "    type: \"%s\",\n"
              + "    className: \"%s\",\n"
              + "    timeout: \"%d\""
              + "  })\n"
              + "});\n";
      String formattedScriptContent;
      if (showDetail) {
        formattedScriptContent =
            String.format(scriptContent, detail, summary, errorType, severityStyleClass, timeout);
      } else {
        formattedScriptContent =
            String.format(scriptContent, "", summary, errorType, severityStyleClass, timeout);
      }
      writer.writeText(formattedScriptContent, null);
      writer.endElement("script");
    }
  }