JBoss Rich Faces SVN: r15622 - root/framework/trunk/impl/src/main/resources/META-INF/resources.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-09-18 11:41:43 -0400 (Fri, 18 Sep 2009)
New Revision: 15622
Modified:
root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js
Log:
Code review fixes for richfaces.js
Modified: root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js
===================================================================
--- root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js 2009-09-18 13:25:36 UTC (rev 15621)
+++ root/framework/trunk/impl/src/main/resources/META-INF/resources/richfaces.js 2009-09-18 15:41:43 UTC (rev 15622)
@@ -48,7 +48,7 @@
this.each(function() { out += xs.serializeToString(this); });
} else if (this[0].xml !== undefined) {
this.each(function() { out += this.xml; });
- } else if (this.length > 0) { // PY: [if] not needed, was upper
+ } else {
this.each( function() { out += this; } );
}
}
@@ -123,7 +123,7 @@
var useBrowserConsole = false;
- var AM_PM = /(\s*(?:a|p)m)$/ig; // PY: [g] not needed when $ - end of string
+ var AM_PM = /(\s*(?:a|p)m)$/i;
var getMessagePrefix = function(level) {
var date = new Date();
@@ -234,10 +234,12 @@
return value || "";
};
+ var ALPHA_NUMERIC_MULTI_CHAR_REGEXP = /^\w+$/;
+
richfaces.interpolate = function (placeholders, context) {
var contextVarsArray = new Array();
for (var contextVar in context) {
- if (/^\w+$/.test(contextVar)) { // PY: define regexp before for
+ if (ALPHA_NUMERIC_MULTI_CHAR_REGEXP.test(contextVar)) {
//guarantees that no escaping for the below RegExp is necessary
contextVarsArray.push(contextVar);
}
@@ -263,7 +265,7 @@
richfaces.stopPush(pushId);
- pushTracker[pushId] = setTimeout(function() { // PY: may be define this function in richfaces object to avoid definition every time when call startPush
+ pushTracker[pushId] = setTimeout(function() { // TODO: define this function in richfaces object to avoid definition every time when call startPush
var ajaxOptions = {
type: "HEAD",
//TODO - encodeURIComponent; URL sessionId handling check
@@ -278,12 +280,10 @@
if (xhr.status == 200 && xhr.getResponseHeader("Ajax-Push-Status") == "READY") {
var pushElement = document.getElementById(clientId);
- if (pushElement) {
- try {
- ondataavailable.call(pushElement);
- } catch (e) {
- // TODO: handle exception
- }
+ try {
+ ondataavailable.call(pushElement || window);
+ } catch (e) {
+ // TODO: handle exception
}
}
16 years, 1 month
JBoss Rich Faces SVN: r15621 - branches/community/3.3.X/docs/userguide/en/src/main/docbook/included.
by richfaces-svn-commits@lists.jboss.org
Author: ochikvina
Date: 2009-09-18 09:25:36 -0400 (Fri, 18 Sep 2009)
New Revision: 15621
Modified:
branches/community/3.3.X/docs/userguide/en/src/main/docbook/included/rich_inputNumberSlider.xml
branches/community/3.3.X/docs/userguide/en/src/main/docbook/included/rich_inputNumberSpinner.xml
Log:
https://jira.jboss.org/jira/browse/RF-7803 - the component description is reviewed;
Modified: branches/community/3.3.X/docs/userguide/en/src/main/docbook/included/rich_inputNumberSlider.xml
===================================================================
--- branches/community/3.3.X/docs/userguide/en/src/main/docbook/included/rich_inputNumberSlider.xml 2009-09-18 06:45:52 UTC (rev 15620)
+++ branches/community/3.3.X/docs/userguide/en/src/main/docbook/included/rich_inputNumberSlider.xml 2009-09-18 13:25:36 UTC (rev 15621)
@@ -80,7 +80,7 @@
<emphasis>
<property moreinfo="none">"step"</property>
</emphasis>
- (on default is "1") attributes, which define the
+ (by default is "1") attributes, which define the
beginning and the end of a numerical area and a
<property moreinfo="none">slider</property>
property step.
@@ -89,7 +89,7 @@
<emphasis role="bold">Example:</emphasis>
</para>
<programlisting role="XML" format="linespecific"><![CDATA[<rich:inputNumberSlider></rich:inputNumberSlider>]]></programlisting>
- <para>It's generated on a page:</para>
+ <para>Here is a component generated on a page:</para>
<figure float="0">
<title>
Generated
@@ -108,7 +108,7 @@
<emphasis>
<property moreinfo="none">"showInput"</property>
</emphasis>
- (default is "true") and
+ (default value is "true") and
<emphasis>
<property moreinfo="none">"enableManualInput"</property>
</emphasis>
@@ -125,7 +125,7 @@
<emphasis role="bold">Example:</emphasis>
</para>
<programlisting role="XML" format="linespecific"><![CDATA[<rich:inputNumberSlider minValue="1" maxValue="100" showInput="false"/>]]></programlisting>
- <para>It's displayed at a page like:</para>
+ <para>It's displayed on a page like this:</para>
<figure float="0">
<title>
<emphasis role="bold">
@@ -148,12 +148,12 @@
<property moreinfo="none">"showBoundaryValues"</property>
</emphasis>
which is responsible for "boundary values"
- displaying (default is true) and
+ displaying (default value is "true") and
<emphasis>
<property moreinfo="none">"showToolTip"</property>
</emphasis>
- which is responsible for tooltTip displaying (default is
- "true").
+ which is responsible for tooltTip displaying (default value is
+ "true").
</para>
<para>
Moreover, to add e.g. some JavaScript effects, events
@@ -208,7 +208,7 @@
<emphasis>
<property moreinfo="none">"label"</property>
</emphasis>
- attribute provides an association between a component, and
+ attribute provides an association between the component and
the message that the component (indirectly) produced. This
attribute defines the parameters of a localized error and
informational messages that occur as a result of conversion,
@@ -246,7 +246,7 @@
</figure>--><para>The <emphasis>
<property moreinfo="none">"showArrows"</property>
</emphasis> boolean attribute when set to "true" enables additional controls for increasing and decreasing slider value.
- The controls (arrows by default) are placed in the beginning and in the end of slider track:</para>
+ The controls (arrows by default) are placed in the beginning and in the end of a slider track:</para>
<figure float="0">
<title>
<emphasis role="bold">
@@ -313,89 +313,194 @@
</tbody>
</tgroup>
</table>
- <table id="tab_cn">
- <title>
- Classes names that define a component appearance
- </title>
- <tgroup cols="2">
- <thead>
- <row>
- <entry>Class name</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>rich-slider</entry>
- <entry>
- Defines styles for a wrapper table element
- of a component
- </entry>
- </row>
- <row>
- <entry>rich-inslider-track</entry>
- <entry>Defines styles for a bar</entry>
- </row>
- <row>
- <entry>rich-inslider-handler</entry>
- <entry>
- Defines styles for a slider handler
- </entry>
- </row>
- <row>
- <entry>rich-inslider-handler-selected</entry>
- <entry>
- Defines styles for a selected handler
- </entry>
- </row>
- <row>
- <entry>rich-inslider-field</entry>
- <entry>Defines styles for a text field</entry>
- </row>
- <row>
- <entry>rich-inslider-right-num</entry>
- <entry>
- Defines styles for the right number
- </entry>
- </row>
- <row>
- <entry>rich-inslider-left-num</entry>
- <entry>
- Defines styles for the left number
- </entry>
- </row>
- <row>
- <entry>rich-inslider-track-border</entry>
- <entry>
- Defines styles for track border
- </entry>
- </row>
- <row>
- <entry>rich-inslider-tip</entry>
- <entry>Defines styles for a hint</entry>
- </row>
- <row>
- <entry>inputNumberSlider-increase-vertical</entry>
- <entry>Defines styles for the top arrow</entry>
- </row>
- <row>
- <entry>inputNumberSlider-decrease-vertical</entry>
- <entry>Defines styles for the bottom arrow</entry>
- </row>
- <row>
- <entry>inputNumberSlider-increase-horizontal</entry>
- <entry>Defines styles for the right arrow</entry>
- </row>
- <row>
- <entry>inputNumberSlider-decrease-horizontal</entry>
- <entry>Defines styles for the left arrow</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- You can find all necessary information about style classes redefinition in
+
+ <table>
+ <title>Style classes (selectors) with the corresponding skin parameters</title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Class (selector) name</entry>
+ <entry>Description</entry>
+ <entry>Skin Parameters</entry>
+ <entry>CSS properties mapped</entry>
+
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry morerows="3">.rich-inslider-tip</entry>
+ <entry morerows="3">Defines styles for a hint</entry>
+ <entry>tipBackgroundColor</entry>
+ <entry>background-color</entry>
+ </row>
+ <row>
+ <entry>tipBorderColor</entry>
+ <entry>border-color</entry>
+ </row>
+ <row>
+ <entry>generalFamilyFont</entry>
+ <entry>font-family</entry>
+ </row>
+ <row>
+ <entry>generalSizeFont</entry>
+ <entry>font-size</entry>
+ </row>
+
+ <row>
+ <entry morerows="3">.rich-inslider-left-num</entry>
+ <entry morerows="3">Defines styles for the left number</entry>
+ <entry>panelBorderColor</entry>
+ <entry>border-color</entry>
+ </row>
+ <row>
+ <entry>generalFamilyFont</entry>
+ <entry>font-family</entry>
+ </row>
+ <row>
+ <entry>generalSizeFont</entry>
+ <entry>font-size, line-height</entry>
+ </row>
+ <row>
+ <entry>generalTextColor</entry>
+ <entry>color</entry>
+ </row>
+
+ <row>
+ <entry morerows="3">.rich-inslider-right-num</entry>
+ <entry morerows="3">Defines styles for the right number</entry>
+ <entry>panelBorderColor</entry>
+ <entry>border-color</entry>
+ </row>
+ <row>
+ <entry>generalFamilyFont</entry>
+ <entry>font-family</entry>
+ </row>
+ <row>
+ <entry>generalSizeFont</entry>
+ <entry>font-size, line-height</entry>
+ </row>
+ <row>
+ <entry>generalTextColor</entry>
+ <entry>color</entry>
+ </row>
+
+ <row>
+ <entry>.rich-inslider-track</entry>
+ <entry>Defines styles for the wrapper <div> element of the slider track</entry>
+ <entry>controlBackgroundColor</entry>
+ <entry>background-color</entry>
+ </row>
+
+ <row>
+ <entry>.rich-inslider-track-decor-1</entry>
+ <entry>Defines styles for the wrapper <table> element of the slider track</entry>
+ <entry>panelBorderColor</entry>
+ <entry>border-color</entry>
+ </row>
+
+ <row>
+ <entry>.rich-inslider-track-decor-2</entry>
+ <entry>Defines styles for the slider track</entry>
+ <entry>controlBackgroundColor</entry>
+ <entry>border-color</entry>
+ </row>
+
+ <row>
+ <entry morerows="4">.rich-inslider-field</entry>
+ <entry morerows="4">Defines styles for a text field</entry>
+ <entry>controlBackgroundColor</entry>
+ <entry>background-color</entry>
+ </row>
+ <row>
+ <entry>generalFamilyFont</entry>
+ <entry>font-family</entry>
+ </row>
+ <row>
+ <entry>generalSizeFont</entry>
+ <entry>font-size</entry>
+ </row>
+ <row>
+ <entry>controlTextColor</entry>
+ <entry>color</entry>
+ </row>
+ <row>
+ <entry>panelBorderColor</entry>
+ <entry>border-color</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <table id="tab_cn">
+ <title>Style classes (selectors) without skin parameters</title>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>Class name</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>.rich-slider</entry>
+ <entry>Defines styles for the wrapper <table> element of the component</entry>
+ </row>
+
+ <row>
+ <entry>.rich-inslider-handler</entry>
+ <entry>Defines styles for the slider handler</entry>
+ </row>
+
+ <row>
+ <entry>.rich-inslider-handler-vertical</entry>
+ <entry>Defines styles for the vertical slider handler</entry>
+ </row>
+
+ <row>
+ <entry>.rich-inslider-track-vertical</entry>
+ <entry>Defines styles for the vertical slider track</entry>
+ </row>
+
+ <row>
+ <entry>.rich-inslider-handler-selected</entry>
+ <entry>Defines styles for a selected handler</entry>
+ </row>
+
+ <row>
+ <entry>.rich-inslider-handler-selected-vertical</entry>
+ <entry>Defines styles for a selected handler on the vertical slider</entry>
+ </row>
+
+ <row>
+ <entry>.rich-inslider-track-border</entry>
+ <entry>Defines styles for track border</entry>
+ </row>
+
+ <row>
+ <entry>.inputNumberSlider-increase-vertical</entry>
+ <entry>Defines styles for the top arrow</entry>
+ </row>
+
+ <row>
+ <entry>.inputNumberSlider-decrease-vertical</entry>
+ <entry>Defines styles for the bottom arrow</entry>
+ </row>
+
+ <row>
+ <entry>.inputNumberSlider-increase-horizontal</entry>
+ <entry>Defines styles for the right arrow</entry>
+ </row>
+
+ <row>
+ <entry>.inputNumberSlider-decrease-horizontal</entry>
+ <entry>Defines styles for the left arrow</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+ <para>You can find all necessary information about style classes redefinition in
<link linkend="customstyles">Definition of Custom Style Classes</link>
- section.
+ section.</para>
</section>
<section>
<title>Relevant Resources Links</title>
Modified: branches/community/3.3.X/docs/userguide/en/src/main/docbook/included/rich_inputNumberSpinner.xml
===================================================================
--- branches/community/3.3.X/docs/userguide/en/src/main/docbook/included/rich_inputNumberSpinner.xml 2009-09-18 06:45:52 UTC (rev 15620)
+++ branches/community/3.3.X/docs/userguide/en/src/main/docbook/included/rich_inputNumberSpinner.xml 2009-09-18 13:25:36 UTC (rev 15621)
@@ -229,50 +229,83 @@
</tbody>
</tgroup>
</table>
- <table id="tab_cn1">
- <title> Classes names that define a component appearance </title>
-
- <tgroup cols="2">
- <thead>
- <row>
- <entry>Class name</entry>
- <entry>Description</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>rich-spinner-c</entry>
- <entry> Defines styles for a wrapper
- table element of a component
- </entry>
- </row>
- <row>
- <entry>rich-spinner-input-container</entry>
- <entry>Defines styles for a
- container</entry>
- </row>
- <row>
- <entry>rich-spinner-input</entry>
- <entry> Defines styles for a wrapper
- <td> element for
- input fields </entry>
- </row>
- <row>
- <entry>rich-spinner-button</entry>
- <entry>Defines styles for a
- button</entry>
- </row>
- <row>
- <entry>rich-spinner-buttons</entry>
- <entry>Defines styles for all
- buttons</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- You can find all necessary information about style classes redefinition in
+
+ <table>
+ <title>Style classes (selectors) with the corresponding skin parameters</title>
+ <tgroup cols="4">
+ <thead>
+ <row>
+ <entry>Class (selector) name</entry>
+ <entry>Description</entry>
+ <entry>Skin Parameters</entry>
+ <entry>CSS properties mapped</entry>
+
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry morerows="1">.rich-spinner-buttons</entry>
+ <entry morerows="1">Defines styles for all buttons</entry>
+ <entry>headerBackgroundColor</entry>
+ <entry>background-color</entry>
+ </row>
+ <row>
+ <entry>panelBorderColor</entry>
+ <entry>border-color</entry>
+ </row>
+
+ <row>
+ <entry morerows="1">.rich-spinner-input</entry>
+ <entry morerows="1"> Defines styles for a wrapper <td> element for input fields</entry>
+ <entry>buttonSizeFont</entry>
+ <entry>font-size</entry>
+ </row>
+ <row>
+ <entry>buttonFamilyFont</entry>
+ <entry>font-family</entry>
+ </row>
+
+ <row>
+ <entry morerows="1">.rich-spinner-input-container</entry>
+ <entry morerows="1">Defines styles for a container</entry>
+ <entry>controlBackgroundColor</entry>
+ <entry>background-color</entry>
+ </row>
+ <row>
+ <entry>panelBorderColor</entry>
+ <entry>border-color</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+
+ <table>
+ <title>Style classes (selectors) without skin parameters</title>
+ <tgroup cols="2">
+ <thead>
+ <row>
+ <entry>Class name</entry>
+ <entry>Description</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>.rich-spinner-c</entry>
+ <entry> Defines styles for a wrapper <table> element of a component</entry>
+ </row>
+
+ <row>
+ <entry>.rich-spinner-button</entry>
+ <entry>Defines styles for a button</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </table>
+
+ <para>You can find all necessary information about style classes redefinition in
<link linkend="customstyles">Definition of Custom Style Classes</link>
- section.
+ section.</para>
</section>
<section>
<title>Relevant Resources Links</title>
16 years, 1 month
JBoss Rich Faces SVN: r15620 - branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/component.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2009-09-18 02:45:52 -0400 (Fri, 18 Sep 2009)
New Revision: 15620
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java
Log:
https://jira.jboss.org/jira/browse/RF-7700 - log warnings for non-processed 'ajaxSingle' components.
Modified: branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java 2009-09-18 02:04:18 UTC (rev 15619)
+++ branches/community/3.3.X/framework/impl/src/main/java/org/ajax4jsf/component/AjaxViewRoot.java 2009-09-18 06:45:52 UTC (rev 15620)
@@ -236,11 +236,17 @@
}
} else {
InvokerCallback invokerCallback = new InvokerCallbackWrapper(callback);
- invokeOnComponent(context, ajaxSingleClientId, invokerCallback);
+ boolean invoked = invokeOnComponent(context, ajaxSingleClientId, invokerCallback);
+ if(!invoked){
+ _log.warn("No component found to process as 'ajaxSingle' for clientId "+ajaxSingleClientId);
+ }
Set<String> areasToProcess = ajaxContext.getAjaxAreasToProcess();
if(null != areasToProcess){
for (String areaId : areasToProcess) {
- invokeOnComponent(context, areaId, invokerCallback);
+ boolean areaProcessed = invokeOnComponent(context, areaId, invokerCallback);
+ if(!areaProcessed){
+ _log.warn("No component found to process for clientId "+ajaxSingleClientId);
+ }
}
}
}
16 years, 1 month
JBoss Rich Faces SVN: r15619 - in root/cdk/trunk/plugins/generator/src: test/resources/org/richfaces/cdk/xmlconfig and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2009-09-17 22:04:18 -0400 (Thu, 17 Sep 2009)
New Revision: 15619
Added:
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/properties.xml
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java
Log:
remove unnecessary fragment unmarshaller method.
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java 2009-09-18 01:05:13 UTC (rev 15618)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java 2009-09-18 02:04:18 UTC (rev 15619)
@@ -155,33 +155,6 @@
}
}
- /**
- * This method parses XML fragment and bind information into designated class instance.
- * @param <T>
- * @param url
- * @param schemaLocation
- * @param bindClass
- * @return
- * @throws CdkException
- */
- public <T> T unmarshalFragment(String url, String schemaLocation, Class<T> bindClass) throws CdkException{
- try {
- InputSource inputSource = resolver.resolveSystemId(url);
- if (null == inputSource) {
- inputSource = new InputSource(url);
- }
-// DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
-// DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
-// documentBuilder.
- T unmarshal = unmarshal(schemaLocation, bindClass, inputSource);
- return unmarshal;
- } catch (FileNotFoundException e) {
- throw new CdkException("XML file not found", e);
- }
-
- }
-
-
@SuppressWarnings("unchecked")
public <T> T unmarshal(String schemaLocation, Class<T> bindClass,
InputSource inputSource) throws CdkException {
@@ -189,6 +162,8 @@
Source source = createXmlSource(inputSource, schemaLocation);
try {
// Setup JAXB to unmarshal
+ // TODO - create xinclude content handler that process xinclude directives
+ // and send SAX event to the unmarshaller handler.
JAXBContext jc = JAXBContext.newInstance(bindClass);
Unmarshaller u = jc.createUnmarshaller();
ValidationEventCollector vec = new ValidationEventCollector();
Added: root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/properties.xml
===================================================================
--- root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/properties.xml (rev 0)
+++ root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/properties.xml 2009-09-18 02:04:18 UTC (rev 15619)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<cdk:properties xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:cdk="http://richfaces.org/cdk/extensions">
+ <property>
+ <description><![CDATA[test2 property]]></description>
+ <display-name>test2 event property</display-name>
+ <icon>ontest2.png</icon>
+ <property-name>ontest2</property-name>
+ <property-class>int</property-class>
+ <default-value>3</default-value>
+ <suggested-value>15</suggested-value>
+ <property-extension>
+ <cdk:literal>true</cdk:literal>
+ <cdk:generate>true</cdk:generate>
+ <cdk:hidden>true</cdk:hidden>
+ <cdk:required>true</cdk:required>
+ <cdk:pass-through>true</cdk:pass-through>
+ <cdk:event-name>ontest2</cdk:event-name>
+ <cdk:event-name default="true">action</cdk:event-name>
+ <cdk:signature>
+ <cdk:param>boolean</cdk:param>
+ <cdk:param>java.lang.String</cdk:param>
+ </cdk:signature>
+ <cdk:alias>foo</cdk:alias>
+ <cdk:alias>bar</cdk:alias>
+ </property-extension>
+ </property>
+</cdk:properties>
Property changes on: root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/properties.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
16 years, 1 month
JBoss Rich Faces SVN: r15618 - in root/cdk/trunk/plugins: generator and 31 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2009-09-17 21:05:13 -0400 (Thu, 17 Sep 2009)
New Revision: 15618
Added:
root/cdk/trunk/plugins/xinclude/
root/cdk/trunk/plugins/xinclude/pom.xml
root/cdk/trunk/plugins/xinclude/src/
root/cdk/trunk/plugins/xinclude/src/main/
root/cdk/trunk/plugins/xinclude/src/main/java/
root/cdk/trunk/plugins/xinclude/src/main/java/org/
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformer.java
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/PointerPart.java
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/ShorthandPart.java
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/UnsupportedPart.java
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointer.java
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerContext.java
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerPart.java
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XmlnsPart.java
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMStreamer.java
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMUtils.java
root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/ElementInfo.java
root/cdk/trunk/plugins/xinclude/src/main/javacc/
root/cdk/trunk/plugins/xinclude/src/main/javacc/xpointer-fw.jj
root/cdk/trunk/plugins/xinclude/src/test/
root/cdk/trunk/plugins/xinclude/src/test/java/
root/cdk/trunk/plugins/xinclude/src/test/java/org/
root/cdk/trunk/plugins/xinclude/src/test/java/org/apache/
root/cdk/trunk/plugins/xinclude/src/test/java/org/apache/cocoon/
root/cdk/trunk/plugins/xinclude/src/test/java/org/apache/cocoon/pipeline/
root/cdk/trunk/plugins/xinclude/src/test/java/org/apache/cocoon/pipeline/component/
root/cdk/trunk/plugins/xinclude/src/test/java/org/apache/cocoon/pipeline/component/sax/
root/cdk/trunk/plugins/xinclude/src/test/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformerTest.java
root/cdk/trunk/plugins/xinclude/src/test/resources/
root/cdk/trunk/plugins/xinclude/src/test/resources/just-text.txt
root/cdk/trunk/plugins/xinclude/src/test/resources/test.xml
root/cdk/trunk/plugins/xinclude/src/test/resources/test.xslt
root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-deprecated_xpointer.xml
root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-fallback.xml
root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-text-only.xml
root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-xml.xml
root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-xpointer.xml
Modified:
root/cdk/trunk/plugins/generator/pom.xml
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkContextBase.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/RichFacesConventions.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/NamingConventionsTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ComponentProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbMarshalTest.java
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/include.xml
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/parent.xml
root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/GenerateMojo.java
root/cdk/trunk/plugins/pom.xml
Log:
add cocoon xinclude processor
Modified: root/cdk/trunk/plugins/generator/pom.xml
===================================================================
--- root/cdk/trunk/plugins/generator/pom.xml 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/pom.xml 2009-09-18 01:05:13 UTC (rev 15618)
@@ -140,7 +140,7 @@
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
- <version>2.9.1</version>
+ <version>2.8.1</version>
</dependency>
<!--
<dependency> <groupId>com.google.collections</groupId>
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkContextBase.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkContextBase.java 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkContextBase.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -142,8 +142,8 @@
}
- public <W extends CdkWorker> void addWorker(Class<W> workerClass, W worker) {
- workers.put(workerClass, worker);
+ public void addWorker(Class<? extends CdkWorker> workerClass, CdkWorker workerInstance) {
+ workers.put(workerClass, workerInstance);
}
@Override
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/RichFacesConventions.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/RichFacesConventions.java 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/RichFacesConventions.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -16,7 +16,7 @@
*
*/
public final class RichFacesConventions implements NamingConventions {
-
+
private static final String ABSTRACT = "Abstract";
private static final String UI = "UI";
private static final String BASE = "Base";
@@ -24,25 +24,23 @@
* <p class="changed_added_4_0">
* </p>
*/
- private final String baseName;
+ private String baseName;
private CdkContext context;
-
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @param componentLibrary
*/
- public RichFacesConventions(String baseName) {
- this.baseName = baseName;
+ public RichFacesConventions() {
}
-
@Override
public void init(CdkContext context) throws CdkException {
this.context = context;
}
-
private final String[] COMPONENT_SUFFIXES = { BASE };
private final String[] COMPONENT_PREFIXES = { UI, ABSTRACT };
@@ -56,7 +54,10 @@
}
Name name = Name.create(className);
// Use base library prefix.
- name.setPrefix(this.getBaseName());
+ String baseName = this.getBaseName();
+ if (null != baseName) {
+ name.setPrefix(baseName);
+ }
// Component type does not contain class or markup parts.
name.setClassifier(null);
name.setMarkup(null);
@@ -72,8 +73,7 @@
// Remove common suffixes.
for (int i = 0; i < COMPONENT_SUFFIXES.length; i++) {
if (simpleName.endsWith(COMPONENT_SUFFIXES[i])) {
- simpleName = simpleName.substring(0, simpleName
- .length()
+ simpleName = simpleName.substring(0, simpleName.length()
- COMPONENT_SUFFIXES[i].length());
break;
}
@@ -85,22 +85,21 @@
}
}
-
@Override
public String inferUIComponentClass(String componentType,
String explicitClass, String baseClass, boolean baseClassIsAbstract)
throws InvalidNameException {
String className;
- if(!Strings.isEmpty(explicitClass)){
+ if (!Strings.isEmpty(explicitClass)) {
// Class name provided by developer.
className = explicitClass;
} else if (isAbstract(baseClass, baseClassIsAbstract)) {
// Infer UI class name from component type.
- Name name = Name.create(componentType);
- name.setClassifier(Classifier.component);
- name.setMarkup(null);
- name.setSimpleName(UI+name.getSimpleName());
- className = name.toString();
+ Name name = Name.create(componentType);
+ name.setClassifier(Classifier.component);
+ name.setMarkup(null);
+ name.setSimpleName(UI + name.getSimpleName());
+ className = name.toString();
} else {
// Do not generate class, use base name.
className = baseClass;
@@ -108,34 +107,32 @@
return className;
}
-
private boolean isAbstract(String baseClass, boolean baseClassIsAbstract) {
- return baseClassIsAbstract || baseClass.startsWith(ABSTRACT)|| baseClass.endsWith(BASE);
+ return baseClassIsAbstract || baseClass.startsWith(ABSTRACT)
+ || baseClass.endsWith(BASE);
}
-
@Override
public String inferUIComponentBaseClass(String componentType,
String baseClassName, boolean baseClassIsAbstract) {
- return isAbstract(baseClassName, baseClassIsAbstract)?baseClassName:null;
+ return isAbstract(baseClassName, baseClassIsAbstract) ? baseClassName
+ : null;
}
-
@Override
public String inferUIComponentFamily(String componentType,
String explicitFamily) {
- return Strings.isEmpty(explicitFamily)?componentType:explicitFamily;
+ return Strings.isEmpty(explicitFamily) ? componentType : explicitFamily;
}
-
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @return the baseName
*/
protected String getBaseName() {
return baseName;
}
-
-
}
\ No newline at end of file
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -93,7 +93,7 @@
public ComponentProcessor(CdkContext context, ComponentLibrary library) throws CdkException {
super(context);
this.library = library;
- fragmentParser = FragmentParser.getInstance(context);
+ fragmentParser = context.getWorkerInstance(FragmentParser.class);
}
/*
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -57,7 +57,7 @@
@Override
public void init(CdkContext context) throws CdkException {
this.context = context;
- jaxbBinding = JAXBBinding.getInstance(context);
+ jaxbBinding = context.getWorkerInstance(JAXBBinding.class);
libraryAdapter = new FacesConfigAdapter();
}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -81,7 +81,7 @@
@Override
public void init(CdkContext context) throws CdkException {
this.context = context;
- jaxbBinding = JAXBBinding.getInstance(context);
+ jaxbBinding = context.getWorkerInstance(JAXBBinding.class);
}
}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -28,6 +28,7 @@
import org.richfaces.cdk.CdkContext;
import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.CdkWorker;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.Property;
import org.richfaces.cdk.xmlconfig.model.Properties;
@@ -41,20 +42,14 @@
* @author asmirnov(a)exadel.com
*
*/
-public class FragmentParser {
+public class FragmentParser implements CdkWorker {
private CdkContext context;
private JAXBBinding binding;
- public static FragmentParser getInstance(CdkContext context) throws CdkException{
- FragmentParser parser = new FragmentParser();
- parser.init(context);
- return parser;
- }
- protected FragmentParser() {
- // TODO Auto-generated constructor stub
+ public FragmentParser() {
}
/**
* <p class="changed_added_4_0">
@@ -65,7 +60,7 @@
*/
public void init(CdkContext context) throws CdkException {
this.context = context;
- binding = JAXBBinding.getInstance(context);
+ binding = context.getWorkerInstance(JAXBBinding.class);
}
/**
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -43,6 +43,8 @@
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.util.ValidationEventCollector;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
@@ -53,6 +55,7 @@
import org.richfaces.cdk.CdkContext;
import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.CdkWorker;
import org.richfaces.cdk.model.ClassDescription;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ConfigExtension;
@@ -74,7 +77,7 @@
* @author asmirnov(a)exadel.com
*
*/
-public class JAXBBinding {
+public class JAXBBinding implements CdkWorker {
private static final FacesConfigNamespacePreffixMapper PREFFIX_MAPPER = new FacesConfigNamespacePreffixMapper();
@@ -84,23 +87,8 @@
private SAXParserFactory spf;
- /**
- * <p class="changed_added_4_0">
- * Factory method for binding instance.
- * </p>
- *
- * @param context
- * @return
- * @throws CdkException
- */
- public static JAXBBinding getInstance(CdkContext context)
- throws CdkException {
- JAXBBinding jaxbBinding = new JAXBBinding();
- jaxbBinding.init(context);
- return jaxbBinding;
- }
- protected JAXBBinding() {
+ public JAXBBinding() {
}
@@ -167,6 +155,33 @@
}
}
+ /**
+ * This method parses XML fragment and bind information into designated class instance.
+ * @param <T>
+ * @param url
+ * @param schemaLocation
+ * @param bindClass
+ * @return
+ * @throws CdkException
+ */
+ public <T> T unmarshalFragment(String url, String schemaLocation, Class<T> bindClass) throws CdkException{
+ try {
+ InputSource inputSource = resolver.resolveSystemId(url);
+ if (null == inputSource) {
+ inputSource = new InputSource(url);
+ }
+// DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
+// DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
+// documentBuilder.
+ T unmarshal = unmarshal(schemaLocation, bindClass, inputSource);
+ return unmarshal;
+ } catch (FileNotFoundException e) {
+ throw new CdkException("XML file not found", e);
+ }
+
+ }
+
+
@SuppressWarnings("unchecked")
public <T> T unmarshal(String schemaLocation, Class<T> bindClass,
InputSource inputSource) throws CdkException {
Modified: root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/NamingConventionsTest.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/NamingConventionsTest.java 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/NamingConventionsTest.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -42,7 +42,7 @@
@Before
public void createConventions() {
- conventions = new RichFacesConventions(BASE);
+ conventions = new RichFacesConventions();
}
@After
@@ -65,7 +65,7 @@
*/
@Test
public void testInferComponentTypeFromUIClass() throws Exception {
- assertEquals("foo.bar.Test", conventions.inferComponentType("","foo.baz.component.UITest"));
+ assertEquals("foo.baz.Test", conventions.inferComponentType("","foo.baz.component.UITest"));
}
/**
@@ -74,7 +74,7 @@
*/
@Test
public void testInferComponentTypeFromAbstractClass() throws Exception {
- assertEquals("foo.bar.Test", conventions.inferComponentType("","foo.baz.component.AbstractTest"));
+ assertEquals("foo.baz.Test", conventions.inferComponentType("","foo.baz.component.AbstractTest"));
}
/**
@@ -83,7 +83,7 @@
*/
@Test
public void testInferComponentTypeFromBaseClass() throws Exception {
- assertEquals("foo.bar.Test", conventions.inferComponentType("","foo.baz.component.TestBase"));
+ assertEquals("foo.baz.Test", conventions.inferComponentType("","foo.baz.component.TestBase"));
}
/**
@@ -92,7 +92,7 @@
*/
@Test
public void testInferComponentTypeFromMarkupClass() throws Exception {
- assertEquals("foo.bar.HtmlTest", conventions.inferComponentType("","foo.baz.component.html.HtmlTest"));
+ assertEquals("foo.baz.HtmlTest", conventions.inferComponentType("","foo.baz.component.html.HtmlTest"));
}
/**
Modified: root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ComponentProcessorTest.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ComponentProcessorTest.java 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ComponentProcessorTest.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -51,6 +51,8 @@
import org.richfaces.cdk.model.Component;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.Property;
+import org.richfaces.cdk.xmlconfig.FragmentParser;
+import org.richfaces.cdk.xmlconfig.JAXBBinding;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
@@ -124,8 +126,16 @@
expect(cdkContext.getOutputFolder((OutputType) anyObject())).andStubReturn(null);
expect(cdkContext.getLoader()).andStubReturn(
TestAnnotation.class.getClassLoader());
- expect(cdkContext.getWorkerInstance(NamingConventions.class)).andStubReturn(new RichFacesConventions("foo.bar"));
+ RichFacesConventions richFacesConventions = new RichFacesConventions();
+ expect(cdkContext.getWorkerInstance(NamingConventions.class)).andStubReturn(richFacesConventions);
+ FragmentParser fragmentParser = new FragmentParser();
+ expect(cdkContext.getWorkerInstance(FragmentParser.class)).andStubReturn(fragmentParser);
+ JAXBBinding jaxbBinding = new JAXBBinding();
+ expect(cdkContext.getWorkerInstance(JAXBBinding.class)).andStubReturn(jaxbBinding);
replay(cdkContext);
+ richFacesConventions.init(cdkContext);
+ jaxbBinding.init(cdkContext);
+ fragmentParser.init(cdkContext);
return cdkContext;
}
Modified: root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -49,7 +49,9 @@
@Test
public void testComponentUnmarshal() throws Exception {
- JAXBBinding jaxbBinding = JAXBBinding.getInstance(new CdkContextBase(this.getClass().getClassLoader()));
+ CdkContextBase contextBase = new CdkContextBase(this.getClass().getClassLoader());
+ JAXBBinding jaxbBinding = new JAXBBinding();
+ jaxbBinding.init(contextBase);
FacesConfigBean library = jaxbBinding.unmarshal("urn:resource:org/richfaces/cdk/xmlconfig/component.xml", ComponentLibrary.FACES_CONFIG_SCHEMA_LOCATION, FacesConfigBean.class);
assertEquals(1,library.getComponents().size());
Component component = library.getComponents().get(0);
Modified: root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -46,22 +46,28 @@
@Test
public void parserTest() throws Exception {
- FragmentParser parser = FragmentParser.getInstance(new CdkContextBase(this.getClass().getClassLoader()));
+ FragmentParser parser = new FragmentParser();
+ CdkContextBase contextBase = new CdkContextBase(this.getClass().getClassLoader());
+ parser.init(contextBase);
Collection<Property> properties = parser.parseProperties("urn:resource:org/richfaces/cdk/xmlconfig/fragment.xml");
assertEquals(3,properties.size());
}
@Test
public void xincludeTest() throws Exception {
- FragmentParser parser = FragmentParser.getInstance(new CdkContextBase(this.getClass().getClassLoader()));
+ FragmentParser parser = new FragmentParser();
+ CdkContextBase contextBase = new CdkContextBase(this.getClass().getClassLoader());
+ parser.init(contextBase);
Collection<Property> properties = parser.parseProperties("urn:resource:org/richfaces/cdk/xmlconfig/parent.xml");
- assertEquals(1,properties.size());
+ assertEquals(2,properties.size());
}
@Test
public void propertyTest() throws Exception {
- FragmentParser parser = FragmentParser.getInstance(new CdkContextBase(this.getClass().getClassLoader()));
- Collection<Property> properties = parser.parseProperties("urn:resource:org/richfaces/cdk/xmlconfig/include.xml");
+ FragmentParser parser = new FragmentParser();
+ CdkContextBase contextBase = new CdkContextBase(this.getClass().getClassLoader());
+ parser.init(contextBase);
+ Collection<Property> properties = parser.parseProperties("urn:resource:org/richfaces/cdk/xmlconfig/properties.xml");
assertEquals(1,properties.size());
Property property = Iterables.getOnlyElement(properties);
assertEquals("ontest2",property.getName().toString());
Modified: root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbMarshalTest.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbMarshalTest.java 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbMarshalTest.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -18,7 +18,9 @@
@Test
public void testMarshalResultStringT() throws Exception {
- JAXBBinding jaxbBinding = JAXBBinding.getInstance(new CdkContextBase(this.getClass().getClassLoader()));
+ CdkContextBase contextBase = new CdkContextBase(this.getClass().getClassLoader());
+ JAXBBinding jaxbBinding = new JAXBBinding();
+ jaxbBinding.init(contextBase);
ComponentLibrary library = new ComponentLibrary();
Component component = library.findOrCreateComponent("foo.bar");
RenderKit renderKit = library.findOrCreateRenderKit("HTML");
Modified: root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/include.xml
===================================================================
--- root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/include.xml 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/include.xml 2009-09-18 01:05:13 UTC (rev 15618)
@@ -1,8 +1,22 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<cdk:properties xmlns:xi="http://www.w3.org/2001/XInclude"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:cdk="http://richfaces.org/cdk/extensions">
- <property>
+ <property xmlns="http://java.sun.com/xml/ns/javaee" xmlns:cdk="http://richfaces.org/cdk/extensions">
+ <description><![CDATA[test property]]></description>
+ <display-name>test event property</display-name>
+ <icon>ontest.png</icon>
+ <property-name>ontest</property-name>
+ <property-class>boolean</property-class>
+ <default-value>1</default-value>
+ <suggested-value>1</suggested-value>
+ <property-extension>
+ <cdk:literal>true</cdk:literal>
+ <cdk:generate>true</cdk:generate>
+ <cdk:hidden>true</cdk:hidden>
+ <cdk:required>true</cdk:required>
+ <cdk:pass-through>true</cdk:pass-through>
+ <cdk:event-name>test</cdk:event-name>
+ <cdk:event-name default="true">action</cdk:event-name>
+ </property-extension>
+ </property >
+ <property xmlns="http://java.sun.com/xml/ns/javaee" xmlns:cdk="http://richfaces.org/cdk/extensions">
<description><![CDATA[test2 property]]></description>
<display-name>test2 event property</display-name>
<icon>ontest2.png</icon>
@@ -26,4 +40,4 @@
<cdk:alias>bar</cdk:alias>
</property-extension>
</property>
-</cdk:properties>
+
Modified: root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/parent.xml
===================================================================
--- root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/parent.xml 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/parent.xml 2009-09-18 01:05:13 UTC (rev 15618)
@@ -8,8 +8,6 @@
-->
<xi:include
- href="urn:resource:org/richfaces/cdk/xmlconfig/include.xml"
-
- xpointer="element(/1/1)"/>
+ href="urn:resource:org/richfaces/cdk/xmlconfig/include.xml"/>
</cdk:properties>
Modified: root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/GenerateMojo.java
===================================================================
--- root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/GenerateMojo.java 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/maven-cdk-plugin/src/main/java/org/richfaces/builder/mojo/GenerateMojo.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -28,12 +28,16 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import java.util.Map.Entry;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.model.FileSet;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -42,6 +46,7 @@
import org.codehaus.plexus.util.DirectoryScanner;
import org.richfaces.cdk.CdkContextBase;
import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.CdkWorker;
import org.richfaces.cdk.LibraryBuilder;
import org.richfaces.cdk.ModelValidator;
import org.richfaces.cdk.NamingConventions;
@@ -61,7 +66,17 @@
* @goal generate
*/
public class GenerateMojo extends AbstractMojo {
-
+
+ private static final String MAIN_CONFIG = "src/main/config";
+
+ private static final String XML_INCLUDES = "**/*.xml";
+
+ private static final String[] JAVA_INCLUDES = new String[] { "**/*.java" };
+
+ private static final String[] STRINGS_ARRAY = new String[0];
+
+ private static final String MAIN_TEMPLATES = "src/main/templates";
+
/**
* Top maven project.
*
@@ -69,36 +84,55 @@
* @readonly
*/
protected MavenProject project;
+
/**
* @parameter
*/
- protected Resource[] facesConfigs;
+ protected String[] sourceIncludes;
-
/**
* @parameter
*/
- protected Resource[] templates;
-
+ protected String[] sourceExcludes;
+
/**
+ * @parameter
+ */
+ protected FileSet[] facesConfigs;
+
+ /**
+ * @parameter
+ */
+ protected FileSet[] templates;
+
+ /**
* Directory where the output Java Files will be located.
*
- * @parameter expression="${project.build.directory}/generated-component/java"
+ * @parameter expression="${project.build.directory}/generated-sources/java"
*/
protected File outputJavaDirectory;
/**
- * @parameter expression="${project.build.directory}/generated-component/test"
+ * @parameter expression="${project.build.directory}/generated-sources/test"
*/
protected File outputTestsDirectory;
/**
* Directory where the output Java Files will be located.
*
- * @parameter expression="${project.build.directory}/generated-component/resources"
+ * @parameter
+ * expression="${project.build.directory}/generated-sources/resources"
*/
protected File outputResourcesDirectory;
+
/**
+ * Directory where the output Java Files will be located.
+ *
+ * @parameter
+ * expression="${project.build.directory}/generated-sources/testresources"
+ */
+ protected File outputTestResourcesDirectory;
+ /**
* The source directories containing the sources to be compiled.
*
* @parameter expression="${project.compileSourceRoots}"
@@ -123,6 +157,11 @@
*/
protected File outputDirectory;
+ /**
+ * @parameter
+ */
+ protected Map<String, String> workers;
+
/*
* (non-Javadoc)
*
@@ -131,38 +170,99 @@
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
// TODO set logging.
- checkLibraryConfig();
CdkContextBase context = new CdkContextBase(this
.createProjectClassLoader(project));
ArrayList<File> folders = new ArrayList<File>(compileSourceRoots.size());
for (String sourceFolder : compileSourceRoots) {
File folder = new File(sourceFolder);
- if(folder.exists() && folder.isDirectory()){
+ if (folder.exists() && folder.isDirectory()) {
folders.add(folder);
}
}
context.setSourceFolders(StandardSources.JAVA_SOURCES, folders);
- if(!outputJavaDirectory.exists()){
+ if (!outputJavaDirectory.exists()) {
outputJavaDirectory.mkdirs();
}
- context.setOutputFolder(StandardOutputFolders.JAVA_CLASSES, outputJavaDirectory);
- if(!outputResourcesDirectory.exists()){
+ context.setOutputFolder(StandardOutputFolders.JAVA_CLASSES,
+ outputJavaDirectory);
+ if (!outputResourcesDirectory.exists()) {
outputResourcesDirectory.mkdirs();
}
- context.setOutputFolder(StandardOutputFolders.RESOURCES, outputResourcesDirectory);
- if(!outputTestsDirectory.exists()){
+ context.setOutputFolder(StandardOutputFolders.RESOURCES,
+ outputResourcesDirectory);
+
+ if (!outputTestsDirectory.exists()) {
outputTestsDirectory.mkdirs();
}
- context.setOutputFolder(StandardOutputFolders.TEST_JAVA_CLASSES, outputTestsDirectory);
+ context.setOutputFolder(StandardOutputFolders.TEST_JAVA_CLASSES,
+ outputTestsDirectory);
+ if (!outputTestResourcesDirectory.exists()) {
+ outputTestResourcesDirectory.mkdirs();
+ }
+ context.setOutputFolder(StandardOutputFolders.TEST_RESOURCES,
+ outputTestResourcesDirectory);
// TODO - configure.
- context.addWorker(NamingConventions.class, new RichFacesConventions(null));
- context.addWorker(ModelValidator.class, new ValidatorImpl());
+ boolean namingConventionsConfigured = false;
+ boolean validatorConfigured = false;
+ if (null != workers) {
+ for (Entry<String, String> workerEntry : workers.entrySet()) {
+ try {
+ Class<? extends CdkWorker> workerClass = Class.forName(
+ workerEntry.getKey()).asSubclass(CdkWorker.class);
+ Class<? extends CdkWorker> workerImplementationClass = Class
+ .forName(workerEntry.getValue()).asSubclass(
+ CdkWorker.class);
+ CdkWorker workerInstance = workerImplementationClass
+ .newInstance();
+ workerInstance.init(context);
+ context.addWorker(workerClass, workerInstance);
+ if (NamingConventions.class.equals(workerClass)) {
+ namingConventionsConfigured = true;
+ }
+ if (ModelValidator.class.equals(workerClass)) {
+ validatorConfigured = true;
+ }
+ } catch (ClassNotFoundException e) {
+ throw new MojoFailureException("Worker class not found", e);
+ } catch (InstantiationException e) {
+ throw new MojoFailureException(
+ "Worker instance can't be created", e);
+ } catch (IllegalAccessException e) {
+ throw new MojoFailureException(
+ "Worker instance can't be created", e);
+ } catch (CdkException e) {
+ throw new MojoFailureException(
+ "Worker initialization error", e);
+ }
+ }
+
+ }
+ if (namingConventionsConfigured) {
+ RichFacesConventions facesConventions = new RichFacesConventions();
+ try {
+ facesConventions.init(context);
+ } catch (CdkException e) {
+ throw new MojoFailureException(
+ "Naming conventions initialization error", e);
+ }
+ context.addWorker(NamingConventions.class, facesConventions);
+ }
+ if (validatorConfigured) {
+ ValidatorImpl validatorImpl = new ValidatorImpl();
+ try {
+ validatorImpl.init(context);
+ } catch (CdkException e) {
+ throw new MojoFailureException(
+ "RichFaces Validator initialization error", e);
+ }
+ context.addWorker(ModelValidator.class, validatorImpl);
+ }
context.addSources(StandardSources.JAVA_SOURCES, findJavaFiles());
context.addSources(StandardSources.RENDERER_TEMPLATES,
findTemplateFiles());
context.addSources(StandardSources.FACES_CONFIGS,
findFacesConfigFiles());
-
+
try {
LibraryBuilder builder = LibraryBuilder.createInstance(context);
ComponentLibrary model = builder.buildModel();
@@ -171,7 +271,12 @@
Resource resource = new Resource();
resource.setDirectory(outputResourcesDirectory.getAbsolutePath());
project.addResource(resource);
- project.addTestCompileSourceRoot(outputTestsDirectory.getAbsolutePath());
+ project.addTestCompileSourceRoot(outputTestsDirectory
+ .getAbsolutePath());
+ Resource testResource = new Resource();
+ testResource.setDirectory(outputTestResourcesDirectory
+ .getAbsolutePath());
+ project.addTestResource(testResource);
} catch (CdkException e) {
throw new MojoExecutionException("CDK build error", e);
}
@@ -179,20 +284,30 @@
protected void checkLibraryConfig() {
// TODO Auto-generated method stub
-
+
}
- private Iterable<File> findTemplateFiles() {
- // TODO Auto-generated method stub
- return null;
+ private Iterable<File> findTemplateFiles() throws MojoExecutionException {
+ if (null == templates) {
+ File defaultDirectory = new File(MAIN_TEMPLATES);
+ if (defaultDirectory.exists() && defaultDirectory.isDirectory()) {
+ FileSet fileSet = new FileSet();
+ fileSet.setDirectory(MAIN_TEMPLATES);
+ fileSet.addInclude(XML_INCLUDES);
+ templates = new FileSet[] { fileSet };
+ }
+ }
+ return doScan(templates);
+
}
- private Set<File> findJavaFiles() throws MojoExecutionException {
+ private Iterable<File> findJavaFiles() throws MojoExecutionException {
Set<File> javaSources = new HashSet<File>();
+ String[] includes = null == sourceIncludes ? JAVA_INCLUDES
+ : sourceIncludes;
for (String compileRoot : compileSourceRoots) {
File rootFolder = new File(compileRoot);
- String[] sources = doScan(new String[] { "**/*.java" }, null,
- rootFolder);
+ String[] sources = doScan(includes, sourceExcludes, rootFolder);
for (String src : sources) {
javaSources.add(new File(rootFolder, src));
}
@@ -200,34 +315,34 @@
return javaSources;
}
- private Set<File> findFacesConfigFiles() throws MojoExecutionException {
- Set<File> javaSources = new HashSet<File>();
-// if (facesConfigInclude.exists() && facesConfigInclude.isDirectory()) {
-// String[] sources = doScan(new String[] { "**/*.xml" }, null,
-// facesConfigInclude);
-// for (String src : sources) {
-// javaSources.add(new File(facesConfigInclude, src));
-// }
-//
-// }
- return javaSources;
+ private Iterable<File> findFacesConfigFiles() throws MojoExecutionException {
+ if (null == facesConfigs) {
+ File defaultDirectory = new File(MAIN_CONFIG);
+ if (defaultDirectory.exists() && defaultDirectory.isDirectory()) {
+ FileSet fileSet = new FileSet();
+ fileSet.setDirectory(MAIN_CONFIG);
+ fileSet.addInclude(XML_INCLUDES);
+ facesConfigs = new FileSet[] { fileSet };
+ }
+ }
+ return doScan(facesConfigs);
}
-
+
protected ClassLoader createProjectClassLoader(MavenProject project) {
ClassLoader classLoader = null;
try {
List<?> compileClasspathElements = project
- .getCompileClasspathElements();
+ .getCompileClasspathElements();
String outputDirectory = project.getBuild().getOutputDirectory();
URL[] urls = new URL[compileClasspathElements.size() + 1];
int i = 0;
urls[i++] = new File(outputDirectory).toURI().toURL();
for (Iterator<?> iter = compileClasspathElements.iterator(); iter
- .hasNext();) {
+ .hasNext();) {
String element = (String) iter.next();
urls[i++] = new File(element).toURI().toURL();
}
- classLoader = new URLClassLoader(urls);
+ classLoader = new URLClassLoader(urls);
} catch (MalformedURLException e) {
getLog().error("Bad URL in classpath", e);
} catch (DependencyResolutionRequiredException e) {
@@ -237,8 +352,8 @@
return classLoader;
}
- protected String[] doScan(String[] includes, String[] excludes, File rootFolder)
- throws MojoExecutionException {
+ protected String[] doScan(String[] includes, String[] excludes,
+ File rootFolder) throws MojoExecutionException {
try {
DirectoryScanner directoryScanner = new DirectoryScanner();
directoryScanner.setFollowSymlinks(true);
@@ -251,9 +366,36 @@
return directoryScanner.getIncludedFiles();
} catch (IllegalStateException e) {
- throw new MojoExecutionException(
- "Error scanning source root: \'" + rootFolder + "\'", e );
+ throw new MojoExecutionException("Error scanning source root: \'"
+ + rootFolder + "\'", e);
}
}
+ /**
+ * Skan Array of filesets for selected resources.
+ *
+ * @param fileset
+ * @return
+ * @throws MojoExecutionException
+ */
+ @SuppressWarnings("unchecked")
+ protected Collection<File> doScan(FileSet[] filesets)
+ throws MojoExecutionException {
+ List<File> files = new ArrayList<File>();
+ if (null != filesets) {
+ for (FileSet fileSet : filesets) {
+ String[] includes = (String[]) fileSet.getIncludes().toArray(
+ STRINGS_ARRAY);
+ String[] excludes = (String[]) fileSet.getExcludes().toArray(
+ STRINGS_ARRAY);
+ String[] scan = doScan(includes, excludes, new File(fileSet
+ .getDirectory()));
+ for (String filename : scan) {
+ files.add(new File(filename));
+ }
+ }
+
+ }
+ return files;
+ }
}
Modified: root/cdk/trunk/plugins/pom.xml
===================================================================
--- root/cdk/trunk/plugins/pom.xml 2009-09-18 00:55:24 UTC (rev 15617)
+++ root/cdk/trunk/plugins/pom.xml 2009-09-18 01:05:13 UTC (rev 15618)
@@ -15,9 +15,10 @@
<modules>
+ <module>annotations</module>
+ <module>xinclude</module>
<module>generator</module>
<module>maven-cdk-plugin</module>
- <module>annotations</module>
</modules>
</project>
\ No newline at end of file
Added: root/cdk/trunk/plugins/xinclude/pom.xml
===================================================================
--- root/cdk/trunk/plugins/xinclude/pom.xml (rev 0)
+++ root/cdk/trunk/plugins/xinclude/pom.xml 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,128 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ -->
+ <!-- $Id: pom.xml 699337 2008-09-26 14:24:57Z reinhard $ -->
+ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>jar</packaging>
+ <parent>
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>maven-plugins</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.richfaces.cdk</groupId>
+ <artifactId>xinclude</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ <name>Cocoon 3: xinclude transformer</name>
+ <description>Cocoon 3 xinclude transformer with Xpointer scheme support.</description>
+
+ <dependencies>
+<dependency>
+ <groupId>org.apache.cocoon.pipeline</groupId>
+ <artifactId>cocoon-pipeline</artifactId>
+ <version>3.0.0-alpha-1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Other dependencies -->
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>xmlunit</groupId>
+ <artifactId>xmlunit</artifactId>
+ <scope>test</scope>
+ <version>1.2</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.1</version>
+ <configuration>
+ <archive>
+ <manifestEntries>
+ <Cocoon-Block-Name>${pom.artifactId}</Cocoon-Block-Name>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>javacc-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>javacc</id>
+ <goals>
+ <goal>javacc</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>add-source</id>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>target/generated-sources/javacc</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+</project>
Property changes on: root/cdk/trunk/plugins/xinclude/pom.xml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformer.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformer.java (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformer.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,516 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.pipeline.component.sax;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.cocoon.pipeline.ProcessingException;
+import org.apache.cocoon.pipeline.component.xpointer.XPointer;
+import org.apache.cocoon.pipeline.component.xpointer.XPointerContext;
+import org.apache.cocoon.pipeline.component.xpointer.parser.ParseException;
+import org.apache.cocoon.pipeline.component.xpointer.parser.XPointerFrameworkParser;
+import org.apache.cocoon.pipeline.util.URLConnectionUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.xml.sax.Attributes;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+
+
+public final class XIncludeTransformer
+ extends AbstractXMLProducer
+ implements XMLConsumer {
+
+ private static final String XINCLUDE_NAMESPACE_URI = "http://www.w3.org/2001/XInclude";
+
+ private static final String XINCLUDE_INCLUDE = "include";
+
+ private static final String XINCLUDE_FALLBACK = "fallback";
+
+ private static final String XINCLUDE_HREF = "href";
+
+ private static final String XINCLUDE_XPOINTER = "xpointer";
+
+ private static final String XINCLUDE_PARSE = "parse";
+
+ private static final String XINCLUDE_ENCODING = "encoding";
+
+ private static final String DEFAULT_CHARSET = "UTF-8";
+
+ private static final String XINCLUDE_ACCEPT = "accept";
+
+ private static final String XINCLUDE_ACCEPT_LANGUAGE = "accept-language";
+
+ private static final String XINCLUDE_PARSE_XML = "xml";
+
+ private static final String XINCLUDE_PARSE_TEXT = "text";
+
+ private static final String UNKNOWN_LOCATION = "unknow location";
+
+ private static final String HTTP_ACCEPT = "Accept";
+
+ private static final String HTTP_ACCEPT_LANGUAGE = "Accept-Language";
+
+ private final Log logger = LogFactory.getLog(getClass());
+
+ /** The nesting level of xi:include elements that have been encountered. */
+ private int xIncludeElementLevel = 0;
+
+ /** The nesting level of fallback that should be used */
+ private int useFallbackLevel = 0;
+
+ /** The nesting level of xi:fallback elements that have been encountered. */
+ private int fallbackElementLevel;
+
+ /**
+ * Locator of the current stream, stored here so that it can be restored after
+ * another document send its content to the consumer.
+ */
+ private Locator locator;
+
+ private URL baseUrl;
+
+ /**
+ * Keep a map of namespaces prefix in the source document to pass it
+ * to the XPointerContext for correct namespace identification.
+ */
+ private final Map<String, String> namespaces = new HashMap<String, String>();
+
+ public XIncludeTransformer() {
+ // default empty constructor
+ }
+
+ public XIncludeTransformer(URL baseUrl) {
+ this.setBaseUrl(baseUrl);
+ }
+
+ @Override
+ public void setConfiguration(Map<String, ? extends Object> configuration) {
+ this.setBaseUrl((URL) configuration.get("baseUrl"));
+ }
+
+ public void setBaseUrl(URL baseUrl) {
+ this.baseUrl = baseUrl;
+ }
+
+ /**
+ * Eventually previous errors don't reset local variables status, so
+ * every time a new consumer is set, local variables should be re-initialized
+ */
+ @Override
+ protected void setXMLConsumer(XMLConsumer xmlConsumer) {
+ super.setXMLConsumer(xmlConsumer);
+ this.xIncludeElementLevel = 0;
+ this.fallbackElementLevel = 0;
+ this.useFallbackLevel = 0;
+ }
+
+ /**
+ * Determine whether the pipe is currently in a state where contents
+ * should be evaluated, i.e. xi:include elements should be resolved
+ * and elements in other namespaces should be copied through. Will
+ * return false for fallback contents within a successful xi:include,
+ * and true for contents outside any xi:include or within an xi:fallback
+ * for an unsuccessful xi:include.
+ */
+ private boolean isEvaluatingContent() {
+ return xIncludeElementLevel == 0 ||
+ (fallbackElementLevel > 0 && fallbackElementLevel == useFallbackLevel);
+ }
+
+ private String getLocation() {
+ if (locator == null) {
+ return UNKNOWN_LOCATION;
+ } else {
+ return locator.getSystemId()
+ + ":"
+ + locator.getColumnNumber()
+ + ":" + locator.getLineNumber();
+ }
+ }
+
+ public void startDocument() throws SAXException {
+ if (xIncludeElementLevel == 0) {
+ getXMLConsumer().startDocument();
+ }
+ }
+
+ public void endDocument() throws SAXException {
+ if (xIncludeElementLevel == 0) {
+ getXMLConsumer().endDocument();
+ }
+ }
+
+ public void startElement(String uri, String localName, String name,
+ Attributes atts) throws SAXException {
+ if (XINCLUDE_NAMESPACE_URI.equals(uri)) {
+ // Handle xi:include:
+ if (XINCLUDE_INCLUDE.equals(localName)) {
+ // Process the include, unless in an ignored fallback:
+ if (isEvaluatingContent()) {
+ String href = atts.getValue("", XINCLUDE_HREF);
+
+ String parse = atts.getValue("", XINCLUDE_PARSE);
+ // Default for @parse is "xml"
+ if (parse == null) {
+ parse = XINCLUDE_PARSE_XML;
+ }
+
+ String xpointer = atts.getValue("", XINCLUDE_XPOINTER);
+ String encoding = atts.getValue("", XINCLUDE_ENCODING);
+
+ String accept = atts.getValue("", XINCLUDE_ACCEPT);
+ String acceptLanguage = atts.getValue("", XINCLUDE_ACCEPT_LANGUAGE);
+
+ processXIncludeElement(href, parse, xpointer, encoding,
+ accept, acceptLanguage);
+ }
+ xIncludeElementLevel++;
+ } else if (XINCLUDE_FALLBACK.equals(localName)) {
+ // Handle xi:fallback
+ fallbackElementLevel++;
+ } else {
+ // Unknown element:
+ throw new SAXException("Unknown XInclude element "
+ + localName
+ + " at "
+ + getLocation());
+ }
+ } else if (isEvaluatingContent()) {
+ // Copy other elements through when appropriate:
+ getXMLConsumer().startElement(uri, localName, name, atts);
+ }
+ }
+
+ private void processXIncludeElement(String href, String parse,
+ String xpointer, String encoding, String accept,
+ String acceptLanguage) throws SAXException {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Processing XInclude element: href="
+ + href
+ + ", parse="
+ + parse
+ + ", xpointer="
+ + xpointer
+ + ", encoding="
+ + encoding
+ + ", accept="
+ + accept
+ + ", acceptLanguage="
+ + acceptLanguage);
+ }
+
+ int fragmentIdentifierPos = href.indexOf('#');
+ if (fragmentIdentifierPos != -1) {
+ logger.warn("Fragment identifer found in 'href' attribute: "
+ + href +
+ "\nFragment identifiers are forbidden by the XInclude specification. "
+ + "They are still handled by XIncludeTransformer for backward "
+ + "compatibility, but their use is deprecated and will be prohibited "
+ + "in a future release. Use the 'xpointer' attribute instead.");
+ if (xpointer == null) {
+ xpointer = href.substring(fragmentIdentifierPos + 1);
+ }
+ href = href.substring(0, fragmentIdentifierPos);
+ }
+
+ // An empty or absent href is a reference to the current document -- this can be different than the current base
+ if (href == null || href.length() == 0) {
+ throw new SAXException("XIncludeTransformer: encountered empty href (= href pointing to the current document).");
+ }
+ URL source = createSource(href);
+ URLConnection urlConnection = null;
+
+ try {
+ urlConnection = source.openConnection();
+ } catch (IOException ioe) {
+ useFallbackLevel++;
+ logger.error("Error including document: " + source, ioe);
+ }
+
+ if (urlConnection != null) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Parse type=" + parse);
+ }
+
+ if (XINCLUDE_PARSE_XML.equals(parse)) {
+ /* sends Accept and Accept-Language */
+ if (urlConnection instanceof HttpURLConnection) {
+ HttpURLConnection httpURLConnection =
+ (HttpURLConnection) urlConnection;
+
+ if (accept != null && accept.length() > 0) {
+ httpURLConnection.setRequestProperty(HTTP_ACCEPT, accept);
+ }
+
+ if (acceptLanguage != null && acceptLanguage.length() > 0) {
+ httpURLConnection.setRequestProperty(HTTP_ACCEPT_LANGUAGE, acceptLanguage);
+ }
+ }
+
+ if (xpointer != null && xpointer.length() > 0) {
+ try {
+ XPointer xPointer = XPointerFrameworkParser.parse(xpointer);
+ XPointerContext xPointerContext = new XPointerContext(xpointer, source, this, logger);
+ for (Entry<String, String> namespace : namespaces.entrySet()) {
+ xPointerContext.addPrefix(namespace.getKey(), namespace.getValue());
+ }
+ xPointer.process(xPointerContext);
+ } catch (ParseException e) {
+ // this exception is thrown in case of an invalid xpointer expression
+ useFallbackLevel++;
+ logger.error("Error parsing XPointer expression, will try to use fallback.", e);
+ } catch (IOException e) {
+ useFallbackLevel++;
+ logger.error("Error processing an xInclude, will try to use fallback.", e);
+ }
+ } else {
+ // just parses the document and streams it
+ URLConnectionUtils.toSax(urlConnection, this);
+ }
+ } else if (XINCLUDE_PARSE_TEXT.equals(parse)) {
+ if (xpointer != null) {
+ throw new SAXException("xpointer attribute must not be present when parse='text': "
+ + getLocation());
+ }
+
+ // content type will be string like "text/xml; charset=UTF-8" or "text/xml"
+ String rawContentType = urlConnection.getContentType();
+
+ if (encoding == null) {
+ // text/xml and application/xml offer only one optional parameter
+ int index = (rawContentType != null) ? rawContentType.indexOf(';') : -1;
+
+ String charset = null;
+ if (index != -1) {
+ // this should be something like "charset=UTF-8", but we want to
+ // strip it down to just "UTF-8"
+ charset = rawContentType.substring(index + 1).trim();
+ if (charset.startsWith("charset=")) {
+ // 8 is the length of "charset="
+ charset = charset.substring(8).trim();
+ // strip quotes, if present
+ if ((charset.charAt(0) == '"'
+ && charset.charAt(charset.length() - 1) == '"')
+ || (charset.charAt(0) == '\''
+ && charset.charAt(charset.length() - 1)
+ == '\'')) {
+ encoding =
+ charset.substring(1, charset.length() - 1);
+ }
+ } else {
+ encoding = DEFAULT_CHARSET;
+ }
+ } else {
+ encoding = DEFAULT_CHARSET;
+ }
+ }
+
+ InputStream is = null;
+ InputStreamReader isr = null;
+ Reader reader = null;
+
+ try {
+ is = urlConnection.getInputStream();
+ isr = new InputStreamReader(is, encoding);
+ reader = new BufferedReader(isr);
+
+ int read;
+ char ary[] = new char[1024 * 4];
+ while ((read = reader.read(ary)) != -1) {
+ getXMLConsumer().characters(ary, 0, read);
+ }
+ } catch (IOException e) {
+ useFallbackLevel++;
+ logger.error("Error including text: ", e);
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ // ignored
+ }
+ }
+ if (isr != null) {
+ try {
+ isr.close();
+ } catch (IOException e) {
+ // ignored
+ }
+ }
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // ignored
+ }
+ }
+ }
+ } else {
+ throw new SAXException("Found 'parse' attribute with unknown value "
+ + parse
+ + " at "
+ + getLocation());
+ }
+ }
+ }
+
+ private URL createSource(String sourceAtt) {
+ try {
+ URL source = null;
+ if (sourceAtt.contains(":")) {
+ source = new URL(sourceAtt);
+ } else {
+ source = new URL(this.baseUrl, sourceAtt);
+ }
+ if (this.logger.isDebugEnabled()) {
+ this.logger.debug("Including source: " + source);
+ }
+
+ return source;
+ } catch (MalformedURLException e) {
+ String message = "Can't parse URL " + sourceAtt;
+ this.logger.error(message, e);
+ throw new ProcessingException(message, e);
+ }
+ }
+
+ public void endElement(String uri, String localName, String name)
+ throws SAXException {
+ // Handle elements in xinclude namespace:
+ if (XINCLUDE_NAMESPACE_URI.equals(uri)) {
+ // Handle xi:include:
+ if (XINCLUDE_INCLUDE.equals(localName)) {
+ xIncludeElementLevel--;
+ if (useFallbackLevel > xIncludeElementLevel) {
+ useFallbackLevel = xIncludeElementLevel;
+ }
+ } else if (XINCLUDE_FALLBACK.equals(localName)) {
+ // Handle xi:fallback:
+ fallbackElementLevel--;
+ }
+ } else if (isEvaluatingContent()) {
+ // Copy other elements through when appropriate:
+ getXMLConsumer().endElement(uri, localName, name);
+ }
+ }
+
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException {
+ if (isEvaluatingContent()) {
+ // removed xinclude namespace from result document
+ if (!uri.equals(XINCLUDE_NAMESPACE_URI)) {
+ getXMLConsumer().startPrefixMapping(prefix, uri);
+ }
+ namespaces.put(prefix, uri);
+ }
+ }
+
+ public void endPrefixMapping(String prefix) throws SAXException {
+ if (isEvaluatingContent()) {
+ getXMLConsumer().endPrefixMapping(prefix);
+ namespaces.remove(prefix);
+ }
+ }
+
+ public void startCDATA() throws SAXException {
+ if (isEvaluatingContent()) {
+ getXMLConsumer().startCDATA();
+ }
+ }
+
+ public void endCDATA() throws SAXException {
+ if (isEvaluatingContent()) {
+ getXMLConsumer().startCDATA();
+ }
+ }
+
+ public void startDTD(String name, String publicId, String systemId)
+ throws SAXException {
+ // ignoring DTD
+ }
+
+ public void endDTD() throws SAXException {
+ // ignoring DTD
+ }
+
+ public void startEntity(String name) throws SAXException {
+ if (isEvaluatingContent()) {
+ getXMLConsumer().startEntity(name);
+ }
+ }
+
+ public void endEntity(String name) throws SAXException {
+ if (isEvaluatingContent()) {
+ getXMLConsumer().endEntity(name);
+ }
+ }
+
+ public void characters(char[] ch, int start, int length)
+ throws SAXException {
+ if (isEvaluatingContent()) {
+ getXMLConsumer().characters(ch, start, length);
+ }
+ }
+
+ public void ignorableWhitespace(char[] ch, int start, int length)
+ throws SAXException {
+ if (isEvaluatingContent()) {
+ getXMLConsumer().ignorableWhitespace(ch, start, length);
+ }
+ }
+
+ public void comment(char[] ch, int start, int length) throws SAXException {
+ // skip comments
+ }
+
+ public void processingInstruction(String target, String data)
+ throws SAXException {
+ if (isEvaluatingContent()) {
+ getXMLConsumer().processingInstruction(target, data);
+ }
+ }
+
+ public void setDocumentLocator(Locator locator) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("setDocumentLocator called " + locator.getSystemId());
+ }
+
+ this.locator = locator;
+ getXMLConsumer().setDocumentLocator(locator);
+ }
+
+ public void skippedEntity(String name) throws SAXException {
+ if (isEvaluatingContent()) {
+ getXMLConsumer().skippedEntity(name);
+ }
+ }
+
+}
Property changes on: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformer.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/PointerPart.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/PointerPart.java (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/PointerPart.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.pipeline.component.xpointer;
+
+import java.io.IOException;
+
+import org.xml.sax.SAXException;
+
+/**
+ * Interface to be implemented by pointer parts (xpointer schemes).
+ */
+public interface PointerPart {
+
+ /**
+ * If this pointer part successfully identifies any subresources, it should
+ * stream them to the XMLConsumer available from the XPointerContext and return true.
+ * Otherwise this method should return false.
+ */
+ boolean process(XPointerContext xpointerContext) throws SAXException, IOException;
+
+}
Property changes on: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/PointerPart.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/ShorthandPart.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/ShorthandPart.java (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/ShorthandPart.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.pipeline.component.xpointer;
+
+import java.io.IOException;
+
+import org.apache.cocoon.pipeline.util.dom.DOMUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXException;
+
+/**
+ * Implements support for shorthand XPointers (= id-based lookup). We treat them here as if they
+ * were a pointerpart too.
+ *
+ * <p>Note that although this is implemented here, this feature depends on the presence of a DTD,
+ * and a validating parser. Currently, this means its unuseable within Cocoon.
+ */
+public final class ShorthandPart implements PointerPart {
+
+ private String shorthand;
+
+ public ShorthandPart(String shorthand) {
+ this.shorthand = shorthand;
+ }
+
+ public boolean process(XPointerContext xpointerContext)
+ throws SAXException, IOException {
+ Document document = xpointerContext.getDocument();
+ Element element = document.getElementById(shorthand);
+ if (element != null) {
+ DOMUtils.stream(element, xpointerContext.getXmlConsumer());
+ return true;
+ } else {
+ if (xpointerContext.getLogger().isDebugEnabled())
+ xpointerContext.getLogger().debug("XPointer: found no element with id "
+ + shorthand
+ + " in document "
+ + xpointerContext.getSource());
+ }
+ return false;
+ }
+
+}
Property changes on: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/ShorthandPart.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/UnsupportedPart.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/UnsupportedPart.java (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/UnsupportedPart.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.pipeline.component.xpointer;
+
+import java.io.IOException;
+
+import org.xml.sax.SAXException;
+
+
+public final class UnsupportedPart implements PointerPart {
+
+ private String schemeName;
+
+ public UnsupportedPart(String schemeName) {
+ this.schemeName = schemeName;
+ }
+
+ public boolean process(XPointerContext xpointerContext)
+ throws SAXException, IOException {
+ throw new SAXException("Scheme "
+ + schemeName
+ + " not supported by this XPointer implementation, as used in the fragment identifier "
+ + xpointerContext.getXPointer());
+ }
+
+}
Property changes on: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/UnsupportedPart.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointer.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointer.java (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointer.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.pipeline.component.xpointer;
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.xml.sax.SAXException;
+
+
+public final class XPointer {
+
+ private final List<PointerPart> pointerParts = new LinkedList<PointerPart>();
+
+ public void addPart(PointerPart part) {
+ pointerParts.add(part);
+ }
+
+ public void process(XPointerContext xpointerContext) throws SAXException, IOException {
+ for (PointerPart pointerPart : pointerParts) {
+ pointerPart.process(xpointerContext);
+ }
+ }
+
+}
Property changes on: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointer.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerContext.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerContext.java (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerContext.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.pipeline.component.xpointer;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+
+import org.apache.cocoon.pipeline.component.sax.XMLConsumer;
+import org.apache.cocoon.pipeline.util.dom.DOMUtils;
+import org.apache.commons.logging.Log;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+
+public final class XPointerContext implements NamespaceContext {
+
+ private final static String XML = "xml";
+
+ private final static String XMLNS = "xmlns";
+
+ private final static String XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace";
+
+ private final static String XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
+
+ private Map<String, String> prefixes = new HashMap<String, String>();
+
+ private String xPointer;
+
+ private URL source;
+
+ private XMLConsumer xmlConsumer;
+
+ private Log logger;
+
+ private Document document;
+
+ public XPointerContext(String xPointer, URL source, XMLConsumer xmlConsumer, Log logger) {
+ this.xPointer = xPointer;
+ this.source = source;
+ this.xmlConsumer = xmlConsumer;
+ this.logger = logger;
+ }
+
+ public String getXPointer() {
+ return xPointer;
+ }
+
+ public URL getSource() {
+ return source;
+ }
+
+ public XMLConsumer getXmlConsumer() {
+ return xmlConsumer;
+ }
+
+ public Log getLogger() {
+ return logger;
+ }
+
+ public Document getDocument() throws IOException, SAXException {
+ if (document == null) {
+ document = DOMUtils.toDOM(source);
+ }
+ return document;
+ }
+
+ public void addPrefix(String prefix, String namespaceURI) {
+ if (prefix.equalsIgnoreCase(XML)
+ || prefix.equals(XMLNS)) {
+ return;
+ }
+
+ if (namespaceURI.equals(XML_NAMESPACE)
+ || namespaceURI.equals(XMLNS_NAMESPACE)) {
+ return;
+ }
+
+ prefixes.put(prefix, namespaceURI);
+ }
+
+ public String getNamespaceURI(String prefix) {
+ return prefixes.get(prefix);
+ }
+
+ // This method isn't necessary for XPath processing.
+ public String getPrefix(String namespaceURI) {
+ throw new UnsupportedOperationException();
+ }
+
+ @SuppressWarnings("unchecked")
+ // This method isn't necessary for XPath processing either.
+ public Iterator getPrefixes(String namespaceURI) {
+ throw new UnsupportedOperationException();
+ }
+
+}
Property changes on: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerContext.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerPart.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerPart.java (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerPart.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.pipeline.component.xpointer;
+
+import java.io.IOException;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.apache.cocoon.pipeline.component.sax.XMLConsumer;
+import org.apache.cocoon.pipeline.util.dom.DOMUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.LocatorImpl;
+
+
+public final class XPointerPart implements PointerPart {
+
+ private final static XPathFactory XPF = XPathFactory.newInstance();
+
+ private String expression;
+
+ public XPointerPart(String expression) {
+ this.expression = expression;
+ }
+
+ public boolean process(XPointerContext xpointerContext)
+ throws SAXException, IOException {
+ Document document = xpointerContext.getDocument();
+
+ XPath xpath = XPF.newXPath();
+ xpath.setNamespaceContext(xpointerContext);
+
+ XPathExpression xpathExpression;
+ try {
+ xpathExpression = xpath.compile(expression);
+ } catch (XPathExpressionException e) {
+ throw new SAXException("XPointer: expression \""
+ + expression
+ + "\" is not a valid XPath expression", e);
+ }
+
+ try {
+ NodeList nodeList =
+ (NodeList) xpathExpression.evaluate(document, XPathConstants.NODESET);
+ if (nodeList.getLength() > 0) {
+ XMLConsumer consumer = xpointerContext.getXmlConsumer();
+ LocatorImpl locator = new LocatorImpl();
+ locator.setSystemId(xpointerContext.getSource().toString());
+ consumer.setDocumentLocator(locator);
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ DOMUtils.stream(nodeList.item(i), consumer);
+ }
+ return true;
+ } else {
+ if (xpointerContext.getLogger().isDebugEnabled())
+ xpointerContext.getLogger().debug("XPointer: expression \""
+ + expression
+ + "\" gave no results.");
+ return false;
+ }
+ } catch (XPathExpressionException e) {
+ throw new SAXException("XPointer: impossible to select DOM fragment using expression \""
+ + expression
+ + "\", see nested exception", e);
+ }
+ }
+
+}
Property changes on: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XPointerPart.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XmlnsPart.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XmlnsPart.java (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XmlnsPart.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.pipeline.component.xpointer;
+
+import java.io.IOException;
+
+import org.xml.sax.SAXException;
+
+
+public final class XmlnsPart implements PointerPart {
+
+ private String prefix;
+
+ private String namespace;
+
+ /**
+ * Creates an XmlnsPart.
+ */
+ public XmlnsPart(String prefix, String namespace) {
+ this.prefix = prefix;
+ this.namespace = namespace;
+ }
+
+ public boolean process(XPointerContext xpointerContext)
+ throws SAXException, IOException {
+ xpointerContext.addPrefix(prefix, namespace);
+ return false;
+ }
+
+}
Property changes on: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/component/xpointer/XmlnsPart.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMStreamer.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMStreamer.java (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMStreamer.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,412 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.pipeline.util.dom;
+
+import java.util.Map.Entry;
+
+import org.apache.cocoon.pipeline.component.sax.XMLConsumer;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Element;
+import org.w3c.dom.EntityReference;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+
+final class DOMStreamer {
+
+ private XMLConsumer xmlConsumer;
+
+ private ElementInfo currentElementInfo;
+
+ /** Counter used when generating new namespace prefixes. */
+ private int newPrefixCounter;
+
+ public DOMStreamer(XMLConsumer xmlConsumer) {
+ this.xmlConsumer = xmlConsumer;
+ }
+
+ /**
+ * Start the production of SAX events.
+ */
+ public void stream(Node node) throws SAXException {
+ // Start document only if we're streaming a document
+ boolean isDoc = (node.getNodeType() == Node.DOCUMENT_NODE);
+ if (isDoc) {
+ xmlConsumer.startDocument();
+ }
+
+ Node top = node;
+ while (null != node) {
+ startNode(node);
+
+ Node nextNode = node.getFirstChild();
+ while (null == nextNode) {
+ endNode(node);
+
+ if (top.equals(node)) {
+ break;
+ }
+
+ nextNode = node.getNextSibling();
+ if (null == nextNode) {
+ node = node.getParentNode();
+
+ if ((null == node) || (top.equals(node))) {
+ if (null != node) {
+ endNode(node);
+ }
+ nextNode = null;
+
+ break;
+ }
+ }
+ }
+
+ node = nextNode;
+ }
+
+ if (isDoc) {
+ xmlConsumer.endDocument();
+ }
+ }
+
+ private void startNode(Node node) throws SAXException {
+ switch (node.getNodeType()) {
+ case Node.COMMENT_NODE:
+ // ignore comment
+ break;
+
+ case Node.DOCUMENT_FRAGMENT_NODE:
+ // ??;
+ break;
+
+ case Node.DOCUMENT_NODE:
+ break;
+
+ case Node.ELEMENT_NODE:
+ NamedNodeMap atts = node.getAttributes();
+ int nAttrs = atts.getLength();
+
+ // create a list of localy declared namespace prefixes
+ currentElementInfo = new ElementInfo(currentElementInfo);
+ for (int i = 0; i < nAttrs; i++) {
+ Node attr = atts.item(i);
+ String attrName = attr.getNodeName();
+
+ if (attrName.equals("xmlns") || attrName.startsWith("xmlns:")) {
+ int index;
+ String prefix = (index = attrName.indexOf(":")) < 0
+ ? "" : attrName.substring(index + 1);
+
+ currentElementInfo.put(prefix, attr.getNodeValue());
+ }
+ }
+
+ String namespaceURI = node.getNamespaceURI();
+ String prefix = node.getPrefix();
+ String localName = node.getLocalName();
+
+ if (localName == null) {
+ // this is an element created with createElement instead of createElementNS
+ String[] prefixAndLocalName = getPrefixAndLocalName(node.getNodeName());
+ prefix = prefixAndLocalName[0];
+ localName = prefixAndLocalName[1];
+ // note: if prefix is null, there can still be a default namespace...
+ namespaceURI = getNamespaceForPrefix(prefix, (Element)node);
+ }
+
+ if (namespaceURI != null) {
+ // no prefix means: make this the default namespace
+ if (prefix == null) {
+ prefix = "";
+ }
+ // check that is declared
+ String uri = currentElementInfo.findNamespaceURI(prefix);
+ if (uri != null && uri.equals(namespaceURI)) {
+ // System.out.println("namespace is declared");
+ // prefix is declared correctly, do nothing
+ } else if (uri != null) {
+ // System.out.println("prefix is declared with other namespace, overwriting it");
+ // prefix exists but is bound to another namespace, overwrite it
+ currentElementInfo.put(prefix, namespaceURI);
+ } else {
+ // System.out.println("prefix is not yet declared, declaring it now");
+ currentElementInfo.put(prefix, namespaceURI);
+ }
+ } else {
+ // element has no namespace
+ // check if there is a default namespace, if so undeclare it
+ String uri = currentElementInfo.findNamespaceURI("");
+ if (uri != null && uri.length() > 0) {
+ // System.out.println("undeclaring default namespace");
+ currentElementInfo.put("", "");
+ }
+ }
+
+ // SAX uses empty string to denote no namespace, while DOM uses null.
+ if (namespaceURI == null)
+ namespaceURI = "";
+
+ String qName;
+ if (prefix != null && prefix.length() > 0) {
+ qName = prefix + ":" + localName;
+ } else {
+ qName = localName;
+ }
+
+ // make the attributes
+ AttributesImpl newAttrs = new AttributesImpl();
+ for (int i = 0; i < nAttrs; i++) {
+ Node attr = atts.item(i);
+ String attrName = attr.getNodeName();
+ String assignedAttrPrefix = null;
+
+ // only do non-namespace attributes
+ if (!(attrName.equals("xmlns") || attrName.startsWith("xmlns:"))) {
+ String attrPrefix;
+ String attrLocalName;
+ String attrNsURI;
+
+ if (attr.getLocalName() == null) {
+ // this is an attribute created with setAttribute instead of setAttributeNS
+ String[] prefixAndLocalName = getPrefixAndLocalName(attrName);
+ attrPrefix = prefixAndLocalName[0];
+ // the statement below causes the attribute to keep its prefix even if it is not
+ // bound to a namespace (to support pre-namespace XML).
+ assignedAttrPrefix = attrPrefix;
+ attrLocalName = prefixAndLocalName[1];
+ // note: if prefix is null, the attribute has no namespace (namespace defaulting
+ // does not apply to attributes)
+ if (attrPrefix != null)
+ attrNsURI = getNamespaceForPrefix(attrPrefix, (Element) node);
+ else
+ attrNsURI = null;
+ } else {
+ attrLocalName = attr.getLocalName();
+ attrPrefix = attr.getPrefix();
+ attrNsURI = attr.getNamespaceURI();
+ }
+
+ if (attrNsURI != null) {
+ String declaredUri = currentElementInfo.findNamespaceURI(attrPrefix);
+ // if the prefix is null, or the prefix has not been declared, or conflicts with an in-scope binding
+ if (declaredUri == null || !declaredUri.equals(attrNsURI)) {
+ String availablePrefix = currentElementInfo.findPrefix(attrNsURI);
+ if (availablePrefix != null && !availablePrefix.equals(""))
+ assignedAttrPrefix = availablePrefix;
+ else {
+ if (attrPrefix != null && declaredUri == null) {
+ // prefix is not null and is not yet declared: declare it
+ assignedAttrPrefix = attrPrefix;
+ currentElementInfo.put(assignedAttrPrefix, attrNsURI);
+ } else {
+ // attribute has no prefix (which is not allowed for namespaced attributes) or
+ // the prefix is already bound to something else: generate a new prefix
+ newPrefixCounter++;
+ assignedAttrPrefix = "NS" + newPrefixCounter;
+ currentElementInfo.put(assignedAttrPrefix, attrNsURI);
+ }
+ }
+ } else {
+ assignedAttrPrefix = attrPrefix;
+ }
+ }
+
+ String assignedAttrNsURI = attrNsURI != null ? attrNsURI : "";
+ String attrQName;
+ if (assignedAttrPrefix != null) {
+ attrQName = assignedAttrPrefix + ":" + attrLocalName;
+ } else {
+ attrQName = attrLocalName;
+ }
+ newAttrs.addAttribute(assignedAttrNsURI, attrLocalName, attrQName, "CDATA", attr.getNodeValue());
+ }
+ }
+
+ // add local namespace declaration and fire startPrefixMapping events
+ if (currentElementInfo.namespaceDeclarations != null && currentElementInfo.namespaceDeclarations.size() > 0) {
+ for (Entry<String, String> entry : currentElementInfo.namespaceDeclarations.entrySet()) {
+ String pr = (String) entry.getKey();
+ String ns = (String) entry.getValue();
+ // the following lines enable the creation of explicit xmlns attributes
+ //String pr1 = pr.equals("") ? "xmlns" : pr;
+ //String qn = pr.equals("") ? "xmlns" : "xmlns:" + pr;
+ //newAttrs.addAttribute("", pr1, qn, "CDATA", ns);
+ // System.out.println("starting prefix mapping for prefix " + pr + " for " + ns);
+ xmlConsumer.startPrefixMapping(pr, ns);
+ }
+ }
+
+ xmlConsumer.startElement(namespaceURI, localName, qName, newAttrs);
+
+ currentElementInfo.localName = localName;
+ currentElementInfo.namespaceURI = namespaceURI;
+ currentElementInfo.qName = qName;
+ break;
+ case Node.PROCESSING_INSTRUCTION_NODE:
+ {
+ ProcessingInstruction pi = (ProcessingInstruction) node;
+ xmlConsumer.processingInstruction(pi.getNodeName(), pi.getData());
+ }
+ break;
+ case Node.CDATA_SECTION_NODE:
+ {
+ if (xmlConsumer != null)
+ xmlConsumer.startCDATA();
+
+ dispatchChars(node);
+
+ if (xmlConsumer != null)
+ xmlConsumer.endCDATA();
+ }
+ break;
+ case Node.TEXT_NODE:
+ {
+ dispatchChars(node);
+ }
+ break;
+ case Node.ENTITY_REFERENCE_NODE:
+ {
+ EntityReference eref = (EntityReference) node;
+
+ if (xmlConsumer != null) {
+ xmlConsumer.startEntity(eref.getNodeName());
+ } else {
+ // warning("Can not output entity to a pure SAX xmlConsumer");
+ }
+ }
+ break;
+ default :
+ }
+ }
+
+ private void endNode(Node node) throws SAXException {
+ switch (node.getNodeType()) {
+ case Node.DOCUMENT_NODE:
+ break;
+
+ case Node.ELEMENT_NODE:
+ xmlConsumer.endElement(currentElementInfo.namespaceURI,
+ currentElementInfo.localName, currentElementInfo.qName);
+
+ // generate endPrefixMapping events if needed
+ if (currentElementInfo.namespaceDeclarations != null && currentElementInfo.namespaceDeclarations.size() > 0) {
+ for (Entry<String, String> entry : currentElementInfo.namespaceDeclarations.entrySet()) {
+ xmlConsumer.endPrefixMapping((String) entry.getKey());
+ }
+ }
+
+ currentElementInfo = currentElementInfo.parent;
+ break;
+ case Node.CDATA_SECTION_NODE:
+ break;
+ case Node.ENTITY_REFERENCE_NODE:
+ {
+ EntityReference eref = (EntityReference) node;
+
+ if (xmlConsumer != null) {
+ xmlConsumer.endEntity(eref.getNodeName());
+ }
+ }
+ break;
+ default :
+ }
+ }
+
+ private void dispatchChars(Node node) throws SAXException {
+ final String data = ((Text) node).getData();
+ if ( data != null ) {
+ xmlConsumer.characters(data.toCharArray(), 0, data.length());
+ }
+ }
+
+ /**
+ * Searches the namespace for a given namespace prefix starting from a
+ * given Element.
+ *
+ * <p>Note that this resolves the prefix in the orginal DOM-tree, not in
+ * the {@link ElementInfo} objects. This is used to resolve prefixes
+ * of elements or attributes created with createElement or setAttribute
+ * instead of createElementNS or setAttributeNS.
+ *
+ * <p>The code in this method is largely based on
+ * org.apache.xml.utils.DOMHelper.getNamespaceForPrefix() (from Xalan).
+ *
+ * @param prefix the prefix to look for, can be empty or null to find the
+ * default namespace
+ *
+ * @return the namespace, or null if not found.
+ */
+ private String getNamespaceForPrefix(String prefix, Element namespaceContext) {
+ int type;
+ Node parent = namespaceContext;
+ String namespace = null;
+
+ if (prefix == null)
+ prefix = "";
+
+ if (prefix.equals("xml")) {
+ namespace = "http://www.w3.org/XML/1998/namespace";
+ } else if(prefix.equals("xmlns")) {
+ namespace = "http://www.w3.org/2000/xmlns/";
+ } else {
+ // Attribute name for this prefix's declaration
+ String declname = (prefix.length() == 0) ? "xmlns" : "xmlns:" + prefix;
+
+ // Scan until we run out of Elements or have resolved the namespace
+ while ((null != parent) && (null == namespace)
+ && (((type = parent.getNodeType()) == Node.ELEMENT_NODE)
+ || (type == Node.ENTITY_REFERENCE_NODE))) {
+ if (type == Node.ELEMENT_NODE) {
+ Attr attr= ((Element)parent).getAttributeNode(declname);
+ if (attr != null) {
+ namespace = attr.getNodeValue();
+ break;
+ }
+ }
+ parent = parent.getParentNode();
+ }
+ }
+ return namespace;
+ }
+
+ /**
+ * Splits a nodeName into a prefix and a localName
+ *
+ * @return an array containing two elements, the first one is the prefix (can be null), the
+ * second one is the localName
+ */
+ private String[] getPrefixAndLocalName(String nodeName) {
+ String prefix, localName;
+ int colonPos = nodeName.indexOf(":");
+ if (colonPos != -1) {
+ prefix = nodeName.substring(0, colonPos);
+ localName = nodeName.substring(colonPos + 1, nodeName.length());
+ } else {
+ prefix = null;
+ localName = nodeName;
+ }
+ return new String[] {prefix, localName};
+ }
+
+}
Property changes on: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMStreamer.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMUtils.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMUtils.java (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMUtils.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.pipeline.util.dom;
+
+import java.io.IOException;
+import java.net.URL;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.cocoon.pipeline.component.sax.XMLConsumer;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+
+public final class DOMUtils {
+
+ private final static DocumentBuilderFactory DBF = DocumentBuilderFactory.newInstance();
+
+ private DOMUtils() {
+ // instances are not allowed
+ }
+
+ public static Document toDOM(URL source) throws SAXException, IOException {
+ DocumentBuilder documentBuilder;
+ try {
+ documentBuilder = DBF.newDocumentBuilder();
+ return documentBuilder.parse(source.openStream());
+ } catch (ParserConfigurationException e) {
+ throw new SAXException("Error during XPointer evaluation while trying to load "
+ + source, e);
+ }
+ }
+
+ public static void stream(Node node, XMLConsumer xmlConsumer) throws SAXException {
+ new DOMStreamer(xmlConsumer).stream(node);
+ }
+
+}
Property changes on: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/DOMUtils.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/ElementInfo.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/ElementInfo.java (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/ElementInfo.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.pipeline.util.dom;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+
+final class ElementInfo {
+
+ public String localName;
+
+ public String namespaceURI;
+
+ public String qName;
+
+ public Map<String, String> namespaceDeclarations = null;
+
+ public ElementInfo parent;
+
+ public ElementInfo(ElementInfo parent) {
+ this.parent = parent;
+ }
+
+ /**
+ * Declare a new namespace prefix on this element, possibly overriding
+ * an existing one.
+ */
+ public void put(String prefix, String namespaceURI) {
+ if (namespaceDeclarations == null)
+ namespaceDeclarations = new HashMap<String, String>();
+ namespaceDeclarations.put(prefix, namespaceURI);
+ }
+
+ /**
+ * Finds a prefix declared on this element.
+ */
+ public String getPrefix(String namespaceURI) {
+ if (namespaceDeclarations == null || namespaceDeclarations.size() == 0)
+ return null;
+ // note: there could be more than one prefix for the same namespaceURI, but
+ // we return the first found one.
+ for (Entry<String, String> entry : namespaceDeclarations.entrySet()) {
+ if (entry.getValue().equals(namespaceURI)) {
+ return (String) entry.getKey();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Finds a namespace URI declared on this element.
+ */
+ public String getNamespaceURI(String prefix) {
+ if (namespaceDeclarations == null || namespaceDeclarations.size() == 0)
+ return null;
+
+ return (String) namespaceDeclarations.get(prefix);
+ }
+
+ /**
+ * Finds a prefix declaration on this element or containing elements.
+ */
+ public String findPrefix(String namespaceURI) {
+ if (namespaceDeclarations != null && namespaceDeclarations.size() != 0) {
+ String prefix = getPrefix(namespaceURI);
+ if (prefix != null) {
+ return prefix;
+ }
+ }
+ if (parent != null) {
+ return parent.findPrefix(namespaceURI);
+ }
+ return null;
+ }
+
+ /**
+ * Finds a namespace declaration on this element or containing elements.
+ */
+ public String findNamespaceURI(String prefix) {
+ if (namespaceDeclarations != null && namespaceDeclarations.size() != 0) {
+ String uri = (String) namespaceDeclarations.get(prefix);
+ if (uri != null) {
+ return uri;
+ }
+ }
+ if (parent != null) {
+ return parent.findNamespaceURI(prefix);
+ }
+ return null;
+ }
+
+}
Property changes on: root/cdk/trunk/plugins/xinclude/src/main/java/org/apache/cocoon/pipeline/util/dom/ElementInfo.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/main/javacc/xpointer-fw.jj
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/main/javacc/xpointer-fw.jj (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/main/javacc/xpointer-fw.jj 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,284 @@
+/*
+ Parser for the XPointer Framework Syntax, see the specification at:
+ http://www.w3.org/TR/2003/REC-xptr-framework-20030325/
+
+ Some of the token definitions (for recognizing NCName's) were copied from
+ the JXPath parser from Apache Commons (to save some typing), written by
+ Ingo Macherius, Gerald Huck <{macherius, huck}(a)gmd.de> and Dmitri Plotnikov.
+*/
+
+options {
+ STATIC = false;
+}
+
+PARSER_BEGIN(XPointerFrameworkParser)
+
+ package org.apache.cocoon.pipeline.component.xpointer.parser;
+
+ import org.apache.cocoon.pipeline.component.xpointer.*;
+ import java.util.Map;
+ import java.util.HashMap;
+
+ public class XPointerFrameworkParser {
+
+ private XPointer xpointer = new XPointer();
+
+ private Map<String, String> namespaces = new HashMap<String, String>();
+
+ public static XPointer parse(String xpointer) throws ParseException {
+ XPointerFrameworkParser xfp = new XPointerFrameworkParser(new java.io.StringReader(xpointer));
+ xfp.pointer();
+ return xfp.getXPointer();
+ }
+
+ public XPointer getXPointer() {
+ return xpointer;
+ }
+
+ private String unescape(String data) throws ParseException {
+ StringBuffer result = new StringBuffer(data.length());
+ boolean inCircumflex = false;
+ for (int i = 0; i < data.length(); i++) {
+ char c = data.charAt(i);
+ if (inCircumflex) {
+ switch (c) {
+ case '^':
+ case '(':
+ case ')':
+ result.append(c);
+ inCircumflex = false;
+ break;
+ default:
+ throw new ParseException("Incorrect use of circumflex character at position " + i + " in the string " + data);
+ }
+ } else if (c == '^') {
+ inCircumflex = true;
+ } else {
+ result.append(c);
+ }
+ }
+ return result.toString();
+ }
+ }
+
+PARSER_END(XPointerFrameworkParser)
+
+TOKEN :
+{
+ <#Letter : <BaseChar> | <Ideographic> >
+| <#BaseChar :
+ (
+ ["\u0041"-"\u005A"] | ["\u0061"-"\u007A"] | ["\u00C0"-"\u00D6"] | ["\u00D8"-"\u00F6"] |
+ ["\u00F8"-"\u00FF"] | ["\u0100"-"\u0131"] | ["\u0134"-"\u013E"] | ["\u0141"-"\u0148"] |
+ ["\u014A"-"\u017E"] | ["\u0180"-"\u01C3"] | ["\u01CD"-"\u01F0"] | ["\u01F4"-"\u01F5"] |
+ ["\u01FA"-"\u0217"] | ["\u0250"-"\u02A8"] | ["\u02BB"-"\u02C1"] | "\u0386" | ["\u0388"-"\u038A"] |
+ "\u038C" | ["\u038E"-"\u03A1"] | ["\u03A3"-"\u03CE"] | ["\u03D0"-"\u03D6"] | "\u03DA" |
+ "\u03DC" | "\u03DE" | "\u03E0" | ["\u03E2"-"\u03F3"] | ["\u0401"-"\u040C"] | ["\u040E"-"\u044F"] |
+ ["\u0451"-"\u045C"] | ["\u045E"-"\u0481"] | ["\u0490"-"\u04C4"] | ["\u04C7"-"\u04C8"] |
+ ["\u04CB"-"\u04CC"] | ["\u04D0"-"\u04EB"] | ["\u04EE"-"\u04F5"] | ["\u04F8"-"\u04F9"] |
+ ["\u0531"-"\u0556"] | "\u0559" | ["\u0561"-"\u0586"] | ["\u05D0"-"\u05EA"] | ["\u05F0"-"\u05F2"] |
+ ["\u0621"-"\u063A"] | ["\u0641"-"\u064A"] | ["\u0671"-"\u06B7"] | ["\u06BA"-"\u06BE"] |
+ ["\u06C0"-"\u06CE"] | ["\u06D0"-"\u06D3"] | "\u06D5" | ["\u06E5"-"\u06E6"] | ["\u0905"-"\u0939"] |
+ "\u093D" | ["\u0958"-"\u0961"] | ["\u0985"-"\u098C"] | ["\u098F"-"\u0990"] | ["\u0993"-"\u09A8"] |
+ ["\u09AA"-"\u09B0"] | "\u09B2" | ["\u09B6"-"\u09B9"] | ["\u09DC"-"\u09DD"] | ["\u09DF"-"\u09E1"] |
+ ["\u09F0"-"\u09F1"] | ["\u0A05"-"\u0A0A"] | ["\u0A0F"-"\u0A10"] | ["\u0A13"-"\u0A28"] |
+ ["\u0A2A"-"\u0A30"] | ["\u0A32"-"\u0A33"] | ["\u0A35"-"\u0A36"] | ["\u0A38"-"\u0A39"] |
+ ["\u0A59"-"\u0A5C"] | "\u0A5E" | ["\u0A72"-"\u0A74"] | ["\u0A85"-"\u0A8B"] | "\u0A8D" |
+ ["\u0A8F"-"\u0A91"] | ["\u0A93"-"\u0AA8"] | ["\u0AAA"-"\u0AB0"] | ["\u0AB2"-"\u0AB3"] |
+ ["\u0AB5"-"\u0AB9"] | "\u0ABD" | "\u0AE0" | ["\u0B05"-"\u0B0C"] | ["\u0B0F"-"\u0B10"] |
+ ["\u0B13"-"\u0B28"] | ["\u0B2A"-"\u0B30"] | ["\u0B32"-"\u0B33"] | ["\u0B36"-"\u0B39"] |
+ "\u0B3D" | ["\u0B5C"-"\u0B5D"] | ["\u0B5F"-"\u0B61"] | ["\u0B85"-"\u0B8A"] | ["\u0B8E"-"\u0B90"] |
+ ["\u0B92"-"\u0B95"] | ["\u0B99"-"\u0B9A"] | "\u0B9C" | ["\u0B9E"-"\u0B9F"] | ["\u0BA3"-"\u0BA4"] |
+ ["\u0BA8"-"\u0BAA"] | ["\u0BAE"-"\u0BB5"] | ["\u0BB7"-"\u0BB9"] | ["\u0C05"-"\u0C0C"] |
+ ["\u0C0E"-"\u0C10"] | ["\u0C12"-"\u0C28"] | ["\u0C2A"-"\u0C33"] | ["\u0C35"-"\u0C39"] |
+ ["\u0C60"-"\u0C61"] | ["\u0C85"-"\u0C8C"] | ["\u0C8E"-"\u0C90"] | ["\u0C92"-"\u0CA8"] |
+ ["\u0CAA"-"\u0CB3"] | ["\u0CB5"-"\u0CB9"] | "\u0CDE" | ["\u0CE0"-"\u0CE1"] | ["\u0D05"-"\u0D0C"] |
+ ["\u0D0E"-"\u0D10"] | ["\u0D12"-"\u0D28"] | ["\u0D2A"-"\u0D39"] | ["\u0D60"-"\u0D61"] |
+ ["\u0E01"-"\u0E2E"] | "\u0E30" | ["\u0E32"-"\u0E33"] | ["\u0E40"-"\u0E45"] | ["\u0E81"-"\u0E82"] |
+ "\u0E84" | ["\u0E87"-"\u0E88"] | "\u0E8A" | "\u0E8D" | ["\u0E94"-"\u0E97"] | ["\u0E99"-"\u0E9F"] |
+ ["\u0EA1"-"\u0EA3"] | "\u0EA5" | "\u0EA7" | ["\u0EAA"-"\u0EAB"] | ["\u0EAD"-"\u0EAE"] | "\u0EB0" |
+ ["\u0EB2"-"\u0EB3"] | "\u0EBD" | ["\u0EC0"-"\u0EC4"] | ["\u0F40"-"\u0F47"] | ["\u0F49"-"\u0F69"] |
+ ["\u10A0"-"\u10C5"] | ["\u10D0"-"\u10F6"] | "\u1100" | ["\u1102"-"\u1103"] | ["\u1105"-"\u1107"] |
+ "\u1109" | ["\u110B"-"\u110C"] | ["\u110E"-"\u1112"] | "\u113C" | "\u113E" | "\u1140" | "\u114C" |
+ "\u114E" | "\u1150" | ["\u1154"-"\u1155"] | "\u1159" | ["\u115F"-"\u1161"] | "\u1163" | "\u1165" |
+ "\u1167" | "\u1169" | ["\u116D"-"\u116E"] | ["\u1172"-"\u1173"] | "\u1175" | "\u119E" | "\u11A8" |
+ "\u11AB" | ["\u11AE"-"\u11AF"] | ["\u11B7"-"\u11B8"] | "\u11BA" | ["\u11BC"-"\u11C2"] | "\u11EB" |
+ "\u11F0" | "\u11F9" | ["\u1E00"-"\u1E9B"] | ["\u1EA0"-"\u1EF9"] | ["\u1F00"-"\u1F15"] |
+ ["\u1F18"-"\u1F1D"] |
+ ["\u1F20"-"\u1F45"] | ["\u1F48"-"\u1F4D"] | ["\u1F50"-"\u1F57"] | "\u1F59" | "\u1F5B" | "\u1F5D" |
+ ["\u1F5F"-"\u1F7D"] | ["\u1F80"-"\u1FB4"] | ["\u1FB6"-"\u1FBC"] | "\u1FBE" | ["\u1FC2"-"\u1FC4"] |
+ ["\u1FC6"-"\u1FCC"] | ["\u1FD0"-"\u1FD3"] | ["\u1FD6"-"\u1FDB"] | ["\u1FE0"-"\u1FEC"] |
+ ["\u1FF2"-"\u1FF4"] | ["\u1FF6"-"\u1FFC"] | "\u2126" | ["\u212A"-"\u212B"] | "\u212E" |
+ ["\u2180"-"\u2182"] | ["\u3041"-"\u3094"] | ["\u30A1"-"\u30FA"] | ["\u3105"-"\u312C"] |
+ ["\uAC00"-"\uD7A3"]
+ ) >
+| <#Ideographic : (["\u4E00"-"\u9FA5"] | "\u3007" | ["\u3021"-"\u3029"]) >
+| <#CombiningChar :
+ (
+ ["\u0300"-"\u0345"] | ["\u0360"-"\u0361"] | ["\u0483"-"\u0486"] | ["\u0591"-"\u05A1"] |
+ ["\u05A3"-"\u05B9"] | ["\u05BB"-"\u05BD"] | "\u05BF" | ["\u05C1"-"\u05C2"] |
+ "\u05C4" | ["\u064B"-"\u0652"] | "\u0670" | ["\u06D6"-"\u06DC"] |
+ ["\u06DD"-"\u06DF"] | ["\u06E0"-"\u06E4"] | ["\u06E7"-"\u06E8"] | ["\u06EA"-"\u06ED"] |
+ ["\u0901"-"\u0903"] | "\u093C" |["\u093E"-"\u094C"] | "\u094D" | ["\u0951"-"\u0954"] |
+ ["\u0962"-"\u0963"] | ["\u0981"-"\u0983"] | "\u09BC" | "\u09BE" | "\u09BF" | ["\u09C0"-"\u09C4"] |
+ ["\u09C7"-"\u09C8"] | ["\u09CB"-"\u09CD"] | "\u09D7" | ["\u09E2"-"\u09E3"] | "\u0A02" | "\u0A3C" |
+ "\u0A3E" | "\u0A3F" | ["\u0A40"-"\u0A42"] |
+ ["\u0A47"-"\u0A48"] | ["\u0A4B"-"\u0A4D"] | ["\u0A70"-"\u0A71"] | ["\u0A81"-"\u0A83"] | "\u0ABC" |
+ ["\u0ABE"-"\u0AC5"] | ["\u0AC7"-"\u0AC9"] | ["\u0ACB"-"\u0ACD"] | ["\u0B01"-"\u0B03"] | "\u0B3C" |
+ ["\u0B3E"-"\u0B43"] | ["\u0B47"-"\u0B48"] | ["\u0B4B"-"\u0B4D"] | ["\u0B56"-"\u0B57"] |
+ ["\u0B82"-"\u0B83"] | ["\u0BBE"-"\u0BC2"] | ["\u0BC6"-"\u0BC8"] | ["\u0BCA"-"\u0BCD"] | "\u0BD7" |
+ ["\u0C01"-"\u0C03"] | ["\u0C3E"-"\u0C44"] | ["\u0C46"-"\u0C48"] | ["\u0C4A"-"\u0C4D"] |
+ ["\u0C55"-"\u0C56"] | ["\u0C82"-"\u0C83"] | ["\u0CBE"-"\u0CC4"] | ["\u0CC6"-"\u0CC8"] |
+ ["\u0CCA"-"\u0CCD"] | ["\u0CD5"-"\u0CD6"] | ["\u0D02"-"\u0D03"] | ["\u0D3E"-"\u0D43"] |
+ ["\u0D46"-"\u0D48"] | ["\u0D4A"-"\u0D4D"] | "\u0D57" | "\u0E31" | ["\u0E34"-"\u0E3A"] |
+ ["\u0E47"-"\u0E4E"] | "\u0EB1" | ["\u0EB4"-"\u0EB9"] | ["\u0EBB"-"\u0EBC"] | ["\u0EC8"-"\u0ECD"] |
+ ["\u0F18"-"\u0F19"] | "\u0F35" | "\u0F37" | "\u0F39" | "\u0F3E" | "\u0F3F" | ["\u0F71"-"\u0F84"] |
+ ["\u0F86"-"\u0F8B"] | ["\u0F90"-"\u0F95"] | "\u0F97" | ["\u0F99"-"\u0FAD"] | ["\u0FB1"-"\u0FB7"] |
+ "\u0FB9" | ["\u20D0"-"\u20DC"] | "\u20E1" | ["\u302A"-"\u302F"] | "\u3099" | "\u309A"
+ )
+ >
+| <#UnicodeDigit :
+ ["\u0030"-"\u0039"] | ["\u0660"-"\u0669"] | ["\u06F0"-"\u06F9"] | ["\u0966"-"\u096F"] |
+ ["\u09E6"-"\u09EF"] | ["\u0A66"-"\u0A6F"] | ["\u0AE6"-"\u0AEF"] | ["\u0B66"-"\u0B6F"] |
+ ["\u0BE7"-"\u0BEF"] | ["\u0C66"-"\u0C6F"] | ["\u0CE6"-"\u0CEF"] | ["\u0D66"-"\u0D6F"] |
+ ["\u0E50"-"\u0E59"] | ["\u0ED0"-"\u0ED9"] | ["\u0F20"-"\u0F29"]
+ >
+| <#Extender :
+ "\u00B7" | "\u02D0" | "\u02D1" | "\u0387" | "\u0640" | "\u0E46" | "\u0EC6" |
+ "\u3005" | ["\u3031"-"\u3035"] | ["\u309D"-"\u309E"] | ["\u30FC"-"\u30FE"]
+ >
+| <NCName : (<Letter> | ["_"]) (<Letter> | <UnicodeDigit> | [".","-","_"] | <CombiningChar> | <Extender>)* >
+| <WS: ["\t", "\r", "\n", " "] >
+| <QName : (<NCName> ":")? <NCName> >
+}
+
+<DEFAULT, IN_SCHEME>
+TOKEN :
+{
+ <LBRACE: "(" >
+| <RBRACE: ")" >
+}
+
+<IN_SCHEME>
+TOKEN :
+{
+ <CIRC_LBRACE: "^(" >
+| <CIRC_RBRACE: "^)" >
+| <DOUBLE_CIRC: "^^" >
+| <NormalChar: ~["(", ")", "^"] >
+}
+
+void pointer():
+{
+}
+{
+ LOOKAHEAD(2) schemeBased() | shortHand()
+}
+
+void shortHand():
+{
+ Token x;
+}
+{
+ x = <NCName>
+ {
+ xpointer.addPart(new ShorthandPart(x.image));
+ }
+}
+
+void schemeBased():
+{
+}
+{
+ pointerPart() ( (<WS>)* pointerPart() )*
+}
+
+void pointerPart():
+{
+ Token x;
+ String schemeName;
+ String schemeData;
+}
+{
+ (x = <NCName> | x = <QName>)
+ <LBRACE>
+ {
+ // when going inside the scheme data, swith to a different lexical state
+ token_source.SwitchTo(IN_SCHEME);
+
+ // store the scheme name
+ schemeName = x.image;
+ }
+ schemeData = schemeData()
+ <RBRACE>
+ {
+ // when going outside the scheme data, swith back to the default lexical state
+ token_source.SwitchTo(DEFAULT);
+
+ // parse schemeName in prefix and localName
+ String schemeNamespace = null, schemeLocalName = null;
+ int colonPos = schemeName.indexOf(':');
+ if (colonPos != -1) {
+ String schemePrefix = schemeName.substring(0, colonPos);
+ schemeNamespace = (String)namespaces.get(schemePrefix);
+ schemeLocalName = schemeName.substring(colonPos + 1);
+ } else {
+ schemeLocalName = schemeName;
+ }
+
+
+ // add the pointer part
+ if (schemeNamespace == null && schemeLocalName.equals("xmlns")) {
+ int eqPos = schemeData.indexOf("=");
+ if (eqPos == -1)
+ throw new ParseException("xmlns scheme data should contain an equals sign");
+
+ // Note: the trimming below is not entirely correct, since space is only allowed left
+ // and right of the equal sign, but not at the beginning and end of the schemeData
+ String prefix = schemeData.substring(0, eqPos).trim();
+ String namespace = schemeData.substring(eqPos + 1, schemeData.length()).trim();
+ xpointer.addPart(new XmlnsPart(prefix, namespace));
+ namespaces.put(prefix, namespace);
+ } else if (schemeNamespace == null && schemeLocalName.equals("xpointer")) {
+ xpointer.addPart(new XPointerPart(schemeData));
+ } else {
+ xpointer.addPart(new UnsupportedPart(schemeName));
+ }
+ }
+}
+
+String schemeData():
+{
+ String temp;
+ StringBuffer schemeData = new StringBuffer();
+}
+{
+ (
+ ( temp = escapedData() { schemeData.append(temp); } )*
+ )
+ {
+ return unescape(schemeData.toString());
+ }
+}
+
+String escapedData():
+{
+ Token x;
+ String temp;
+ StringBuffer data = new StringBuffer();
+}
+{
+ // The reason for not making a token out of this all is that tokens cannot contain recursive definitions
+ (
+ x = <NormalChar> { data.append(x.image); }
+ | x = <CIRC_LBRACE> { data.append(x.image); }
+ | x = <CIRC_RBRACE> { data.append(x.image); }
+ | x = <DOUBLE_CIRC> { data.append(x.image); }
+ | x = <LBRACE> { data.append(x.image); }
+ temp = schemeData() { data.append(temp); }
+ x = <RBRACE> { data.append(x.image); }
+ )
+ {
+ return data.toString();
+ }
+}
Added: root/cdk/trunk/plugins/xinclude/src/test/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformerTest.java
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/test/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformerTest.java (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/test/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformerTest.java 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cocoon.pipeline.component.sax;
+
+import static junit.framework.Assert.assertTrue;
+
+import java.io.ByteArrayOutputStream;
+import java.net.URL;
+
+import org.apache.cocoon.pipeline.NonCachingPipeline;
+import org.apache.cocoon.pipeline.Pipeline;
+import org.custommonkey.xmlunit.Diff;
+import org.junit.Test;
+
+
+public final class XIncludeTransformerTest {
+
+ /**
+ * A pipeline that reads from a file and perform a simple XInclude operation.
+ */
+ @Test
+ public void testPipelineWithXInclude() throws Exception {
+ internalXIncludeTest("xinclude-xml.xml",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x>\n <test/>\n</x>");
+ }
+
+ /**
+ * A pipeline that performs an XInclude operation, including just text.
+ **/
+ @Test
+ public void testPipelineWithXIncludeText() throws Exception {
+ internalXIncludeTest("xinclude-text-only.xml",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x>\n in girum imus nocte et cosumimur igni\n</x>");
+ }
+
+ /**
+ * A pipeline that performs an XInclude operation, forced to use the fallback.
+ **/
+ @Test
+ public void testPipelineWithXIncludeFallback() throws Exception {
+ internalXIncludeTest("xinclude-fallback.xml",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x>\n \n <error>the linked document has not found</error>\n \n</x>");
+ }
+
+ /**
+ * A pipeline that performs an XInclude operation and use XPointer to extract
+ * a fragment from the included document.
+ **/
+ @Test
+ public void testPipelineWithXIncludeAndXPointer() throws Exception {
+ internalXIncludeTest("xinclude-xpointer.xml",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n <p>\n <xsl:value-of select=\"$myParam\"/>\n </p>\n</x>");
+ }
+
+ /**
+ * A pipeline that performs an XInclude operation and use the deprecated
+ * XPointer to extract a fragment from the included document.
+ **/
+ @Test
+ public void testPipelineWithXIncludeAndDeprecatedXPointer() throws Exception {
+ internalXIncludeTest("xinclude-deprecated_xpointer.xml",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?><x xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n <p>\n <xsl:value-of select=\"$myParam\"/>\n </p>\n</x>");
+ }
+
+ /**
+ *
+ */
+ private void internalXIncludeTest(String testResource, String expectedDocument) throws Exception {
+ URL base = getClass().getResource("/");
+ URL source = new URL(base, testResource);
+
+ Pipeline pipeline = new NonCachingPipeline();
+ pipeline.addComponent(new FileGenerator(source));
+ pipeline.addComponent(new XIncludeTransformer(base));
+ pipeline.addComponent(new XMLSerializer());
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ pipeline.setup(baos);
+ pipeline.execute();
+
+ String actualDocument = new String(baos.toByteArray());
+
+ Diff diff = new Diff(expectedDocument, actualDocument);
+ assertTrue("XInclude transformation didn't work as expected " + diff,
+ diff.identical());
+ }
+
+}
Property changes on: root/cdk/trunk/plugins/xinclude/src/test/java/org/apache/cocoon/pipeline/component/sax/XIncludeTransformerTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/test/resources/just-text.txt
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/test/resources/just-text.txt (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/test/resources/just-text.txt 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1 @@
+in girum imus nocte et cosumimur igni
\ No newline at end of file
Property changes on: root/cdk/trunk/plugins/xinclude/src/test/resources/just-text.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/test/resources/test.xml
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/test/resources/test.xml (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/test/resources/test.xml 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- $Id: test.xml 701981 2008-10-06 08:04:01Z reinhard $ -->
+<test/>
\ No newline at end of file
Property changes on: root/cdk/trunk/plugins/xinclude/src/test/resources/test.xml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/test/resources/test.xslt
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/test/resources/test.xslt (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/test/resources/test.xslt 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!-- $Id: test.xslt 734169 2009-01-13 16:20:05Z stevendolg $ -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+
+ <xsl:param name="myParam" />
+
+ <xsl:template match="/">
+ <p>
+ <xsl:value-of select="$myParam" />
+ </p>
+ </xsl:template>
+
+</xsl:stylesheet>
Added: root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-deprecated_xpointer.xml
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-deprecated_xpointer.xml (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-deprecated_xpointer.xml 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,4 @@
+<x xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xi:include href="test.xslt#xmlns(xsl=http://www.w3.org/1999/XSL/Transform)xpointer(//p)"/>
+</x>
\ No newline at end of file
Property changes on: root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-deprecated_xpointer.xml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-fallback.xml
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-fallback.xml (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-fallback.xml 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,7 @@
+<x xmlns:xi="http://www.w3.org/2001/XInclude">
+ <xi:include href="document-not-found.txt" parse="text">
+ <xi:fallback>
+ <error>the linked document has not found</error>
+ </xi:fallback>
+ </xi:include>
+</x>
\ No newline at end of file
Property changes on: root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-fallback.xml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-text-only.xml
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-text-only.xml (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-text-only.xml 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,3 @@
+<x xmlns:xi="http://www.w3.org/2001/XInclude">
+ <xi:include href="just-text.txt" parse="text"/>
+</x>
\ No newline at end of file
Property changes on: root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-text-only.xml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-xml.xml
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-xml.xml (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-xml.xml 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,3 @@
+<x xmlns:xi="http://www.w3.org/2001/XInclude">
+ <xi:include href="test.xml"/>
+</x>
\ No newline at end of file
Property changes on: root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-xml.xml
___________________________________________________________________
Name: svn:eol-style
+ native
Added: root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-xpointer.xml
===================================================================
--- root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-xpointer.xml (rev 0)
+++ root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-xpointer.xml 2009-09-18 01:05:13 UTC (rev 15618)
@@ -0,0 +1,5 @@
+<x xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xi:include href="test.xslt"
+ xpointer="xmlns(xsl=http://www.w3.org/1999/XSL/Transform)xpointer(//p)"/>
+</x>
\ No newline at end of file
Property changes on: root/cdk/trunk/plugins/xinclude/src/test/resources/xinclude-xpointer.xml
___________________________________________________________________
Name: svn:eol-style
+ native
16 years, 1 month
JBoss Rich Faces SVN: r15617 - branches/community/3.3.X/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-09-17 20:55:24 -0400 (Thu, 17 Sep 2009)
New Revision: 15617
Modified:
branches/community/3.3.X/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js
Log:
https://jira.jboss.org/jira/browse/RF-7910
Modified: branches/community/3.3.X/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js
===================================================================
--- branches/community/3.3.X/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js 2009-09-18 00:38:27 UTC (rev 15616)
+++ branches/community/3.3.X/ui/combobox/src/main/resources/org/richfaces/renderkit/html/scripts/combobox.js 2009-09-18 00:55:24 UTC (rev 15617)
@@ -321,8 +321,10 @@
}
} else {
if (!this.comboList.visible()) {
+ this.comboList.createDefaultList();
this.comboList.showWithDelay();
}
+
var item = this.comboList.findItemBySubstr(this.field.value);
if (item) {
this.comboList.doActiveItem(item);
16 years, 1 month
JBoss Rich Faces SVN: r15616 - in branches/community/3.3.X/ui/panelmenu/src/main: java/org/richfaces/renderkit/html and 2 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-09-17 20:38:27 -0400 (Thu, 17 Sep 2009)
New Revision: 15616
Added:
branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererHelper.java
Modified:
branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererBase.java
branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java
branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java
branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java
branches/community/3.3.X/ui/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js
branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx
branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuGroup.jspx
branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuItem.jspx
Log:
https://jira.jboss.org/jira/browse/RF-7796
Modified: branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererBase.java
===================================================================
--- branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererBase.java 2009-09-18 00:34:01 UTC (rev 15615)
+++ branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererBase.java 2009-09-18 00:38:27 UTC (rev 15616)
@@ -35,6 +35,7 @@
import org.richfaces.component.UIPanelMenu;
import org.richfaces.component.UIPanelMenuGroup;
import org.richfaces.component.UIPanelMenuItem;
+import org.richfaces.renderkit.PanelMenuRendererHelper.PanelMenuState;
import org.richfaces.renderkit.html.PanelMenuGroupRenderer;
import org.richfaces.renderkit.html.iconimages.PanelMenuIconChevron;
import org.richfaces.renderkit.html.iconimages.PanelMenuIconChevronDown;
@@ -285,4 +286,18 @@
}
+ protected abstract String getName(UIComponent component);
+
+ public String getSelectedClass(boolean isSelected) {
+ if (isSelected) {
+ return UIPanelMenu.SELECTED_CLASS;
+ }
+ return "";
+ }
+
+ public boolean queryAndMarkSelection(FacesContext context, UIComponent component){
+ UIPanelMenu parentMenu = findMenu(component);
+ PanelMenuState panelMenuState = PanelMenuRendererHelper.getOrCreateState(context, parentMenu);
+ return panelMenuState.queryAndMarkSelection(getName(component));
+ }
}
Added: branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererHelper.java
===================================================================
--- branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererHelper.java (rev 0)
+++ branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/PanelMenuRendererHelper.java 2009-09-18 00:38:27 UTC (rev 15616)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright ${year}, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.richfaces.renderkit;
+
+import java.util.Map;
+
+import javax.faces.context.FacesContext;
+
+import org.richfaces.component.UIPanelMenu;
+import org.richfaces.context.RequestContext;
+
+/**
+ * @author Nick Belaevski
+ */
+public final class PanelMenuRendererHelper {
+
+ private static final String CONTEXT_ATTRIBUTE_NAME = PanelMenuRendererHelper.class.getName();
+
+ public static final class PanelMenuState {
+
+ private boolean childMarked = false;
+
+ private String selectedChildName;
+
+ public PanelMenuState(String selectedChildName) {
+ super();
+ this.selectedChildName = selectedChildName;
+ }
+
+ /**
+ * Queries whether the child with such name is the currently selected item.
+ * Marks in state that selected child has been encoded.
+ * @param childName
+ * @return <code>true</code> if the named is selected, <code>false</code> otherwise
+ */
+ public boolean queryAndMarkSelection(String childName) {
+ if (selectedChildName == null || selectedChildName.length() == 0) {
+ return false;
+ }
+
+ boolean selected = false;
+
+ if (selectedChildName.equals(childName)) {
+ this.childMarked = true;
+ selected = true;
+ }
+
+ return selected;
+ }
+
+ /**
+ * @return the selectedChildName
+ */
+ public String getSelectedItemInputValue() {
+ return childMarked ? selectedChildName : null;
+ }
+ }
+
+ private PanelMenuRendererHelper() {
+ }
+
+ public static PanelMenuState getOrCreateState(FacesContext context, UIPanelMenu panelMenu) {
+ RequestContext requestContext = RequestContext.getInstance(context);
+ Map<String, Object> panelMenuStatesMap = requestContext.getOrCreateNestedMap(CONTEXT_ATTRIBUTE_NAME);
+
+ String clientId = panelMenu.getClientId(context);
+ PanelMenuState panelMenuState = (PanelMenuState) panelMenuStatesMap.get(clientId);
+ if (panelMenuState == null) {
+ panelMenuState = new PanelMenuState(panelMenu.getSelectedName());
+ panelMenuStatesMap.put(clientId, panelMenuState);
+ }
+
+ return panelMenuState;
+ }
+}
Modified: branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java
===================================================================
--- branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java 2009-09-18 00:34:01 UTC (rev 15615)
+++ branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuGroupRenderer.java 2009-09-18 00:38:27 UTC (rev 15616)
@@ -248,13 +248,6 @@
return value;
}
- public String getSelectedClass(FacesContext context, UIComponent component) {
- if (isSelected(context, component)) {
- return UIPanelMenu.SELECTED_CLASS;
- }
- return "";
- }
-
public String getLabelClass(FacesContext context, UIComponent component) {
UIPanelMenuGroup group = (UIPanelMenuGroup)component;
UIPanelMenu parentMenu = findMenu(group);
@@ -305,10 +298,8 @@
return result;
}
- public boolean isSelected(FacesContext context, UIComponent component){
- UIPanelMenuGroup group = (UIPanelMenuGroup)component;
- UIPanelMenu parentMenu = findMenu(group);
- return group.getName().equals(parentMenu.getSelectedName());
+ @Override
+ protected String getName(UIComponent component) {
+ return ((UIPanelMenuGroup) component).getName();
}
-
}
Modified: branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java
===================================================================
--- branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java 2009-09-18 00:34:01 UTC (rev 15615)
+++ branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuItemRenderer.java 2009-09-18 00:38:27 UTC (rev 15616)
@@ -207,13 +207,6 @@
return styleBuffer.toString();
}
- public String getSelectedClass(FacesContext context, UIComponent component) {
- if (isSelected(context, component)) {
- return UIPanelMenu.SELECTED_CLASS;
- }
- return "";
- }
-
public String getLabelClass(FacesContext context, UIComponent component) {
StringBuffer resClass = new StringBuffer();
UIPanelMenuItem item = (UIPanelMenuItem)component;
@@ -251,10 +244,9 @@
return iconClass;
}
-
- public boolean isSelected(FacesContext context, UIComponent component){
- UIPanelMenuItem item = (UIPanelMenuItem)component;
- UIPanelMenu parentMenu = findMenu(item);
- return item.getName().equals(parentMenu.getSelectedName());
+
+ @Override
+ protected String getName(UIComponent component) {
+ return ((UIPanelMenuItem) component).getName();
}
}
Modified: branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java
===================================================================
--- branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java 2009-09-18 00:34:01 UTC (rev 15615)
+++ branches/community/3.3.X/ui/panelmenu/src/main/java/org/richfaces/renderkit/html/PanelMenuRenderer.java 2009-09-18 00:38:27 UTC (rev 15616)
@@ -44,6 +44,8 @@
import org.richfaces.component.UIPanelMenuGroup;
import org.richfaces.component.UIPanelMenuItem;
import org.richfaces.renderkit.PanelMenuRendererBase;
+import org.richfaces.renderkit.PanelMenuRendererHelper;
+import org.richfaces.renderkit.PanelMenuRendererHelper.PanelMenuState;
public class PanelMenuRenderer extends PanelMenuRendererBase {
@@ -117,15 +119,12 @@
boolean expandSingle = parentMenu.isExpandSingle();
- String selectedChild = parentMenu.getSelectedName();
-
flatten(component.getChildren(), flatList, levels, 0);
panelMenu.append("var ids = new PanelMenu('")
.append(component.getClientId(context).toString())
.append("',")
.append(new Boolean(expandSingle).toString())
- .append(",").append("'").append(selectedChild).append("'")
.append(").getIds();\n");
for (Iterator iter = flatList.iterator(); iter.hasNext();) {
@@ -522,8 +521,8 @@
if(component instanceof UIPanelMenu){
UIPanelMenu panelMenu = (UIPanelMenu)component;
if(panelMenu.getChildCount() > 0){
- for (Iterator it = component.getChildren().iterator(); it.hasNext();) {
- UIComponent child = (UIComponent) it.next();
+ for (Iterator<UIComponent> it = component.getChildren().iterator(); it.hasNext();) {
+ UIComponent child = it.next();
if(child instanceof UIPanelMenuGroup) {
UIPanelMenuGroup group = (UIPanelMenuGroup)child;
@@ -556,4 +555,13 @@
}
}
+ @Override
+ protected String getName(UIComponent component) {
+ return null;
+ }
+
+ public String getSelectedItemInputValue(FacesContext context, UIPanelMenu panelMenu) {
+ PanelMenuState panelMenuState = PanelMenuRendererHelper.getOrCreateState(context, panelMenu);
+ return panelMenuState.getSelectedItemInputValue();
+ }
}
Modified: branches/community/3.3.X/ui/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js
===================================================================
--- branches/community/3.3.X/ui/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js 2009-09-18 00:34:01 UTC (rev 15615)
+++ branches/community/3.3.X/ui/panelmenu/src/main/resources/org/richfaces/renderkit/html/scripts/panelMenu.js 2009-09-18 00:38:27 UTC (rev 15616)
@@ -11,16 +11,16 @@
PanelMenu = Class.create();
PanelMenu.prototype = {
- initialize: function(myId, so, selectedChild){
+ initialize: function(myId, so) {
this.myId = myId;
this.childObj = new Array();
this.expandSingle = so;
this.lastExpanded = null;
- this.selectedChild = selectedChild;
this.selectedClass = 'rich-pmenu-selected-element';
this.is = 'panelMenu';
this.selectedNameInput = $(myId + 'selectedItemName');
+ this.selectedChild = this.selectedNameInput.value;
PanelMenuStorage[myId] = this;
},
Modified: branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx
===================================================================
--- branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx 2009-09-18 00:34:01 UTC (rev 15615)
+++ branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx 2009-09-18 00:38:27 UTC (rev 15616)
@@ -41,10 +41,11 @@
<div style="width:#{component.width}; #{style}" class="rich-pmenu #{component.styleClass}"
id="#{clientId}"
x:passThruWithExclusions="style,width,class,styleClass,id">
- <input autocomplete="off" type="hidden" id="#{clientId}selectedItemName" name="#{clientId}selectedItemName" value="#{component.selectedName}" />
<vcp:body>
<f:call name="renderChildren" />
</vcp:body>
+ <f:clientid var="clientId"/>
+ <input autocomplete="off" type="hidden" id="#{clientId}selectedItemName" name="#{clientId}selectedItemName" value="#{this:getSelectedItemInputValue(context, component)}" />
<div style="display:none">
<f:call name="insertScript"/>
</div>
Modified: branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuGroup.jspx
===================================================================
--- branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuGroup.jspx 2009-09-18 00:34:01 UTC (rev 15615)
+++ branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuGroup.jspx 2009-09-18 00:38:27 UTC (rev 15616)
@@ -15,9 +15,15 @@
<div id="#{clientId}" style="#{this:getHideStyle(context, component)}"
class="#{this:getDivClass(context, component)}" >
+
+ <c:object type="boolean" var="isNodeSelected" value="#{false}" />
<jsp:scriptlet>
<![CDATA[
String isNodeOpened = isOpened(context, component) ? "opened" : "closed";
+
+ //marks current selection in renderer helper object - method should be called
+ //even if return value is not necessary
+ isNodeSelected = queryAndMarkSelection(context, component);
]]>
</jsp:scriptlet>
<table cellspacing="0" cellpadding="0" border="0"
@@ -28,7 +34,7 @@
<tbody>
<tr id="row_#{clientId}"
- class="#{this:getSelectedClass( context, component )}" >
+ class="#{this:getSelectedClass(isNodeSelected)}" >
<td class="rich-pmenu-nowrap #{this:getIconClass( context, component,'left')}">
<f:call name="insertSpacerImages" />
<f:call name="insertImage">
Modified: branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuItem.jspx
===================================================================
--- branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuItem.jspx 2009-09-18 00:34:01 UTC (rev 15615)
+++ branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenuItem.jspx 2009-09-18 00:38:27 UTC (rev 15616)
@@ -13,6 +13,15 @@
<f:clientid var="clientId"/>
+ <c:object type="boolean" var="isNodeSelected" value="#{false}" />
+ <jsp:scriptlet>
+ <![CDATA[
+ //marks current selection in renderer helper object - method should be called
+ //even if return value is not necessary
+ isNodeSelected = queryAndMarkSelection(context, component);
+ ]]>
+ </jsp:scriptlet>
+
<div id="#{clientId}" style="#{this:getHideStyle(context, component)}" >
<table cellspacing="0" cellpadding="0" border="0"
id="tablehide#{clientId}"
@@ -21,7 +30,7 @@
x:passThruWithExclusions="cellspacing,cellpadding,border,id,class,styleClass,style">
<tbody>
<tr id="row_#{clientId}"
- class="#{this:getSelectedClass( context, component )}" >
+ class="#{this:getSelectedClass(isNodeSelected)}" >
<td class="rich-pmenu-nowrap #{this:getIconClass( context, component,'left')}">
<f:call name="insertSpacerImages" />
<f:call name="insertImage">
16 years, 1 month
JBoss Rich Faces SVN: r15615 - branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/context.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-09-17 20:34:01 -0400 (Thu, 17 Sep 2009)
New Revision: 15615
Modified:
branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/context/RequestContext.java
Log:
https://jira.jboss.org/jira/browse/RF-7796
Modified: branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/context/RequestContext.java
===================================================================
--- branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/context/RequestContext.java 2009-09-17 18:31:06 UTC (rev 15614)
+++ branches/community/3.3.X/framework/impl/src/main/java/org/richfaces/context/RequestContext.java 2009-09-18 00:34:01 UTC (rev 15615)
@@ -84,4 +84,14 @@
}
}
+ public Map<String, Object> getOrCreateNestedMap(String attributeName) {
+ @SuppressWarnings("unchecked")
+ Map<String, Object> nestedMap = (Map<String, Object>) getAttribute(attributeName);
+ if (nestedMap == null) {
+ nestedMap = new HashMap<String, Object>();
+ setAttribute(attributeName, nestedMap);
+ }
+
+ return nestedMap;
+ }
}
16 years, 1 month
JBoss Rich Faces SVN: r15614 - branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-09-17 14:31:06 -0400 (Thu, 17 Sep 2009)
New Revision: 15614
Modified:
branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx
Log:
https://jira.jboss.org/jira/browse/RF-7796
Modified: branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx
===================================================================
--- branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx 2009-09-17 17:21:37 UTC (rev 15613)
+++ branches/community/3.3.X/ui/panelmenu/src/main/templates/org/richfaces/htmlPanelMenu.jspx 2009-09-17 18:31:06 UTC (rev 15614)
@@ -41,7 +41,7 @@
<div style="width:#{component.width}; #{style}" class="rich-pmenu #{component.styleClass}"
id="#{clientId}"
x:passThruWithExclusions="style,width,class,styleClass,id">
- <input autocomplete="off" type="hidden" id="#{clientId}selectedItemName" name="#{clientId}selectedItemName" value="" />
+ <input autocomplete="off" type="hidden" id="#{clientId}selectedItemName" name="#{clientId}selectedItemName" value="#{component.selectedName}" />
<vcp:body>
<f:call name="renderChildren" />
</vcp:body>
16 years, 1 month
JBoss Rich Faces SVN: r15613 - branches/community/3.3.X/ui/simpleTogglePanel/src/main/java/org/richfaces/renderkit/html.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-09-17 13:21:37 -0400 (Thu, 17 Sep 2009)
New Revision: 15613
Modified:
branches/community/3.3.X/ui/simpleTogglePanel/src/main/java/org/richfaces/renderkit/html/SimpleTogglePanelRenderer.java
Log:
https://jira.jboss.org/jira/browse/RF-7811
Modified: branches/community/3.3.X/ui/simpleTogglePanel/src/main/java/org/richfaces/renderkit/html/SimpleTogglePanelRenderer.java
===================================================================
--- branches/community/3.3.X/ui/simpleTogglePanel/src/main/java/org/richfaces/renderkit/html/SimpleTogglePanelRenderer.java 2009-09-17 16:35:38 UTC (rev 15612)
+++ branches/community/3.3.X/ui/simpleTogglePanel/src/main/java/org/richfaces/renderkit/html/SimpleTogglePanelRenderer.java 2009-09-17 17:21:37 UTC (rev 15613)
@@ -275,7 +275,7 @@
}
public String getSwitchStatus(FacesContext context, UIComponent component, boolean isSwitchOn) {
- return ((UISimpleTogglePanel) component).isOpened() ^ isSwitchOn ? EMPTY : NONE;
+ return ((UISimpleTogglePanel) component).isOpened() ^ isSwitchOn ? NONE : EMPTY;
}
private boolean isEmpty(String str) {
16 years, 1 month