Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.drupal.project.async_command
Class DrupalUtils

    java.lang.Object
      org.drupal.project.async_command.DrupalUtils

    public final class DrupalUtils

extends java.lang.Object

A group of useful tools to help with Drupal apps. Note: You can potentially run any Drupal API using executeDrush() with "drush eval". Make sure you have a local copy of Drupal, and set its database to the Drupal database you try to connect to.

Field Summary
`static java.lang.String` | `VERSION` Version string to keep track of jar changes.

Constructor Summary
`DrupalUtils()`

Method Summary
`static java.lang.String` | `convertBlobToString(java.lang.Object blobValue)` Convert the byte[] blog value from this.queryValue() to a string.
`static java.util.Properties` | `convertSettingsToConfig(java.io.File settingsFile)` Make config properties out of Drupal settings.php.
`static java.lang.String` | `evalPhp(java.lang.String phpCode)` Evaluates PHP code and return the output.
`static java.lang.String` | `evalPhp(java.lang.String pattern, java.lang.Object... params)` Execute PHP using substitutes.
`static java.lang.String` | `executeDrush(java.lang.String... vars)` Execute drush using the given parameters.
`static java.lang.String` | `executeSystemCommand(java.util.List<java.lang.String> command, java.io.File workingDir)` Execute a command in the working dir, and return the output as a String.
`static java.io.File` | `getConfigPropertiesFile()` Find the config.properties file under various locations.
`static java.lang.String` | `getContent(java.io.Reader input)` From the input reader and get all its content.
`static java.io.File` | `getDrupalSettingsFile()` Try to get Drupal's settings.php file in various locations.
`static java.lang.String` | `getIdentifier(java.lang.Class<?> classObject)` Get either the identifier if presented, or the class name.
`static long` | `getLocalUnixTimestamp()` Get the unix timestamp of the local server.
`static java.lang.Long` | `getLong(java.lang.Object value)` Get the long value from any Object, if possible.
`static java.util.logging.Logger` | `getPackageLogger()`
`static java.util.Properties` | `loadProperties(java.io.File configFile)` Helper function to load properties from a config file.
`static java.util.Properties` | `loadProperties(java.lang.String configString)` Helper function to load properties from a String.
`static void` | `prepareConfig(java.util.Properties config)` Prepare config properties, e.g.
`static java.lang.Object` | `unserializePhp(java.lang.String serialized)` Unserialize any PHP variable.
`static java.util.Map<java.lang.String,java.lang.Object>` | `unserializePhpArray(java.lang.String serialized)` Unserialize PHP array string

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### VERSION

    public static final java.lang.String VERSION

  Version string to keep track of jar changes.

  See Also:
    Constant Field Values

Constructor Detail

### DrupalUtils

    public DrupalUtils()

Method Detail

### getPackageLogger

    public static java.util.logging.Logger getPackageLogger()

  Returns:
    Default logger for the whole package.

### evalPhp

    public static java.lang.String evalPhp(java.lang.String phpCode)

  Evaluates PHP code and return the output. TODO: Use JSR 223 instead of using direct CLI.

  Parameters:
    `phpCode` - PHP code snippet.
  Returns:
    PHP code execution output.

### evalPhp

    public static java.lang.String evalPhp(java.lang.String pattern,
                                           java.lang.Object... params)

  Execute PHP using substitutes. Be very careful of using single quote in pattern. Needs to use two single quotes for PHP string.

  Parameters:
    `pattern` - PHP code pattern
    `params` - Values to insert into the PHP code pattern
  Returns:
    PHP execute output.
  See Also:
    `MessageFormat`

### unserializePhpArray

    public static java.util.Map<java.lang.String,java.lang.Object> unserializePhpArray(java.lang.String serialized)

  Unserialize PHP array string

  Parameters:
    `serialized` - The string of the PHP serialized array
  Returns:
    unserialized PHP array as a Map.

