setting xml Doctype using jdom - doctype

Can any one help me in setting [ Doctype and xml:lang="en" ] while creating XML using JDOM?

The xml:lang attribute can be set on any Element with the following:
public static void main(String[] args) throws IOException {
Element root = new Element("root");
DocType dtype = new DocType(root.getName());
Document doc = new Document(root, dtype);
root.setAttribute("lang", "en", Namespace.XML_NAMESPACE);
new XMLOutputter(Format.getPrettyFormat()).output(doc, System.out);
}
Here I have also created a DocType, but it is pretty empty. You can change it to suite your needs by reading the documentation
The code above produces:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root>
<root xml:lang="en" />

Related

Why Primefaces donutChart is not working?

I tried to use donut chart from primefaces cause I used primefaces but the chart won't working.
So this is my XHTML
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
template="/WEB-INF/templates/new-dashbord-landing-page.xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:define name="postMetadata">
</ui:define>
<ui:define name="content">
<div class="chart-donut">
<p:donutChart model="#{bean.donutModel}"/>
</div>
</ui:define>
</ui:composition>
for p:donutChart in my case I cannot use it, I don't know why
and this is my java
import org.apache.poi.ss.usermodel.charts.ChartData;
import org.primefaces.model.chart.DonutChartModel;
import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
public class Bean {
private DonutChartModel donutModel;
#PostConstruct
public void init() {
donutModel = new DonutChartModel();
ChartData data = new ChartData();
DonutChartDataSet dataSet = new DonutChartDataSet();
List<Number> values = new ArrayList<>();
values.add(300);
values.add(50);
values.add(100);
dataSet.setData(values);
List<String> bgColors = new ArrayList<>();
bgColors.add("rgb(255, 99, 132)");
bgColors.add("rgb(54, 162, 235)");
bgColors.add("rgb(255, 205, 86)");
dataSet.setBackgroundColor(bgColors);
data.addChartDataSet(dataSet);
List<String> labels = new ArrayList<>();
labels.add("Red");
labels.add("Blue");
labels.add("Yellow");
data.setLabels(labels);
donutModel.setData(data);
}
public DonutChartModel getDonutModel() {
return donutModel;
}
}
and I use the same code like on primefaces documentation. I just want use the chart :(
The problem is the import for DonutChartModel. You're picking up the older version used for p:chart components. For the Charts.js based components the correct package name is:
org.primefaces.model.charts.donut.DonutChartModel
Slightly off topic, the bean also needs annotating. e.g. #Named and #RequestScoped.

Spring Jpa Repositories - Orm.xml

I'm working with Spring Jpa Repositories.
I don't want to define my "named queries" in java classes (entities or repositories). I would like to define my "named queries" in different xml files (like orm.xml).
.... XML FILE ....
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd">
<named-query name="MyEntity.findByField1">
<query>
<![CDATA[
SELECT m
FROM MyEntity m
WHERE
m.field1 = :field1
]]>
</query>
</named-query>
</entity-mappings>
.... REPOSITORY CODE ....
public interface MyEntityRepository extends JpaRepository<MyEntity, String>
{
public Optional<MyEntity> findByField1(#Param("field1") String field1);
}
But my repositories are not finding the xml files with my named queries. How do I configure spring-data-jpa to use these xml files? I do not have a persistence.xml.
Thanks!
Since your MyEntity already has field1 property inside using findByField1 as the Repository method name might be confusing. Change the orm.xml as following and place it inside META-INF/orm.xml
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm http://xmlns.jcp.org/xml/ns/persistence/orm_2_1.xsd">
<named-query name="MyEntity.findByField1OrmXml">
<query>
<![CDATA[
SELECT m
FROM MyEntity m
WHERE
m.field1 = :field1
]]>
</query>
</named-query>
</entity-mappings>
And change the Repository as following
public interface MyEntityRepository extends JpaRepository<MyEntity, String>
{
public Optional<MyEntity> findByField1OrmXml(#Param("field1") String field1);
}

INVALID_REQUEST: Field [order.avsDetails.billToFirstname] was not in charset [ISO-8859-1]

For some Reasons when I use OnTap MasterCard Extension, Any Arabic characters in shippment addresses throws an error:
INVALID_REQUEST: Field [order.avsDetails.billToFirstname] was not in charset [ISO-8859-1]
The extension link :
https://marketplace.magento.com/ontap-module-mastercard.html
Please help.
You can try encoding the data generated in the Builders (inside the Gateway/Request folder) by using plugins.
You can read more how to create plugins here that perform the encoding on all the fields in the builders when needed.
You will create a new module that is doing the modifications needed on the extension you took from the market.
To define your builder in this case your di.xml will look something like:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="\OnTap\MasterCard\Gateway\Request\ShippingDataBuilder">
<plugin name="jsparo_ontap_mastercard_gateway_request_shippingdatabuilder" type="Jsparo\MasterCard\Plugin\Gateway\Request\ShippingDataBuilder" sortOrder="1"/>
</type>
</config>
And the Plugin/Gateway/Request/ShippingDataBuilder.php that you will be something like:
<?php
namespace Jsparo\MasterCard\Plugin\Gateway\Request;
class ShippingDataBuilder {
public function afterBuild(array $subject, $result) {
array_walk_recursive($result, function(&$value) {
$value = mb_convert_encoding($value, 'ISO-8859-1', 'UTF-8');
}
return $result;
}
}
You will have to do this for all the builders that generate incorrect data.

Symfony Basic Translation Example

I am new to Symfony2. Trying to establish translation Service. I am following the steps given in the official documentation. But not successful.
Following are steps followed
In 'symfony/app/config/config.yml' translation service by defining locale "#translator:{ fallback: %locale% }"
In 'symfony/app/config/parameters.yml' defined locale parameter "locale:de"
In 'src/MyBundle/translateBundle/Resources/translations/messages.de.xlf' is created
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>Symfony2 is great</source>
<target>J'aime Symfony2</target>
</trans-unit>
</body>
</file>
</xliff>
Now I hope with this coding now I should get: 'J'aime Symfony2' on execution of following code.
<?php
namespace MyDays\translateBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
class DefaultController extends Controller {
public function indexAction() {
$t = $this->get ( 'translator' )->trans ( 'Symfony2 is great' );
return new Response ( $t );
}
}
But still getting original text as 'Symfony2 is great'!
Is there anything I have to do apart from the steps given in documentation?
Have you removed # before translator... in config.yml?
Also you need to clear the cache after adding a new translation file.

Joomla 1.7: change meta tags from system plugin

Joomla version 1.7
Plugin enabled in admin part
Plugin code:
<?php
// no direct access
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
class plgSystemMetatags extends JPlugin
{
public function __construct(&$subject, $config)
{
parent::__construct($subject, $config);
}
public function onBeforeRender()
{
$document =& JFactory::getDocument();
$document->setMetaData('keywords', 'test keywords');
}
}
But this doesn't work
Meta description renders value, which set in global configuration
plugin xml file
<?xml version="1.0" encoding="utf-8"?>
<extension version="1.7" type="plugin" group="system" method="upgrade" client="site">
<name>System - Metatags</name>
<author>Joomla! Project</author>
<creationDate>November 2005</creationDate>
<copyright>Copyright (C) 2005 - 2011 Open Source Matters. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>admin#joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>1.7.0</version>
<description></description>
<files>
<filename plugin="metatags">metatags.php</filename>
<filename>index.html</filename>
</files>
</extension>
use onBeforeRender instead of onAfterRender.
When onAfterRender event is triggered the output of the application is already available in the response buffer.