You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by so...@apache.org on 2008/03/08 23:59:02 UTC
svn commit: r635107 [4/7] - in /lenya/branches/revolution/1.3.x: ./
src/cocoon/ src/java/org/apache/cocoon/components/source/
src/java/org/apache/lenya/ac/ src/java/org/apache/lenya/ac/cache/
src/java/org/apache/lenya/ac/file/ src/java/org/apache/lenya...
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/LinkRewritingTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/LinkRewritingTransformer.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/LinkRewritingTransformer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/LinkRewritingTransformer.java Sat Mar 8 14:58:32 2008
@@ -15,11 +15,10 @@
*
*/
package org.apache.lenya.cms.cocoon.transformation;
-
import java.io.IOException;
import java.util.Map;
-import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.service.ServiceSelector;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.ObjectModelHelper;
@@ -38,7 +37,6 @@
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.DocumentBuilder;
import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
import org.apache.lenya.cms.publication.Proxy;
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationException;
@@ -46,15 +44,13 @@
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
-
/**
* <p>
* Link rewriting transformer.
* </p>
*
* <p>
- * This transformer is applied to an XHMTL document. It processes <code><xhtml:a href="..."></code>
- * attributes of the following form:
+ * This transformer is applied to an XHMTL document. It processes <code><xhtml:a href="..."></code> attributes of the following form:
* </p>
* <p>
* <code>{context-prefix}/{publication-id}/{area}{document-url}</code>
@@ -71,326 +67,272 @@
* $Id: LinkRewritingTransformer.java,v 1.7 2004/03/16 11:12:16 gregor
*/
public class LinkRewritingTransformer extends AbstractSAXTransformer implements Disposable {
-
- private boolean ignoreAElement = false;
- private ServiceSelector serviceSelector;
- private PolicyManager policyManager;
- private AccessControllerResolver acResolver;
- private AccreditableManager accreditableManager;
-
- private Document currentDocument;
-
- /**
- * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
- * java.util.Map, java.lang.String,
- * org.apache.avalon.framework.parameters.Parameters)
- */
- public void setup(SourceResolver resolver, Map objectModel, String source, Parameters parameters)
- throws ProcessingException, SAXException, IOException {
- super.setup(resolver, objectModel, source, parameters);
-
- try {
- PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
- this.currentDocument = envelope.getDocument();
-
- } catch (Exception e) {
- throw new ProcessingException(e);
- }
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Setting up transformer");
- getLogger().debug(" Processed version: [" + getCurrentDocument() + "]");
- }
-
- Request request = ObjectModelHelper.getRequest(objectModel);
-
- this.serviceSelector = null;
- this.acResolver = null;
- this.policyManager = null;
-
- try {
- this.serviceSelector = (ServiceSelector) this.manager
- .lookup(AccessControllerResolver.ROLE + "Selector");
- this.acResolver = (AccessControllerResolver) this.serviceSelector
- .select(AccessControllerResolver.DEFAULT_RESOLVER);
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(" Resolved AC resolver [" + this.acResolver + "]");
- }
- String webappUrl = ServletHelper.getWebappURI(request);
- AccessController accessController = this.acResolver.resolveAccessController(webappUrl);
- if (accessController instanceof DefaultAccessController) {
- DefaultAccessController defaultAccessController = (DefaultAccessController) accessController;
- this.accreditableManager = defaultAccessController.getAccreditableManager();
- Authorizer[] authorizers = defaultAccessController.getAuthorizers();
- for (int i = 0; i < authorizers.length; i++) {
- if (authorizers[i] instanceof PolicyAuthorizer) {
- PolicyAuthorizer policyAuthorizer = (PolicyAuthorizer) authorizers[i];
- this.policyManager = policyAuthorizer.getPolicyManager();
- }
- }
- }
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(" Using policy manager [" + this.policyManager + "]");
- }
- } catch (Exception e) {
- throw new ProcessingException(e);
- }
- }
-
- /**
- * Returns the currently processed document.
- *
- * @return A document.
- */
- protected Document getCurrentDocument() {
- return this.currentDocument;
- }
-
- /**
- * The local name of the HTML <a> href attribute.
- */
- public static final String ATTRIBUTE_HREF = "href";
-
- private String indent = "";
-
- /**
- * (non-Javadoc)
- *
- * @see org.xml.sax.ContentHandler#startElement(java.lang.String,
- * java.lang.String, java.lang.String, org.xml.sax.Attributes)
- */
- public void startElement(String uri, String name, String qname, Attributes attrs)
- throws SAXException {
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(this.indent + "<" + qname + "> (ignoreAElement = "
- + isIgnoreAElement() + ")");
- this.indent += " ";
- }
-
- AttributesImpl newAttrs = null;
- if (lookingAtLinkElement(name)) {
-
- setIgnoreAElement(false);
-
- String href = attrs.getValue(ATTRIBUTE_HREF);
- if (href != null) {
-
- Publication publication = getCurrentDocument().getPublication();
- DocumentBuilder builder = publication.getDocumentBuilder();
-
- try {
-
- newAttrs = new AttributesImpl(attrs);
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(this.indent + "href URL: [" + href + "]");
- }
-
- String context = this.request.getContextPath();
-
- if (href.startsWith(context + "/" + publication.getId())) {
-
- final String webappUrlWithQueryString = href.substring(context.length());
- String webappUrlWithAnchor;
-
- String queryString = null;
- int queryStringIndex = webappUrlWithQueryString.indexOf("?");
- if (queryStringIndex > -1) {
- webappUrlWithAnchor = webappUrlWithQueryString.substring(0, queryStringIndex);
- queryString = webappUrlWithQueryString.substring(queryStringIndex + 1);
- }
- else {
- webappUrlWithAnchor = webappUrlWithQueryString;
- }
-
- String anchor = null;
- String webappUrl = null;
-
- int anchorIndex = webappUrlWithAnchor.indexOf("#");
- if (anchorIndex > -1) {
- webappUrl = webappUrlWithAnchor.substring(0, anchorIndex);
- anchor = webappUrlWithAnchor.substring(anchorIndex + 1);
- }
- else {
- webappUrl = webappUrlWithAnchor;
- }
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(this.indent + "webapp URL: [" + webappUrl + "]");
- getLogger().debug(this.indent + "anchor: [" + anchor + "]");
- }
- if (builder.isDocument(publication, webappUrl)) {
-
- Document targetDocument = builder.buildDocument(publication, webappUrl);
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(this.indent + "Resolved target document: ["
- + targetDocument + "]");
- }
-
- String currentAreaUrl = builder.buildCanonicalUrl(publication,
- getCurrentDocument().getArea(),
- targetDocument.getId(),
- targetDocument.getLanguage());
- targetDocument = builder.buildDocument(publication, currentAreaUrl);
-
- if (targetDocument.exists()) {
- rewriteLink(newAttrs, targetDocument, anchor, queryString);
- } else {
- setIgnoreAElement(true);
- }
- }
- }
- } catch (Exception e) {
- getLogger().error("startElement failed: ", e);
- throw new SAXException(e);
- }
- }
-
- }
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(this.indent + "ignoreAElement: " + isIgnoreAElement());
- }
-
- if (!(lookingAtAElement(name) && isIgnoreAElement())) {
- if (newAttrs != null) {
- attrs = newAttrs;
- }
- super.startElement(uri, name, qname, attrs);
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(this.indent + "<" + qname + "> sent");
- }
- }
- }
-
- /**
- * Rewrites a link.
- *
- * @param newAttrs The new attributes.
- * @param targetDocument The target document.
- * @param anchor The anchor (the string after the # character in the URL).
- * @param queryString The query string without question mark.
- * @throws AccessControlException when something went wrong.
- * @throws PublicationException when something went wrong.
- */
- protected void rewriteLink(AttributesImpl newAttrs, Document targetDocument, String anchor, String queryString)
- throws AccessControlException, PublicationException {
- String webappUrl = targetDocument.getCompleteURL();
- Policy policy = this.policyManager.getPolicy(this.accreditableManager, webappUrl);
-
- Proxy proxy = targetDocument.getPublication().getProxy(targetDocument, policy.isSSLProtected());
-
- String rewrittenURL;
- if (proxy == null) {
- rewrittenURL = this.request.getContextPath() + webappUrl;
- } else {
- rewrittenURL = proxy.getURL(targetDocument);
- }
-
- if (anchor != null) {
- rewrittenURL += "#" + anchor;
- }
-
- if (queryString != null) {
- rewrittenURL += "?" + queryString;
- }
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(this.indent + "SSL protection: [" + policy.isSSLProtected() + "]");
- getLogger().debug(this.indent + "Resolved proxy: [" + proxy + "]");
- getLogger().debug(this.indent + "Rewriting URL to: [" + rewrittenURL + "]");
- }
-
- setHrefAttribute(newAttrs, rewrittenURL);
- }
-
- /**
- * Sets the value of the href attribute.
- *
- * @param attr The attributes.
- * @param value The value.
- * @throws IllegalArgumentException if the href attribute is not contained
- * in this attributes.
- */
- protected void setHrefAttribute(AttributesImpl attr, String value) {
- int position = attr.getIndex(ATTRIBUTE_HREF);
- if (position == -1) {
- throw new IllegalArgumentException("The href attribute is not available!");
- }
- attr.setValue(position, value);
- }
-
- /**
- * (non-Javadoc)
- *
- * @see org.xml.sax.ContentHandler#endElement(java.lang.String,
- * java.lang.String, java.lang.String)
- */
- public void endElement(String uri, String name, String qname) throws SAXException {
- if (getLogger().isDebugEnabled()) {
- this.indent = this.indent.substring(2);
- getLogger().debug(this.indent + "</" + qname + ">");
- }
- if (lookingAtAElement(name) && isIgnoreAElement()) {
- setIgnoreAElement(false);
- } else {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug(this.indent + "</" + qname + "> sent");
+ private boolean ignoreAElement = false;
+ private ServiceSelector serviceSelector;
+ private PolicyManager policyManager;
+ private AccessControllerResolver acResolver;
+ private AccreditableManager accreditableManager;
+ private Document currentDocument;
+ /**
+ * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
+ */
+ public void setup(SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws ProcessingException, SAXException, IOException {
+ super.setup(resolver, objectModel, source, parameters);
+ try{
+ PageEnvelope envelope = PageEnvelope.getCurrent();
+ this.currentDocument = envelope.getDocument();
+ }catch(Exception e){
+ throw new ProcessingException(e);
+ }
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Setting up transformer");
+ getLogger().debug(" Processed version: [" + getCurrentDocument() + "]");
+ }
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ this.serviceSelector = null;
+ this.acResolver = null;
+ this.policyManager = null;
+ try{
+ this.serviceSelector = (ServiceSelector) this.manager.lookup(AccessControllerResolver.ROLE + "Selector");
+ this.acResolver = (AccessControllerResolver) this.serviceSelector.select(AccessControllerResolver.DEFAULT_RESOLVER);
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug(" Resolved AC resolver [" + this.acResolver + "]");
+ }
+ String webappUrl = ServletHelper.getWebappURI(request);
+ AccessController accessController = this.acResolver.resolveAccessController(webappUrl);
+ if(accessController instanceof DefaultAccessController){
+ DefaultAccessController defaultAccessController = (DefaultAccessController) accessController;
+ this.accreditableManager = defaultAccessController.getAccreditableManager();
+ Authorizer[] authorizers = defaultAccessController.getAuthorizers();
+ for(int i = 0; i < authorizers.length; i++){
+ if(authorizers[i] instanceof PolicyAuthorizer){
+ PolicyAuthorizer policyAuthorizer = (PolicyAuthorizer) authorizers[i];
+ this.policyManager = policyAuthorizer.getPolicyManager();
+ }
}
- super.endElement(uri, name, qname);
- }
- }
-
- /**
- * Check if we are looking at a link element
- *
- * @param name name of the element
- *
- * @return true if we are looking at a link element
- */
- protected boolean lookingAtLinkElement(String name) {
- return lookingAtAElement(name);
- }
-
- protected boolean lookingAtAElement(String name) {
- return name.equals("a");
- }
-
- /**
- * @see org.apache.avalon.framework.activity.Disposable#dispose()
- */
- public void dispose() {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Disposing transformer");
- }
- if (this.serviceSelector != null) {
- if (this.acResolver != null) {
- this.serviceSelector.release(this.acResolver);
+ }
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug(" Using policy manager [" + this.policyManager + "]");
+ }
+ }catch(Exception e){
+ throw new ProcessingException(e);
+ }
+ }
+ /**
+ * Returns the currently processed document.
+ *
+ * @return A document.
+ */
+ protected Document getCurrentDocument() {
+ return this.currentDocument;
+ }
+ /**
+ * The local name of the HTML <a> href attribute.
+ */
+ public static final String ATTRIBUTE_HREF = "href";
+ private String indent = "";
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
+ */
+ public void startElement(String uri, String name, String qname, Attributes attrs) throws SAXException {
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug(this.indent + "<" + qname + "> (ignoreAElement = " + isIgnoreAElement() + ")");
+ this.indent += " ";
+ }
+ AttributesImpl newAttrs = null;
+ if(lookingAtLinkElement(name)){
+ setIgnoreAElement(false);
+ String href = attrs.getValue(ATTRIBUTE_HREF);
+ if(href != null){
+ Publication publication = getCurrentDocument().getPublication();
+ DocumentBuilder builder = publication.getDocumentBuilder();
+ try{
+ newAttrs = new AttributesImpl(attrs);
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug(this.indent + "href URL: [" + href + "]");
+ }
+ String context = this.request.getContextPath();
+ if(href.startsWith(context + "/" + publication.getId())){
+ final String webappUrlWithQueryString = href.substring(context.length());
+ String webappUrlWithAnchor;
+ String queryString = null;
+ int queryStringIndex = webappUrlWithQueryString.indexOf("?");
+ if(queryStringIndex > -1){
+ webappUrlWithAnchor = webappUrlWithQueryString.substring(0, queryStringIndex);
+ queryString = webappUrlWithQueryString.substring(queryStringIndex + 1);
+ }else{
+ webappUrlWithAnchor = webappUrlWithQueryString;
+ }
+ String anchor = null;
+ String webappUrl = null;
+ int anchorIndex = webappUrlWithAnchor.indexOf("#");
+ if(anchorIndex > -1){
+ webappUrl = webappUrlWithAnchor.substring(0, anchorIndex);
+ anchor = webappUrlWithAnchor.substring(anchorIndex + 1);
+ }else{
+ webappUrl = webappUrlWithAnchor;
+ }
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug(this.indent + "webapp URL: [" + webappUrl + "]");
+ getLogger().debug(this.indent + "anchor: [" + anchor + "]");
+ }
+ if(builder.isDocument(publication, webappUrl)){
+ Document targetDocument = builder.buildDocument(publication, webappUrl);
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug(this.indent + "Resolved target document: [" + targetDocument + "]");
+ }
+ String currentAreaUrl = builder.buildCanonicalUrl(publication, getCurrentDocument().getArea(), targetDocument.getId(), targetDocument.getLanguage());
+ targetDocument = builder.buildDocument(publication, currentAreaUrl);
+ if(targetDocument.exists()){
+ rewriteLink(newAttrs, targetDocument, anchor, queryString);
+ }else{
+ setIgnoreAElement(true);
+ }
+ }
+ }
+ }catch(Exception e){
+ getLogger().error("startElement failed: ", e);
+ throw new SAXException(e);
}
- this.manager.release(this.serviceSelector);
- }
- }
-
- /**
- * (non-Javadoc)
- * @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
- */
- public void recycle() {
- this.ignoreAElement = false;
- }
- /**
- * @return Returns the ignoreAElement.
- */
- protected boolean isIgnoreAElement() {
- return ignoreAElement;
- }
- /**
- * @param ignoreAElement The ignoreAElement to set.
- */
- protected void setIgnoreAElement(boolean ignoreAElement) {
- this.ignoreAElement = ignoreAElement;
- }
+ }
+ }
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug(this.indent + "ignoreAElement: " + isIgnoreAElement());
+ }
+ if(!(lookingAtAElement(name) && isIgnoreAElement())){
+ if(newAttrs != null){
+ attrs = newAttrs;
+ }
+ super.startElement(uri, name, qname, attrs);
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug(this.indent + "<" + qname + "> sent");
+ }
+ }
+ }
+ /**
+ * Rewrites a link.
+ *
+ * @param newAttrs
+ * The new attributes.
+ * @param targetDocument
+ * The target document.
+ * @param anchor
+ * The anchor (the string after the # character in the URL).
+ * @param queryString
+ * The query string without question mark.
+ * @throws AccessControlException
+ * when something went wrong.
+ * @throws PublicationException
+ * when something went wrong.
+ */
+ protected void rewriteLink(AttributesImpl newAttrs, Document targetDocument, String anchor, String queryString) throws AccessControlException, PublicationException {
+ String webappUrl = targetDocument.getCompleteURL();
+ Policy policy = this.policyManager.getPolicy(this.accreditableManager, webappUrl);
+ Proxy proxy = targetDocument.getPublication().getProxy(targetDocument, policy.isSSLProtected());
+ String rewrittenURL;
+ if(proxy == null){
+ rewrittenURL = this.request.getContextPath() + webappUrl;
+ }else{
+ rewrittenURL = proxy.getURL(targetDocument);
+ }
+ if(anchor != null){
+ rewrittenURL += "#" + anchor;
+ }
+ if(queryString != null){
+ rewrittenURL += "?" + queryString;
+ }
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug(this.indent + "SSL protection: [" + policy.isSSLProtected() + "]");
+ getLogger().debug(this.indent + "Resolved proxy: [" + proxy + "]");
+ getLogger().debug(this.indent + "Rewriting URL to: [" + rewrittenURL + "]");
+ }
+ setHrefAttribute(newAttrs, rewrittenURL);
+ }
+ /**
+ * Sets the value of the href attribute.
+ *
+ * @param attr
+ * The attributes.
+ * @param value
+ * The value.
+ * @throws IllegalArgumentException
+ * if the href attribute is not contained in this attributes.
+ */
+ protected void setHrefAttribute(AttributesImpl attr, String value) {
+ int position = attr.getIndex(ATTRIBUTE_HREF);
+ if(position == -1){
+ throw new IllegalArgumentException("The href attribute is not available!");
+ }
+ attr.setValue(position, value);
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
+ */
+ public void endElement(String uri, String name, String qname) throws SAXException {
+ if(getLogger().isDebugEnabled()){
+ this.indent = this.indent.substring(2);
+ getLogger().debug(this.indent + "</" + qname + ">");
+ }
+ if(lookingAtAElement(name) && isIgnoreAElement()){
+ setIgnoreAElement(false);
+ }else{
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug(this.indent + "</" + qname + "> sent");
+ }
+ super.endElement(uri, name, qname);
+ }
+ }
+ /**
+ * Check if we are looking at a link element
+ *
+ * @param name
+ * name of the element
+ *
+ * @return true if we are looking at a link element
+ */
+ protected boolean lookingAtLinkElement(String name) {
+ return lookingAtAElement(name);
+ }
+ protected boolean lookingAtAElement(String name) {
+ return name.equals("a");
+ }
+ /**
+ * @see org.apache.avalon.framework.activity.Disposable#dispose()
+ */
+ public void dispose() {
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Disposing transformer");
+ }
+ if(this.serviceSelector != null){
+ if(this.acResolver != null){
+ this.serviceSelector.release(this.acResolver);
+ }
+ this.manager.release(this.serviceSelector);
+ }
+ }
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
+ */
+ public void recycle() {
+ this.ignoreAElement = false;
+ }
+ /**
+ * @return Returns the ignoreAElement.
+ */
+ protected boolean isIgnoreAElement() {
+ return ignoreAElement;
+ }
+ /**
+ * @param ignoreAElement
+ * The ignoreAElement to set.
+ */
+ protected void setIgnoreAElement(boolean ignoreAElement) {
+ this.ignoreAElement = ignoreAElement;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/SimpleLinkRewritingTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/SimpleLinkRewritingTransformer.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/SimpleLinkRewritingTransformer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/SimpleLinkRewritingTransformer.java Sat Mar 8 14:58:32 2008
@@ -26,9 +26,8 @@
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
-import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.service.ServiceSelector;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.ObjectModelHelper;
@@ -52,10 +51,10 @@
import org.apache.lenya.cms.publication.Publication;
import org.apache.lenya.cms.publication.PublicationException;
import org.apache.lenya.util.ServletHelper;
+import org.apache.log4j.Category;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
-import org.apache.log4j.Category;
/**
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java Sat Mar 8 14:58:32 2008
@@ -21,7 +21,6 @@
import java.io.IOException;
import java.util.Map;
-
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.service.ServiceSelector;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/transformation/WorkflowMenuTransformer.java Sat Mar 8 14:58:32 2008
@@ -14,14 +14,10 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.cocoon.transformation;
-
import java.io.IOException;
import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.SourceResolver;
@@ -29,7 +25,6 @@
import org.apache.lenya.cms.cocoon.workflow.WorkflowHelper;
import org.apache.lenya.cms.publication.Document;
import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
import org.apache.lenya.cms.workflow.WorkflowFactory;
import org.apache.lenya.workflow.Event;
import org.apache.lenya.workflow.Situation;
@@ -39,162 +34,137 @@
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
-
/**
- * This transformer disables menu items (by removing the href attribute)
- * which are not allowed with respect to the current workflow state.
+ * This transformer disables menu items (by removing the href attribute) which are not allowed with respect to the current workflow state.
*/
public class WorkflowMenuTransformer extends AbstractSAXTransformer {
- public static final String MENU_ELEMENT = "menu";
- public static final String ITEM_ELEMENT = "item";
- public static final String EVENT_ATTRIBUTE = "event";
-
- /** (non-Javadoc)
- * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
- */
- public void startElement(String uri, String localName, String raw, Attributes attr)
- throws SAXException {
- boolean passed = true;
-
- if (hasWorkflow() && localName.equals(ITEM_ELEMENT)) {
- String event = attr.getValue(Workflow.NAMESPACE, EVENT_ATTRIBUTE);
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Event: [" + event + "]");
+ public static final String MENU_ELEMENT = "menu";
+ public static final String ITEM_ELEMENT = "item";
+ public static final String EVENT_ATTRIBUTE = "event";
+ /**
+ * (non-Javadoc)
+ *
+ * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
+ */
+ public void startElement(String uri, String localName, String raw, Attributes attr) throws SAXException {
+ boolean passed = true;
+ if(hasWorkflow() && localName.equals(ITEM_ELEMENT)){
+ String event = attr.getValue(Workflow.NAMESPACE, EVENT_ATTRIBUTE);
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Event: [" + event + "]");
+ }
+ // filter item if command not allowed
+ if(event != null){
+ passed = false;
+ AttributesImpl attributes = new AttributesImpl(attr);
+ int hrefIndex = attributes.getIndex("href");
+ if(hrefIndex > -1){
+ if(!containsEvent(event)){
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Removing href attribute");
+ }
+ attributes.removeAttribute(hrefIndex);
+ }else{
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Adding event to href attribute");
+ }
+ String href = attributes.getValue("href");
+ attributes.setValue(hrefIndex, href + "&lenya.event=" + event);
+ }
}
-
- // filter item if command not allowed
- if (event != null) {
- passed = false;
-
- AttributesImpl attributes = new AttributesImpl(attr);
-
- int hrefIndex = attributes.getIndex("href");
- if (hrefIndex > -1) {
-
- if (!containsEvent(event)) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Removing href attribute");
- }
- attributes.removeAttribute(hrefIndex);
- } else {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Adding event to href attribute");
- }
- String href = attributes.getValue("href");
- attributes.setValue(hrefIndex, href + "&lenya.event=" + event);
- }
-
- }
-
- super.startElement(uri, localName, raw, attributes);
- }
- }
-
- if (passed) {
- super.startElement(uri, localName, raw, attr);
- }
-
- }
-
- /**
- * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
- */
- public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters)
- throws ProcessingException, SAXException, IOException {
-
- super.setup(resolver, objectModel, src, parameters);
-
- PageEnvelope envelope = null;
-
- try {
- envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
- } catch (Exception e) {
+ super.startElement(uri, localName, raw, attributes);
+ }
+ }
+ if(passed){
+ super.startElement(uri, localName, raw, attr);
+ }
+ }
+ /**
+ * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
+ */
+ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters parameters) throws ProcessingException, SAXException, IOException {
+ super.setup(resolver, objectModel, src, parameters);
+ PageEnvelope envelope = null;
+ try{
+ envelope = PageEnvelope.getCurrent();
+ }catch(Exception e){
+ throw new ProcessingException(e);
+ }
+ Document document = envelope.getDocument();
+ WorkflowFactory factory = WorkflowFactory.newInstance();
+ setHasWorkflow(factory.hasWorkflow(document));
+ if(hasWorkflow()){
+ Situation situation = null;
+ try{
+ setInstance(factory.buildSynchronizedInstance(document));
+ situation = WorkflowHelper.buildSituation(objectModel);
+ }catch(Exception e){
throw new ProcessingException(e);
- }
-
- Document document = envelope.getDocument();
- WorkflowFactory factory = WorkflowFactory.newInstance();
-
- setHasWorkflow(factory.hasWorkflow(document));
-
- if (hasWorkflow()) {
- Situation situation = null;
-
- try {
- setInstance(factory.buildSynchronizedInstance(document));
- situation = WorkflowHelper.buildSituation(objectModel);
- } catch (Exception e) {
- throw new ProcessingException(e);
- }
-
- try {
- this.events = getInstance().getExecutableEvents(situation);
-
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Executable events: ");
- for (int i = 0; i < events.length; i++) {
- getLogger().debug(" [" + events[i] + "]");
- }
- }
-
- } catch (WorkflowException e) {
- throw new ProcessingException(e);
+ }
+ try{
+ this.events = getInstance().getExecutableEvents(situation);
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Executable events: ");
+ for(int i = 0; i < events.length; i++){
+ getLogger().debug(" [" + events[i] + "]");
+ }
}
- }
- }
-
- private boolean hasWorkflow;
- private SynchronizedWorkflowInstances instance;
-
- /**
- * Get the workflow instance.
- *
- * @return a <code>WorkflowInstance</code>
- */
- protected SynchronizedWorkflowInstances getInstance() {
- return instance;
- }
-
- private Event[] events;
-
- /**
- * Returns if the events contain a specific event.
- * @param eventName The name of the event to check for.
- * @return A boolean value.
- */
- protected boolean containsEvent(String eventName) {
- boolean result = false;
-
- for (int i = 0; i < events.length; i++) {
- if (events[i].getName().equals(eventName)) {
- result = true;
- }
- }
-
- return result;
- }
-
- /**
- * Returns if the current document has a workflow.
- * @return A boolean value.
- */
- protected boolean hasWorkflow() {
- return hasWorkflow;
- }
-
- /**
- * Sets if the current document has a workflow.
- * @param hasWorkflow A boolean value.
- */
- public void setHasWorkflow(boolean hasWorkflow) {
- this.hasWorkflow = hasWorkflow;
- }
-
- /**
- * Sets the workflow instance for the current request.
- * @param instance A workflow instance.
- */
- public void setInstance(SynchronizedWorkflowInstances instance) {
- this.instance = instance;
- }
+ }catch(WorkflowException e){
+ throw new ProcessingException(e);
+ }
+ }
+ }
+ private boolean hasWorkflow;
+ private SynchronizedWorkflowInstances instance;
+ /**
+ * Get the workflow instance.
+ *
+ * @return a <code>WorkflowInstance</code>
+ */
+ protected SynchronizedWorkflowInstances getInstance() {
+ return instance;
+ }
+ private Event[] events;
+ /**
+ * Returns if the events contain a specific event.
+ *
+ * @param eventName
+ * The name of the event to check for.
+ * @return A boolean value.
+ */
+ protected boolean containsEvent(String eventName) {
+ boolean result = false;
+ for(int i = 0; i < events.length; i++){
+ if(events[i].getName().equals(eventName)){
+ result = true;
+ }
+ }
+ return result;
+ }
+ /**
+ * Returns if the current document has a workflow.
+ *
+ * @return A boolean value.
+ */
+ protected boolean hasWorkflow() {
+ return hasWorkflow;
+ }
+ /**
+ * Sets if the current document has a workflow.
+ *
+ * @param hasWorkflow
+ * A boolean value.
+ */
+ public void setHasWorkflow(boolean hasWorkflow) {
+ this.hasWorkflow = hasWorkflow;
+ }
+ /**
+ * Sets the workflow instance for the current request.
+ *
+ * @param instance
+ * A workflow instance.
+ */
+ public void setInstance(SynchronizedWorkflowInstances instance) {
+ this.instance = instance;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/uriparameterizer/URIParameterizer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/uriparameterizer/URIParameterizer.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/uriparameterizer/URIParameterizer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/uriparameterizer/URIParameterizer.java Sat Mar 8 14:58:32 2008
@@ -20,7 +20,6 @@
package org.apache.lenya.cms.cocoon.uriparameterizer;
import java.util.Map;
-
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.parameters.Parameters;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/uriparameterizer/URIParameterizerImpl.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/uriparameterizer/URIParameterizerImpl.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/uriparameterizer/URIParameterizerImpl.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/uriparameterizer/URIParameterizerImpl.java Sat Mar 8 14:58:32 2008
@@ -21,7 +21,6 @@
import java.util.HashMap;
import java.util.Map;
-
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.parameters.Parameters;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/workflow/WorkflowHelper.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/workflow/WorkflowHelper.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/workflow/WorkflowHelper.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/cocoon/workflow/WorkflowHelper.java Sat Mar 8 14:58:32 2008
@@ -21,7 +21,6 @@
package org.apache.lenya.cms.cocoon.workflow;
import java.util.Map;
-
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.Session;
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentInputModule.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentInputModule.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentInputModule.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentInputModule.java Sat Mar 8 14:58:32 2008
@@ -7,6 +7,7 @@
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.lenya.cms.cocoon.components.modules.input.AbstractPageEnvelopeModule;
import org.apache.lenya.cms.publication.PageEnvelope;
+import org.apache.lenya.cms.publication.PageEnvelopeException;
import org.apache.lenya.cms.publication.Publication;
/**
* Retrieves Content Variables from the appropriate Resource
@@ -25,23 +26,39 @@
if(getLogger().isDebugEnabled()){
getLogger().debug("Resolving [" + name + "]");
}
- PageEnvelope pe = getEnvelope(objectModel);
+ PageEnvelope pe;
+ try{
+ pe = PageEnvelope.getCurrent();
+ }catch(PageEnvelopeException e){
+ throw new ConfigurationException("Resolving page envelope failed: ", e);
+ }
Publication pub = pe.getPublication();
// String publication = pub.getId();
Content content = pub.getContent();
String unid = "";
+ // System.out.println("ContentInputModule name=" + name);
int pos = name.indexOf(":");
- if(pos < 1)
+ if(pos > 0){
+ unid = name.substring(pos + 1);
+ name = name.substring(0, pos);
+ }else{
+ // unid = Globals.getUNID();
return "error";
- unid = name.substring(pos + 1);
- name = name.substring(0, pos);
+ }
Resource resource = content.getResource(unid);
- if(name.equalsIgnoreCase("type"))
+ if(null == resource){
+ System.out.println("ContentInputModule: No Resource NAME=" + name + " UNID=" + unid);
+ }
+ if(name.equalsIgnoreCase("type")){
+ // System.out.println("ContentInputModule NAME=" + name + " UNID=" + unid + " TYPE=" + resource.getType());
return resource.getType();
- if(name.equalsIgnoreCase("doctype") || name.equalsIgnoreCase("documenttype"))
+ }
+ if(name.equalsIgnoreCase("doctype") || name.equalsIgnoreCase("documenttype")){
return resource.getDocumentType();
- if(name.equalsIgnoreCase("defaultlanguage"))
+ }
+ if(name.equalsIgnoreCase("defaultlanguage")){
return resource.getDefaultLanguage();
+ }
return "";
}
/**
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentSourceFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentSourceFactory.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentSourceFactory.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ContentSourceFactory.java Sat Mar 8 14:58:32 2008
@@ -10,7 +10,6 @@
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.components.CocoonComponentManager;
-import org.apache.cocoon.components.ContextHelper;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceFactory;
import org.apache.excalibur.source.SourceNotFoundException;
@@ -19,7 +18,6 @@
import org.apache.excalibur.source.URIAbsolutizer;
import org.apache.lenya.cms.cocoon.components.source.impl.StringSource;
import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeFactory;
import org.apache.lenya.cms.publication.Publication;
import org.w3c.dom.Document;
/**
@@ -47,8 +45,8 @@
public void contextualize(org.apache.avalon.framework.context.Context context) throws ContextException {
this.context = context;
}
- public Source getSource(String plocation, Map parameters) throws IOException, MalformedURLException {
- String location = plocation;
+ public Source getSource(String location, Map parameters) throws IOException, MalformedURLException {
+ String workLocation = location;
int pos;
// Map contextmap = ContextHelper.getObjectModel(context);
// org.apache.cocoon.environment.http.HttpContext httpcontext = (org.apache.cocoon.environment.http.HttpContext) contextmap.get("context");
@@ -60,7 +58,7 @@
}catch(org.apache.avalon.framework.component.ComponentException ce){
}
if(null == resolver){
- throw new SourceNotFoundException("No Resolver: " + plocation);
+ throw new SourceNotFoundException("No Resolver: " + location);
}
String uri = resolver.resolveURI("").getURI();
pos = uri.indexOf("/pubs/");
@@ -77,7 +75,7 @@
Publication pub;
Content content;
try{
- PageEnvelope envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(ContextHelper.getObjectModel(context));
+ PageEnvelope envelope = PageEnvelope.getCurrent();
pub = envelope.getPublication();
// publication = pub.getId();
content = pub.getContent();
@@ -85,28 +83,16 @@
}catch(org.apache.lenya.cms.publication.PageEnvelopeException pee){
throw new MalformedURLException("Could not get Publication ID.");
}
- // Revision
- String revision = "live";
- pos = location.lastIndexOf("!");
- if(pos != -1){
- revision = location.substring(pos + 1);
- location = location.substring(0, pos);
- }
- // Language
- String language = "";
- pos = location.lastIndexOf("_");
- if(pos != -1){
- language = location.substring(pos + 1);
- location = location.substring(0, pos);
- }
- // TODO: Set language to document or publication's default if not specified.
- // System.out.println("LOC="+location);
+ // Parse Location
+ Location locationParser = new Location(workLocation);
+ // Removes everything after first period, underscore, or exclamation mark.
+ workLocation = locationParser.getUnid();
// Decide Usage
- StringTokenizer tokens = new StringTokenizer(location, "/:", true);
+ StringTokenizer tokens = new StringTokenizer(workLocation, "/:", true);
if(!tokens.hasMoreTokens())
throw new MalformedURLException("Nothing specified.");
String token = tokens.nextToken();
- if(location.indexOf(":") > 0)
+ if(workLocation.indexOf(":") > 0)
token = tokens.nextToken(); // Remove protocol
int colonCount = 0;
while(token.equals(":")){
@@ -139,30 +125,6 @@
}
slashCount = (slashCount > slashCount2 ? slashCount : slashCount2);
}
- // System.out.println("SL=" + slashCount + "TOK=" + token);
- // ## Decide UNID
- // String structure = "";
- // String unid = "";
- // String fullid = "";
- // if(slashCount == 1){
- // if(tokens.hasMoreTokens()){
- // slashCount = 0;
- // }else unid = token;
- // }
- // if((slashCount == 0) || (slashCount == 2)){
- // structure = token;
- // }
- // if((slashCount == 0) || (slashCount == 2) || (slashCount == 3)){
- // StringBuffer buffer = new StringBuffer();
- // while(tokens.hasMoreTokens())
- // buffer.append(tokens.nextToken());
- // fullid = buffer.toString();
- // }
- // // Convert fullid to unid
- // if(unid.length() < 1){
- // unid = content.getUNID(structure, fullid);
- // }
- // ## 20070927 solprovider: This rewrite did not work. Simpler is good. Test later.
String structure = (2 < slashCount ? "" : token);
String unid = token;
StringBuffer buffer = new StringBuffer();
@@ -172,60 +134,66 @@
if((1 < slashCount) || (0 < fullid.length()))
unid = content.getUNID(structure, fullid);
// ASSUME: UNID
- // ## Defaults
- if(language.length() < 1){
- Resource resource = content.getResource(unid);
- if(resource != null)
- language = resource.getDefaultLanguage();
- }
- if(language.length() < 1)
- language = pub.getDefaultLanguage();
/** ******** Get Source (uses Content) ************ */
Source source;
if(REQUEST_INFO == requestType){
// TODO: Catch errors
Resource resource = content.getResource(unid);
- if(resource == null)
- System.out.println("NO RESOURCE");
+ if(resource == null){
+ throw new SourceNotFoundException("Source not found (no Resource): " + location);
+ }
Document doc = resource.getInfoDocument();
- if(doc == null)
- System.out.println("NO DOC");
+ if(doc == null){
+ throw new SourceNotFoundException("Source not found (no Document): " + location);
+ }
source = new StringSource(manager, doc);
- if(source == null)
- System.out.println("NO SOURCE");
+ if(source == null){
+ throw new SourceNotFoundException("Source not found (no Source): " + location);
+ }
return source;
}
+ // Revision
+ String revision = locationParser.getRevision();
+ if(0 == revision.length()){
+ revision = "live";
+ }
+ // Language
+ String language = locationParser.getLanguage();
+ if(language.length() < 1){
+ Resource resource = content.getResource(unid);
+ if(resource != null){
+ language = resource.getDefaultLanguage();
+ }
+ }
+ if(language.length() < 1){
+ language = pub.getDefaultLanguage();
+ }
if(REQUEST_META == requestType){
source = resolver.resolveURI(content.getMetaURI(unid, language, revision));
if(source.exists()){
if(resolver != null)
manager.release((Component) resolver);
return source;
+ }else{
+ throw new SourceNotFoundException("Source not found (no Meta Source): " + location);
}
}
- // System.out.println("CSF UNID=" + unid + " LANG=" + language + " REV=" + revision);
String curi = content.getURI(unid, language, revision);
- // System.out.println("CSF CURI=" + curi);
+ // System.out.println("ContentSourceFactory.getSource UNID=" + unid + " LANG=" + language + " REV=" + revision + " CURI=" + curi);
+ if(curi.length() < 1){
+ throw new SourceNotFoundException("Source not found (no URI): " + location + " UNID=" + unid + " LANG=" + language + " REV=" + revision);
+ }
source = resolver.resolveURI(curi);
+ if(resolver != null)
+ manager.release((Component) resolver);
if(source.exists()){
- if(resolver != null)
- manager.release((Component) resolver);
return source;
}
- if(resolver != null)
- manager.release((Component) resolver);
- throw new SourceNotFoundException("Not found: " + plocation + " (" + curi + ")");
+ throw new SourceNotFoundException("Source not found: " + location + " (" + curi + ")");
}
public void release(Source source1) {
}
public String absolutize(String baseURI, String location) {
return SourceUtil.absolutize(baseURI, location, false, false);
}
- // private Publication getPublication(String publication) {
- // try{
- // return PublicationFactory.getPublication(publication, servletContextPath);
- // }catch(org.apache.lenya.cms.publication.PublicationException pe){
- // return (Publication) null;
- // }
- // }
}
Added: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Location.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Location.java?rev=635107&view=auto
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Location.java (added)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Location.java Sat Mar 8 14:58:32 2008
@@ -0,0 +1,79 @@
+package org.apache.lenya.cms.content;
+import java.util.StringTokenizer;
+/**
+ * Parses location from URL. Not aware of Content -- unid may be unid or id.
+ *
+ * @author solprovider
+ * @since 1.3
+ */
+public class Location {
+ private String unid = "";
+ private String language = "";
+ private String revision = "";
+ private String extension = "";
+ /**
+ * Separate on periods, exclamation marks, and underscores <br>
+ * revision = part after last exclamation mark. <br>
+ * extension = part after last period. <br>
+ * language = first two-character part after an underscore and additional parts until period or exclamation mark. <br>
+ * unid = first part and underscore-separated parts until another part is found.
+ *
+ * @param location
+ */
+ public Location(String location) {
+ StringTokenizer tokens = new StringTokenizer(location, "!_.", true);
+ if(tokens.hasMoreTokens()){
+ unid = tokens.nextToken();
+ }
+ boolean inLanguage = false;
+ boolean inUnid = true;
+ while(tokens.hasMoreTokens()){
+ String token = tokens.nextToken();
+ if("!".equals(token)){
+ inLanguage = false;
+ inUnid = false;
+ if(tokens.hasMoreTokens()){
+ revision = tokens.nextToken();
+ }
+ }else if("_".equals(token)){
+ if(tokens.hasMoreTokens()){
+ token = tokens.nextToken();
+ if(inLanguage){
+ if(tokens.hasMoreTokens()){
+ language = language + "_" + token;
+ }
+ }else{
+ if(2 == token.length()){
+ language = token;
+ inLanguage = true;
+ inUnid = false;
+ }else if(inUnid){
+ unid = unid + "_" + token;
+ }
+ }
+ }
+ }else if(".".equals(token)){
+ inLanguage = false;
+ inUnid = false;
+ if(tokens.hasMoreTokens()){
+ extension = tokens.nextToken();
+ }
+ }else{
+ inLanguage = false;
+ System.out.println("Location part not found in " + location);
+ }
+ }
+ }
+ public String getUnid() {
+ return unid;
+ }
+ public String getLanguage() {
+ return language;
+ }
+ public String getRevision() {
+ return revision;
+ }
+ public String getExtension() {
+ return extension;
+ }
+}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Resource.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Resource.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Resource.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/Resource.java Sat Mar 8 14:58:32 2008
@@ -12,6 +12,11 @@
public String getUNID();
public String getID();
public String getType();
+ /**
+ * Used by Lenya-1.2 Publications.
+ *
+ * @deprecated Use getType()
+ */
public String getDocumentType();
public String getLanguage();
public String getDefaultLanguage();
Added: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceException.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceException.java?rev=635107&view=auto
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceException.java (added)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceException.java Sat Mar 8 14:58:32 2008
@@ -0,0 +1,62 @@
+/*
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed 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: PublicationException.java 617035 2008-01-31 07:44:03Z solprovider $ */
+package org.apache.lenya.cms.content;
+/**
+ *
+ * @author solprovider
+ * @since 1.3
+ */
+public class ResourceException extends Exception {
+ private static final long serialVersionUID = 1L;
+ /**
+ * Creates a new ResourceException.
+ *
+ */
+ public ResourceException() {
+ super();
+ }
+ /**
+ * Creates a new ResourceException.
+ *
+ * @param message
+ * the exception message
+ */
+ public ResourceException(String message) {
+ super(message);
+ }
+ /**
+ * Creates a new ResourceException.
+ *
+ * @param message
+ * the exception message
+ * @param cause
+ * the cause of the exception
+ */
+ public ResourceException(String message, Throwable cause) {
+ super(message, cause);
+ }
+ /**
+ * Creates a new ResourceException.
+ *
+ * @param cause
+ * the cause of the exception
+ */
+ public ResourceException(Throwable cause) {
+ super(cause);
+ }
+}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceTransformer.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceTransformer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/ResourceTransformer.java Sat Mar 8 14:58:32 2008
@@ -3,6 +3,7 @@
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.transformation.AbstractDOMTransformer;
import org.apache.lenya.cms.publication.PageEnvelope;
+import org.apache.lenya.cms.publication.PageEnvelopeException;
import org.apache.lenya.cms.publication.Publication;
/**
* This transformer modifies the structural information of a Resource. It accepts a UNID as the src parameter. It can: - change the id and defaultlanguage of the Resource, - delete Translations and Revisions, - change the live and edit Revisions of Translations. <resource [id="newid"] [defaultlanguage="aa"]> <translation language="xx" [action="delete"] [live="1137958604000"] [edit="1137958604000"]> <revision revision="1137958604000" [action="delete"]/> </translation> </resource> action="delete" has top priority. Any settings not included will not be affected.
@@ -18,12 +19,16 @@
return transformDocument(request, unid, doc);
}
static public org.w3c.dom.Document transformDocument(Request request, String unid, org.w3c.dom.Document doc) {
- PageEnvelope envelope = (PageEnvelope) request.getAttribute(PageEnvelope.class.getName());
+ PageEnvelope envelope;
+ try{
+ envelope = PageEnvelope.getCurrent();
+ }catch(PageEnvelopeException e){
+ return null;
+ }
Publication pub = envelope.getPublication();
Content content = pub.getContent();
Resource resource = content.getResource(unid);
resource.update(doc);
- // System.out.println("ResourceTransformer - RETURN");
return doc;
}
}
Added: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/CreateResourceTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/CreateResourceTransformer.java?rev=635107&view=auto
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/CreateResourceTransformer.java (added)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/CreateResourceTransformer.java Sat Mar 8 14:58:32 2008
@@ -0,0 +1,68 @@
+package org.apache.lenya.cms.content.flat;
+import org.apache.cocoon.ProcessingException;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.transformation.AbstractDOMTransformer;
+import org.apache.lenya.cms.content.ResourceException;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+/**
+ * @cocoon.sitemap.component.documentation This transformer creates a new Resource.
+ *
+ * @author solprovider
+ * @since 1.3
+ */
+// <?xml version="1.0" encoding="UTF-8"?>
+// <resource defaultlanguage="en" doctype="xhtml" id="doctypes" type="xml" unid="0002" xmlns=""/>
+public class CreateResourceTransformer extends AbstractDOMTransformer {
+ public static final String CONTENT_PREFIX = "content";
+ public static final String FILE_NAME_REGEXP = "[-a-zA-Z0-9_. ]+";
+ protected org.w3c.dom.Document transform(org.w3c.dom.Document doc) {
+ Request request = ObjectModelHelper.getRequest(super.objectModel);
+ createResource(request, doc);
+ return doc;
+ }
+ static public org.w3c.dom.Document transformDocument(Request request, org.w3c.dom.Document doc) throws ProcessingException {
+ createResource(request, doc);
+ return doc;
+ }
+ /**
+ * @param request
+ * The request
+ * @param doc
+ * The data to be inserted.
+ * @throws ProcessingException
+ * @throws ResourceException
+ */
+ static private void createResource(Request request, org.w3c.dom.Document doc) {
+ if(doc == null){
+ System.out.println("CreateResource: Document is required.");
+ // throw new ProcessingException("CreateResource: document is required.");
+ return;
+ }
+ Element root = doc.getDocumentElement();
+ NodeList nodes = root.getElementsByTagName("newresource");
+ int length = nodes.getLength();
+ for(int n = 0; n < length; n++){
+ Element element = (Element) nodes.item(n);
+ String unid = element.getAttribute("unid");
+ String type = element.getAttribute("type");
+ String id = element.getAttribute("id");
+ FlatResource resource;
+ try{
+ resource = FlatResource.create(unid, type, id);
+ unid = resource.getUNID();
+ // Attempts to make UNID accessible to XMAP.
+ // request.setAttribute("unid", unid);
+ // Globals.getRequest().setAttribute("unid", unid);
+ // ContextMap contextMap = ContextMap.getCurrentContext();
+ // contextMap.set("unid", unid);
+ element.setAttribute("unid", unid);
+ element.setAttribute("status", "SUCCESS");
+ }catch(ResourceException e){
+ element.setAttribute("status", "FAILURE");
+ element.setNodeValue(e.getLocalizedMessage());
+ }
+ }
+ }
+}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/CreateRevisionTransformer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/CreateRevisionTransformer.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/CreateRevisionTransformer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/CreateRevisionTransformer.java Sat Mar 8 14:58:32 2008
@@ -7,14 +7,12 @@
import java.util.Map;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
-import org.apache.cocoon.environment.Session;
import org.apache.cocoon.servlet.multipart.Part;
import org.apache.cocoon.transformation.AbstractDOMTransformer;
-import org.apache.lenya.ac.Identity;
-import org.apache.lenya.ac.User;
import org.apache.lenya.cms.content.Content;
import org.apache.lenya.cms.publication.PageEnvelope;
import org.apache.lenya.cms.publication.Publication;
+import org.apache.lenya.util.Globals;
import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.NamespaceHelper;
import org.w3c.dom.Document;
@@ -111,18 +109,8 @@
// ASSUME: Upload is saved.
// Store creator, when, revision and extension.
root.setAttribute("revision", revision);
- String userid = "anonymous";
- Session session = request.getSession();
- if(session != null){
- Identity identity = (Identity) session.getAttribute(Identity.class.getName());
- if(identity != null){
- User user = identity.getUser();
- if(user != null)
- userid = user.getId();
- }
- }
- root.setAttribute("creator", userid);
- root.setAttribute("when", getDateString());
+ root.setAttribute("creator", Globals.getUser());
+ root.setAttribute("when", Globals.getDateString());
if(extension.length() > 0)
root.setAttribute("extension", extension);
try{
@@ -202,8 +190,5 @@
// meta.appendChild(helper.createElement(tagName, tagValue));
root.appendChild(helper.createElement(tagName, tagValue));
}
- }
- static private String getDateString() {
- return Long.toString(new java.util.Date().getTime());
}
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatContent.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatContent.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatContent.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatContent.java Sat Mar 8 14:58:32 2008
@@ -16,15 +16,15 @@
languages = planguages;
indexer = new FlatIndexer(new File(directory, "index"), this);
// The next line starts indexing everything in the background when Lenya starts.
- new Thread((Runnable) indexer).start();
+ updateIndexes();
}
/* Content API */
public String getIndexFilename(String indexName, String language) {
return indexer.getIndexFilename(indexName, language);
}
- public String getURI(String unid, String language, String revision) {
- Resource resource = getResource(unid, language, revision);
- return resource.getURI();
+ /* FlatContent API */
+ public String[] getLanguages() {
+ return languages;
}
public String getMetaURI(String unid, String language, String revision) {
Resource resource = getResource(unid, language, revision);
@@ -34,24 +34,30 @@
Resource resource = getResource(unid, language, "edit");
return resource.getNewURI();
}
- public String getUNID(String structure, String id) {
- FlatRelations relations = getRelations(structure);
- return relations.getUNID(id);
+ public FlatRelations getRelations(String structure) {
+ return new FlatRelations(new File(directory, "relation" + File.separator + structure + ".xml"));
}
public Resource getResource(String unid) {
return (Resource) new FlatResource(directory, unid);
}
- /* FlatContent API */
- public String[] getLanguages() {
- return languages;
+ public Resource getResource(String unid, String language, String revision) {
+ return (Resource) new FlatResource(directory, unid, language, revision);
}
public String[] getResources() {
return (new File(directory, "resource")).list();
}
- public Resource getResource(String unid, String language, String revision) {
- return (Resource) new FlatResource(directory, unid, language, revision);
+ public String getUNID(String structure, String id) {
+ FlatRelations relations = getRelations(structure);
+ return relations.getUNID(id);
}
- public FlatRelations getRelations(String structure) {
- return new FlatRelations(new File(directory, "relation" + File.separator + structure + ".xml"));
+ public String getURI(String unid, String language, String revision) {
+ Resource resource = getResource(unid, language, revision);
+ return resource.getURI();
+ }
+ /**
+ * Updates Indexes in background.
+ */
+ void updateIndexes() {
+ new Thread((Runnable) indexer).start();
}
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatIndex.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatIndex.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatIndex.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatIndex.java Sat Mar 8 14:58:32 2008
@@ -13,73 +13,84 @@
* @since 1.3
*/
public class FlatIndex {
- File configurationFile;
+ File configurationFile = null;
File indexFile;
FlatContent content;
String indexName;
- String language = "en";
+ String language = "";
String structure = "";
String revision = "live";
Map filter = new HashMap();
Map include = new HashMap();
- public FlatIndex(FlatContent pcontent, File indexDirectory, String pindexName, String planguage) {
- indexName = pindexName;
- configurationFile = new File(indexDirectory, indexName + ".xconf");
- indexFile = new File(indexDirectory, indexName + "_" + planguage + ".xml");
- content = pcontent;
- language = planguage;
- // loadConfiguration();
+ public FlatIndex(FlatContent content, File indexDirectory, String indexName, String language) {
+ if(null == indexName){ // SitetreeGenerator called without src attribute.
+ this.indexName = "";
+ }else{
+ this.indexName = indexName;
+ }
+ this.content = content;
+ if(0 == this.indexName.length()){ // Special case: all Resources disregarding Translations
+ indexFile = new File(indexDirectory, "all.xml");
+ }else{
+ this.language = language;
+ configurationFile = new File(indexDirectory, indexName + ".xconf");
+ indexFile = new File(indexDirectory, indexName + "_" + language + ".xml");
+ }
}
private void loadConfiguration() {
- Document document;
- try{
- document = DocumentHelper.readDocument(configurationFile);
- }catch(javax.xml.parsers.ParserConfigurationException pce){
- System.out.println("Indexer: could not parse " + configurationFile.getPath());
- return;
- }catch(org.xml.sax.SAXException saxe){
- System.out.println("Indexer: " + configurationFile.getPath() + " is not valid.");
- return;
- }catch(java.io.IOException ioe){
- System.out.println("Indexer: could not read " + configurationFile.getPath());
- return;
+ if(null == configurationFile){ // Special case: all Resources disregarding Translations
+ include.put("unid", new FlatIndexPart("unid"));
+ include.put("type", new FlatIndexPart("type"));
+ include.put("doctype", new FlatIndexPart("doctype"));
+ include.put("id", new FlatIndexPart("id"));
+ }else{
+ Document document;
+ try{
+ document = DocumentHelper.readDocument(configurationFile);
+ }catch(javax.xml.parsers.ParserConfigurationException pce){
+ System.out.println("Indexer: could not parse " + configurationFile.getPath());
+ return;
+ }catch(org.xml.sax.SAXException saxe){
+ System.out.println("Indexer: " + configurationFile.getPath() + " is not valid.");
+ return;
+ }catch(java.io.IOException ioe){
+ System.out.println("Indexer: could not read " + configurationFile.getPath());
+ return;
+ }
+ Element root = document.getDocumentElement();
+ if(root.hasAttribute("structure")) structure = root.getAttribute("structure");
+ if(root.hasAttribute("revision")) revision = root.getAttribute("revision");
+ NodeList nl;
+ int length;
+ int i;
+ nl = root.getElementsByTagName("filter");
+ length = nl.getLength();
+ for(i = 0; i < length; i++){
+ FlatIndexPart part = new FlatIndexPart((Element) nl.item(i));
+ filter.put(part.getName(), part);
+ }
+ nl = root.getElementsByTagName("include");
+ length = nl.getLength();
+ for(i = 0; i < length; i++){
+ FlatIndexPart part = new FlatIndexPart((Element) nl.item(i));
+ include.put(part.getName(), part);
+ }
+ include.put("unid", new FlatIndexPart("unid"));
+ include.put("type", new FlatIndexPart("type"));
+ include.put("doctype", new FlatIndexPart("doctype"));
+ include.put("id", new FlatIndexPart("id"));
+ include.put("title", new FlatIndexPart("title"));
+ include.put("href", new FlatIndexPart("href"));
+ include.put("extension", new FlatIndexPart("extension"));
}
- Element root = document.getDocumentElement();
- if(root.hasAttribute("structure"))
- structure = root.getAttribute("structure");
- if(root.hasAttribute("revision"))
- revision = root.getAttribute("revision");
- NodeList nl;
- int length;
- int i;
- nl = root.getElementsByTagName("filter");
- length = nl.getLength();
- for(i = 0; i < length; i++){
- FlatIndexPart part = new FlatIndexPart((Element) nl.item(i));
- filter.put(part.getName(), part);
- }
- nl = root.getElementsByTagName("include");
- length = nl.getLength();
- for(i = 0; i < length; i++){
- FlatIndexPart part = new FlatIndexPart((Element) nl.item(i));
- include.put(part.getName(), part);
- }
- include.put("unid", new FlatIndexPart("unid"));
- include.put("type", new FlatIndexPart("type"));
- include.put("doctype", new FlatIndexPart("doctype"));
- include.put("id", new FlatIndexPart("id"));
- include.put("title", new FlatIndexPart("title"));
- include.put("href", new FlatIndexPart("href"));
- include.put("extension", new FlatIndexPart("extension"));
}
public String getIndexFilename() {
- if(!indexFile.exists())
- update();
+ if(!indexFile.exists()) update();
return indexFile.getPath();
}
public void update() {
// TODO: Add publication ID to the log.
- System.out.println("Indexer updating " + indexName + "(" + language + ")");
+ // System.out.println("Indexer updating " + indexName + "(" + language + ")");
loadConfiguration();
// Init Document
Document document;
@@ -96,8 +107,11 @@
if(structure.length() > 0){
include.put("fullid", new FlatIndexPart("fullid"));
updateStructure(document, root);
- }else
+ }else if(0 < this.indexName.length()){
updateFlat(document, root);
+ }else{ // Special case: all Resources disregarding Translations
+ updateAll(document, root);
+ }
// Write document
try{
org.apache.lenya.xml.DocumentHelper.writeDocument(document, indexFile);
@@ -116,13 +130,14 @@
if(null == resourceElement){
System.out.println("Error creating Index " + indexName + "_" + language + ". Could not find Structure " + structure);
}else{
- addStructureResource(document, root, resourceElement, "", "");
+ addStructureResource(document, root, resourceElement, "");
}
}
/**
* Add child "resource" elements of resourceElement to root, and recurse for each. Must pass filters.
*/
- private void addStructureResource(Document document, Element root, Element resourceElement, String parenttype, String parentdoctype) {
+ // private void addStructureResource(Document document, Element root, Element resourceElement, String parenttype, String parentdoctype) {
+ private void addStructureResource(Document document, Element root, Element resourceElement, String parenttype) {
// NodeList children = resourceElement.getElementsByTagName("resource"); //getDescendants, need getChildren
NodeList children = resourceElement.getChildNodes();
int length = children.getLength();
@@ -134,7 +149,7 @@
if(resource.hasRevision()){
String fullid = resourceChild.getAttribute("full");
String fulltype = parenttype + "/" + resource.getType();
- String fulldoctype = parentdoctype + "/" + resource.getDocumentType();
+ // String fulldoctype = parentdoctype + "/" + resource.getDocumentType();
FlatIndexPart part;
// FILTER - BEGIN
Iterator fi = filter.values().iterator();
@@ -142,8 +157,8 @@
while(fi.hasNext() & useResource){
part = (FlatIndexPart) fi.next();
useResource = false;
- if(part.check(resource.get(part.getProperty(), fullid, fulltype, fulldoctype)))
- useResource = true;
+ // if(part.check(resource.get(part.getProperty(), fullid, fulltype, fulldoctype)))
+ if(part.check(resource.get(part.getProperty(), fullid, fulltype))) useResource = true;
}
// FILTER - END
if(useResource){
@@ -154,11 +169,11 @@
while(ii.hasNext()){
part = (FlatIndexPart) ii.next();
String value = resource.get(part.getProperty(), fullid);
- if(value.length() > 0)
- element.setAttribute(part.getName(), value);
+ if(value.length() > 0) element.setAttribute(part.getName(), value);
}
// INCLUDE - END
- addStructureResource(document, element, resourceChild, fulltype, fulldoctype);
+ // addStructureResource(document, element, resourceChild, fulltype, fulldoctype);
+ addStructureResource(document, element, resourceChild, fulltype);
} // if useResource
} // if resource not null
} // if "resource"
@@ -178,8 +193,7 @@
while(fi.hasNext() & useResource){
part = (FlatIndexPart) fi.next();
useResource = false;
- if(part.check(resource.get(part.getProperty())))
- useResource = true;
+ if(part.check(resource.get(part.getProperty()))) useResource = true;
}
// FILTER - END
if(useResource){
@@ -190,13 +204,34 @@
while(ii.hasNext()){
part = (FlatIndexPart) ii.next();
String value = resource.get(part.getProperty());
- if(value.length() > 0)
- element.setAttribute(part.getName(), value);
+ if(value.length() > 0) element.setAttribute(part.getName(), value);
}
// INCLUDE - END
} // if useResource
} // if resource not null
- }
+ } // for
+ }
+ private void updateAll(Document document, Element root) {
+ // System.out.println("updateAll BEGIN");
+ root.setAttribute("description", "Special index containing all Resources ignoring existence of Translations: no filtering by language and no information from Translations and Revisions.");
+ // Build Index
+ String[] unids = content.getResources();
+ int unidsLength = unids.length;
+ for(int u = 0; u < unidsLength; u++){
+ String unid = unids[u];
+ FlatResource resource = (FlatResource) content.getResource(unid, language, revision);
+ FlatIndexPart part;
+ // INCLUDE - BEGIN
+ Element element = addElement(document, root, "resource");
+ element.setAttribute("unid", unid);
+ Iterator ii = include.values().iterator();
+ while(ii.hasNext()){
+ part = (FlatIndexPart) ii.next();
+ String value = resource.get(part.getProperty());
+ if(value.length() > 0) element.setAttribute(part.getName(), value);
+ }
+ // INCLUDE - END
+ } // for
}
private Element addElement(Document document, Element parent, String newElementName) {
Element newElement = document.createElement(newElementName);
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatIndexer.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatIndexer.java?rev=635107&r1=635106&r2=635107&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatIndexer.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatIndexer.java Sat Mar 8 14:58:32 2008
@@ -1,31 +1,57 @@
package org.apache.lenya.cms.content.flat;
import java.io.File;
/**
+ * FlatContent handles threading. This class could be nested in FlatContent.
*
* @author solprovider
* @since 1.3
*/
-public class FlatIndexer implements Runnable {
+class FlatIndexer implements Runnable {
+ // TODO: Build list of Index configurations from Modules. Move .xconf files to Modules. Change extension (to .icx, .xic, .index?)
File indexDirectory;
FlatContent content;
- boolean isCurrent = false;
- public FlatIndexer(File pindexDirectory, FlatContent pcontent) {
+ private volatile boolean isRunning = false;
+ private volatile boolean runAgain = false; //
+ private Object lock = new Object(); // for locking synchronization.
+ FlatIndexer(File pindexDirectory, FlatContent pcontent) {
indexDirectory = pindexDirectory;
content = pcontent;
}
public void run() {
- updateAll();
- }
- public void updateAll() {
- if(isCurrent)
+ // Only the first thread updates. Additional requests set flag so the first thread will repeat the update.
+ // runAgain cannot be false on later threads unless the Indexer is updating
+ // If already queued, do nothing.
+ if(runAgain){
return;
- if(!indexDirectory.exists())
+ }
+ runAgain = true;
+ // Set to run, but return if already running,
+ if(isRunning){
return;
+ }
+ // synchronized so two threads do not conflict if both believe are first thread.
+ synchronized (lock){
+ isRunning = true;
+ // Run. Run again if another request was queued.
+ while(runAgain){
+ // runAgain is only set to false just before an update
+ runAgain = false;
+ update();
+ }
+ isRunning = false;
+ }
+ }
+ /**
+ * Updates all Indexes.
+ */
+ void update() {
+ System.out.println("Starting Indexer for " + indexDirectory.getAbsolutePath());
+ updateIndexAll();
+ if(!indexDirectory.exists()) return;
// System.out.println("Starting Indexer UpdateAll");
String[] files = indexDirectory.list();
- // System.out.println("FI-uA: iD=" + indexDirectory.getPath());
- if(null == files)
- return;
+ // System.out.println("FlatIndexer.updateAll ID=" + indexDirectory.getPath());
+ if(null == files) return;
int filesLength = files.length;
for(int f = 0; f < filesLength; f++){
String filename = files[f];
@@ -40,8 +66,38 @@
}
}
}
- isCurrent = true;
}
+ /**
+ * Updates all Indexes for one language.
+ *
+ * @param language
+ */
+ void update(String language) {
+ updateIndexAll();
+ if(!indexDirectory.exists()) return;
+ String[] files = indexDirectory.list();
+ if(null == files) return;
+ int filesLength = files.length;
+ for(int f = 0; f < filesLength; f++){
+ String filename = files[f];
+ if(filename.endsWith(".xconf")){
+ String indexName = filename.substring(0, filename.lastIndexOf(".xconf"));
+ FlatIndex index = new FlatIndex(content, indexDirectory, indexName, language);
+ index.update();
+ }
+ }
+ }
+ private void updateIndexAll() {
+ // Update the all Resources index (ignores Translations and Revisions).
+ FlatIndex index = new FlatIndex(content, indexDirectory, "", "");
+ index.update();
+ }
+ /**
+ *
+ * @param indexName
+ * @param language
+ * @return filename of specified Index
+ */
public String getIndexFilename(String indexName, String language) {
return (new FlatIndex(content, indexDirectory, indexName, language)).getIndexFilename();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org