Equals functionality not working in velocity macro - macros

Can I know what I am making wrong in the below velocity macro code.
I have followed the below link. Still now luck.
https://velocity.apache.org/engine/1.4/user-guide.html
#macro( ccase $profiles,$databasename )
#foreach( $profile in $profiles.split(','))
#if( $profile == $databasename)
#set($result = $profile)
#$result
#end
#end
#end
#set($databaseName="sql")
#set($sqlDatabase = "#ccase( $profile-db,$databaseName )" )
#if($sqlDatabase == "sql") <!-- Fails Here This is not getting passed at all-->
Below code notexecuted
#end

Related

How do I retrieve PR_RULE_ACTIONS via PowerShell and the EWS Managed API?

I have need of retrieving and inspecting the delegate forwarding rule (the built-in delegate commands in EWS being inadequate for my needs since they choke on groups being used as delegates).
I am able to successfully locate the rule created by "Schedule+ EMS Interface". However, I am unable to retrieve PR_RULE_ACTIONS. Turning on tracing.
I see that the PidTagRuleMsgProvider property is getting returned just fine, but PR_RULE_ACTIONS never does.
I suspect that I am using the wrong MAPI property type in the propertyset definition, but I've gone through everything listed at http://msdn.microsoft.com/en-us/library/exchangewebservices.mapipropertytypetype(v=exchg.140).aspx . Any clues?
Here is the relevant snippet of code:
# Setup Basic EWS Properties for Message Search - Used to locate Hidden Forwarding Rule
$searchFilterForwardRule = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+ContainsSubstring([Microsoft.Exchange.WebServices.Data.ItemSchema]::ItemClass, "IPM.Rule", [Microsoft.Exchange.WebServices.Data.ContainmentMode]::Prefixed, [Microsoft.Exchange.WebServices.Data.ComparisonMode]::Exact)
$itemViewForwardRule = New-Object Microsoft.Exchange.WebServices.Data.ItemView(30, 0, [Microsoft.Exchange.Webservices.Data.OffsetBasePoint]::Beginning)
$itemViewForwardRule.PropertySet = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties, [Microsoft.Exchange.WebServices.Data.ItemSchema]::ItemClass, [Microsoft.Exchange.WebServices.Data.ItemSchema]::Subject)
$itemViewForwardRule.Traversal = [Microsoft.Exchange.WebServices.Data.ItemTraversal]::Associated
# Properties for Hidden Delegate Forwarding Rule
$PID_TAG_RULE_MSG_PROVIDER = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x65EB,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String)
$PID_TAG_RULE_ACTIONS = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition(0x6680,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary)
# Property Set for Delegate Forward Rule
$propertySetForwardRule = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties, $PID_TAG_RULE_MSG_PROVIDER)
$forwardRuleExists = $false
$findResults = $service.FindItems([Microsoft.Exchange.Webservices.Data.WellKnownFolderName]::Inbox, $searchFilterForwardRule, $itemViewForwardRule)
If ($findResults.TotalCount -lt 1) {
Write-Error "Failed to find rule" "Error"
} Else {
Foreach ($item in $findResults.Items) {
$item.Load($propertySetForwardRule)
If ($item.ExtendedProperties.Count -ge 1) {
If ($item.ExtendedProperties[0].Value -eq "Schedule+ EMS Interface") {
$forwardRuleExists = $true
write-host "Delegate forwarding rule found." -ForegroundColor Cyan
$propertySetForwardRule.Add($PID_TAG_RULE_ACTIONS)
$item.Load($propertySetForwardRule)
Write-Host "Attempting to retrieve x6680 PR_RULE_ACTIONS (PidTagRuleActions)" -ForegroundColor Cyan
$PR_RULE_ACTIONS = $null
if($Item.TryGetProperty($Pid_Tag_Rule_Actions,[ref]$PR_RULE_ACTIONS)){
return $PR_RULE_ACTIONS
} # endif
else {write-host "TryGetProperty for PR_RULE_ACTIONS failed!" -ForegroundColor Red
} # endelse
} # End If - Correct Message
} # End If - Has Extended Properties
} # End ForEach
} # End If - Message Count
Glen Scales was able to set me on the right path. It turns out that PR_RULE_ACTIONS is not exposed via EWS, but the same data exposed via an attribute called PR_EXTENDED_RULE_ACTIONS. Now I'm happily slinging code to parse the binary blob.
http://msdn.microsoft.com/en-us/library/ee218391(v=EXCHG.80).aspx
The property tag for PR_RULE_ACTIONS is 0x668000FE. You can see it (and the property data) in OutlookSpy (I am its author) - go to the Inbox folder, click IMAPIFolder button, go to the PR_RULES_TABLE tab, select the rule, double click on the PR_RULE_ACTIONS property.
Note that PT_ACTIONS MAPI type (0x000FE) is only accessing in Extended MAPI, I don't think EWS will be able to return it.

