svn commit: r617035 [6/22] - in /lenya/branches/revolution/1.3.x: ./ src/java/org/apache/lenya/ac/ src/java/org/apache/lenya/ac/cache/ src/java/org/apache/lenya/ac/cifs/ src/java/org/apache/lenya/ac/file/ src/java/org/apache/lenya/ac/impl/ src/java/org...
[email protected] Thu, 31 Jan 2008 07:44:36 -0000
Newsgroups
gmane.comp.cms.lenya.cvs
Message-ID
<[email protected] >
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=617035&r1=617034&r2=617035&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 Wed Jan 30 23:44:03 2008
@@ -21,7 +21,8 @@
import org.w3c.dom.Element;
/**
* @cocoon.sitemap.component.documentation This transformer creates a new Revision. It takes the UNID as the src parameter, uses the current language, and create a new Revision It will be enhanced to take "/structure/path/docid" as the src. That will be easy. If there is a slash, then convert using Content.getUNID().
- * @author <a href="mailto:[email protected] ">Paul Ercolino</a>
+ * @author solprovider
+ * @since 1.3
*/
public class CreateRevisionTransformer extends AbstractDOMTransformer {
public static final String UPLOADASSET_PARAM_PREFIX = "dc.";
@@ -46,7 +47,7 @@
* @param doc
* The data to be inserted.
*/
- static private void createRevision(Request request, String punid, org.w3c.dom.Document doc, boolean setLive) {
+ static private void createRevision(Request request, String unid, org.w3c.dom.Document doc, boolean setLive) {
if(doc == null){
System.out.println("CreateRevision: Document is required.");
// throw new ProcessingException("CreateRevision: document is required.");
@@ -54,16 +55,16 @@
PageEnvelope envelope = (PageEnvelope) request.getAttribute(PageEnvelope.class.getName());
Publication pub = envelope.getPublication();
Content content = pub.getContent();
- String unid = punid;
+ String workUnid = unid;
String language = envelope.getDocument().getLanguage(); // default
// check if unid contains language
- int pos = unid.indexOf("_");
+ int pos = workUnid.indexOf("_");
if(pos > 0){
- unid = unid.substring(0, pos);
- language = unid.substring(pos);
+ workUnid = workUnid.substring(0, pos);
+ language = workUnid.substring(pos);
}
// System.out.println("CreateRevision TEST: u=" + unid + " l=" + language);
- String newFilename = content.getNewURI(unid, language);
+ String newFilename = content.getNewURI(workUnid, language);
if(newFilename == null){
System.out.println("CreateRevision: Could not get new filename.");
// throw new ProcessingException("CreateRevision: Could not get new filename.");
@@ -134,7 +135,7 @@
System.out.println("CreateRevision: IOException writing XML file.");
}
// Update Translation
- FlatResource resource = (FlatResource) ((FlatContent) content).getResource(unid, language, "edit");
+ FlatResource resource = (FlatResource) ((FlatContent) content).getResource(workUnid, language, "edit");
FlatTranslation translation = resource.getTranslation();
translation.setEdit(revision);
if(setLive)
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=617035&r1=617034&r2=617035&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 Wed Jan 30 23:44:03 2008
@@ -1,59 +1,57 @@
package org.apache.lenya.cms.content.flat;
-
import java.io.File;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceNotFoundException;
import org.apache.lenya.cms.content.Content;
-//import org.apache.lenya.cms.content.Indexer;
import org.apache.lenya.cms.content.Resource;
-import org.apache.lenya.cms.publication.Publication;
-
-public class FlatContent implements Content{
+/**
+ *
+ * @author solprovider
+ * @since 1.3
+ */
+public class FlatContent implements Content {
File directory;
FlatIndexer indexer;
- String[] languages = { "en" };
-
- public FlatContent(File pdirectory, String[] planguages){
+ String[] languages = {"en"};
+ public FlatContent(File pdirectory, String[] planguages) {
directory = pdirectory;
languages = planguages;
indexer = new FlatIndexer(new File(directory, "index"), this);
-// The next line starts indexing everything in the background when Lenya starts.
+ // The next line starts indexing everything in the background when Lenya starts.
new Thread((Runnable) indexer).start();
}
-/* Content API */
- public String getIndexFilename(String indexName, String language){
- return indexer.getIndexFilename(indexName, language);
+ /* Content API */
+ public String getIndexFilename(String indexName, String language) {
+ return indexer.getIndexFilename(indexName, language);
}
- public String getURI(String unid, String language, String revision){
+ public String getURI(String unid, String language, String revision) {
Resource resource = getResource(unid, language, revision);
return resource.getURI();
}
- public String getMetaURI(String unid, String language, String revision){
+ public String getMetaURI(String unid, String language, String revision) {
Resource resource = getResource(unid, language, revision);
return resource.getMetaURI();
}
- public String getNewURI(String unid, String language){
+ public String getNewURI(String unid, String language) {
Resource resource = getResource(unid, language, "edit");
return resource.getNewURI();
}
- public String getUNID(String structure, String id){
+ public String getUNID(String structure, String id) {
FlatRelations relations = getRelations(structure);
return relations.getUNID(id);
}
- public Resource getResource(String unid){
+ public Resource getResource(String unid) {
return (Resource) new FlatResource(directory, unid);
}
-/* FlatContent API */
- public String[] getLanguages(){
+ /* FlatContent API */
+ public String[] getLanguages() {
return languages;
}
- public String[] getResources(){
+ public String[] getResources() {
return (new File(directory, "resource")).list();
}
- public Resource getResource(String unid, String language, String revision){
+ public Resource getResource(String unid, String language, String revision) {
return (Resource) new FlatResource(directory, unid, language, revision);
}
- public FlatRelations getRelations(String structure){
- return new FlatRelations(new File(directory, "relation" + File.separator + structure + ".xml"));
+ public FlatRelations getRelations(String structure) {
+ return new FlatRelations(new File(directory, "relation" + File.separator + structure + ".xml"));
}
}
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=617035&r1=617034&r2=617035&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 Wed Jan 30 23:44:03 2008
@@ -1,19 +1,17 @@
package org.apache.lenya.cms.content.flat;
-
import java.io.File;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import java.util.HashMap;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceNotFoundException;
-import org.apache.lenya.cms.content.Content;
-import org.apache.lenya.cms.content.Resource;
-import org.apache.lenya.cms.content.flat.index.FlatIndexPart;
import org.apache.lenya.xml.DocumentHelper;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
-
+/**
+ *
+ * @author solprovider
+ * @since 1.3
+ */
public class FlatIndex {
File configurationFile;
File indexFile;
@@ -24,16 +22,15 @@
String revision = "live";
Map filter = new HashMap();
Map include = new HashMap();
-
- public FlatIndex(FlatContent pcontent, File indexDirectory, String pindexName, String planguage){
+ 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();
+ // loadConfiguration();
}
- private void loadConfiguration(){
+ private void loadConfiguration() {
Document document;
try{
document = DocumentHelper.readDocument(configurationFile);
@@ -48,8 +45,10 @@
return;
}
Element root = document.getDocumentElement();
- if(root.hasAttribute("structure")) structure = root.getAttribute("structure");
- if(root.hasAttribute("revision")) revision = root.getAttribute("revision");
+ if(root.hasAttribute("structure"))
+ structure = root.getAttribute("structure");
+ if(root.hasAttribute("revision"))
+ revision = root.getAttribute("revision");
NodeList nl;
int length;
int i;
@@ -73,13 +72,14 @@
include.put("href", new FlatIndexPart("href"));
include.put("extension", new FlatIndexPart("extension"));
}
- public String getIndexFilename(){
- if(!indexFile.exists()) update();
+ public String getIndexFilename() {
+ if(!indexFile.exists())
+ update();
return indexFile.getPath();
}
- public void update(){
-//TODO: Add publication ID to the log.
-System.out.println("Indexer updating " + indexName + "(" + language + ")");
+ public void update() {
+ // TODO: Add publication ID to the log.
+ System.out.println("Indexer updating " + indexName + "(" + language + ")");
loadConfiguration();
// Init Document
Document document;
@@ -92,24 +92,25 @@
Element root = document.getDocumentElement();
root.setAttribute("name", indexName);
root.setAttribute("language", language);
- //Update
+ // Update
if(structure.length() > 0){
include.put("fullid", new FlatIndexPart("fullid"));
updateStructure(document, root);
- }else updateFlat(document, root);
+ }else
+ updateFlat(document, root);
// Write document
try{
org.apache.lenya.xml.DocumentHelper.writeDocument(document, indexFile);
}catch(javax.xml.transform.TransformerConfigurationException tce){
- System.out.println("FlatIndex: TransformerConfigurationException");
+ System.out.println("FlatIndex: TransformerConfigurationException");
}catch(javax.xml.transform.TransformerException te){
- System.out.println("FlatIndex: TransformerException");
+ System.out.println("FlatIndex: TransformerException");
}catch(java.io.IOException ioe){
- System.out.println("FlatIndex: IOException");
+ System.out.println("FlatIndex: IOException");
}
-//System.out.println("Indexing " + indexName + "_" + language + " Completed");
+ // System.out.println("Indexing " + indexName + "_" + language + " Completed");
}
- private void updateStructure(Document document, Element root){
+ private void updateStructure(Document document, Element root) {
FlatRelations relations = content.getRelations(structure);
Element resourceElement = relations.getRoot();
if(null == resourceElement){
@@ -118,51 +119,52 @@
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){
-// NodeList children = resourceElement.getElementsByTagName("resource"); //getDescendants, need getChildren
+ /**
+ * 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) {
+ // NodeList children = resourceElement.getElementsByTagName("resource"); //getDescendants, need getChildren
NodeList children = resourceElement.getChildNodes();
int length = children.getLength();
for(int i = 0; i < length; i++){
if(children.item(i).getNodeName().equals("resource")){
Element resourceChild = (Element) children.item(i);
String unid = resourceChild.getAttribute("unid");
- FlatResource resource =
- (FlatResource) content.getResource(unid, language, revision);
+ FlatResource resource = (FlatResource) content.getResource(unid, language, revision);
if(resource.hasRevision()){
String fullid = resourceChild.getAttribute("full");
String fulltype = parenttype + "/" + resource.getType();
String fulldoctype = parentdoctype + "/" + resource.getDocumentType();
FlatIndexPart part;
- //FILTER - BEGIN
+ // FILTER - BEGIN
Iterator fi = filter.values().iterator();
boolean useResource = true;
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)))
+ useResource = true;
}
- //FILTER - END
+ // FILTER - END
if(useResource){
- //INCLUDE - BEGIN
+ // 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(), fullid);
- if(value.length() > 0) element.setAttribute(part.getName(), value);
+ if(value.length() > 0)
+ element.setAttribute(part.getName(), value);
}
- //INCLUDE - END
+ // INCLUDE - END
addStructureResource(document, element, resourceChild, fulltype, fulldoctype);
- } //if useResource
- } //if resource not null
- } //if "resource"
- } //for
- } //function
- private void updateFlat(Document document, Element root){
+ } // if useResource
+ } // if resource not null
+ } // if "resource"
+ } // for
+ } // function
+ private void updateFlat(Document document, Element root) {
// Build Index
String[] unids = content.getResources();
int unidsLength = unids.length;
@@ -170,31 +172,33 @@
FlatResource resource = (FlatResource) content.getResource(unids[u], language, revision);
if(resource.hasRevision()){
FlatIndexPart part;
- //FILTER - BEGIN
+ // FILTER - BEGIN
Iterator fi = filter.values().iterator();
boolean useResource = true;
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
+ // FILTER - END
if(useResource){
- //INCLUDE - BEGIN
+ // INCLUDE - BEGIN
Element element = addElement(document, root, "resource");
element.setAttribute("unid", unids[u]);
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);
+ if(value.length() > 0)
+ element.setAttribute(part.getName(), value);
}
- //INCLUDE - END
- } //if useResource
- } //if resource not null
+ // INCLUDE - END
+ } // if useResource
+ } // if resource not null
}
}
- private Element addElement(Document document, Element parent, String newElementName){
+ private Element addElement(Document document, Element parent, String newElementName) {
Element newElement = document.createElement(newElementName);
parent.appendChild(newElement);
return newElement;
Copied: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatIndexPart.java (from r615136, lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/index/FlatIndexPart.java)
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatIndexPart.java?p2=lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatIndexPart.java&p1=lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/index/FlatIndexPart.java&r1=615136&r2=617035&rev=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/index/FlatIndexPart.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatIndexPart.java Wed Jan 30 23:44:03 2008
@@ -1,46 +1,59 @@
-package org.apache.lenya.cms.content.flat.index;
-
+package org.apache.lenya.cms.content.flat;
import java.util.StringTokenizer;
import org.w3c.dom.Element;
-
+/**
+ *
+ * @author solprovider
+ * @since 1.3
+ */
public class FlatIndexPart {
- String name="";
+ String name = "";
String property = "";
String value = "";
-
- public FlatIndexPart(Element element){
+ public FlatIndexPart(Element element) {
if(element.hasAttribute("property")){
property = element.getAttribute("property");
name = property;
}
- if(element.hasAttribute("name")) property = element.getAttribute("name");
-
+ if(element.hasAttribute("name"))
+ property = element.getAttribute("name");
if(null != element.getFirstChild()){
value = element.getFirstChild().getNodeValue();
- if(null == value) value = "";
+ if(null == value)
+ value = "";
}
}
- public FlatIndexPart(String variable){
+ public FlatIndexPart(String variable) {
name = variable;
property = variable;
}
- public String getName(){ return name; }
- public String getProperty(){ return property; }
- public String getValue(){ return value; }
-
- public boolean check(String test){
-//System.out.print(" T=" + test + " V=" + value);
- if(test.length() < 1) return true;
- if(test.equals("/")) return true; //Structured indexes add slash prefix.
- if(test.equalsIgnoreCase("true")) return true;
+ public String getName() {
+ return name;
+ }
+ public String getProperty() {
+ return property;
+ }
+ public String getValue() {
+ return value;
+ }
+ public boolean check(String test) {
+ // System.out.print(" T=" + test + " V=" + value);
+ if(test.length() < 1)
+ return true;
+ if(test.equals("/"))
+ return true; // Structured indexes add slash prefix.
+ if(test.equalsIgnoreCase("true"))
+ return true;
String token;
StringTokenizer tokens = new StringTokenizer(value, "|,;");
do{
token = tokens.nextToken();
- if(test.equals(token)) return true;
- if(test.endsWith(token)) return true;
+ if(test.equals(token))
+ return true;
+ if(test.endsWith(token))
+ return true;
}while(tokens.hasMoreTokens());
-//System.out.print(" FALSE ");
+ // System.out.print(" FALSE ");
return false;
}
}
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=617035&r1=617034&r2=617035&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 Wed Jan 30 23:44:03 2008
@@ -1,32 +1,31 @@
package org.apache.lenya.cms.content.flat;
-
import java.io.File;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceNotFoundException;
-import org.apache.lenya.cms.content.Content;
-import org.apache.lenya.cms.content.Resource;
-
+/**
+ *
+ * @author solprovider
+ * @since 1.3
+ */
public class FlatIndexer implements Runnable {
File indexDirectory;
FlatContent content;
boolean isCurrent = false;
-
- public FlatIndexer(File pindexDirectory, FlatContent pcontent){
+ public FlatIndexer(File pindexDirectory, FlatContent pcontent) {
indexDirectory = pindexDirectory;
content = pcontent;
}
-
- public void run(){
+ public void run() {
updateAll();
}
-
- public void updateAll(){
- if(isCurrent) return;
- if(!indexDirectory.exists()) return;
-//System.out.println("Starting Indexer UpdateAll");
+ public void updateAll() {
+ if(isCurrent)
+ return;
+ 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("FI-uA: iD=" + indexDirectory.getPath());
+ if(null == files)
+ return;
int filesLength = files.length;
for(int f = 0; f < filesLength; f++){
String filename = files[f];
@@ -43,7 +42,7 @@
}
isCurrent = true;
}
- public String getIndexFilename(String indexName, String language){
+ public String getIndexFilename(String indexName, String language) {
return (new FlatIndex(content, indexDirectory, indexName, language)).getIndexFilename();
}
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatRelations.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatRelations.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatRelations.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatRelations.java Wed Jan 30 23:44:03 2008
@@ -1,5 +1,4 @@
package org.apache.lenya.cms.content.flat;
-
import java.io.File;
import java.util.HashMap;
import java.util.Map;
@@ -7,50 +6,54 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
-
+/**
+ *
+ * @author solprovider
+ * @since 1.3
+ */
public class FlatRelations {
File file;
Document relations;
Element root;
Map map;
-
- public FlatRelations(File pfile){
+ public FlatRelations(File pfile) {
file = pfile;
reset();
}
-
- public void reset(){
+ public void reset() {
try{
relations = DocumentHelper.readDocument(file);
map = new HashMap();
root = relations.getDocumentElement();
addResourceToMap(root);
-//WORK: Log Catches properly
+ // WORK: Log Catches properly
}catch(javax.xml.parsers.ParserConfigurationException pce){
System.out.println("FlatRelations 1: Could not parse " + file.toString());
}catch(org.xml.sax.SAXException saxe){
System.out.println("FlatRelations 2: Could not parse " + file.toString());
}catch(java.io.IOException ioe){
- // File not found. Expected for non-Lenya1.3 pubs.
+ // File not found. Expected for non-Lenya1.3 pubs.
}
}
- private void addResourceToMap(Element root){
- NodeList resources = root.getElementsByTagName("resource");
- int length = resources.getLength();
- for(int i = 0; i < length; i++){
- Element resource = (Element) resources.item(i);
- map.put(resource.getAttribute("full"), resource.getAttribute("unid"));
- addResourceToMap(resource);
- }
+ private void addResourceToMap(Element root) {
+ NodeList resources = root.getElementsByTagName("resource");
+ int length = resources.getLength();
+ for(int i = 0; i < length; i++){
+ Element resource = (Element) resources.item(i);
+ map.put(resource.getAttribute("full"), resource.getAttribute("unid"));
+ addResourceToMap(resource);
+ }
+ }
+ public Element getRoot() {
+ return root;
}
- public Element getRoot(){ return root; }
- public String getUNID(String unid){
+ public String getUNID(String unid) {
update();
- if(map.containsKey(unid)) return (String) map.get(unid);
+ if(map.containsKey(unid))
+ return (String) map.get(unid);
return "";
}
- private void update(){
-//WORK: Reset if file modified
+ private void update() {
+ // WORK: Reset if file modified
}
-
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatResource.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatResource.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatResource.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatResource.java Wed Jan 30 23:44:03 2008
@@ -1,5 +1,4 @@
package org.apache.lenya.cms.content.flat;
-
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
@@ -9,368 +8,399 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
-
+/**
+ *
+ * @author solprovider
+ * @since 1.3
+ */
public class FlatResource implements Resource {
- File contentDirectory;
- File resourceDirectory;
- Document resource;
- Element root;
- String unid = "";
- String id = "";
- String type = "xml";
- String doctype = "";
- String defaultLanguage = "en";
- String defaultLanguageParameter = "";
- String defaultRevision = "live";
- String extension = "";
- String[] languages;
- boolean isChanged = false;
- public FlatResource(File directory, String punid, String language, String revision) {
- contentDirectory = directory;
- unid = punid;
- if(language.length() > 0) defaultLanguage = language;
- defaultRevision = revision;
- init(false);
- }
- public FlatResource(File directory, String punid, String language) {
- contentDirectory = directory;
- unid = punid;
- if(language.length() > 0) defaultLanguage = language;
- init(false);
- }
- public FlatResource(File directory, String punid) {
- contentDirectory = directory;
- unid = punid;
- init(true);
- }
- private void init(boolean puseDefaultLanguage) {
- boolean useDefaultLanguage = puseDefaultLanguage;
- // Check if unid_lang!revision format
- int pos = unid.lastIndexOf("!");
- if(pos > 0){
- defaultRevision = unid.substring(pos);
- unid = unid.substring(0, pos);
- }
- pos = unid.lastIndexOf("_");
- if(pos > 0){
- defaultLanguage = unid.substring(pos + 1);
- unid = unid.substring(0, pos);
- useDefaultLanguage = false;
- }
- // TODO: defaultLanguage = Publication's default language.
- resourceDirectory = new File(contentDirectory, "resource" + File.separator + unid);
- try{
- resource = DocumentHelper.readDocument(new File(resourceDirectory, "resource.xml"));
- root = resource.getDocumentElement();
- if(root.hasAttribute("defaultlanguage")){
- defaultLanguageParameter = root.getAttribute("defaultlanguage");
+ File contentDirectory;
+ File resourceDirectory;
+ Document resource;
+ Element root;
+ String unid = "";
+ String id = "";
+ String type = "xml";
+ String doctype = "";
+ String defaultLanguage = "en";
+ String defaultLanguageParameter = "";
+ String defaultRevision = "live";
+ String extension = "";
+ String[] languages;
+ boolean isChanged = false;
+ public FlatResource(File directory, String punid, String language, String revision) {
+ contentDirectory = directory;
+ unid = punid;
+ if(language.length() > 0)
+ defaultLanguage = language;
+ defaultRevision = revision;
+ init(false);
+ }
+ public FlatResource(File directory, String punid, String language) {
+ contentDirectory = directory;
+ unid = punid;
+ if(language.length() > 0)
+ defaultLanguage = language;
+ init(false);
+ }
+ public FlatResource(File directory, String punid) {
+ contentDirectory = directory;
+ unid = punid;
+ init(true);
+ }
+ private void init(boolean puseDefaultLanguage) {
+ boolean useDefaultLanguage = puseDefaultLanguage;
+ // Check if unid_lang!revision format
+ int pos = unid.lastIndexOf("!");
+ if(pos > 0){
+ defaultRevision = unid.substring(pos);
+ unid = unid.substring(0, pos);
+ }
+ pos = unid.lastIndexOf("_");
+ if(pos > 0){
+ defaultLanguage = unid.substring(pos + 1);
+ unid = unid.substring(0, pos);
+ useDefaultLanguage = false;
+ }
+ // TODO: defaultLanguage = Publication's default language.
+ resourceDirectory = new File(contentDirectory, "resource" + File.separator + unid);
+ try{
+ resource = DocumentHelper.readDocument(new File(resourceDirectory, "resource.xml"));
+ root = resource.getDocumentElement();
+ if(root.hasAttribute("defaultlanguage")){
+ defaultLanguageParameter = root.getAttribute("defaultlanguage");
+ }
+ if(useDefaultLanguage){
+ if(defaultLanguageParameter.length() > 0){
+ defaultLanguage = defaultLanguageParameter;
+ }else{
+ // TODO: Use Publication's Default Language
}
- if(useDefaultLanguage){
- if(defaultLanguageParameter.length() > 0){
- defaultLanguage = defaultLanguageParameter;
- }else{
- // TODO: Use Publication's Default Language
- }
+ }
+ if(root.hasAttribute("doctype"))
+ doctype = root.getAttribute("doctype");
+ if(root.hasAttribute("type"))
+ type = root.getAttribute("type");
+ if(root.hasAttribute("id"))
+ id = root.getAttribute("id");
+ String[] files = resourceDirectory.list();
+ int length = files.length;
+ List list = new ArrayList();
+ for(int i = 0; i < length; i++){
+ File file = new File(resourceDirectory, files[i]);
+ if(file.isDirectory())
+ list.add(files[i]);
+ }
+ languages = (String[]) list.toArray(new String[0]);
+ Arrays.sort(languages);
+ }catch(javax.xml.parsers.ParserConfigurationException pce){
+ }catch(org.xml.sax.SAXException saxe){
+ }catch(java.io.IOException ioe){
+ }
+ }
+ public String getURI() {
+ return getTranslation(defaultLanguage).getURI();
+ }
+ public String getMetaURI() {
+ return getTranslation(defaultLanguage).getMetaURI();
+ }
+ public String getNewURI() {
+ return getTranslation(defaultLanguage).getNewURI();
+ }
+ public String getUNID() {
+ return unid;
+ }
+ public String getID() {
+ return id;
+ }
+ public String getType() {
+ return type;
+ }
+ public String getDocumentType() {
+ return doctype;
+ }
+ public String getLanguage() {
+ return defaultLanguage;
+ }
+ // Maintain separately?
+ public String getDefaultLanguage() {
+ return defaultLanguage;
+ }
+ public String[] getLanguages() {
+ return languages;
+ }
+ /**
+ * Get Navigation Title from live revision of current language.
+ */
+ public String getTitle() {
+ return getTitle(defaultLanguage, defaultRevision);
+ }
+ /**
+ * Get Navigation Title from live revision of specified language.
+ */
+ public String getTitle(String language) {
+ return getTitle(language, defaultRevision);
+ }
+ /**
+ * Get Navigation Title from specified revision of specified language.
+ */
+ public String getTitle(String language, String revision) {
+ try{
+ return getTranslation(language).getRevision(revision).getTitle();
+ }catch(java.lang.NullPointerException npe){
+ System.out.println("FlatResource.getTitle NullPointerException UNID=" + unid);
+ return "";
+ }
+ }
+ public String getExtension() {
+ return getTranslation().getExtension();
+ }
+ public String getHREF() {
+ return getTranslation().getHREF();
+ }
+ /**
+ * Get variable for Index Filters
+ */
+ public String get(String property, String fullid, String fulltype, String fulldoctype) {
+ if(property.equalsIgnoreCase("type")){
+ return fulltype;
+ }else if(property.equalsIgnoreCase("doctype")){
+ return fulldoctype;
+ }
+ return get(property, fullid);
+ }
+ /**
+ * Get variable for Structured Index Filters
+ */
+ public String get(String property, String fullid) {
+ if(property.equalsIgnoreCase("fullid")){
+ return fullid;
+ }
+ return get(property);
+ }
+ /**
+ * Get variable for Flat Index Includes
+ */
+ public String get(String property) {
+ if(property.equalsIgnoreCase("unid")){
+ return getUNID();
+ }else if(property.equalsIgnoreCase("id")){
+ return getID();
+ }else if(property.equalsIgnoreCase("type")){
+ return getType();
+ }else if(property.equalsIgnoreCase("doctype")){
+ return getDocumentType();
+ }else if(property.equalsIgnoreCase("extension")){
+ return getExtension();
+ }else if(property.equalsIgnoreCase("title")){
+ return getTitle();
+ }else if(property.equalsIgnoreCase("language")){
+ return getLanguage();
+ }else if(property.equalsIgnoreCase("fullid")){
+ return getID();
+ }else if(property.equalsIgnoreCase("href")){
+ return getHREF();
+ }
+ return getXPath(property);
+ }
+ private String getXPath(String property) {
+ return "";
+ }
+ public FlatTranslation getTranslation() {
+ return getTranslation(defaultLanguage, true);
+ }
+ public FlatTranslation getTranslation(String language) {
+ return getTranslation(language, true);
+ }
+ public FlatTranslation getTranslation(String language, boolean allowDefaultLanguage) {
+ if(allowDefaultLanguage){
+ return new FlatTranslation(resourceDirectory, language, defaultRevision, defaultLanguage);
+ }else
+ return new FlatTranslation(resourceDirectory, language, defaultRevision);
+ }
+ public boolean hasRevision() {
+ FlatTranslation translation = getTranslation(defaultLanguage, false);
+ if(null == translation)
+ return false;
+ FlatRevision revision = translation.getRevision(defaultRevision);
+ if(null == revision)
+ return false;
+ // DEV TEST
+ // boolean exists = revision.exists();
+ // if(getTitle().length() < 1){
+ // System.out.println("Exists=" + exists + " U=" + unid + " L=" + defaultLanguage + " R=" + defaultRevision);
+ // return false;
+ // }
+ try{
+ return getTranslation(defaultLanguage, false).getRevision(defaultRevision).exists();
+ }catch(java.lang.NullPointerException npe){
+ return false;
+ }
+ }
+ public Document getInfoDocument() {
+ Document document;
+ try{
+ document = org.apache.lenya.xml.DocumentHelper.createDocument("", "resource", null);
+ }catch(javax.xml.parsers.ParserConfigurationException pce){
+ System.out.println("Resource InfoDocument: ParserConfigurationException");
+ return (Document) null;
+ }
+ Element root = document.getDocumentElement();
+ root.setAttribute("unid", unid);
+ root.setAttribute("type", type);
+ root.setAttribute("id", id);
+ if(defaultLanguageParameter.length() > 0)
+ root.setAttribute("defaultlanguage", defaultLanguageParameter);
+ if(doctype.length() > 0)
+ root.setAttribute("doctype", doctype);
+ String tmp;
+ for(int l = 0; l < languages.length; l++){
+ Element te = addElement(document, root, "translation");
+ te.setAttribute("language", languages[l]);
+ FlatTranslation translation = getTranslation(languages[l]);
+ tmp = translation.getEdit();
+ if(tmp.length() > 0)
+ te.setAttribute("edit", tmp);
+ tmp = translation.getLive();
+ if(tmp.length() > 0)
+ te.setAttribute("live", tmp);
+ String[] revisions = translation.getRevisions();
+ for(int r = 0; r < revisions.length; r++){
+ Element re = addElement(document, te, "revision");
+ re.setAttribute("revision", revisions[r]);
+ FlatRevision revision = translation.getRevision(revisions[r]);
+ tmp = revision.getTitle();
+ if(tmp.length() > 0)
+ re.setAttribute("title", tmp);
+ tmp = revision.getExtension();
+ if(tmp.length() > 0)
+ re.setAttribute("extension", tmp);
+ tmp = revision.getHREF();
+ if(tmp.length() > 0)
+ re.setAttribute("href", tmp);
+ }
+ }
+ return document;
+ }
+ /* Used by getInfoDocument() */
+ private Element addElement(Document document, Element parent, String newElementName) {
+ Element newElement = document.createElement(newElementName);
+ parent.appendChild(newElement);
+ return newElement;
+ }
+ public Document update(Document document) {
+ // System.out.println("FlatResource.update - BEGIN");
+ Element root = document.getDocumentElement();
+ if(root.hasAttribute("id"))
+ setID(root.getAttribute("id"));
+ if(root.hasAttribute("defaultlanguage"))
+ setDefaultLanguage(root.getAttribute("defaultlanguage"));
+ save();
+ NodeList translations = root.getElementsByTagName("translation");
+ int translationslength = translations.getLength();
+ FlatTranslation ft = null;
+ for(int t = 0; t < translationslength; t++){
+ Element translation = (Element) translations.item(t);
+ String language = translation.getAttribute("language");
+ boolean exist = true;
+ if(translation.hasAttribute("action")){
+ String action = translation.getAttribute("action");
+ if(action.equalsIgnoreCase("delete")){
+ System.out.println("FlatResource.update - Delete Translation");
+ deleteTranslation(language);
+ exist = false;
}
- if(root.hasAttribute("doctype")) doctype = root.getAttribute("doctype");
- if(root.hasAttribute("type")) type = root.getAttribute("type");
- if(root.hasAttribute("id")) id = root.getAttribute("id");
- String[] files = resourceDirectory.list();
- int length = files.length;
- int count = 0;
- List list = new ArrayList();
- for(int i = 0; i < length; i++){
- File file = new File(resourceDirectory, files[i]);
- if(file.isDirectory()) list.add(files[i]);
+ }
+ // System.out.println("FlatResource.update - Get translation");
+ if(exist){
+ ft = getTranslation(language, false);
+ if(null == ft)
+ exist = false;
+ }
+ // System.out.println("FlatResource.update - Update Translation");
+ if(exist){
+ if(translation.hasAttribute("live"))
+ ft.setLive(translation.getAttribute("live"));
+ if(translation.hasAttribute("edit"))
+ ft.setEdit(translation.getAttribute("edit"));
+ NodeList revisions = translation.getElementsByTagName("revision");
+ int revisionslength = revisions.getLength();
+ for(int r = 0; r < revisionslength; r++){
+ System.out.println("FlatResource.update - BEFORE");
+ Element revision = (Element) revisions.item(r);
+ System.out.println("FlatResource.update - AFTER");
+ if(revision.hasAttribute("action")){
+ String action = revision.getAttribute("action");
+ if(action.equalsIgnoreCase("delete")){
+ System.out.println("FlatResource.update - Delete Revision");
+ String revisionid = revision.getAttribute("revision");
+ ft.deleteRevision(revisionid);
+ }
+ }
}
- languages = (String[]) list.toArray(new String[0]);
- Arrays.sort(languages);
- }catch(javax.xml.parsers.ParserConfigurationException pce){
- }catch(org.xml.sax.SAXException saxe){
- }catch(java.io.IOException ioe){
- }
- }
- public String getURI() {
- return getTranslation(defaultLanguage).getURI();
- }
- public String getMetaURI() {
- return getTranslation(defaultLanguage).getMetaURI();
- }
- public String getNewURI() {
- return getTranslation(defaultLanguage).getNewURI();
- }
- public String getUNID() {
- return unid;
- }
- public String getID() {
- return id;
- }
- public String getType() {
- return type;
- }
- public String getDocumentType() {
- return doctype;
- }
- public String getLanguage() {
- return defaultLanguage;
- }
- // Maintain separately?
- public String getDefaultLanguage() {
- return defaultLanguage;
- }
- public String[] getLanguages() {
- return languages;
- }
- /**
- * Get Navigation Title from live revision of current language.
- */
- public String getTitle() {
- return getTitle(defaultLanguage, defaultRevision);
- }
- /**
- * Get Navigation Title from live revision of specified language.
- */
- public String getTitle(String language) {
- return getTitle(language, defaultRevision);
- }
- /**
- * Get Navigation Title from specified revision of specified language.
- */
- public String getTitle(String language, String revision) {
- try{
- return getTranslation(language).getRevision(revision).getTitle();
- }catch(java.lang.NullPointerException npe){
- System.out.println("FlatResource.getTitle NullPointerException UNID=" + unid);
- return "";
- }
- }
- public String getExtension() {
- return getTranslation().getExtension();
- }
- public String getHREF() {
- return getTranslation().getHREF();
- }
- /**
- * Get variable for Index Filters
- */
- public String get(String property, String fullid, String fulltype, String fulldoctype) {
- if(property.equalsIgnoreCase("type")){
- return fulltype;
- }else if(property.equalsIgnoreCase("doctype")){ return fulldoctype; }
- return get(property, fullid);
- }
- /**
- * Get variable for Structured Index Filters
- */
- public String get(String property, String fullid) {
- if(property.equalsIgnoreCase("fullid")){ return fullid; }
- return get(property);
- }
- /**
- * Get variable for Flat Index Includes
- */
- public String get(String property) {
- if(property.equalsIgnoreCase("unid")){
- return getUNID();
- }else if(property.equalsIgnoreCase("id")){
- return getID();
- }else if(property.equalsIgnoreCase("type")){
- return getType();
- }else if(property.equalsIgnoreCase("doctype")){
- return getDocumentType();
- }else if(property.equalsIgnoreCase("extension")){
- return getExtension();
- }else if(property.equalsIgnoreCase("title")){
- return getTitle();
- }else if(property.equalsIgnoreCase("language")){
- return getLanguage();
- }else if(property.equalsIgnoreCase("fullid")){
- return getID();
- }else if(property.equalsIgnoreCase("href")){ return getHREF(); }
- return getXPath(property);
- }
- private String getXPath(String property) {
- return "";
- }
- public FlatTranslation getTranslation() {
- return getTranslation(defaultLanguage, true);
- }
- public FlatTranslation getTranslation(String language) {
- return getTranslation(language, true);
- }
- public FlatTranslation getTranslation(String language, boolean allowDefaultLanguage) {
- if(allowDefaultLanguage){
- return new FlatTranslation(resourceDirectory, language, defaultRevision, defaultLanguage);
- }else return new FlatTranslation(resourceDirectory, language, defaultRevision);
- }
- public boolean hasRevision() {
- FlatTranslation translation = getTranslation(defaultLanguage, false);
- if(null == translation) return false;
- FlatRevision revision = translation.getRevision(defaultRevision);
- if(null == revision) return false;
- boolean exists = revision.exists();
- // DEV TEST
- // if(getTitle().length() < 1){
- // System.out.println("Exists=" + exists + " U=" + unid + " L=" + defaultLanguage + " R=" + defaultRevision);
- // return false;
- // }
- try{
- return getTranslation(defaultLanguage, false).getRevision(defaultRevision).exists();
- }catch(java.lang.NullPointerException npe){
- return false;
- }
- }
- public Document getInfoDocument() {
- Document document;
- try{
- document = org.apache.lenya.xml.DocumentHelper.createDocument("", "resource", null);
- }catch(javax.xml.parsers.ParserConfigurationException pce){
- System.out.println("Resource InfoDocument: ParserConfigurationException");
- return (Document) null;
- }
- Element root = document.getDocumentElement();
- root.setAttribute("unid", unid);
- root.setAttribute("type", type);
- root.setAttribute("id", id);
- if(defaultLanguageParameter.length() > 0) root.setAttribute("defaultlanguage", defaultLanguageParameter);
- if(doctype.length() > 0) root.setAttribute("doctype", doctype);
- String tmp;
- for(int l = 0; l < languages.length; l++){
- Element te = addElement(document, root, "translation");
- te.setAttribute("language", languages[l]);
- FlatTranslation translation = getTranslation(languages[l]);
- tmp = translation.getEdit();
- if(tmp.length() > 0) te.setAttribute("edit", tmp);
- tmp = translation.getLive();
- if(tmp.length() > 0) te.setAttribute("live", tmp);
- String[] revisions = translation.getRevisions();
- for(int r = 0; r < revisions.length; r++){
- Element re = addElement(document, te, "revision");
- re.setAttribute("revision", revisions[r]);
- FlatRevision revision = translation.getRevision(revisions[r]);
- tmp = revision.getTitle();
- if(tmp.length() > 0) re.setAttribute("title", tmp);
- tmp = revision.getExtension();
- if(tmp.length() > 0) re.setAttribute("extension", tmp);
- tmp = revision.getHREF();
- if(tmp.length() > 0) re.setAttribute("href", tmp);
- }
- }
- return document;
- }
- /* Used by getInfoDocument() */
- private Element addElement(Document document, Element parent, String newElementName) {
- Element newElement = document.createElement(newElementName);
- parent.appendChild(newElement);
- return newElement;
- }
- public Document update(Document document) {
- // System.out.println("FlatResource.update - BEGIN");
- Element root = document.getDocumentElement();
- if(root.hasAttribute("id")) setID(root.getAttribute("id"));
- if(root.hasAttribute("defaultlanguage")) setDefaultLanguage(root.getAttribute("defaultlanguage"));
- save();
- NodeList translations = root.getElementsByTagName("translation");
- int translationslength = translations.getLength();
- FlatTranslation ft = null;
- for(int t = 0; t < translationslength; t++){
- Element translation = (Element) translations.item(t);
- String language = translation.getAttribute("language");
- boolean exist = true;
- if(translation.hasAttribute("action")){
- String action = translation.getAttribute("action");
- if(action.equalsIgnoreCase("delete")){
- System.out.println("FlatResource.update - Delete Translation");
- deleteTranslation(language);
- exist = false;
- }
- }
- // System.out.println("FlatResource.update - Get translation");
- if(exist){
- ft = getTranslation(language, false);
- if(null == ft) exist = false;
- }
- // System.out.println("FlatResource.update - Update Translation");
- if(exist){
- if(translation.hasAttribute("live")) ft.setLive(translation.getAttribute("live"));
- if(translation.hasAttribute("edit")) ft.setEdit(translation.getAttribute("edit"));
- NodeList revisions = translation.getElementsByTagName("revision");
- int revisionslength = revisions.getLength();
- for(int r = 0; r < revisionslength; r++){
- System.out.println("FlatResource.update - BEFORE");
- Element revision = (Element) revisions.item(r);
- System.out.println("FlatResource.update - AFTER");
- if(revision.hasAttribute("action")){
- String action = revision.getAttribute("action");
- if(action.equalsIgnoreCase("delete")){
- System.out.println("FlatResource.update - Delete Revision");
- String revisionid = revision.getAttribute("revision");
- ft.deleteRevision(revisionid);
- }
- }
- }
- ft.save();
- }
- }
- // System.out.println("FlatResource.update - RETURN");
- return document;
- }
- private void setID(String newid) {
- if(!id.equals(newid)){
- // id = newid;
- // TODO: Must update Structures
- }
- // isChanged = true;
- }
- private void setDefaultLanguage(String language) {
- defaultLanguageParameter = language;
- defaultLanguage = language;
- isChanged = true;
- }
- private void deleteTranslation(String language) {
- File translationDirectory = new File(resourceDirectory, language);
- System.out.println("DELETE=" + translationDirectory.getAbsolutePath());
- deleteFile(translationDirectory);
- }
- // TODO: Backup before delete. Use renameTo() to move outside the resource directory.
- private void deleteFile(File file) {
- if(!file.exists()) return;
- if(file.isDirectory()){
- File[] files = file.listFiles();
- for(int f = 0; f < files.length; f++)
- deleteFile(files[f]);
- }
- file.delete();
- }
- private void save() {
- if(isChanged){
- File file = new File(resourceDirectory, "resource.xml");
- Document doc;
- try{
- doc = DocumentHelper.readDocument(file);
- }catch(javax.xml.parsers.ParserConfigurationException pce){
- System.out.println("FlatResource.save - ParserConfigurationException:" + file.getAbsolutePath());
- return;
- }catch(org.xml.sax.SAXException saxe){
- System.out.println("FlatResource.save - SAXException:" + file.getAbsolutePath());
- return;
- }catch(java.io.IOException ioe){
- System.out.println("FlatResource.save - Could not read file:" + file.getAbsolutePath());
- return;
- }
- root = doc.getDocumentElement();
- root.setAttribute("defaultlanguage", defaultLanguageParameter);
- root.setAttribute("id", id);
- try{
- DocumentHelper.writeDocument(doc, file);
- }catch(javax.xml.transform.TransformerConfigurationException tce){
- System.out.println("FlatResource.save - TransformerConfigurationException:" + file.getAbsolutePath());
- }catch(javax.xml.transform.TransformerException te){
- System.out.println("FlatResource.save - TransformerException:" + file.getAbsolutePath());
- }catch(java.io.IOException ioe2){
- System.out.println("FlatResource.save - Could not write file:" + file.getAbsolutePath());
- }
- }
- isChanged = false;
- }
+ ft.save();
+ }
+ }
+ // System.out.println("FlatResource.update - RETURN");
+ return document;
+ }
+ private void setID(String newid) {
+ if(!id.equals(newid)){
+ // id = newid;
+ // TODO: Must update Structures
+ }
+ // isChanged = true;
+ }
+ private void setDefaultLanguage(String language) {
+ defaultLanguageParameter = language;
+ defaultLanguage = language;
+ isChanged = true;
+ }
+ private void deleteTranslation(String language) {
+ File translationDirectory = new File(resourceDirectory, language);
+ System.out.println("DELETE=" + translationDirectory.getAbsolutePath());
+ deleteFile(translationDirectory);
+ }
+ // TODO: Backup before delete. Use renameTo() to move outside the resource directory.
+ private void deleteFile(File file) {
+ if(!file.exists())
+ return;
+ if(file.isDirectory()){
+ File[] files = file.listFiles();
+ for(int f = 0; f < files.length; f++)
+ deleteFile(files[f]);
+ }
+ file.delete();
+ }
+ private void save() {
+ if(isChanged){
+ File file = new File(resourceDirectory, "resource.xml");
+ Document doc;
+ try{
+ doc = DocumentHelper.readDocument(file);
+ }catch(javax.xml.parsers.ParserConfigurationException pce){
+ System.out.println("FlatResource.save - ParserConfigurationException:" + file.getAbsolutePath());
+ return;
+ }catch(org.xml.sax.SAXException saxe){
+ System.out.println("FlatResource.save - SAXException:" + file.getAbsolutePath());
+ return;
+ }catch(java.io.IOException ioe){
+ System.out.println("FlatResource.save - Could not read file:" + file.getAbsolutePath());
+ return;
+ }
+ root = doc.getDocumentElement();
+ root.setAttribute("defaultlanguage", defaultLanguageParameter);
+ root.setAttribute("id", id);
+ try{
+ DocumentHelper.writeDocument(doc, file);
+ }catch(javax.xml.transform.TransformerConfigurationException tce){
+ System.out.println("FlatResource.save - TransformerConfigurationException:" + file.getAbsolutePath());
+ }catch(javax.xml.transform.TransformerException te){
+ System.out.println("FlatResource.save - TransformerException:" + file.getAbsolutePath());
+ }catch(java.io.IOException ioe2){
+ System.out.println("FlatResource.save - Could not write file:" + file.getAbsolutePath());
+ }
+ }
+ isChanged = false;
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatRevision.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatRevision.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatRevision.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatRevision.java Wed Jan 30 23:44:03 2008
@@ -1,12 +1,13 @@
package org.apache.lenya.cms.content.flat;
-
import java.io.File;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceNotFoundException;
import org.apache.lenya.xml.DocumentHelper;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-
+/**
+ *
+ * @author solprovider
+ * @since 1.3
+ */
public class FlatRevision {
File translationDirectory;
File file;
@@ -17,44 +18,47 @@
String href = "";
Document resource;
Element root;
-
- public FlatRevision(File directory, String prevision){
+ public FlatRevision(File directory, String prevision) {
translationDirectory = directory;
revision = prevision;
init();
}
- private void init(){
+ private void init() {
try{
metafile = new File(translationDirectory, revision + ".xml");
resource = DocumentHelper.readDocument(metafile);
root = resource.getDocumentElement();
- if(root.hasAttribute("title")) title = root.getAttribute("title");
- if(root.hasAttribute("extension")) extension = root.getAttribute("extension");
- if(root.hasAttribute("href")) href = root.getAttribute("href");
+ if(root.hasAttribute("title"))
+ title = root.getAttribute("title");
+ if(root.hasAttribute("extension"))
+ extension = root.getAttribute("extension");
+ if(root.hasAttribute("href"))
+ href = root.getAttribute("href");
}catch(javax.xml.parsers.ParserConfigurationException pce){
}catch(org.xml.sax.SAXException saxe){
}catch(java.io.IOException ioe){
}
if(extension.length() > 0){
file = new File(translationDirectory, revision + "." + extension);
- }else file = metafile;
+ }else
+ file = metafile;
}
- public String getTitle(){
+ public String getTitle() {
return title;
}
- public String getExtension(){
+ public String getExtension() {
return extension;
}
- public String getHREF(){
+ public String getHREF() {
return href;
}
- public String getURI(){
+ public String getURI() {
return file.getPath();
}
- public String getMetaURI(){
+ public String getMetaURI() {
return metafile.getPath();
}
- public boolean exists(){
+ public boolean exists() {
return file.exists();
}
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatTranslation.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatTranslation.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatTranslation.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/FlatTranslation.java Wed Jan 30 23:44:03 2008
@@ -1,197 +1,208 @@
package org.apache.lenya.cms.content.flat;
-
import java.io.File;
import java.util.SortedSet;
import java.util.TreeSet;
import org.apache.lenya.xml.DocumentHelper;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-
+/**
+ *
+ * @author solprovider
+ * @since 1.3
+ */
public class FlatTranslation {
- File resourceDirectory;
- File translationDirectory;
- String language = "en";
- String defaultLanguage = "en";
- String live = "";
- String edit = "last";
- String revision = "live";
- Document document;
- Element root;
- FlatRevision fr;
- boolean initRevisions = false;
- SortedSet revisions = new TreeSet();
- boolean isChanged = false;
- public FlatTranslation(File directory, String planguage, String prevision, String pdefaultLanguage) {
- resourceDirectory = directory;
- language = planguage;
- defaultLanguage = pdefaultLanguage;
- revision = prevision;
- init();
- }
- public FlatTranslation(File directory, String planguage, String prevision) {
- resourceDirectory = directory;
- language = planguage;
- revision = prevision;
- defaultLanguage = planguage; // Set to publication's default
- init();
- }
- public FlatTranslation(File directory, String planguage) {
- resourceDirectory = directory;
- language = planguage;
- defaultLanguage = planguage; // Set to publication's default
- init();
- }
- private void init() {
- translationDirectory = new File(resourceDirectory, language);
- if(!translationDirectory.exists()) translationDirectory = new File(resourceDirectory, defaultLanguage);
- if(!translationDirectory.exists()) return;
- File translationFile = new File(translationDirectory, "translation.xml");
- if(translationFile.exists()){
- try{
- document = DocumentHelper.readDocument(translationFile);
- root = document.getDocumentElement();
- if(root.hasAttribute("live")) live = root.getAttribute("live");
- if(root.hasAttribute("edit")) edit = root.getAttribute("edit");
- }catch(javax.xml.parsers.ParserConfigurationException pce){
- System.out.println("FlatTranslation - ParserConfigurationException: " + translationFile.getAbsolutePath());
- }catch(org.xml.sax.SAXException saxe){
- System.out.println("FlatTranslation - SAXException: " + translationFile.getAbsolutePath());
- }catch(java.io.IOException ioe){
- System.out.println("FlatTranslation - IOException: " + translationFile.getAbsolutePath());
- }
- }else{
- try{
- document = DocumentHelper.createDocument("", "translation", null);
- }catch(javax.xml.parsers.ParserConfigurationException pce){
- System.out.println("New FlatTranslation - ParserConfigurationException:" + translationFile.getAbsolutePath());
- return;
- }
+ File resourceDirectory;
+ File translationDirectory;
+ String language = "en";
+ String defaultLanguage = "en";
+ String live = "";
+ String edit = "last";
+ String revision = "live";
+ Document document;
+ Element root;
+ FlatRevision fr;
+ boolean initRevisions = false;
+ SortedSet revisions = new TreeSet();
+ boolean isChanged = false;
+ public FlatTranslation(File directory, String planguage, String prevision, String pdefaultLanguage) {
+ resourceDirectory = directory;
+ language = planguage;
+ defaultLanguage = pdefaultLanguage;
+ revision = prevision;
+ init();
+ }
+ public FlatTranslation(File directory, String planguage, String prevision) {
+ resourceDirectory = directory;
+ language = planguage;
+ revision = prevision;
+ defaultLanguage = planguage; // Set to publication's default
+ init();
+ }
+ public FlatTranslation(File directory, String planguage) {
+ resourceDirectory = directory;
+ language = planguage;
+ defaultLanguage = planguage; // Set to publication's default
+ init();
+ }
+ private void init() {
+ translationDirectory = new File(resourceDirectory, language);
+ if(!translationDirectory.exists())
+ translationDirectory = new File(resourceDirectory, defaultLanguage);
+ if(!translationDirectory.exists())
+ return;
+ File translationFile = new File(translationDirectory, "translation.xml");
+ if(translationFile.exists()){
+ try{
+ document = DocumentHelper.readDocument(translationFile);
root = document.getDocumentElement();
- root.setAttribute("language", language);
- isChanged = true;
- }
- }
- public String[] getRevisions() {
- if(!initRevisions){
- String[] filelist = translationDirectory.list();
- for(int f = 0; f < filelist.length; f++){
- String filename = filelist[f];
- int pos = filename.lastIndexOf(".");
- if(pos > 0) filename = filename.substring(0, pos);
- if(!filename.equalsIgnoreCase("translation")) revisions.add(filename);
- }
- initRevisions = true;
- }
- return (String[]) revisions.toArray(new String[0]);
- }
- public String getLive() {
- return live;
- }
- public String getEdit() {
- return edit;
- }
- public String getURI() {
- if(null == fr) fr = getRevision();
- if(null == fr) return "";
- return fr.getURI();
- }
- public String getMetaURI() {
- if(null == fr) fr = getRevision();
- if(null == fr) return "";
- return fr.getMetaURI();
- }
- public String getNewURI() {
- String newRevision = getDateString();
- // WORK: Change Edit to newRevision
- return new File(translationDirectory, newRevision + ".xml").getPath();
- }
- public String getExtension() {
- if(null == fr) fr = getRevision();
- if(null == fr) return "";
- return fr.getExtension();
- }
- public String getHREF() {
- if(null == fr) fr = getRevision();
- if(null == fr) return "";
- return fr.getHREF();
- }
- public FlatRevision getRevision() {
- return getRevision(revision);
- }
- public FlatRevision getRevision(String prevision) {
- String rev = prevision;
- if(rev.equalsIgnoreCase("edit")){
- if(edit.length() > 0){
- rev = edit;
- }else rev = live;
- }
- if(rev.equalsIgnoreCase("live")) rev = live;
- try{
- if(rev.equalsIgnoreCase("last")) rev = (String) revisions.last();
- if(rev.equalsIgnoreCase("first")) rev = (String) revisions.first();
- }catch(java.util.NoSuchElementException nsee){
- return null;
- }
- if(null == rev) return null;
- if(rev.length() < 1) return null;
- return new FlatRevision(translationDirectory, rev);
- }
- private String getDateString() {
- return Long.toString(new java.util.Date().getTime());
- }
- void setLive(String revision) {
- live = revision;
- isChanged = true;
- }
- void setEdit(String revision) {
- edit = revision;
- isChanged = true;
- }
- void save() {
- if(isChanged){
- File file = new File(translationDirectory, "translation.xml");
- /*
- Document doc;
- try{
- doc = DocumentHelper.readDocument(file);
- }catch(javax.xml.parsers.ParserConfigurationException pce){
- System.out.println("FlatTranslation.save - ParserConfigurationException:" + file.getAbsolutePath());
- return;
- }catch(org.xml.sax.SAXException saxe){
- System.out.println("FlatTranslation.save - SAXException:" + file.getAbsolutePath());
- return;
- }catch(java.io.IOException ioe){
- System.out.println("FlatTranslation.save - Could not read file:" + file.getAbsolutePath());
- return;
- }
- root = doc.getDocumentElement();
- */
- root.setAttribute("live", live);
- root.setAttribute("edit", edit);
- try{
- // DocumentHelper.writeDocument(doc, file);
- DocumentHelper.writeDocument(document, file);
- }catch(javax.xml.transform.TransformerConfigurationException tce){
- System.out.println("FlatTranslation.save - TransformerConfigurationException:" + file.getAbsolutePath());
- }catch(javax.xml.transform.TransformerException te){
- System.out.println("FlatTranslation.save - TransformerException:" + file.getAbsolutePath());
- }catch(java.io.IOException ioe2){
- System.out.println("FlatTranslation.save - Could not write file:" + file.getAbsolutePath());
- }
- }
- isChanged = false;
- }
- void deleteRevision(String revision) {
- FlatRevision fr = getRevision(revision);
- String extension = fr.getExtension();
- // TODO: Backup before delete. Use renameTo() to move outside the resource directory.
- File file = new File(translationDirectory, revision + ".xml");
- if(file.exists()){
- file.delete();
- if(extension.length() > 0){
- file = new File(translationDirectory, revision + "." + extension);
- if(file.exists()) file.delete();
- }
- }
- }
+ if(root.hasAttribute("live"))
+ live = root.getAttribute("live");
+ if(root.hasAttribute("edit"))
+ edit = root.getAttribute("edit");
+ }catch(javax.xml.parsers.ParserConfigurationException pce){
+ System.out.println("FlatTranslation - ParserConfigurationException: " + translationFile.getAbsolutePath());
+ }catch(org.xml.sax.SAXException saxe){
+ System.out.println("FlatTranslation - SAXException: " + translationFile.getAbsolutePath());
+ }catch(java.io.IOException ioe){
+ System.out.println("FlatTranslation - IOException: " + translationFile.getAbsolutePath());
+ }
+ }else{
+ try{
+ document = DocumentHelper.createDocument("", "translation", null);
+ }catch(javax.xml.parsers.ParserConfigurationException pce){
+ System.out.println("New FlatTranslation - ParserConfigurationException:" + translationFile.getAbsolutePath());
+ return;
+ }
+ root = document.getDocumentElement();
+ root.setAttribute("language", language);
+ isChanged = true;
+ }
+ }
+ public String[] getRevisions() {
+ if(!initRevisions){
+ String[] filelist = translationDirectory.list();
+ for(int f = 0; f < filelist.length; f++){
+ String filename = filelist[f];
+ int pos = filename.lastIndexOf(".");
+ if(pos > 0)
+ filename = filename.substring(0, pos);
+ if(!filename.equalsIgnoreCase("translation"))
+ revisions.add(filename);
+ }
+ initRevisions = true;
+ }
+ return (String[]) revisions.toArray(new String[0]);
+ }
+ public String getLive() {
+ return live;
+ }
+ public String getEdit() {
+ return edit;
+ }
+ public String getURI() {
+ if(null == fr)
+ fr = getRevision();
+ if(null == fr)
+ return "";
+ return fr.getURI();
+ }
+ public String getMetaURI() {
+ if(null == fr)
+ fr = getRevision();
+ if(null == fr)
+ return "";
+ return fr.getMetaURI();
+ }
+ public String getNewURI() {
+ String newRevision = getDateString();
+ // WORK: Change Edit to newRevision
+ return new File(translationDirectory, newRevision + ".xml").getPath();
+ }
+ public String getExtension() {
+ if(null == fr)
+ fr = getRevision();
+ if(null == fr)
+ return "";
+ return fr.getExtension();
+ }
+ public String getHREF() {
+ if(null == fr)
+ fr = getRevision();
+ if(null == fr)
+ return "";
+ return fr.getHREF();
+ }
+ public FlatRevision getRevision() {
+ return getRevision(revision);
+ }
+ public FlatRevision getRevision(String prevision) {
+ String rev = prevision;
+ if(rev.equalsIgnoreCase("edit")){
+ if(edit.length() > 0){
+ rev = edit;
+ }else
+ rev = live;
+ }
+ if(rev.equalsIgnoreCase("live"))
+ rev = live;
+ try{
+ if(rev.equalsIgnoreCase("last"))
+ rev = (String) revisions.last();
+ if(rev.equalsIgnoreCase("first"))
+ rev = (String) revisions.first();
+ }catch(java.util.NoSuchElementException nsee){
+ return null;
+ }
+ if(null == rev)
+ return null;
+ if(rev.length() < 1)
+ return null;
+ return new FlatRevision(translationDirectory, rev);
+ }
+ private String getDateString() {
+ return Long.toString(new java.util.Date().getTime());
+ }
+ void setLive(String revision) {
+ live = revision;
+ isChanged = true;
+ }
+ void setEdit(String revision) {
+ edit = revision;
+ isChanged = true;
+ }
+ void save() {
+ if(isChanged){
+ File file = new File(translationDirectory, "translation.xml");
+ /*
+ * Document doc; try{ doc = DocumentHelper.readDocument(file); }catch(javax.xml.parsers.ParserConfigurationException pce){ System.out.println("FlatTranslation.save - ParserConfigurationException:" + file.getAbsolutePath()); return; }catch(org.xml.sax.SAXException saxe){ System.out.println("FlatTranslation.save - SAXException:" + file.getAbsolutePath()); return; }catch(java.io.IOException ioe){ System.out.println("FlatTranslation.save - Could not read file:" + file.getAbsolutePath()); return; } root = doc.getDocumentElement();
+ */
+ root.setAttribute("live", live);
+ root.setAttribute("edit", edit);
+ try{
+ // DocumentHelper.writeDocument(doc, file);
+ DocumentHelper.writeDocument(document, file);
+ }catch(javax.xml.transform.TransformerConfigurationException tce){
+ System.out.println("FlatTranslation.save - TransformerConfigurationException:" + file.getAbsolutePath());
+ }catch(javax.xml.transform.TransformerException te){
+ System.out.println("FlatTranslation.save - TransformerException:" + file.getAbsolutePath());
+ }catch(java.io.IOException ioe2){
+ System.out.println("FlatTranslation.save - Could not write file:" + file.getAbsolutePath());
+ }
+ }
+ isChanged = false;
+ }
+ void deleteRevision(String revision) {
+ FlatRevision fr = getRevision(revision);
+ String extension = fr.getExtension();
+ // TODO: Backup before delete. Use renameTo() to move outside the resource directory.
+ File file = new File(translationDirectory, revision + ".xml");
+ if(file.exists()){
+ file.delete();
+ if(extension.length() > 0){
+ file = new File(translationDirectory, revision + "." + extension);
+ if(file.exists())
+ file.delete();
+ }
+ }
+ }
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/SitetreeGenerator.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/SitetreeGenerator.java?rev=617035&r1=617034&r2=617035&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/SitetreeGenerator.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/content/flat/SitetreeGenerator.java Wed Jan 30 23:44:03 2008
@@ -1,180 +1,153 @@
package org.apache.lenya.cms.content.flat;
-
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
-import java.io.StringReader;
-import java.net.MalformedURLException;
import java.util.Map;
-import java.util.*;
-import org.apache.avalon.excalibur.pool.Recyclable;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.environment.SourceResolver;
-import org.apache.cocoon.generation.AbstractGenerator;
import org.apache.cocoon.generation.ServiceableGenerator;
-import org.apache.excalibur.xml.sax.XMLConsumer;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceException;
import org.apache.excalibur.source.SourceValidity;
import org.apache.lenya.cms.publication.PageEnvelope;
-import org.apache.lenya.cms.publication.PageEnvelopeException;
import org.apache.lenya.cms.publication.PageEnvelopeFactory;
import org.apache.lenya.cms.publication.Publication;
-import org.apache.lenya.cms.publication.PublicationFactory;
import org.xml.sax.SAXException;
-
/**
- * The <code>SitetreeGenerator</code> is a class that reads XML from a source
- * and generates SAX Events.
- * The SitetreeGenerator implements the <code>CacheableProcessingComponent</code> interface.
+ * The <code>SitetreeGenerator</code> is a class that reads XML from a source and generates SAX Events. The SitetreeGenerator implements the <code>CacheableProcessingComponent</code> interface.
*
- * @cocoon.sitemap.component.name sitetree
- * @cocoon.sitemap.component.label content
+ * @cocoon.sitemap.component.name sitetree
+ * @cocoon.sitemap.component.label content
* @cocoon.sitemap.component.logger sitemap.generator.sitetree
* @cocoon.sitemap.component.documentation.caching
- * @cocoon.sitemap.component.pooling.min 8
- * @cocoon.sitemap.component.pooling.max 32
- * @cocoon.sitemap.component.pooling.grow 4
- *
- * @author <a href="mailto:[email protected] ">Paul Ercolino</a>
+ * @cocoon.sitemap.component.pooling.min 8
+ * @cocoon.sitemap.component.pooling.max 32
+ * @cocoon.sitemap.component.pooling.grow 4
+ *
+ * @author solprovider
+ * @since 1.3
*/
-public class SitetreeGenerator extends ServiceableGenerator
-implements CacheableProcessingComponent {
-
- /** The input source */
- protected Source inputSource;
-
- /**
- * Recycle this component.
- * All instance variables are set to <code>null</code>.
- */
- public void recycle() {
- if (null != this.inputSource) {
- super.resolver.release(this.inputSource);
- this.inputSource = null;
- }
- super.recycle();
- }
-
- /**
- * Setup the file generator.
- * Try to get the last modification date of the source for caching.
- */
- public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
- throws ProcessingException, SAXException, IOException {
- super.setup(resolver, objectModel, src, par);
- try {
- PageEnvelope envelope;
- String publication = "FAILED";
- Publication pub;
- String language = "en";
- try{
+public class SitetreeGenerator extends ServiceableGenerator implements CacheableProcessingComponent {
+ /** The input source */
+ protected Source inputSource;
+ /**
+ * Recycle this component. All instance variables are set to <code>null</code>.
+ */
+ public void recycle() {
+ if(null != this.inputSource){
+ super.resolver.release(this.inputSource);
+ this.inputSource = null;
+ }
+ super.recycle();
+ }
+ /**
+ * Setup the file generator. Try to get the last modification date of the source for caching.
+ */
+ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException {
+ super.setup(resolver, objectModel, src, par);
+ try{
+ PageEnvelope envelope;
+ // String publication = "FAILED";
+ Publication pub;
+ String language = "en";
+ try{
envelope = PageEnvelopeFactory.getInstance().getPageEnvelope(objectModel);
pub = envelope.getPublication();
- publication = pub.getId();
+ // publication = pub.getId();
language = envelope.getDocument().getLanguage();
- }catch(org.apache.lenya.cms.publication.PageEnvelopeException pee){
+ }catch(org.apache.lenya.cms.publication.PageEnvelopeException pee){
System.out.println("PEE EXCEPTION");
- throw new ProcessingException("Sitetree Generator: could not use PageEnvelope.");
- }
-// Lenya1.3
- if(pub.getContentType().equalsIgnoreCase("flat")){
- this.inputSource = super.resolver.resolveURI(pub.getContent().getIndexFilename(src, language));
- }else{
-// Lenya1.2
- File testfile = new File(pub.getContentDirectory(), src + File.separator + "sitetree.xml");
- if(!testfile.exists()) testfile = new File(pub.getContentDirectory(), "live" + File.separator + "sitetree.xml");
+ throw new ProcessingException("Sitetree Generator: could not use PageEnvelope.");
+ }
+ // Lenya1.3
+ if(pub.getContentType().equalsIgnoreCase("flat")){
+ this.inputSource = super.resolver.resolveURI(pub.getContent().getIndexFilename(src, language));
+ }else{
+ // Lenya1.2
+ File testfile = new File(pub.getContentDirectory(), src + File.separator + "sitetree.xml");
+ if(!testfile.exists())
+ testfile = new File(pub.getContentDirectory(), "live" + File.separator + "sitetree.xml");
this.inputSource = super.resolver.resolveURI(testfile.getPath());
- }
- } catch (SourceException se) {
- throw SourceUtil.handle("Error during resolving of '" + src + "'.", se);
- }
- }
-
- /**
- * Generate the unique key.
- * This key must be unique inside the space of this component.
- *
- * @return The generated key hashes the src
- */
- public Serializable getKey() {
- return this.inputSource.getURI();
- }
-
- /**
- * Generate the validity object.
- *
- * @return The generated validity object or <code>null</code> if the
- * component is currently not cacheable.
- */
- public SourceValidity getValidity() {
- return this.inputSource.getValidity();
- }
-
- /**
- * Generate XML data.
- */
- public void generate()
- throws IOException, SAXException, ProcessingException {
- try {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Source " + super.source +
- " resolved to " + this.inputSource.getURI());
- }
- SourceUtil.parse(this.manager, this.inputSource, super.xmlConsumer);
- } catch (SAXException e) {
- SourceUtil.handleSAXException(this.inputSource.getURI(), e);
- }
- }
-
-
-//DEV
- private void showMap(Map map){
- System.out.println("%%% MAP BEGIN %%%");
- Set keys = map.keySet();
- Iterator iterator = keys.iterator();
- while(iterator.hasNext()){
- Object key = iterator.next();
- System.out.println(key + " = " + map.get(key));
- }
- System.out.println("%%% MAP END %%%");
- }
- private void showParameters(Parameters parameters){
- System.out.println("%%% PARAMETERS BEGIN %%%");
- String[] names = parameters.getNames();
- int nlength = names.length;
- for(int i = 0; i < nlength; i++){
- try{
- System.out.println("PAR: " + names[i] + "=" + parameters.getParameter(names[i]));
- }catch(org.apache.avalon.framework.parameters.ParameterException pe){
- System.out.println("PAR: " + names[i] + " FAILURE");
}
+ }catch(SourceException se){
+ throw SourceUtil.handle("Error during resolving of '" + src + "'.", se);
}
- System.out.println("%%% PARAMETERS END %%%");
}
- private String getModuleID(String uri) throws MalformedURLException{
- String module = "";
- int pos = uri.indexOf("modules/");
- if(pos > -1){
- pos += "modules/".length();
- int endpos = uri.indexOf("/", pos);
- if(endpos > -1){
- module = uri.substring(pos, endpos);
- }else module = uri.substring(pos);
- }
- return module;
+ /**
+ * Generate the unique key. This key must be unique inside the space of this component.
+ *
+ * @return The generated key hashes the src
+ */
+ public Serializable getKey() {
+ return this.inputSource.getURI();
}
- private Publication getPublication(String publication, String servletContextPath){
+ /**
+ * Generate the validity object.
+ *
+ * @return The generated validity object or <code>null</code> if the component is currently not cacheable.
+ */
+ public SourceValidity getValidity() {
+ return this.inputSource.getValidity();
+ }
+ /**
+ * Generate XML data.
+ */
+ public void generate() throws IOException, SAXException, ProcessingException {
try{
- return PublicationFactory.getPublication(publication, servletContextPath);
- }catch(org.apache.lenya.cms.publication.PublicationException pe){
-System.out.println("PNF: " + publication + " not found.");
- return (Publication) null;
+ if(getLogger().isDebugEnabled()){
+ getLogger().debug("Source " + super.source + " resolved to " + this.inputSource.getURI());
+ }
+ SourceUtil.parse(this.manager, this.inputSource, super.xmlConsumer);
+ }catch(SAXException e){
+ SourceUtil.handleSAXException(this.inputSource.getURI(), e);
}
}
-
-
+ // DEV
+ // private void showMap(Map map) {
+ // System.out.println("%%% MAP BEGIN %%%");
+ // Set keys = map.keySet();
+ // Iterator iterator = keys.iterator();
+ // while(iterator.hasNext()){
+ // Object key = iterator.next();
+ // System.out.println(key + " = " + map.get(key));
+ // }
+ // System.out.println("%%% MAP END %%%");
+ // }
+ // private void showParameters(Parameters parameters) {
+ // System.out.println("%%% PARAMETERS BEGIN %%%");
+ // String[] names = parameters.getNames();
+ // int nlength = names.length;
+ // for(int i = 0; i < nlength; i++){
+ // try{
+ // System.out.println("PAR: " + names[i] + "=" + parameters.getParameter(names[i]));
+ // }catch(org.apache.avalon.framework.parameters.ParameterException pe){
+ // System.out.println("PAR: " + names[i] + " FAILURE");
+ // }
+ // }
+ // System.out.println("%%% PARAMETERS END %%%");
+ // }
+ // private String getModuleID(String uri) throws MalformedURLException {
+ // String module = "";
+ // int pos = uri.indexOf("modules/");
+ // if(pos > -1){
+ // pos += "modules/".length();
+ // int endpos = uri.indexOf("/", pos);
+ // if(endpos > -1){
+ // module = uri.substring(pos, endpos);
+ // }else
+ // module = uri.substring(pos);
+ // }
+ // return module;
+ // }
+ // private Publication getPublication(String publication, String servletContextPath) {
+ // try{
+ // return PublicationFactory.getPublication(publication, servletContextPath);
+ // }catch(org.apache.lenya.cms.publication.PublicationException pe){
+ // System.out.println("PNF: " + publication + " not found.");
+ // return (Publication) null;
+ // }
+ // }
}