### unserializePhp

    public static java.lang.Object unserializePhp(java.lang.String serialized)

  Unserialize any PHP variable.

  Parameters:
    `serialized` - The string of the PHP serialized array
  Returns:
    The PHP object.
  See Also:
    `SerializedPhpParser`

### getContent

    public static java.lang.String getContent(java.io.Reader input)
                                       throws java.io.IOException

  From the input reader and get all its content.

  Parameters:
    `input` - input reader
  Returns:
    the content of the reader in String.
  Throws:
    `java.io.IOException`

### convertBlobToString

    public static java.lang.String convertBlobToString(java.lang.Object blobValue)

  Convert the byte[] blog value from this.queryValue() to a string. Might not work for all cases.

  Parameters:
    `blobValue` - a byte[] array
  Returns:
    a string of the blob value

### getDrupalSettingsFile

    public static java.io.File getDrupalSettingsFile()
                                              throws java.io.FileNotFoundException

  Try to get Drupal's settings.php file in various locations.

  Returns:
    File The settings.php
  Throws:
    `java.io.FileNotFoundException`

### getConfigPropertiesFile

    public static java.io.File getConfigPropertiesFile()
                                                throws java.io.FileNotFoundException

  Find the config.properties file under various locations.

  Returns:
    config.properties file
  Throws:
    `java.io.FileNotFoundException`

### prepareConfig

    public static void prepareConfig(java.util.Properties config)

  Prepare config properties, e.g. make driverClassName based on database_type, etc.

  Parameters:
    `config` - The original, un-prepared config (will be prepared after execution)

### convertSettingsToConfig

    public static java.util.Properties convertSettingsToConfig(java.io.File settingsFile)

  Make config properties out of Drupal settings.php. You can use `getDrupalSettingsFile()` to locate settings.php. Often, you need to run `prepareConfig(java.util.Properties)` to further process the config. This method only does the raw conversion.

  Parameters:
    `settingsFile` - The settings.php file
  Returns:
    config properties.

### loadProperties

    public static java.util.Properties loadProperties(java.lang.String configString)

  Helper function to load properties from a String.

  Parameters:
    `configString` -
  Returns:

### loadProperties

    public static java.util.Properties loadProperties(java.io.File configFile)

  Helper function to load properties from a config file.

  Parameters:
    `configFile` -
  Returns:

### getLocalUnixTimestamp

    public static long getLocalUnixTimestamp()

  Get the unix timestamp of the local server.

  Returns:

### getLong

    public static java.lang.Long getLong(java.lang.Object value)

  Get the long value from any Object, if possible.

  Parameters:
    `value` - The object that could either be null, or int, or string.
  Returns:
    The long value of the "value".

### executeDrush

    public static java.lang.String executeDrush(java.lang.String... vars)
                                         throws EvaluationFailureException

  Execute drush using the given parameters. You have to set DRUPAL_HOME and DRUSH_HOME before executing this command. Note: You can potentially run any Drupal API using executeDrush() with "drush eval". Make sure you have a local copy of Drupal, and set its database to the Drupal database you try to connect to.

  Parameters:
    `vars` - Parameters for the drush execution.
  Returns:
    The output of drush execution.
  Throws:
    `EvaluationFailureException`

### executeSystemCommand

    public static java.lang.String executeSystemCommand(java.util.List<java.lang.String> command,
                                                        java.io.File workingDir)
                                                 throws EvaluationFailureException

  Execute a command in the working dir, and return the output as a String. If error, log the errors in logger. TODO: potentially use commons-exec instead.

  Parameters:
    `command` - The list of command and parameters.
    `workingDir` - The working directory. Could be null. The it's default user.dir.
  Returns:
    command output.
  Throws:
    `EvaluationFailureException`

### getIdentifier

    public static java.lang.String getIdentifier(java.lang.Class<?> classObject)

  Get either the identifier if presented, or the class name.

  Parameters:
    `classObject` -
  Returns:

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD