logo
down
shadow

How to parse a java properties file and create items populating each section values and putting it into an aray


How to parse a java properties file and create items populating each section values and putting it into an aray

By : user2954471
Date : November 22 2020, 10:31 AM
With these it helps I have a catalog.properties file of the form as shown below , I have finally come up with my own solution for this.
code :
<?php

    require('Asset.php');

    $vodAssetArray = array();

    $catalogMajorVersion = "-1";
    $catalogMinorVersion = "-1";
    $catalogCreated = "-1";

    $catalogFile = "catalog.properties";

    $b = parse_properties($catalogFile);

    $c = array();

    foreach ($b as $key => $values)
    {
        echo $key . "=" . $values . "<br />";
        if ($key === "catalog.package_asset_id_list")
        {
            $c = explode(",", $values);
        }
    }


    foreach ($c as $key_c => $values_c)
    {
        $vodAssetObject = new PushVodAsset();

        $actorsList = array();
        $directorList = array();
        $genreList = array();
        $advisoriesList = array();

        foreach ($b as $key_b => $values_b)
        {
            if (strpos($key_b, $values_c) !== false)
            {

                if (endsWith($key_b, ".name"))
                {
//                    echo $values_b . "<br />";

//                    echo $key_b . "<br />";

                    if ($values_b === "Title")
                    {
                        $key_val = substr_replace($key_b, ".value", strpos($key_b, ".name"));
                        $vodAssetObject->title = $b[$key_val];
//                        echo $b[$key_val] . "<br />";
                    }

                    else if ($values_b === "Summary_Short")
                    {
                        $key_val = substr_replace($key_b, ".value", strpos($key_b, ".name"));
                        $vodAssetObject->description = $b[$key_val];
//                        echo $b[$key_val] . "<br />";
                    }

                    else if ($values_b === "StartDate")
                    {
                        $key_val = substr_replace($key_b, ".value", strpos($key_b, ".name"));
                        $vodAssetObject->sDate = $b[$key_val];
//                        echo $b[$key_val] . "<br />";
                    }

                    else if ($values_b === "EndDate")
                    {
                        $key_val = substr_replace($key_b, ".value", strpos($key_b, ".name"));
                        $vodAssetObject->eDate = $b[$key_val];
//                        echo $b[$key_val] . "<br />";
                    }

                    else if ($values_b === "Director")
                    {
                        $key_val = substr_replace($key_b, ".value", strpos($key_b, ".name"));
                        array_push($directorList, $b[$key_val]);
                        $vodAssetObject->director = $directorList;
//                        echo $b[$key_val] . "<br />";
                    }

                    else if ($values_b === "Actors")
                    {
                        $key_val = substr_replace($key_b, ".value", strpos($key_b, ".name"));
                        array_push($actorsList, $b[$key_val]);
                        $vodAssetObject->actor = $actorsList;
//                        echo $b[$key_val] . "<br />";
                    }

                    else if ($values_b === "Genre")
                    {
                        $key_val = substr_replace($key_b, ".value", strpos($key_b, ".name"));
                        array_push($genreList, $b[$key_val]);
                        $vodAssetObject->genre = $genreList;
//                        echo $b[$key_val] . "<br />";
                    }

                    else if ($values_b === "Advisories")
                    {
                        $key_val = substr_replace($key_b, ".value", strpos($key_b, ".name"));
                        array_push($advisoriesList, $b[$key_val]);
                        $vodAssetObject->advisories = $advisoriesList;
//                        echo $b[$key_val] . "<br />";
                    }
                }

                else if (endsWith($key_b, ".asset_id"))
                {
                    $vodAssetObject->assetId = $values_b;
                }

                else if (endsWith($key_b, ".type"))
                {
                    if ($values_b === "poster")
                    {
                        $key_val = substr_replace($key_b, ".asset_id", strpos($key_b, ".type"));
                        $vodAssetObject->posterUrl = $b[$key_val];
//                        echo $b[$key_val] . "<br />";
                    }
                }
            }
        }

        //Add this item to an ArrayList
        array_push($vodAssetArray, $vodAssetObject);
    }

    //Put this into Tmp folder for access

    function parse_properties($txtProperties)
    {

        $result = array();

        $handle = fopen($txtProperties, "r");
        if ($handle)
        {
            while (($line = fgets($handle)) !== false)
            {
                // process the line read.

                $key = "";
                $value = "";

                $isWaitingOtherLine = false;
                if (empty($line) || (!$isWaitingOtherLine && strpos($line, "#") === 0 && strpos($line, "//") === 0))
                {
                    continue;
                }

                if (!$isWaitingOtherLine)
                {
                    $key = trim(substr($line, 0, strpos($line, '=')));
                    $value = trim(substr($line, strpos($line, '=') + 1, strlen($line)));
                }
                else
                {
                    $value .= $line;
                }

                /* Check if ends with single '\' */
                if (strrpos($value, "\\") === strlen($value) - strlen("\\"))
                {
                    $value = substr($value, 0, strlen($value) - 1) . "\n";
                    $isWaitingOtherLine = true;
                }
                else
                {
                    $isWaitingOtherLine = false;
                }

                $result[$key] = $value;
            }
        }
        else
        {
            // error opening the file.
        }
        fclose($handle);

        return $result;
    }

    function endsWith($string, $subString)
    {
        $strLen = strlen($string);
        $subStringLen = strlen($subString);
        if ($subStringLen > $strLen)
        {
            return false;
        }
        return substr_compare($string, $subString, $strLen - $subStringLen, $subStringLen) === 0;
    }