Joomla 3 replace text plugin using preg replace not working

I am following a tutorial about joomla 3 extension development. I am using Joomla 3.2.4
I have a plugin name clicktocall, which to make all phone number text displayed as a link.
Phone number format is XXXX-XXXX or XXXX XXXX, X is digit. and I want display any phone number as ">
The method is using pattern as replace any text match the pattern by link tag
I installed, enabled the plugin
I do it after a tutorial in an ebook, in the book everything are so smoothly, but in my site, after I view an article which have phone number text, there are nothing happen. The plugin not working.
My code:
clicktocall.php
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
class plgContentClicktocall extends JPlugin {
function plgContentClicktocall(&$subject, $params) {
parent::__construct($subject, $params);
}
public function onContentPrepare($context, &$row, &$params, $page = 0) {
//don't run this when the content is indexing
if ($context == 'com_finder.indexer') {
return true;
}
if (is_object($row)) {
echo $row->text;
return $this->clickToCall($row->text, $params);
}
return $this->clickToCall($row, $params);
}
protected function clickToCall(&$text, &$params) {
// matches 4 numbers followed by an optional hyphen or space,
// then followed by 4 numbers.
// phone number is in the form XXXX-XXXX or XXXX XXXX
$pattern = '/(\W[0-9]{4})-? ?(\W[0-9]{4})/';
$replacement = '$1$2';
$text = preg_replace($pattern, $replacement, $text);
return true;
}
}
clicktocall.xml
<?xml version="1.0" encoding="UTF-8"?>
<extension
version="3.0"
type="plugin"
group="content"
method="upgrade">
<name>Content - Click To Call</name>
<author>Tim Plummer</author>
<creationDate>April 2013</creationDate>
<copyright>Copyright (C) 2013 Packt Publishing. All rights
reserved.</copyright>
<license> http://www.gnu.org/licenses/gpl-3.0.html</license>
<authorEmail>example#packtpub.com</authorEmail>
<authorUrl>http://packtpub.com</authorUrl>
<version>1.0.0</version>
<description>This plugin will replace phone numbers with click
to call links. Requires Joomla! 3.0 or greater.
Don't forget to publish this plugin!
</description>
<files>
<filename plugin="clicktocall">clicktocall.php</filename>
<filename>index.html</filename>
</files>
</extension>
index.html : blank tags only
Sorry for the XML, I try for 10 minutes to make it pre-formatted but seem to be useless, but I confirm it's OK, included all files in my plugin
I believe the issue is you are returning the value from your click2Call() method inside your onContentPrepare() method. Try reformatting like so:
public function onContentPrepare($context, &$row, &$params, $page = 0) {
//don't run this when the content is indexing
if ($context == 'com_finder.indexer') {
return true;
}
if (is_object($row)) {
echo $row->text;
$this->clickToCall($row->text, $params);
} else {
$this->clickToCall($row, $params);
}
return true;
}
Since the row variable is referenced, any changes you make to the row data you're making to the actual data. Therefor, no need to return any data outside of the the return true at the end of the method.

gmake: a target completes but $(realpath ...) doesn't find it

