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 2007/09/21 12:37:48 UTC
svn commit: r578051 [2/31] - in /lenya/branches/revolution/1.3.x/src:
java/org/apache/lenya/cms/content/flat/ webapp/lenya/modules/xinha/
webapp/lenya/modules/xinha/contrib/ webapp/lenya/modules/xinha/examples/
webapp/lenya/modules/xinha/images/ webapp...
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=578051&r1=578050&r2=578051&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 Fri Sep 21 03:36:30 2007
@@ -2,216 +2,195 @@
import java.io.File;
import java.io.FileOutputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import org.apache.cocoon.ProcessingException;
-import org.apache.cocoon.transformation.AbstractDOMTransformer;
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.PageEnvelopeFactory;
import org.apache.lenya.cms.publication.Publication;
-//import org.apache.lenya.cms.publication.ResourcesManager;
import org.apache.lenya.xml.DocumentHelper;
import org.apache.lenya.xml.NamespaceHelper;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-import org.xml.sax.SAXException;
-
-//For userid
-import org.apache.cocoon.environment.Session;
-import org.apache.lenya.ac.Identity;
-import org.apache.lenya.ac.User;
/**
- * @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().
- *
+ * @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:solprovider@apache.org">Paul Ercolino</a>
*/
-public class CreateRevisionTransformer extends AbstractDOMTransformer{
- private static final String SERIALIZER_NAME = "xml";
- public static final String UPLOADASSET_PARAM_PREFIX = "dc.";
- public static final String UPLOADASSET_RETURN_FILESIZE = "file-size";
- public static final String UPLOADASSET_RETURN_MIMETYPE = "mime-type";
- public static final String CONTENT_PREFIX = "content";
- public static final String FILE_NAME_REGEXP = "[-a-zA-Z0-9_. ]+";
- // optional parameters for meta data according to dublin core
- public static final String[] DUBLIN_CORE_PARAMETERS = { "title", "creator", "subject",
- "description", "publisher", "contributor", "date", "type", "format", "identifier",
- "source", "language", "relation", "coverage", "rights" };
-
- protected org.w3c.dom.Document transform(org.w3c.dom.Document doc){
- Request request = ObjectModelHelper.getRequest(super.objectModel);
- createRevision(request, this.source, doc, false);
- return doc;
- }
-
- static public org.w3c.dom.Document transformDocument(Request request, String unid, org.w3c.dom.Document doc, boolean setLive){
- createRevision(request, unid, doc, setLive);
- return doc;
- }
-
- /**
- *
- * @param request The request
- * @param doc The data to be inserted.
- */
- static private void createRevision(Request request, String unid, org.w3c.dom.Document doc, boolean setLive)
-// throws SAXException, IOException, ProcessingException
-{
- if (doc == null){
-System.out.println("CreateRevision: Document is required.");
-// throw new ProcessingException("CreateRevision: document is required.");
- }
- PageEnvelope envelope = (PageEnvelope) request.getAttribute(PageEnvelope.class.getName());
- Publication pub = envelope.getPublication();
- Content content = pub.getContent();
- String language = envelope.getDocument().getLanguage();
- String newFilename = content.getNewURI(unid, language);
- if (newFilename == null){
-System.out.println("CreateRevision: Could not get new filename.");
-// throw new ProcessingException("CreateRevision: Could not get new filename.");
- }
- File file = new File(newFilename);
- if(file.exists()){
-System.out.println("Revision '"+newFilename+"' already exists.");
-// throw new ProcessingException("Revision '" + newFilename + "' already exists.");
- }
- String filenameNoExtension = newFilename;
- int pos = newFilename.lastIndexOf(".");
- if(pos > 0) filenameNoExtension = newFilename.substring(0, pos);
- String revision = (new File(filenameNoExtension)).getName();
-
- File assetFile;
- // determine if the upload is an asset or a content upload
- Map dublinCoreParams = getDublinCoreParameters(request);
- // upload the file to the uploadDir
- String extension = "";
-// Document metadoc = (Document) null;
- Element root = doc.getDocumentElement();
- if(root.hasAttribute("filefield")){
- Part part = (Part) request.get(root.getAttribute("filefield"));
- if(null != part){
- String filename = part.getFileName();
- pos = filename.lastIndexOf(".");
- if(pos > 0) extension = filename.substring(pos + 1);
-//System.out.println("Upload: EXT=" + extension);
- String mimeType = part.getMimeType();
- dublinCoreParams.put("format", mimeType);
- int fileSize = part.getSize();
- dublinCoreParams.put("extent", Integer.toString(fileSize));
- assetFile = new File(filenameNoExtension + "." + extension);
- try{
- saveFileFromPart(assetFile, part);
- }catch(java.lang.Exception e){
-System.out.println("CreateRevision: Exception saving upload.");
+public class CreateRevisionTransformer extends AbstractDOMTransformer {
+ public static final String UPLOADASSET_PARAM_PREFIX = "dc.";
+ public static final String UPLOADASSET_RETURN_FILESIZE = "file-size";
+ public static final String UPLOADASSET_RETURN_MIMETYPE = "mime-type";
+ public static final String CONTENT_PREFIX = "content";
+ public static final String FILE_NAME_REGEXP = "[-a-zA-Z0-9_. ]+";
+ // optional parameters for meta data according to dublin core
+ public static final String[] DUBLIN_CORE_PARAMETERS = {"title", "creator", "subject", "description", "publisher", "contributor", "date", "type", "format", "identifier", "source", "language", "relation", "coverage", "rights" };
+ protected org.w3c.dom.Document transform(org.w3c.dom.Document doc) {
+ Request request = ObjectModelHelper.getRequest(super.objectModel);
+ createRevision(request, this.source, doc, false);
+ return doc;
+ }
+ static public org.w3c.dom.Document transformDocument(Request request, String unid, org.w3c.dom.Document doc, boolean setLive) {
+ createRevision(request, unid, doc, setLive);
+ return doc;
+ }
+ /**
+ * @param request The request
+ * @param doc The data to be inserted.
+ */
+ static private void createRevision(Request request, String punid, org.w3c.dom.Document doc, boolean setLive)
+ // throws SAXException, IOException, ProcessingException
+ {
+ if(doc == null){
+ System.out.println("CreateRevision: Document is required.");
+ // throw new ProcessingException("CreateRevision: document is required.");
+ }
+ PageEnvelope envelope = (PageEnvelope) request.getAttribute(PageEnvelope.class.getName());
+ Publication pub = envelope.getPublication();
+ Content content = pub.getContent();
+ String unid = punid;
+ String language = envelope.getDocument().getLanguage(); // default
+ // check if unid contains language
+ int pos = unid.indexOf("_");
+ if(pos > 0){
+ unid = unid.substring(0, pos);
+ language = unid.substring(pos);
+ }
+ System.out.println("CreateRevision TEST: u=" + unid + " l=" + language);
+ String newFilename = content.getNewURI(unid, language);
+ if(newFilename == null){
+ System.out.println("CreateRevision: Could not get new filename.");
+ // throw new ProcessingException("CreateRevision: Could not get new filename.");
+ }
+ File file = new File(newFilename);
+ if(file.exists()){
+ System.out.println("Revision '" + newFilename + "' already exists.");
+ // throw new ProcessingException("Revision '" + newFilename + "' already exists.");
+ }
+ String filenameNoExtension = newFilename;
+ pos = newFilename.lastIndexOf(".");
+ if(pos > 0) filenameNoExtension = newFilename.substring(0, pos);
+ String revision = (new File(filenameNoExtension)).getName();
+ File assetFile;
+ // determine if the upload is an asset or a content upload
+ Map dublinCoreParams = getDublinCoreParameters(request);
+ // upload the file to the uploadDir
+ String extension = "";
+ // Document metadoc = (Document) null;
+ Element root = doc.getDocumentElement();
+ if(root.hasAttribute("filefield")){
+ Part part = (Part) request.get(root.getAttribute("filefield"));
+ if(null != part){
+ String filename = part.getFileName();
+ pos = filename.lastIndexOf(".");
+ if(pos > 0) extension = filename.substring(pos + 1);
+ // System.out.println("Upload: EXT=" + extension);
+ String mimeType = part.getMimeType();
+ dublinCoreParams.put("format", mimeType);
+ int fileSize = part.getSize();
+ dublinCoreParams.put("extent", Integer.toString(fileSize));
+ assetFile = new File(filenameNoExtension + "." + extension);
+ try{
+ saveFileFromPart(assetFile, part);
+ }catch(java.lang.Exception e){
+ System.out.println("CreateRevision: Exception saving upload.");
+ }
+ // Add Meta to doc
+ addMeta(doc, dublinCoreParams);
+ } // END - part not null
+ } // END - doc has "file" attribute.
+ // 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();
}
- //Add Meta to doc
- addMeta(doc, dublinCoreParams);
- } // END - part not null
- } // END - doc has "file" attribute.
- //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());
- if(extension.length() > 0) root.setAttribute("extension", extension);
- try{
- DocumentHelper.writeDocument(doc, file);
- }catch(javax.xml.transform.TransformerConfigurationException tce){
-System.out.println("CreateRevision: TransformerConfigurationException");
- }catch(javax.xml.transform.TransformerException te){
-System.out.println("CreateRevision: TransformerException");
- }catch(java.io.IOException ioe){
- System.out.println("CreateRevision: IOException writing XML file.");
- }
- //Update Translation
- FlatResource resource = (FlatResource) ((FlatContent)content).getResource(unid, language, "edit");
- FlatTranslation translation = resource.getTranslation();
- translation.setEdit(revision);
- if(setLive) translation.setLive(revision);
- translation.save();
- }
-
+ }
+ root.setAttribute("creator", userid);
+ root.setAttribute("when", getDateString());
+ if(extension.length() > 0) root.setAttribute("extension", extension);
+ try{
+ DocumentHelper.writeDocument(doc, file);
+ }catch(javax.xml.transform.TransformerConfigurationException tce){
+ System.out.println("CreateRevision: TransformerConfigurationException");
+ }catch(javax.xml.transform.TransformerException te){
+ System.out.println("CreateRevision: TransformerException");
+ }catch(java.io.IOException ioe){
+ System.out.println("CreateRevision: IOException writing XML file.");
+ }
+ // Update Translation
+ FlatResource resource = (FlatResource) ((FlatContent) content).getResource(unid, language, "edit");
+ FlatTranslation translation = resource.getTranslation();
+ translation.setEdit(revision);
+ if(setLive) translation.setLive(revision);
+ translation.save();
+ }
/**
* Saves the asset to a file.
- *
* @param assetFile The asset file.
* @param part The part of the multipart request.
* @throws Exception if an error occurs.
*/
static private void saveFileFromPart(File assetFile, Part part) throws Exception {
- if (!assetFile.exists()) {
+ if(!assetFile.exists()){
boolean created = assetFile.createNewFile();
- if (!created) {
- throw new RuntimeException("The file [" + assetFile + "] could not be created.");
- }
+ if(!created){ throw new RuntimeException("The file [" + assetFile + "] could not be created."); }
}
byte[] buf = new byte[4096];
FileOutputStream out = new FileOutputStream(assetFile);
- try {
+ try{
InputStream in = part.getInputStream();
int read = in.read(buf);
- while (read > 0) {
+ while(read > 0){
out.write(buf, 0, read);
read = in.read(buf);
}
- } finally {
+ }finally{
out.close();
}
}
/**
- * Retrieves optional parameters for the meta file which contains dublin core information from
- * the request.
+ * Retrieves optional parameters for the meta file which contains dublin core information from the request.
* @param request The request.
* @return A map.
*/
static private Map getDublinCoreParameters(Request request) {
HashMap dublinCoreParams = new HashMap();
- for (int i = 0; i < DUBLIN_CORE_PARAMETERS.length; i++) {
+ for(int i = 0; i < DUBLIN_CORE_PARAMETERS.length; i++){
String paramName = DUBLIN_CORE_PARAMETERS[i];
String paramValue = request.getParameter(UPLOADASSET_PARAM_PREFIX + paramName);
- if (paramValue == null) paramValue = "";
+ if(paramValue == null) paramValue = "";
dublinCoreParams.put(paramName, paramValue);
}
return dublinCoreParams;
}
-
- static private void addMeta(Document doc, Map dublinCoreParams){
- NamespaceHelper helper = new NamespaceHelper("http://purl.org/dc/elements/1.1/", "dc", doc);
- Element root = doc.getDocumentElement();
-// DESIGN CHANGE: No metadata element.
-// org.w3c.dom.Node meta = root.appendChild(helper.createElement("metadata"));
- Iterator iter = dublinCoreParams.keySet().iterator();
- while (iter.hasNext()) {
- String tagName = (String) iter.next();
- String tagValue = (String) dublinCoreParams.get(tagName);
-// meta.appendChild(helper.createElement(tagName, tagValue));
- root.appendChild(helper.createElement(tagName, tagValue));
- }
- }
- static private String getDateString(){
- return Long.toString(new java.util.Date().getTime());
- }
+ static private void addMeta(Document doc, Map dublinCoreParams) {
+ NamespaceHelper helper = new NamespaceHelper("http://purl.org/dc/elements/1.1/", "dc", doc);
+ Element root = doc.getDocumentElement();
+ // DESIGN CHANGE: No metadata element.
+ // org.w3c.dom.Node meta = root.appendChild(helper.createElement("metadata"));
+ Iterator iter = dublinCoreParams.keySet().iterator();
+ while(iter.hasNext()){
+ String tagName = (String) iter.next();
+ String tagValue = (String) dublinCoreParams.get(tagName);
+ // 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/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=578051&r1=578050&r2=578051&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 Fri Sep 21 03:36:30 2007
@@ -1,11 +1,9 @@
package org.apache.lenya.cms.content.flat;
import java.io.File;
-import java.util.Arrays;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceNotFoundException;
import org.apache.lenya.cms.content.Resource;
import org.apache.lenya.xml.DocumentHelper;
import org.w3c.dom.Document;
@@ -13,362 +11,366 @@
import org.w3c.dom.NodeList;
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");
- }
- if(useDefaultLanguage){
- if(defaultLanguageParameter.length() > 0){
- defaultLanguage = defaultLanguageParameter;
- }else{
-//TODO: Use Publication's Default Language
+ 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(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]);
- }
- 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, defaultLanguage);
- }else return new FlatTranslation(resourceDirectory, language);
- }
- 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;
+ 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;
+ 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]);
+ }
+ 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;
}
- }
-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);
- }
- }
+ 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());
}
- 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;
- }
+ }
+ isChanged = false;
+ }
}
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=578051&r1=578050&r2=578051&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 Fri Sep 21 03:36:30 2007
@@ -3,200 +3,195 @@
import java.io.File;
import java.util.SortedSet;
import java.util.TreeSet;
-import org.apache.excalibur.source.Source;
-import org.apache.excalibur.source.SourceNotFoundException;
-//import org.apache.lenya.cms.content.Revision;
-//import org.apache.lenya.cms.content.Translation;
import org.apache.lenya.xml.DocumentHelper;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
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 pdefaultLanguage, String prevision){
- resourceDirectory = directory;
- language = planguage;
- defaultLanguage = pdefaultLanguage;
- revision = prevision;
- init();
- }
- public FlatTranslation(File directory, String planguage, String pdefaultLanguage){
- resourceDirectory = directory;
- language = planguage;
- defaultLanguage = pdefaultLanguage;
- init();
- }
- public FlatTranslation(File directory, String planguage){
- resourceDirectory = directory;
- language = planguage;
- defaultLanguage = planguage;
- 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);
+ 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;
+ }
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;
- }
-
- 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();
- }
- }
- }
+ 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();
+ }
+ }
+ }
}
Added: lenya/branches/revolution/1.3.x/src/webapp/lenya/modules/xinha/Xinha.css
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/webapp/lenya/modules/xinha/Xinha.css?rev=578051&view=auto
==============================================================================
--- lenya/branches/revolution/1.3.x/src/webapp/lenya/modules/xinha/Xinha.css (added)
+++ lenya/branches/revolution/1.3.x/src/webapp/lenya/modules/xinha/Xinha.css Fri Sep 21 03:36:30 2007
@@ -0,0 +1,263 @@
+.htmlarea { background: #fff; }
+.htmlarea td { margin:0;padding:0; }
+
+.htmlarea .toolbar {
+ cursor: default;
+ background: ButtonFace;
+ padding: 3px;
+ border: 1px solid;
+ border-color: ButtonHighlight ButtonShadow ButtonShadow ButtonHighlight;
+}
+.htmlarea .toolbar table { margin: 0; font-family: tahoma,verdana,sans-serif; font-size: 11px; }
+.htmlarea .toolbar img { border: none; vertical-align: top; }
+.htmlarea .toolbar .label { padding: 0px 3px; }
+
+.htmlarea .toolbar .button {
+ background: ButtonFace;
+ color: ButtonText;
+ border: 1px solid ButtonFace;
+ padding: 1px;
+ margin: 0px;
+ width: 18px;
+ height: 18px;
+}
+.htmlarea .toolbar a.button:hover {
+ border: 1px solid;
+ border-color: ButtonHighlight ButtonShadow ButtonShadow ButtonHighlight;
+}
+.htmlarea .toolbar a.buttonDisabled:hover {
+ border-color: ButtonFace;
+}
+.htmlarea .toolbar .buttonActive,
+.htmlarea .toolbar .buttonPressed
+{
+ padding: 2px 0px 0px 2px;
+ border: 1px solid;
+ border-color: ButtonShadow ButtonHighlight ButtonHighlight ButtonShadow;
+}
+.htmlarea .toolbar .buttonPressed {
+ background: ButtonHighlight;
+}
+.htmlarea .toolbar .indicator {
+ padding: 0px 3px;
+ overflow: hidden;
+ width: 20px;
+ text-align: center;
+ cursor: default;
+ border: 1px solid ButtonShadow;
+}
+
+.htmlarea .toolbar .buttonDisabled img {
+ filter: gray() alpha(opacity = 25);
+ -moz-opacity: 0.25;
+ opacity: 0.25;
+}
+
+.htmlarea .toolbar .separator {
+ /*position: relative;*/
+ margin:0 3px;
+ border-left: 1px solid ButtonShadow;
+ border-right: 1px solid ButtonHighlight;
+ width: 0px;
+ height: 18px;
+ padding: 0px;
+}
+
+.htmlarea .toolbar .space { width: 5px; }
+
+.htmlarea .toolbar select, .htmlarea .toolbar option { font: 11px Tahoma,Verdana,sans-serif;}
+
+.htmlarea .toolbar select,
+.htmlarea .toolbar select:hover,
+.htmlarea .toolbar select:active {
+ margin-top: 2px;
+ margin-bottom: 1px;
+ color: ButtonText;
+ height: 17px;
+}
+
+.htmlarea iframe.xinha_iframe, .htmlarea textarea.xinha_textarea
+{
+ border: none; /*1px solid;*/
+}
+
+.htmlarea .statusBar {
+ border: 1px solid;
+ border-color: ButtonShadow ButtonHighlight ButtonHighlight ButtonShadow;
+ padding: 2px 4px;
+ background-color: ButtonFace;
+ color: ButtonText;
+ font: 11px Tahoma,Verdana,sans-serif;
+ height:16px;
+}
+
+.htmlarea .statusBar .statusBarTree a {
+ padding: 2px 5px;
+ color: #00f;
+}
+
+.htmlarea .statusBar .statusBarTree a:visited { color: #00f; }
+.htmlarea .statusBar .statusBarTree a:hover {
+ background-color: Highlight;
+ color: HighlightText;
+ padding: 1px 4px;
+ border: 1px solid HighlightText;
+}
+
+
+/* popup dialogs */
+
+.dialog {
+ color: ButtonText;
+ background: ButtonFace;
+}
+
+.dialog .content { padding: 2px; }
+
+.dialog, .dialog button, .dialog input, .dialog select, .dialog textarea, .dialog table {
+ font: 11px Tahoma,Verdana,sans-serif;
+}
+
+.dialog table { border-collapse: collapse; }
+
+.dialog .title, .dialog h1
+{
+ background: #008;
+ color: #ff8;
+ border-bottom: 1px solid #000;
+ padding: 1px 0px 2px 5px;
+ font-size: 12px;
+ font-weight: bold;
+ cursor: default;
+}
+.dialog h1 { margin:0px;}
+.dialog .title .button {
+ float: right;
+ border: 1px solid #66a;
+ padding: 0px 1px 0px 2px;
+ margin-right: 1px;
+ color: #fff;
+ text-align: center;
+}
+
+.dialog .title .button-hilite { border-color: #88f; background: #44c; }
+
+.dialog button {
+ width: 5em;
+ padding: 0px;
+}
+
+.dialog .buttonColor {
+ width :1em;
+ padding: 1px;
+ cursor: default;
+ border: 1px solid;
+ border-color: ButtonHighlight ButtonShadow ButtonShadow ButtonHighlight;
+}
+
+.dialog .buttonColor .chooser, .dialog .buttonColor .nocolor {
+ height: 0.6em;
+ border: 1px solid;
+ padding: 0px 1em;
+ border-color: ButtonShadow ButtonHighlight ButtonHighlight ButtonShadow;
+}
+
+.dialog .buttonClick {
+ border-color: ButtonShadow ButtonHighlight ButtonHighlight ButtonShadow;
+}
+.dialog .buttonColor-hilite {
+ border-color: ButtonShadow ButtonHighlight ButtonHighlight ButtonShadow;
+}
+
+.dialog .buttonColor .nocolor { padding: 0px; }
+.dialog .buttonColor .nocolor-hilite { background-color: #fff; color: #f00; }
+
+.dialog .label { text-align: right; width: 6em; }
+.dialog .value input { width: 100%; }
+.dialog .buttons { text-align: right; padding: 2px 4px 0px 4px; }
+
+.dialog legend { font-weight: bold; }
+.dialog fieldset table { margin: 2px 0px; }
+
+.popupwin {
+ padding: 0px;
+ margin: 0px;
+}
+
+.popupwin .title {
+ background: #fff;
+ color: #000;
+ font-weight: bold;
+ font-size: 120%;
+ padding: 3px 10px;
+ margin-bottom: 10px;
+ border-bottom: 1px solid black;
+ letter-spacing: 2px;
+}
+
+form { margin: 0px; border: none; }
+
+
+/** Panels **/
+.htmlarea .panels.top
+{
+ border-bottom : 1px solid;
+ border-color: ButtonShadow;
+}
+
+.htmlarea .panels.right
+{
+ border-left : 1px solid;
+ border-color: ButtonShadow;
+}
+
+.htmlarea .panels.left
+{
+ border-right : 1px solid;
+ border-color: ButtonShadow;
+}
+
+.htmlarea .panels.bottom
+{
+ border-top : 1px solid;
+ border-color: ButtonShadow;
+}
+
+.htmlarea .panel h1 {
+ background: ButtonFace;
+ border: 1px solid;
+ border-color: ButtonHighlight ButtonShadow ButtonShadow ButtonHighlight;
+ margin: 0px;
+ padding: 0px;
+ font-size:100%;
+ font-weight:bold;
+ padding: 2px;
+ clear:left;
+
+}
+
+.htmlarea .panel { overflow:hidden; }
+.htmlarea .panels.left .panel { border-right:none; border-left:none; }
+.htmlarea .panels.left h1 { border-right:none; }
+.htmlarea .panels.right .panel { border-right:none; border-left:none; }
+.htmlarea .panels.left h1 { border-left:none; }
+.htmlarea { border: 1px solid black; }
+
+.loading
+{
+ background-color:#666;
+ position:absolute;
+ z-index:998;
+}
+.loading_main
+{
+ font-size:1.6em;
+ color:#ff6;
+ text-align:center;
+}
+.loading_sub
+{
+ font-size:1.0em;
+ color:#fff;
+ text-align:center;
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org