?>


Share : facebook icon twitter icon
Properties file read java and putting result to string

Properties file read java and putting result to string


By : Waqas Nabi
Date : March 29 2020, 07:55 AM
this one helps. The only property I can see in your property file is 'username', so your example code won't work, as you are trying to get the value of a property named 'login'. If you want to get the usename referenced by a string typed variable you should use
code :
String user = prop.getProperty("username");
Getting values from properties file using shell from a specific section

Getting values from properties file using shell from a specific section


By : Matt Ryan
Date : March 29 2020, 07:55 AM
it should still fix some issue If you really want to do it from bash, see the following awk magic, partially taken from Read certain key from certain section of ini file (sed/awk ?)
So you can create the following script, adjust for your inventory file and section and run it!
code :
#!/bin/bash
INVENTORY="inventory.ini"
SECTION="[linux]"

I_HOSTS="$(awk -v section="$SECTION" ' # Enable a flag when the line is like your section
$0==section{ f=1; next }               # For any lines with [ disable the flag
/\[/{ f=0; next }                      # If flag is set - print the line
f && $0' "$INVENTORY")"

for I_HOST in $I_HOSTS
do
    #add remote server to ansible host known_host file
    echo "ssh-keyscan "$I_HOST" >> /root/.ssh/known_hosts"
    #remmber password
    echo "sshpass -p ROOT_PASSWORD ssh "root@$I_HOST""
done
ssh-keyscan myd-vm11409.company.net >> /root/.ssh/known_hosts
sshpass -p ROOT_PASSWORD ssh root@myd-vm11409.company.net
ssh-keyscan myd-vm14296.company.net >> /root/.ssh/known_hosts
sshpass -p ROOT_PASSWORD ssh root@myd-vm14296.company.net
ssh-keyscan myd-vm20125.company.net >> /root/.ssh/known_hosts
sshpass -p ROOT_PASSWORD ssh root@myd-vm20125.company.net
ssh-keyscan mydvm0091.company.net >> /root/.ssh/known_hosts
sshpass -p ROOT_PASSWORD ssh root@mydvm0091.company.net
Cloning sections using Metalclone putting all new items into the wrong section

Cloning sections using Metalclone putting all new items into the wrong section


By : yaseen
Date : March 29 2020, 07:55 AM
hope this fix your issue I'm the creator of this plugin and you're the one who open the issue from github, am i right?
To cater this situation, you must initialise metalClone call for each sections to clone and use different class name for each section.
Setting Java system properties without putting the values on the command line

Setting Java system properties without putting the values on the command line


By : Siddhartha Singh
Date : March 29 2020, 07:55 AM
I wish this helpful for you You could just read the file somewhere near startup and call System.setProperty(). For a web application use a ServletContextListener so it happens early, see this answer for a quick example.
Update: this is perhaps not early enough for your use case with JBoss loading its configuration files.
Replace properties with it's values in pom.xml before putting the pom file into maven repository

Replace properties with it's values in pom.xml before putting the pom file into maven repository


By : FlyOnTheWall
Date : March 29 2020, 07:55 AM
I hope this helps . When installing the project into (local) maven repository, I would like to replace all properties placeholders with their current actual values, is this somehow possible?
Related Posts Related Posts :
  • php curl headers do not return from website?
  • How to find out, if facebook ID is a user, group or page
  • Connect webhost database to android database
  • preg_match get div content with class
  • Upload multiple files in Laravel 4
  • Count array numbers in multidimensional array
  • PHP Date diff with a difference
  • Search Customer by custom field in Netsuite
  • Is it possible to hide/encode/encrypt php source code and let others have the system?
  • list items to be displayed using php code and array
  • check if row exists mysqli
  • PHP errors loading MySQL
  • setup PostgreSQL with Laravel in MAMP
  • PHP - CodeIgniter Notifications
  • Encrypting a password column in a SQL database
  • New to PHP, trying to extract information from another website
  • JavaScript AmChart to Image for Email
  • Is javascript validation enough to keep my forms secure?
  • Regex extract variables from [shortcode]
  • Download a .mp3 link and save it to computer with PHP
  • Error with the ereg_replace
  • Getting the fields attached to a bundle of an entity in Drupal
  • Php how to check multiple times (within `foreach`) if values from array exists in mysql?
  • MySQL and PHP parsing strange string
  • Pull specific data from multidimensional associative array
  • How to get the original URI extension using PHP Tonic?
  • Upload videos and images from Android to PHP server?
  • Unset a multidimensional array with another multidimensional array with values than key
  • Calling a user e-mail to add to a mailto link PHP
  • Why is override_function coming back as an undefined function
  • PHP mySQLi_fetch_all: iterate through each row
  • Using pow in php
  • What's wrong with my PHP Script? T_String issue
  • how to call a function of another file without including that file
  • is_rgb function in php
  • transform the numbers to letters using php
  • How to catch an exception from another class method PHP
  • PHP exec is blocked by ISP
  • PHP4 to PHP5 migration character encoding. latin1 vs utf8
  • Begin Transaction not defined
  • How much harm can a user do with xss on a page unique to them?
  • How to import data from a php file to javascript variable
  • PHP and Javascript - log complete workflow
  • When I echo !!! 0 it gives me a strange result
  • jquery ajax post dies after submit
  • How to upload file with curl on sftp server
  • Advanced search using a text input to search through only one category
  • Why do I get "Non-static method App\Models\Category::products() should not be called statically" in laravel
  • Stop notices from undefined indexes in arrays
  • PHP Excel Error when entering SUM function to a cell
  • laravel 4 eloquent eager load relation count
  • click submit in html and run php code
  • Extremely frustrating behavior with Internet Explorer, Bootstrap and Respond.js
  • Vkontakte vtag issues
  • Divide the number to a correct decimal
  • mysqli_insert_query not working
  • How to make a sitemap using zend framework 1
  • Laravel: array to Model with relationship tree
  • $_SERVER['DOCUMENT_ROOT'] vs $path = $_SERVER['DOCUMENT_ROOT']
  • What is the best way to store multiple checkbox values in the database and work with it later on
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org