Environment stuff:
Solaris NFS file servers running NFS 3
Errors occur in Linux or Solaris environments
Using GNU Make 3.82
Using Sun Studio compilers, if that matters
This is a vastly simplified example of the build I'm looking at:
all: ${list of shared objects to build}
#do whatever
lib1.so: ${1s objects}
lib2.so: ${2s objects}
lib3.so: ${3s objects}
#...
%.so:
$(call CHECK_DEPENDENCIES_EXIST)
#${LD} ${LDFLAGS} ${^} -o ${#}
%.o : %.c
#do stuff
%.o : %.cc
#do stuff
define CHECK_DEPENDENCIES_EXIST =
$(if $(realpath ${^}),,$(warning No dependencies specified for ${#})false)
endef
The short & sweet: $(realpath x y z) (x/y/z get returned if they exist; returns an absolute path including no symlinks) is removing files from the list under some circumstances, and I think it has to do with NFS. It isn't predictable which target will fail. Sometimes a target will fail when it's succeeded the last 10 times. If I take #false out of the macro, the build continues without error -- that is, the linker does not complain about the supposedly missing file(s).
I'll spare you the drawn-out explanation; suffice it to say, the macro is helpful for debugging.
Turns out there's a bug in gmake. From the GNU Make 3.82 source, function.c, on or about line 2026:
while ((path = find_next_token (&p, &len)) != 0 ) {
/* ... */
if (
#ifdef HAVE_REALPATH
realpath (in, out)
#else
abspath (in, out) && stat (out, &st) == 0
#endif
)
{
/* ... */
}
}
}
/* ... */
Ocasionally, various calls to realpath would get interrupted (EINTR); nothing in this code checks errno, so it just silently fails.
So, it wasn't that the file didn't exist, it was that $(realpath ...) was being interrupted by a signal (presumably a child instance of gmake signaling its completion or something similar) and this function wasn't designed to recover from that sort of event.
To fix the problem:
while ((path = find_next_token (&p, &len)) != 0 ) {
... becomes:
while ( errno == EINTR || (path = find_next_token (&p, &len)) != 0 ) {
The || will shortcut & prevent it from marching on to the next token.

How do I list communities to "logged" out users in Liferay 6?

im trying to create a community select box to enable visitors to jump to open Liferay communities. However it only seems to work for authenticated users. So how I can list 'open' communities to all users including logged out users?
Here's my current code
#set ($myPlaces = $user.getMyPlaces())
#if($listTool.size($myPlaces) > 0)
<select id="communitySelector">
#foreach ($myPlace IN $myPlaces)
#if ($myPlace.isCommunity())
#set ($myPlaceURL = ${myPlace.getFriendlyURL()})
## Only link if theres pages
#if ($myPlace.hasPublicLayouts())
## Prefix web for 'public'
#set ($myPlaceURL = "${public_pages_url}${myPlaceURL}")
## Select if current community
#set($commSelected = "")
#if($themeDisplay.getLayout().getGroup().getName() == $myPlace.getName())
#set($commSelected = " selected='selected' ")
#end
<option $commSelected value="${portal_url}${myPlaceURL.toString()}">$myPlace.getName()</option>
#end
#end
#end
</select>
#end
In the long tradition of answering my own Liferay questions here is the code snippet for the solution I came up with for listing Communities to all users including the public/guest logged out users
## Grab this service as MyPlaces only available to authenticated users
#set($groupLocalService = $serviceLocator.findService("com.liferay.portal.service.GroupLocalService"))
## Get all Groups
#set($groupList = $groupLocalService.getGroups(-1, -1))
## Grab all groups that are Communities
#set($commList = [])
#foreach($group in $groupList)
#if($group.isCommunity())
$commList.add($group)
#end
#end
#foreach($comm in $commList)
## Exclude Control Panel which is also validated as Community in LR
#if($comm.getName()!="Control Panel")
#if($comm.hasPublicLayouts())
$comm.getName()<br />
#elseif($comm.hasPrivateLayouts() && $is_signed_in)
## Community is private so only print this link if user authenticated
$comm.getName()<br />
#end
#end
#end
EDIT - Here's a similar snippet someone else posted https://stackoverflow.com/a/8457759/417933

Nant - Get Newest Folder

Is there a relatively simple way in nant, without writing a custom task, to get the name of the newest folder in a certain directory? Recursion is not needed. I have been trying to do it with directory::get-creation-time and a foreach loop and if statements, yada yada. It's too complex, and I'm about to create a custom task instead. However, I suspect there is some simpler way to do it via existing nant features.
I believe you're correct in stating that doing this in a pure nant fashion might pose to be messy, especially the way properties work in nant. If you don't want to write a custom task, you can always use the script task. For example:
<?xml version="1.0"?>
<project name="testing" basedir=".">
<script language="C#" prefix="test" >
<code>
<![CDATA[
[Function("find-newest-dir")]
public static string FindNewestDir( string startDir ) {
string theNewestDir = string.Empty;
DateTime theCreateTime = new DateTime();
DateTime theLastCreateTime = new DateTime();
string[] theDirs = Directory.GetDirectories( startDir );
for ( int theCurrentIdx = 0; theCurrentIdx < theDirs.Length; ++theCurrentIdx )
{
if ( theCurrentIdx != 0 )
{
DateTime theCurrentDirCreateTime = Directory.GetCreationTime( theDirs[ theCurrentIdx ] );
if ( theCurrentDirCreateTime >= theCreateTime )
{
theNewestDir = theDirs[ theCurrentIdx ];
theCreateTime = theCurrentDirCreateTime;
}
}
else
{
theNewestDir = theDirs[ theCurrentIdx ];
theCreateTime = Directory.GetCreationTime( theDirs[ theCurrentIdx ] );
}
}
return theNewestDir;
}
]]>
</code>
</script>
<property name="dir" value="" overwrite="false"/>
<echo message="The newest directory is: ${test::find-newest-dir( dir )}"/>
</project>
With this, one should be able to call the function to get the newest directory. The implementation of the actual function could be changed to be anything (optimized a bit more or whatever), but I've included a quick one for reference on how to use the script task. It produces output like the following:
nant -D:dir=c:\
NAnt 0.85 (Build 0.85.2478.0; release; 10/14/2006)
Copyright (C) 2001-2006 Gerry Shaw
http://nant.sourceforge.net
Buildfile: file:///C:/tmp/NAnt.build
Target framework: Microsoft .NET Framework 2.0
[script] Scanning assembly "jdrgmbuy" for extensions.
[echo] The newest directory is: C:\tmp
BUILD SUCCEEDED
Total time: 0.3 seconds.