Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentType.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentType.java?rev=574702&r1=574701&r2=574702&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentType.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/DocumentType.java Tue Sep 11 14:39:37 2007
@@ -14,64 +14,57 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
import org.apache.lenya.cms.authoring.ParentChildCreatorInterface;
-
/**
* A document type.
*/
public class DocumentType {
public static final String NAMESPACE = "http://apache.org/cocoon/lenya/doctypes/1.0";
public static final String DEFAULT_PREFIX = "dt";
-
- /** Creates a new instance of DocumentType
+ /**
+ * Creates a new instance of DocumentType
*
- * @param name the name of the document type
+ * @param name
+ * the name of the document type
*
*/
protected DocumentType(String name) {
- assert name != null;
+ // assert name != null;
this.name = name;
}
-
private String name;
-
/**
- * Returns the name of this document type.
+ * Returns the name of this document type.
+ *
* @return A string value.
*/
public String getName() {
return name;
}
-
private ParentChildCreatorInterface creator = null;
-
- /**
- * Get the creator for this document type.
- *
- * @return a <code>ParentChildCreatorInterface</code>
- */
+ /**
+ * Get the creator for this document type.
+ *
+ * @return a <code>ParentChildCreatorInterface</code>
+ */
public ParentChildCreatorInterface getCreator() {
return creator;
}
-
- /**
- * Set the creator
- *
- * @param creator a <code>ParentChildCreatorInterface</code>
- */
+ /**
+ * Set the creator
+ *
+ * @param creator
+ * a <code>ParentChildCreatorInterface</code>
+ */
protected void setCreator(ParentChildCreatorInterface creator) {
- assert creator != null;
+ // assert creator != null;
this.creator = creator;
}
-
private String workflowFile = null;
-
/**
* Returns if this document type has a workflow definition.
*
@@ -80,35 +73,34 @@
public boolean hasWorkflow() {
return workflowFile != null;
}
-
- /**
- * Get the file name of the workflow file.
- *
- * @return a <code>String</code>
- *
- * @throws DocumentTypeBuildException if the document type has no workflow
- */
+ /**
+ * Get the file name of the workflow file.
+ *
+ * @return a <code>String</code>
+ *
+ * @throws DocumentTypeBuildException
+ * if the document type has no workflow
+ */
public String getWorkflowFileName() throws DocumentTypeBuildException {
if (!hasWorkflow()) {
- throw new DocumentTypeBuildException("The document type '" + getName() +
- "' has no workflow!");
+ throw new DocumentTypeBuildException("The document type '" + getName() + "' has no workflow!");
}
-
return workflowFile;
}
-
- /**
- * Set the file name of the workflow file.
- *
- * @param string the new file name
- */
+ /**
+ * Set the file name of the workflow file.
+ *
+ * @param string
+ * the new file name
+ */
public void setWorkflowFileName(String string) {
- assert string != null;
+ // assert string != null;
workflowFile = string;
}
-
- /** (non-Javadoc)
- * @see java.lang.Object#toString()
+ /**
+ * (non-Javadoc)
+ *
+ * @see java.lang.Object#toString()ssss
*/
public String toString() {
return getName();
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/IdentityDocumentIdToPathMapper.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/IdentityDocumentIdToPathMapper.java?rev=574702&r1=574701&r2=574702&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/IdentityDocumentIdToPathMapper.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/IdentityDocumentIdToPathMapper.java Tue Sep 11 14:39:37 2007
@@ -14,56 +14,55 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
import java.io.File;
public class IdentityDocumentIdToPathMapper implements DocumentIdToPathMapper {
-
/**
- * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getFile(org.apache.lenya.cms.publication.Publication, java.lang.String, java.lang.String, java.lang.String)
+ * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getFile(org.apache.lenya.cms.publication.Publication,
+ * java.lang.String, java.lang.String, java.lang.String)
*/
public File getFile(Publication publication, String area, String documentId, String language) {
- File areaDirectory =
- new File(publication.getDirectory(), Publication.CONTENT_PATH + File.separator + area);
+ File areaDirectory = new File(publication.getDirectory(), Publication.CONTENT_PATH + File.separator + area);
File file = new File(areaDirectory, getPath(documentId, language));
return file;
}
-
/**
- * (non-Javadoc)
- * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getDirectory(org.apache.lenya.cms.publication.Publication, java.lang.String, java.lang.String)
+ * (non-Javadoc)
+ *
+ * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getDirectory(org.apache.lenya.cms.publication.Publication,
+ * java.lang.String, java.lang.String)
*/
public File getDirectory(Publication publication, String area, String documentId, String language) {
return getDirectory(publication, area, documentId);
}
-
/**
* @deprecated because language is missing
*
- * (non-Javadoc)
- * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getDirectory(org.apache.lenya.cms.publication.Publication, java.lang.String, java.lang.String)
+ * (non-Javadoc)
+ * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getDirectory(org.apache.lenya.cms.publication.Publication,
+ * java.lang.String, java.lang.String)
*/
public File getDirectory(Publication publication, String area, String documentId) {
return getFile(publication, area, documentId, null).getParentFile();
}
-
/**
- * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getPath(java.lang.String, java.lang.String)
+ * @see org.apache.lenya.cms.publication.DocumentIdToPathMapper#getPath(java.lang.String,
+ * java.lang.String)
*/
public String getPath(String documentId, String language) {
- assert documentId.startsWith("/");
+ // assert documentId.startsWith("/");
// remove leading slash
documentId = documentId.substring(1);
return documentId + getSuffix(language);
}
-
/**
* Constructs the filename for a given language.
- * @param language The language.
+ *
+ * @param language
+ * The language.
* @return A string value.
*/
protected String getSuffix(String language) {
@@ -73,5 +72,4 @@
}
return languageSuffix + ".xml";
}
-
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PageEnvelope.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PageEnvelope.java?rev=574702&r1=574701&r2=574702&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PageEnvelope.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PageEnvelope.java Tue Sep 11 14:39:37 2007
@@ -14,21 +14,18 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
import java.util.Map;
-
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
import org.apache.lenya.cms.rc.RCEnvironment;
import org.apache.lenya.util.ServletHelper;
/**
- * A page envelope carries a set of information that are needed during the presentation of a
- * document.
+ * A page envelope carries a set of information that are needed during the
+ * presentation of a document.
*/
public class PageEnvelope {
public static final String PUBLICATION_ID = "publication-id";
@@ -51,47 +48,62 @@
public static final String DOCUMENT_LANGUAGE = "document-language";
public static final String DOCUMENT_LANGUAGES = "document-languages";
public static final String DOCUMENT_LANGUAGES_CSV = "document-languages-csv";
-
- /** @deprecated Use {@link org.apache.lenya.cms.publication.Document#getDublinCore()} instead */
+ /**
+ * @deprecated Use
+ * {@link org.apache.lenya.cms.publication.Document#getDublinCore()}
+ * instead
+ */
public static final String DOCUMENT_DC_TITLE = "document-dc-title";
-
- /** @deprecated Use {@link org.apache.lenya.cms.publication.Document#getDublinCore()} instead */
+ /**
+ * @deprecated Use
+ * {@link org.apache.lenya.cms.publication.Document#getDublinCore()}
+ * instead
+ */
public static final String DOCUMENT_DC_CREATOR = "document-dc-creator";
-
- /** @deprecated Use {@link org.apache.lenya.cms.publication.Document#getDublinCore()} instead */
+ /**
+ * @deprecated Use
+ * {@link org.apache.lenya.cms.publication.Document#getDublinCore()}
+ * instead
+ */
public static final String DOCUMENT_DC_SUBJECT = "document-dc-subject";
-
- /** @deprecated Use {@link org.apache.lenya.cms.publication.Document#getDublinCore()} instead */
+ /**
+ * @deprecated Use
+ * {@link org.apache.lenya.cms.publication.Document#getDublinCore()}
+ * instead
+ */
public static final String DOCUMENT_DC_PUBLISHER = "document-dc-publisher";
-
- /** @deprecated Use {@link org.apache.lenya.cms.publication.Document#getDublinCore()} instead */
+ /**
+ * @deprecated Use
+ * {@link org.apache.lenya.cms.publication.Document#getDublinCore()}
+ * instead
+ */
public static final String DOCUMENT_DC_DATE_CREATED = "document-dc-date-created";
-
- /** @deprecated Use {@link org.apache.lenya.cms.publication.Document#getDublinCore()} instead */
+ /**
+ * @deprecated Use
+ * {@link org.apache.lenya.cms.publication.Document#getDublinCore()}
+ * instead
+ */
public static final String DOCUMENT_DC_DESCRIPTION = "document-dc-description";
-
- /** @deprecated Use {@link org.apache.lenya.cms.publication.Document#getDublinCore()} instead */
+ /**
+ * @deprecated Use
+ * {@link org.apache.lenya.cms.publication.Document#getDublinCore()}
+ * instead
+ */
public static final String DOCUMENT_DC_RIGHTS = "document-dc-rights";
-
public static final String DOCUMENT_LASTMODIFIED = "document-lastmodified";
-
public static final String BREADCRUMB_PREFIX = "breadcrumb-prefix";
-
public static final String SSL_PREFIX = "ssl-prefix";
-
public static final String NAMESPACE = "http://apache.org/cocoon/lenya/page-envelope/1.0";
public static final String DEFAULT_PREFIX = "lenya";
-
private String context;
-
/**
* Constructor.
*/
protected PageEnvelope() {
}
-
/**
- * Creates a new instance of PageEnvelope from a sitemap inside a publication.
+ * Creates a new instance of PageEnvelope from a sitemap inside a
+ * publication.
*
* @param publication
* The publication the page belongs to.
@@ -99,13 +111,12 @@
* The request that calls the page.
* @exception PageEnvelopeException
* if an error occurs
- * @deprecated Performance problems. Use {@link PageEnvelopeFactory#getPageEnvelope(Map)}
- * instead.
+ * @deprecated Performance problems. Use
+ * {@link PageEnvelopeFactory#getPageEnvelope(Map)} instead.
*/
public PageEnvelope(Publication publication, Request request) throws PageEnvelopeException {
init(publication, request);
}
-
/**
* Creates a page envelope from an object model.
*
@@ -113,50 +124,47 @@
* The object model.
* @throws PageEnvelopeException
* when something went wrong.
- * @deprecated Performance problems. Use {@link PageEnvelopeFactory#getPageEnvelope(Map)}
- * instead.
+ * @deprecated Performance problems. Use
+ * {@link PageEnvelopeFactory#getPageEnvelope(Map)} instead.
*/
public PageEnvelope(Map objectModel) throws PageEnvelopeException {
try {
- init(
- PublicationFactory.getPublication(objectModel),
- ObjectModelHelper.getRequest(objectModel));
+ init(PublicationFactory.getPublication(objectModel), ObjectModelHelper.getRequest(objectModel));
} catch (PublicationException e) {
throw new PageEnvelopeException(e);
}
}
-
/**
- * Creates a new instance of PageEnvelope from a sitemap inside a publication.
+ * Creates a new instance of PageEnvelope from a sitemap inside a
+ * publication.
*
- * @param publication The publication the page belongs to.
- * @param request The request that calls the page.
+ * @param publication
+ * The publication the page belongs to.
+ * @param request
+ * The request that calls the page.
* @param createdByFactory
- * A dummy parameter to allow creating an additional protected constructor that is
- * not deprecated.
- * @exception PageEnvelopeException if an error occurs
+ * A dummy parameter to allow creating an additional protected
+ * constructor that is not deprecated.
+ * @exception PageEnvelopeException
+ * if an error occurs
*/
- public PageEnvelope(Publication publication, Request request, boolean createdByFactory)
- throws PageEnvelopeException {
+ public PageEnvelope(Publication publication, Request request, boolean createdByFactory) throws PageEnvelopeException {
this(publication, request);
}
-
/**
* Creates a page envelope from an object model.
*
* @param objectModel
* The object model.
* @param createdByFactory
- * A dummy parameter to allow creating an additional protected constructor that is
- * not deprecated.
+ * A dummy parameter to allow creating an additional protected
+ * constructor that is not deprecated.
* @throws PageEnvelopeException
* when something went wrong.
*/
- protected PageEnvelope(Map objectModel, boolean createdByFactory)
- throws PageEnvelopeException {
+ protected PageEnvelope(Map objectModel, boolean createdByFactory) throws PageEnvelopeException {
this(objectModel);
}
-
/**
* Setup an instance of Publication.
*
@@ -172,39 +180,39 @@
*/
protected void init(Publication publication, Request request)
// FIXME: this method is mainly needed because the deprecated
- // constructor PageEnvelope(Map objectModel) needs to handle an exception in
- // one of the arguments to another constructor. That's why the constructor
- // functionality is factored out into this method.
- // If the deprecated constructor PageEnvelope(Map objectModel) is removed
- // this method might not be needed anymore and the functionality could
- // be moved back to the constructor PageEnvelope(Publication publication, Request request).
- throws PageEnvelopeException {
- assert publication != null;
- assert request != null;
+ // constructor PageEnvelope(Map objectModel) needs to handle an
+ // exception in
+ // one of the arguments to another constructor. That's why the
+ // constructor
+ // functionality is factored out into this method.
+ // If the deprecated constructor PageEnvelope(Map objectModel) is
+ // removed
+ // this method might not be needed anymore and the functionality
+ // could
+ // be moved back to the constructor PageEnvelope(Publication
+ // publication, Request request).
+ throws PageEnvelopeException {
+ // assert publication != null;
+ // assert request != null;
String webappURI;
try {
-
context = request.getContextPath();
if (context == null) {
context = "";
}
-
webappURI = ServletHelper.getWebappURI(request);
- Document document =
- publication.getDocumentBuilder().buildDocument(publication, webappURI);
+ Document document = publication.getDocumentBuilder().buildDocument(publication, webappURI);
setDocument(document);
-
} catch (Exception e) {
throw new PageEnvelopeException(e);
}
-
// plausibility check
/*
- * if (!webappURI .startsWith( "/" + getPublication().getId() + "/" + document.getArea() +
- * document.getId())) { throw new PageEnvelopeException(createExceptionMessage(request)); }
+ * if (!webappURI .startsWith( "/" + getPublication().getId() + "/" +
+ * document.getArea() + document.getId())) { throw new
+ * PageEnvelopeException(createExceptionMessage(request)); }
*/
}
-
/**
* Creates the message to report when creating the envelope failed.
*
@@ -213,19 +221,8 @@
* @return A string.
*/
protected String createExceptionMessage(Request request) {
- return "Resolving page envelope failed:"
- + "\n URI: "
- + request.getRequestURI()
- + "\n Context: "
- + getContext()
- + "\n Publication ID: "
- + getPublication().getId()
- + "\n Area: "
- + document.getArea()
- + "\n Document ID: "
- + document.getId();
+ return "Resolving page envelope failed:" + "\n URI: " + request.getRequestURI() + "\n Context: " + getContext() + "\n Publication ID: " + getPublication().getId() + "\n Area: " + document.getArea() + "\n Document ID: " + document.getId();
}
-
/**
* Returns the publication of this PageEnvelope.
*
@@ -234,7 +231,6 @@
public Publication getPublication() {
return getDocument().getPublication();
}
-
/**
* Returns the rcEnvironment.
*
@@ -244,7 +240,6 @@
public RCEnvironment getRCEnvironment() {
return RCEnvironment.getInstance(getPublication().getServletContext().getAbsolutePath());
}
-
/**
* Returns the context, e.g. "/lenya".
*
@@ -253,53 +248,18 @@
public String getContext() {
return context;
}
-
/**
* Returns the document-path.
*
* @return a <code>File<code> value
*/
public String getDocumentPath() {
-
- return getPublication().getPathMapper().getPath(
- getDocument().getId(),
- getDocument().getLanguage());
+ return getPublication().getPathMapper().getPath(getDocument().getId(), getDocument().getLanguage());
}
-
/**
* The names of the page envelope parameters.
*/
- public static final String[] PARAMETER_NAMES =
- {
- PageEnvelope.AREA,
- PageEnvelope.CONTEXT,
- PageEnvelope.PUBLICATION_ID,
- PageEnvelope.PUBLICATION,
- PageEnvelope.PUBLICATION_LANGUAGES_CSV,
- PageEnvelope.DOCUMENT,
- PageEnvelope.DOCUMENT_ID,
- PageEnvelope.DOCUMENT_NAME,
- PageEnvelope.DOCUMENT_NODE_ID,
- PageEnvelope.DOCUMENT_LABEL,
- PageEnvelope.DOCUMENT_URL,
- PageEnvelope.DOCUMENT_URL_WITHOUT_LANGUAGE,
- PageEnvelope.DOCUMENT_PATH,
- PageEnvelope.DOCUMENT_EXTENSION,
- PageEnvelope.DEFAULT_LANGUAGE,
- PageEnvelope.DOCUMENT_LANGUAGE,
- PageEnvelope.DOCUMENT_LANGUAGES,
- PageEnvelope.DOCUMENT_LANGUAGES_CSV,
- PageEnvelope.DOCUMENT_DC_TITLE,
- PageEnvelope.DOCUMENT_DC_CREATOR,
- PageEnvelope.DOCUMENT_DC_PUBLISHER,
- PageEnvelope.DOCUMENT_DC_SUBJECT,
- PageEnvelope.DOCUMENT_DC_DATE_CREATED,
- PageEnvelope.DOCUMENT_DC_DESCRIPTION,
- PageEnvelope.DOCUMENT_DC_RIGHTS,
- PageEnvelope.DOCUMENT_LASTMODIFIED,
- PageEnvelope.BREADCRUMB_PREFIX,
- PageEnvelope.SSL_PREFIX };
-
+ public static final String[] PARAMETER_NAMES = { PageEnvelope.AREA, PageEnvelope.CONTEXT, PageEnvelope.PUBLICATION_ID, PageEnvelope.PUBLICATION, PageEnvelope.PUBLICATION_LANGUAGES_CSV, PageEnvelope.DOCUMENT, PageEnvelope.DOCUMENT_ID, PageEnvelope.DOCUMENT_NAME, PageEnvelope.DOCUMENT_NODE_ID, PageEnvelope.DOCUMENT_LABEL, PageEnvelope.DOCUMENT_URL, PageEnvelope.DOCUMENT_URL_WITHOUT_LANGUAGE, PageEnvelope.DOCUMENT_PATH, PageEnvelope.DOCUMENT_EXTENSION, PageEnvelope.DEFAULT_LANGUAGE, PageEnvelope.DOCUMENT_LANGUAGE, PageEnvelope.DOCUMENT_LANGUAGES, PageEnvelope.DOCUMENT_LANGUAGES_CSV, PageEnvelope.DOCUMENT_DC_TITLE, PageEnvelope.DOCUMENT_DC_CREATOR, PageEnvelope.DOCUMENT_DC_PUBLISHER, PageEnvelope.DOCUMENT_DC_SUBJECT, PageEnvelope.DOCUMENT_DC_DATE_CREATED, PageEnvelope.DOCUMENT_DC_DESCRIPT
ION, PageEnvelope.DOCUMENT_DC_RIGHTS, PageEnvelope.DOCUMENT_LASTMODIFIED, PageEnvelope.BREADCRUMB_PREFIX, PageEnvelope.SSL_PREFIX };
/**
* @param string
* The context.
@@ -307,9 +267,7 @@
protected void setContext(String string) {
context = string;
}
-
private Document document;
-
/**
* Returns the document.
*
@@ -318,7 +276,6 @@
public Document getDocument() {
return document;
}
-
/**
* Sets the document.
*
@@ -328,5 +285,4 @@
public void setDocument(Document document) {
this.document = document;
}
-
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationFactory.java?rev=574702&r1=574701&r2=574702&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationFactory.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/PublicationFactory.java Tue Sep 11 14:39:37 2007
@@ -14,16 +14,13 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-
import org.apache.cocoon.environment.Context;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Request;
@@ -38,56 +35,52 @@
* Factory for creating publication objects.
*/
public final class PublicationFactory {
-
private static Category log = Category.getInstance(PublicationFactory.class);
-
/**
* Create a new <code>PublicationFactory</code>.
*/
private PublicationFactory() {
}
-
private static Map keyToPublication = new HashMap();
-
/**
- * Creates a new publication.
- * The publication ID is resolved from the request URI.
- * The servlet context path is resolved from the context object.
-
- * @param objectModel The object model of the Cocoon component.
+ * Creates a new publication. The publication ID is resolved from the
+ * request URI. The servlet context path is resolved from the context
+ * object.
+ *
+ * @param objectModel
+ * The object model of the Cocoon component.
*
* @return a <code>Publication</code>
*
- * @throws PublicationException if there was a problem creating the publication.
+ * @throws PublicationException
+ * if there was a problem creating the publication.
*/
public static Publication getPublication(Map objectModel) throws PublicationException {
-
- assert objectModel != null;
+ // assert objectModel != null;
Request request = ObjectModelHelper.getRequest(objectModel);
Context context = ObjectModelHelper.getContext(objectModel);
return getPublication(request, context);
}
-
/**
- * Create a new publication with the given publication-id and servlet context path.
- * These publications are cached and reused for similar requests.
- *
- * @param id the publication id
- * @param servletContextPath the servlet context path of the publication
- *
+ * Create a new publication with the given publication-id and servlet
+ * context path. These publications are cached and reused for similar
+ * requests.
+ *
+ * @param id
+ * the publication id
+ * @param servletContextPath
+ * the servlet context path of the publication
+ *
* @return a <code>Publication</code>
*
- * @throws PublicationException if there was a problem creating the publication.
+ * @throws PublicationException
+ * if there was a problem creating the publication.
*/
- public static Publication getPublication(String id, String servletContextPath)
- throws PublicationException {
-
- assert id != null;
- assert servletContextPath != null;
-
+ public static Publication getPublication(String id, String servletContextPath) throws PublicationException {
+ // assert id != null;
+ // assert servletContextPath != null;
String key = generateKey(id, servletContextPath);
Publication publication = null;
-
if (keyToPublication.containsKey(key)) {
publication = (Publication) keyToPublication.get(key);
} else {
@@ -96,25 +89,24 @@
keyToPublication.put(key, publication);
}
}
-
if (publication == null) {
throw new PublicationException("The publication for ID [" + id + "] could not be created.");
}
return publication;
}
-
/**
- * Generates a key to cache a publication.
- * The cache key is constructed using the canonical servlet context path
- * and the publication ID.
+ * Generates a key to cache a publication. The cache key is constructed
+ * using the canonical servlet context path and the publication ID.
*
- * @param publicationId The publication ID.
- * @param servletContextPath The servlet context path.
+ * @param publicationId
+ * The publication ID.
+ * @param servletContextPath
+ * The servlet context path.
* @return A cache key.
- * @throws PublicationException when the servlet context does not exist.
+ * @throws PublicationException
+ * when the servlet context does not exist.
*/
- protected static String generateKey(String publicationId, String servletContextPath)
- throws PublicationException {
+ protected static String generateKey(String publicationId, String servletContextPath) throws PublicationException {
String key;
File servletContext = new File(servletContextPath);
String canonicalPath;
@@ -126,79 +118,75 @@
key = canonicalPath + "_" + publicationId;
return key;
}
-
/**
* Creates a new publication based on a request and a context.
*
- * @param request A request.
- * @param context A context.
+ * @param request
+ * A request.
+ * @param context
+ * A context.
*
* @return A publication.
*
- * @throws PublicationException if there was a problem creating the publication.
+ * @throws PublicationException
+ * if there was a problem creating the publication.
*/
- public static Publication getPublication(Request request, Context context)
- throws PublicationException {
-
+ public static Publication getPublication(Request request, Context context) throws PublicationException {
log.debug("Creating publication from Cocoon object model");
String webappUrl = ServletHelper.getWebappURI(request);
String servletContextPath = context.getRealPath("");
return getPublication(webappUrl, new File(servletContextPath));
}
-
/**
* Creates a publication from a webapp URL and a servlet context directory.
- * @param webappUrl The URL within the web application (without context prefix)
- * @param servletContext The Lenya servlet context directory
+ *
+ * @param webappUrl
+ * The URL within the web application (without context prefix)
+ * @param servletContext
+ * The Lenya servlet context directory
* @return A publication
- * @throws PublicationException when something went wrong
+ * @throws PublicationException
+ * when something went wrong
*/
- public static Publication getPublication(String webappUrl, File servletContext)
- throws PublicationException {
+ public static Publication getPublication(String webappUrl, File servletContext) throws PublicationException {
log.debug("Creating publication from webapp URL and servlet context");
-
log.debug(" Webapp URL: [" + webappUrl + "]");
String publicationId = new URLInformation(webappUrl).getPublicationId();
Publication publication = getPublication(publicationId, servletContext.getAbsolutePath());
return publication;
}
-
/**
* Checks if a publication with a certain ID exists in a certain context.
- * @param id The publication ID.
- * @param servletContextPath The webapp context path.
- * @return <code>true</code> if the publication exists, <code>false</code> otherwise.
+ *
+ * @param id
+ * The publication ID.
+ * @param servletContextPath
+ * The webapp context path.
+ * @return <code>true</code> if the publication exists, <code>false</code>
+ * otherwise.
*/
public static boolean existsPublication(String id, String servletContextPath) {
-
if (servletContextPath.endsWith("/")) {
servletContextPath = servletContextPath.substring(0, servletContextPath.length() - 1);
}
-
- File publicationDirectory =
- new File(
- servletContextPath
- + File.separator
- + Publication.PUBLICATION_PREFIX
- + File.separator
- + id);
-
+ File publicationDirectory = new File(servletContextPath + File.separator + Publication.PUBLICATION_PREFIX + File.separator + id);
boolean exists = true;
exists = exists && publicationDirectory.isDirectory();
exists = exists && new File(publicationDirectory, Publication.CONFIGURATION_FILE).exists();
-
return exists;
}
-
/**
* Creates a publication using a source resolver and a request.
- * @param resolver The source resolver.
- * @param request The request.
+ *
+ * @param resolver
+ * The source resolver.
+ * @param request
+ * The request.
* @return A publication.
- * @throws PublicationException when something went wrong.
+ * @throws PublicationException
+ * when something went wrong.
*/
- public static Publication getPublication(SourceResolver resolver, Request request)
- throws PublicationException {
+ public static Publication getPublication(SourceResolver resolver, Request request) throws PublicationException {
log.debug("Creating publication from resolver and request");
Publication publication;
String webappUri = ServletHelper.getWebappURI(request);
@@ -216,5 +204,4 @@
}
return publication;
}
-
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/ResourcesManager.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/ResourcesManager.java?rev=574702&r1=574701&r2=574702&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/ResourcesManager.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/ResourcesManager.java Tue Sep 11 14:39:37 2007
@@ -14,36 +14,29 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
import java.io.File;
import java.io.FileFilter;
-
import org.apache.lenya.util.FileUtil;
/**
* Manager for resources of a CMS document.
*/
public class ResourcesManager {
-
private Document document;
-
public static final String RESOURCES_PREFIX = "resources";
-
public static final String RESOURCES_META_SUFFIX = ".meta";
-
/**
* Create a new instance of Resources.
*
- * @param document the document for which the resources are managed
+ * @param document
+ * the document for which the resources are managed
*/
public ResourcesManager(Document document) {
this.document = document;
}
-
/**
* Get the path to the resources.
*
@@ -52,7 +45,6 @@
public String getPathFromPublication() {
return RESOURCES_PREFIX + "/" + getDocument().getArea() + getDocument().getId();
}
-
/**
* Get the path to the resources.
*
@@ -60,62 +52,52 @@
*/
public File getPath() {
File publicationPath = getDocument().getPublication().getDirectory();
- File resourcesPath = new File(publicationPath, getPathFromPublication().replace('/',
- File.separatorChar));
+ File resourcesPath = new File(publicationPath, getPathFromPublication().replace('/', File.separatorChar));
return resourcesPath;
}
-
/**
* Returns the path of a resource relative to the context prefix.
+ *
* @return The path of a resource relative to the context prefix.
*/
public String getResourceUrl(File resource) {
- return
- getDocument().getPublication().getId()
- + "/"
- + getDocument().getArea()
- + getDocument().getId()
- + "/"
- + resource.getName();
+ return getDocument().getPublication().getId() + "/" + getDocument().getArea() + getDocument().getId() + "/" + resource.getName();
}
-
/**
* Get all resources for the associated document.
*
* @return all resources of the associated document
*/
public File[] getResources() {
-
// filter the meta files out. We only want to see the "real" resources.
FileFilter filter = new FileFilter() {
-
public boolean accept(File file) {
return file.isFile() && !file.getName().endsWith(RESOURCES_META_SUFFIX);
}
};
-
return getFiles(filter);
}
-
/**
* Return all resources which are images.
+ *
* @return All image resources.
*/
public File[] getImageResources() {
- final String[] IMAGE_FILE_EXTENSIONS = {".jpg", ".png", ".bmp", ".gif", ".svg"};
- return getFiles( new FileFilter() {
- public boolean accept(File file) {
- for(int i=0; i<IMAGE_FILE_EXTENSIONS.length; i++)
- if (file.getName().toLowerCase().endsWith(IMAGE_FILE_EXTENSIONS[i]))
- return true;
- return false;
- }
- });
+ final String[] IMAGE_FILE_EXTENSIONS = { ".jpg", ".png", ".bmp", ".gif", ".svg" };
+ return getFiles(new FileFilter() {
+ public boolean accept(File file) {
+ for (int i = 0; i < IMAGE_FILE_EXTENSIONS.length; i++)
+ if (file.getName().toLowerCase().endsWith(IMAGE_FILE_EXTENSIONS[i]))
+ return true;
+ return false;
+ }
+ });
}
-
/**
* Returns the resources that are matched by a certain file filter.
- * @param filter A file filter.
+ *
+ * @param filter
+ * A file filter.
* @return A file array.
*/
protected File[] getFiles(FileFilter filter) {
@@ -123,68 +105,60 @@
if (getPath().isDirectory()) {
files = getPath().listFiles(filter);
}
-
return files;
}
-
/**
* Get the meta data for all resources for the associated document.
*
- * @return all meta data files for the resources for the associated document.
+ * @return all meta data files for the resources for the associated
+ * document.
*/
public File[] getMetaFiles() {
FileFilter filter = new FileFilter() {
-
public boolean accept(File file) {
return file.isFile() && file.getName().endsWith(RESOURCES_META_SUFFIX);
}
};
return getFiles(filter);
}
-
/**
* Returns a meta file for a given resource.
- * @param resource A resource the meta file should be returned for.
- * @return A file containing meta information about a resource.
- * Returns null if no meta file was found.
- * @throws IllegalArgumentException If resource is a meta file itself.
+ *
+ * @param resource
+ * A resource the meta file should be returned for.
+ * @return A file containing meta information about a resource. Returns null
+ * if no meta file was found.
+ * @throws IllegalArgumentException
+ * If resource is a meta file itself.
*/
public File getMetaFile(final File resource) throws IllegalArgumentException {
- if(resource.getName().endsWith(RESOURCES_META_SUFFIX))
+ if (resource.getName().endsWith(RESOURCES_META_SUFFIX))
throw new IllegalArgumentException("File is itself a meta file.");
-
final FileFilter filter = new FileFilter() {
public boolean accept(File file) {
- return file.isFile() &&
- file.getName().equals(resource.getName().concat(RESOURCES_META_SUFFIX));
+ return file.isFile() && file.getName().equals(resource.getName().concat(RESOURCES_META_SUFFIX));
}
};
-
final File[] metaFiles = getFiles(filter);
- assert(metaFiles.length == 0);
+ // assert(metaFiles.length == 0);
return metaFiles[0];
}
-
/**
* Deletes all resources.
*/
public void deleteResources() {
-
File stopDirectory = new File(getDocument().getPublication().getDirectory(), RESOURCES_PREFIX);
-
File[] resources = getResources();
for (int i = 0; i < resources.length; i++) {
resources[i].delete();
FileUtil.deleteParentDirs(resources[i], stopDirectory);
}
-
File[] metas = getMetaFiles();
for (int i = 0; i < metas.length; i++) {
metas[i].delete();
FileUtil.deleteParentDirs(metas[i], stopDirectory);
}
}
-
public Document getDocument() {
return document;
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/URLInformation.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/URLInformation.java?rev=574702&r1=574701&r2=574702&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/URLInformation.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/URLInformation.java Tue Sep 11 14:39:37 2007
@@ -14,86 +14,74 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.publication;
/**
* This class resolves all Lenya-specific information from a webapp URL.
*/
public class URLInformation {
-
private String publicationId = null;
private String area = null;
- private String completeArea = null;
+ private String completeArea = null;
private String documentUrl = null;
-
/**
* Returns the area (without the "info-" prefix).
+ *
* @return A string.
*/
public String getArea() {
return area;
}
-
- /**
- * Returns the complete area (including the "info-" prefix).
- * @return A string.
- */
- public String getCompleteArea() {
- return completeArea;
- }
-
+ /**
+ * Returns the complete area (including the "info-" prefix).
+ *
+ * @return A string.
+ */
+ public String getCompleteArea() {
+ return completeArea;
+ }
/**
* Returns the document URL.
+ *
* @return A string.
*/
public String getDocumentUrl() {
return documentUrl;
}
-
/**
* Returns the publication ID.
+ *
* @return A string.
*/
public String getPublicationId() {
return publicationId;
}
-
/**
* Ctor.
- * @param webappUrl A webapp URL (without context prefix).
+ *
+ * @param webappUrl
+ * A webapp URL (without context prefix).
*/
public URLInformation(String webappUrl) {
- assert webappUrl.startsWith("/");
-
+ // assert webappUrl.startsWith("/");
String url = webappUrl.substring(1);
-
String[] fragments = url.split("/");
this.publicationId = fragments[0];
-
if (fragments.length > 1) {
this.completeArea = fragments[1];
-
if (url.length() > (this.publicationId + "/" + completeArea).length()) {
this.documentUrl = url.substring((this.publicationId + "/" + completeArea).length());
- }
- else {
+ } else {
this.documentUrl = "";
}
-
if (completeArea.startsWith(Publication.INFO_AREA_PREFIX)) {
- this.area = completeArea.substring(Publication.INFO_AREA_PREFIX.length());
- }
- else if (completeArea.startsWith(Publication.SEARCH_AREA_PREFIX)) {
+ this.area = completeArea.substring(Publication.INFO_AREA_PREFIX.length());
+ } else if (completeArea.startsWith(Publication.SEARCH_AREA_PREFIX)) {
this.area = completeArea.substring(Publication.SEARCH_AREA_PREFIX.length());
- }
- else {
- this.area = completeArea;
+ } else {
+ this.area = completeArea;
}
}
}
-
-
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java?rev=574702&r1=574701&r2=574702&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/publication/task/PublicationTask.java Tue Sep 11 14:39:37 2007
@@ -201,7 +201,7 @@
Event event = getExecutableEvent(instance, situation);
- assert event != null;
+// assert event != null;
if (log.isDebugEnabled()) {
log.debug("Invoking event [" + event.getName() + "]");
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/task/WorkflowInvoker.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/task/WorkflowInvoker.java?rev=574702&r1=574701&r2=574702&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/task/WorkflowInvoker.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/task/WorkflowInvoker.java Tue Sep 11 14:39:37 2007
@@ -223,7 +223,7 @@
}
}
- assert event != null;
+// assert event != null;
log.debug("Invoking transition.");
instance.invoke(situation, event);
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/workflow/CMSHistory.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/workflow/CMSHistory.java?rev=574702&r1=574701&r2=574702&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/workflow/CMSHistory.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/workflow/CMSHistory.java Tue Sep 11 14:39:37 2007
@@ -185,7 +185,7 @@
* @throws WorkflowException when something went wrong.
*/
protected void move(Document newDocument) throws WorkflowException {
- assert newDocument != null;
+// assert newDocument != null;
move(getHistoryFile(newDocument));
setDocument(newDocument);
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/workflow/WorkflowDocument.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/workflow/WorkflowDocument.java?rev=574702&r1=574701&r2=574702&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/workflow/WorkflowDocument.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/workflow/WorkflowDocument.java Tue Sep 11 14:39:37 2007
@@ -14,9 +14,7 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.workflow;
import org.apache.lenya.cms.publication.Document;
@@ -27,54 +25,52 @@
import org.apache.lenya.workflow.impl.WorkflowInstanceImpl;
public class WorkflowDocument extends WorkflowInstanceImpl {
-
- /**
- * Create a new <code>WorkflowDocument</code>
- *
- * @param document the document
- *
- * @throws WorkflowException if an error occurs
- */
+ /**
+ * Create a new <code>WorkflowDocument</code>
+ *
+ * @param document
+ * the document
+ *
+ * @throws WorkflowException
+ * if an error occurs
+ */
protected WorkflowDocument(Document document) throws WorkflowException {
- assert document != null;
+ // assert document != null;
this.document = document;
}
-
private Document document;
-
/**
* Returns the document of this WorkflowDocument object.
+ *
* @return A document object.
*/
public Document getDocument() {
return document;
}
-
/**
* DOCUMENT ME!
- *
- * @param situation DOCUMENT ME!
- * @param eventName DOCUMENT ME!
- *
- * @throws WorkflowException DOCUMENT ME!
+ *
+ * @param situation
+ * DOCUMENT ME!
+ * @param eventName
+ * DOCUMENT ME!
+ *
+ * @throws WorkflowException
+ * DOCUMENT ME!
*/
- public void invoke(Situation situation, String eventName)
- throws WorkflowException {
- assert eventName != null;
-
+ public void invoke(Situation situation, String eventName) throws WorkflowException {
+ // assert eventName != null;
Event event = ((WorkflowImpl) getWorkflow()).getEvent(eventName);
invoke(situation, event);
}
-
- /** (non-Javadoc)
+ /**
+ * (non-Javadoc)
+ *
* @see org.apache.lenya.workflow.impl.WorkflowInstanceImpl#getWorkflow(java.lang.String)
*/
- protected WorkflowImpl getWorkflow(String workflowName)
- throws WorkflowException {
- assert workflowName != null && !"".equals(workflowName);
- WorkflowImpl workflow = (WorkflowImpl) WorkflowFactory.buildWorkflow(document.getPublication(),
- workflowName);
-
+ protected WorkflowImpl getWorkflow(String workflowName) throws WorkflowException {
+ // assert workflowName != null && !"".equals(workflowName);
+ WorkflowImpl workflow = (WorkflowImpl) WorkflowFactory.buildWorkflow(document.getPublication(), workflowName);
return workflow;
}
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/workflow/WorkflowFactory.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/workflow/WorkflowFactory.java?rev=574702&r1=574701&r2=574702&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/workflow/WorkflowFactory.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/cms/workflow/WorkflowFactory.java Tue Sep 11 14:39:37 2007
@@ -14,13 +14,10 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.cms.workflow;
import java.io.File;
-
import org.apache.lenya.ac.Identity;
import org.apache.lenya.ac.Machine;
import org.apache.lenya.ac.Role;
@@ -41,40 +38,42 @@
* Workflow factory.
*/
public class WorkflowFactory {
- public static final String WORKFLOW_DIRECTORY =
- "config/workflow".replace('/', File.separatorChar);
-
+ public static final String WORKFLOW_DIRECTORY = "config/workflow".replace('/', File.separatorChar);
/** Creates a new instance of WorkflowFactory */
protected WorkflowFactory() {
}
-
/**
* Returns an instance of the workflow factory.
+ *
* @return A workflow factory.
*/
public static WorkflowFactory newInstance() {
return new WorkflowFactory();
}
-
/**
* Creates a new workflow instance.
- * @param document The document to create the instance for.
+ *
+ * @param document
+ * The document to create the instance for.
* @return A workflow instance.
- * @throws WorkflowException when something went wrong.
+ * @throws WorkflowException
+ * when something went wrong.
*/
public WorkflowInstance buildInstance(Document document) throws WorkflowException {
- assert document != null;
+ // assert document != null;
return getHistory(document).getInstance();
}
-
/**
* Creates a new synchronized workflow instances object..
- * @param document The document to create the instances for.
+ *
+ * @param document
+ * The document to create the instances for.
* @return A synchronized workflow instances object.
- * @throws WorkflowException when something went wrong.
+ * @throws WorkflowException
+ * when something went wrong.
*/
public SynchronizedWorkflowInstances buildSynchronizedInstance(Document document) throws WorkflowException {
- assert document != null;
+ // assert document != null;
LanguageVersions versions;
try {
versions = new LanguageVersions(document);
@@ -83,63 +82,73 @@
}
return new WorkflowDocumentSet(versions, document);
}
-
/**
* Moves the history of a document.
- * @param oldDocument The document to move the instance for.
- * @param newDocument The new document.
- * @throws WorkflowException when something went wrong.
+ *
+ * @param oldDocument
+ * The document to move the instance for.
+ * @param newDocument
+ * The new document.
+ * @throws WorkflowException
+ * when something went wrong.
*/
public static void moveHistory(Document oldDocument, Document newDocument) throws WorkflowException {
- assert oldDocument != null;
+ // assert oldDocument != null;
new CMSHistory(oldDocument).move(newDocument);
}
-
/**
* Deletes the history of a document.
- * @param document The document to delete the instance for.
- * @throws WorkflowException when something went wrong.
+ *
+ * @param document
+ * The document to delete the instance for.
+ * @throws WorkflowException
+ * when something went wrong.
*/
public static void deleteHistory(Document document) throws WorkflowException {
- assert document != null;
+ // assert document != null;
getHistory(document).delete();
}
-
/**
- * Checks if a workflow is assigned to the document.
- * This is done by looking for the workflow history file.
- * @param document The document to check.
- * @return <code>true</code> if the document has a workflow, <code>false</code> otherwise.
+ * Checks if a workflow is assigned to the document. This is done by looking
+ * for the workflow history file.
+ *
+ * @param document
+ * The document to check.
+ * @return <code>true</code> if the document has a workflow,
+ * <code>false</code> otherwise.
*/
public boolean hasWorkflow(Document document) {
return getHistory(document).isInitialized();
}
-
/**
* Builds a workflow for a given publication.
- * @param publication The publication.
- * @param workflowFileName The workflow definition filename.
+ *
+ * @param publication
+ * The publication.
+ * @param workflowFileName
+ * The workflow definition filename.
* @return A workflow object.
- * @throws WorkflowException when something went wrong.
+ * @throws WorkflowException
+ * when something went wrong.
*/
- protected static Workflow buildWorkflow(Publication publication, String workflowFileName)
- throws WorkflowException {
- assert publication != null;
- assert(workflowFileName != null) && !"".equals(workflowFileName);
-
+ protected static Workflow buildWorkflow(Publication publication, String workflowFileName) throws WorkflowException {
+ // assert publication != null;
+ // assert(workflowFileName != null) && !"".equals(workflowFileName);
File workflowDirectory = new File(publication.getDirectory(), WORKFLOW_DIRECTORY);
File workflowFile = new File(workflowDirectory, workflowFileName);
Workflow workflow = WorkflowBuilder.buildWorkflow(workflowFile);
-
return workflow;
}
-
/**
* Creates a situation for a set of roles and an identity.
- * @param roles The roles.
- * @param identity The identity.
+ *
+ * @param roles
+ * The roles.
+ * @param identity
+ * The identity.
* @return A workflow situation.
- * @throws WorkflowException when something went wrong.
+ * @throws WorkflowException
+ * when something went wrong.
*/
public Situation buildSituation(Role[] roles, Identity identity) throws WorkflowException {
if (identity == null) {
@@ -150,63 +159,70 @@
if (user != null) {
userId = user.getId();
}
-
String machineIp = null;
Machine machine = identity.getMachine();
if (machine != null) {
machineIp = machine.getIp();
}
-
String[] roleIds = new String[roles.length];
for (int i = 0; i < roles.length; i++) {
roleIds[i] = roles[i].getId();
}
-
return buildSituation(roleIds, userId, machineIp);
}
-
/**
- * Builds a situation from a role name set, a user ID and a machine IP address.
- * @param roleIds The role IDs.
- * @param userId The user ID.
- * @param machineIp The machine IP address.
+ * Builds a situation from a role name set, a user ID and a machine IP
+ * address.
+ *
+ * @param roleIds
+ * The role IDs.
+ * @param userId
+ * The user ID.
+ * @param machineIp
+ * The machine IP address.
* @return A situation.
*/
public Situation buildSituation(String[] roleIds, String userId, String machineIp) {
return new CMSSituation(roleIds, userId, machineIp);
}
-
/**
* Initializes the history of a document.
- * @param document The document object.
- * @param workflowId The ID of the workflow.
- * @param situation The current situation.
- * @throws WorkflowException When something goes wrong.
+ *
+ * @param document
+ * The document object.
+ * @param workflowId
+ * The ID of the workflow.
+ * @param situation
+ * The current situation.
+ * @throws WorkflowException
+ * When something goes wrong.
*/
public static void initHistory(Document document, String workflowId, Situation situation) throws WorkflowException {
new CMSHistory(document).initialize(workflowId, situation);
}
-
/**
* Returns the workflow history of a document.
- * @param document A document.
+ *
+ * @param document
+ * A document.
* @return A workflow history.
*/
public static History getHistory(Document document) {
return new CMSHistory(document);
}
-
/**
- * Initializes the workflow history of a document that is a copy of
- * another document.
- * @param sourceDocument The original document.
- * @param destinationDocument The document to initialize the history for.
- * @throws WorkflowException When something goes wrong.
+ * Initializes the workflow history of a document that is a copy of another
+ * document.
+ *
+ * @param sourceDocument
+ * The original document.
+ * @param destinationDocument
+ * The document to initialize the history for.
+ * @throws WorkflowException
+ * When something goes wrong.
*/
- public static void initHistory(Document sourceDocument, Document destinationDocument, Situation situation)
- throws WorkflowException {
+ public static void initHistory(Document sourceDocument, Document destinationDocument, Situation situation) throws WorkflowException {
CMSHistory history = new CMSHistory(sourceDocument);
history.initialize(destinationDocument, situation);
}
-
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/FileDocument.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/FileDocument.java?rev=574702&r1=574701&r2=574702&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/FileDocument.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/FileDocument.java Tue Sep 11 14:39:37 2007
@@ -14,9 +14,7 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.lucene;
import java.io.BufferedReader;
@@ -24,8 +22,7 @@
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
-
-import org.apache.lucene.document.DateField;
+import org.apache.lucene.document.DateTools;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
@@ -35,53 +32,54 @@
public class FileDocument {
private FileDocument() {
}
-
/**
* Makes a document for a File.
- *
+ *
* <p>
* The document has three fields:
- *
+ *
* <ul>
- * <li>
- * <code>path</code>--containing the pathname of the file, as a stored, tokenized field;
- * </li>
- * <li>
- * <code>modified</code>--containing the last modified date of the file as a keyword field as
- * encoded by <a href="lucene.document.DateField.html">DateField</a>; and
- * </li>
- * <li>
- * <code>contents</code>--containing the full contents of the file, as a Reader field.
- * </li>
+ * <li> <code>path</code>--containing the pathname of the file, as a
+ * stored, tokenized field; </li>
+ * <li> <code>modified</code>--containing the last modified date of the
+ * file as a keyword field as encoded by <a
+ * href="lucene.document.DateField.html">DateField</a>; and </li>
+ * <li> <code>contents</code>--containing the full contents of the file,
+ * as a Reader field. </li>
* </ul>
* </p>
- *
- * @param f DOCUMENT ME!
- *
+ *
+ * @param f
+ * DOCUMENT ME!
+ *
* @return DOCUMENT ME!
- *
- * @throws java.io.FileNotFoundException DOCUMENT ME!
+ *
+ * @throws java.io.FileNotFoundException
+ * DOCUMENT ME!
*/
public static Document Document(File f) throws java.io.FileNotFoundException {
// make a new, empty document
Document doc = new Document();
-
- // Add the path of the file as a field named "path". Use a Text field, so
+ // Add the path of the file as a field named "path". Use a Text field,
+ // so
// that the index stores the path, and so that the path is searchable
- doc.add(Field.Text("path", f.getPath()));
-
- // Add the last modified date of the file a field named "modified". Use a
- // Keyword field, so that it's searchable, but so that no attempt is made
+ // doc.add(Field.Text("path", f.getPath()));
+ doc.add(new Field("path", f.getPath(), Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.YES));
+ // Add the last modified date of the file a field named "modified". Use
+ // a
+ // Keyword field, so that it's searchable, but so that no attempt is
+ // made
// to tokenize the field into words.
- doc.add(Field.Keyword("modified", DateField.timeToString(f.lastModified())));
-
- // Add the contents of the file a field named "contents". Use a Text
- // field, specifying a Reader, so that the text of the file is tokenized.
+ // doc.add(Field.Keyword("modified", DateField.timeToString(f.lastModified())));
+ doc.add(new Field("modified", DateTools.timeToString(f.lastModified(), DateTools.Resolution.MILLISECOND), Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.YES));
+ // Add the contents of the file a field named "contents". Use a Text
+ // field, specifying a Reader, so that the text of the file is
+ // tokenized.
// ?? why doesn't FileReader work here ??
FileInputStream is = new FileInputStream(f);
Reader reader = new BufferedReader(new InputStreamReader(is));
- doc.add(Field.Text("contents", reader));
-
+ // doc.add(Field.Text("contents", reader));
+ doc.add(new Field("contents", reader));
// return the document
return doc;
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/HTMLDocument.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/HTMLDocument.java?rev=574702&r1=574701&r2=574702&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/HTMLDocument.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/HTMLDocument.java Tue Sep 11 14:39:37 2007
@@ -14,141 +14,145 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.lucene;
import java.io.File;
import java.io.IOException;
-
import org.apache.lenya.lucene.html.HTMLParser;
import org.apache.lucene.document.DateField;
+import org.apache.lucene.document.DateTools;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
-
/**
* A utility for making Lucene Documents for HTML documents.
*/
public class HTMLDocument {
static char dirSep = System.getProperty("file.separator").charAt(0);
-
private HTMLDocument() {
}
-
/**
- * Append path and date into a string in such a way that lexicographic sorting gives the same
- * results as a walk of the file hierarchy. Thus null (\u0000) is used both to separate
- * directory components and to separate the path from the date.
- *
- * @param f DOCUMENT ME!
- * @param htdocsDumpDir DOCUMENT ME!
- *
+ * Append path and date into a string in such a way that lexicographic
+ * sorting gives the same results as a walk of the file hierarchy. Thus null
+ * (\u0000) is used both to separate directory components and to separate
+ * the path from the date.
+ *
+ * @param f
+ * DOCUMENT ME!
+ * @param htdocsDumpDir
+ * DOCUMENT ME!
+ *
* @return DOCUMENT ME!
*/
public static String uid(File f, File htdocsDumpDir) {
String requestURI = f.getPath().substring(htdocsDumpDir.getPath().length());
- String uid = requestURI.replace(dirSep, '\u0000') + "\u0000" +
- DateField.timeToString(f.lastModified());
-
+ String uid = requestURI.replace(dirSep, '\u0000') + "\u0000" + DateField.timeToString(f.lastModified());
return uid;
}
-
/**
* DOCUMENT ME!
- *
- * @param uid DOCUMENT ME!
- *
+ *
+ * @param uid
+ * DOCUMENT ME!
+ *
* @return DOCUMENT ME!
*/
public static String uid2url(String uid) {
- String url = uid.replace('\u0000', '/'); // replace nulls with slashes
-
+ String url = uid.replace('\u0000', '/'); // replace nulls with
+ // slashes
return url.substring(0, url.lastIndexOf('/')); // remove date from end
}
-
/**
* DOCUMENT ME!
- *
- * @param f DOCUMENT ME!
- * @param htdocsDumpDir DOCUMENT ME!
- *
+ *
+ * @param f
+ * DOCUMENT ME!
+ * @param htdocsDumpDir
+ * DOCUMENT ME!
+ *
* @return org.apache.lucene.document.Document
- *
- * @throws IOException DOCUMENT ME!
- * @throws InterruptedException DOCUMENT ME!
+ *
+ * @throws IOException
+ * DOCUMENT ME!
+ * @throws InterruptedException
+ * DOCUMENT ME!
*/
- public static Document Document(File f, File htdocsDumpDir)
- throws IOException, InterruptedException {
+ public static Document Document(File f, File htdocsDumpDir) throws IOException, InterruptedException {
System.out.println("HTMLDocument.Document(File,File): " + f);
-
// make a new, empty document
Document doc = new Document();
-
- // Add the url as a field named "url". Use an UnIndexed field, so
+ // Add the url as a field named "url". Use an UnIndexed field, so
// that the url is just stored with the document, but is not searchable.
- String requestURI = f.getPath().replace(dirSep, '/').substring(htdocsDumpDir.getPath()
- .length());
+ String requestURI = f.getPath().replace(dirSep, '/').substring(htdocsDumpDir.getPath().length());
if (requestURI.substring(requestURI.length() - 8).equals(".pdf.txt")) {
- requestURI = requestURI.substring(0, requestURI.length() - 4); // Remove .txt extension from PDF text file
+ requestURI = requestURI.substring(0, requestURI.length() - 4); // Remove
+ // .txt
+ // extension
+ // from
+ // PDF
+ // text
+ // file
}
-
- doc.add(Field.UnIndexed("url", requestURI));
-
+ // doc.add(Field.UnIndexed("url", requestURI));
+ doc.add(new Field("url", requestURI, Field.Store.YES, Field.Index.NO));
// Add the mime-type as a field named "mime-type"
if (requestURI.substring(requestURI.length() - 5).equals(".html")) {
- doc.add(Field.UnIndexed("mime-type", "text/html"));
+ // doc.add(Field.UnIndexed("mime-type", "text/html"));
+ doc.add(new Field("mime-type", "text/html", Field.Store.YES, Field.Index.NO));
} else if (requestURI.substring(requestURI.length() - 4).equals(".txt")) {
- doc.add(Field.UnIndexed("mime-type", "text/plain"));
+ // doc.add(Field.UnIndexed("mime-type", "text/plain"));
+ doc.add(new Field("mime-type", "text/plain", Field.Store.YES, Field.Index.NO));
} else if (requestURI.substring(requestURI.length() - 4).equals(".pdf")) {
- doc.add(Field.UnIndexed("mime-type", "application/pdf"));
+ // doc.add(Field.UnIndexed("mime-type", "application/pdf"));
+ doc.add(new Field("mime-type", "application/pdf", Field.Store.YES, Field.Index.NO));
} else {
- doc.add(Field.UnIndexed("mime-type", "null"));
+ // doc.add(Field.UnIndexed("mime-type", "null"));
+ doc.add(new Field("mime-type", "null", Field.Store.YES, Field.Index.NO));
}
-
- // Add the last modified date of the file a field named "modified". Use a
- // Keyword field, so that it's searchable, but so that no attempt is made
+ // Add the last modified date of the file a field named "modified". Use
+ // a
+ // Keyword field, so that it's searchable, but so that no attempt is
+ // made
// to tokenize the field into words.
- doc.add(Field.Keyword("modified", DateField.timeToString(f.lastModified())));
-
- // Add the uid as a field, so that index can be incrementally maintained.
+ // doc.add(Field.Keyword("modified", DateField.timeToString(f.lastModified())));
+ doc.add(new Field("modified", DateTools.timeToString(f.lastModified(), DateTools.Resolution.MILLISECOND), Field.Store.YES, Field.Index.UN_TOKENIZED, Field.TermVector.YES));
+ // Add the uid as a field, so that index can be incrementally
+ // maintained.
// This field is not stored with document, it is indexed, but it is not
// tokenized prior to indexing.
- doc.add(new Field("uid", uid(f, htdocsDumpDir), false, true, false));
-
- //HtmlDocument htmlDoc = new HtmlDocument(f);
+ doc.add(new Field("uid", uid(f, htdocsDumpDir),
+ // false, true, false));
+ Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.NO));
+ // HtmlDocument htmlDoc = new HtmlDocument(f);
HTMLParser parser = new HTMLParser(f);
-
- // Add the summary as an UnIndexed field, so that it is stored and returned
+ // Add the summary as an UnIndexed field, so that it is stored and
+ // returned
// with hit documents for display.
- // Add the title as a separate Text field, so that it can be searched separately.
+ // Add the title as a separate Text field, so that it can be searched
+ // separately.
/*
- String title = htmlDoc.getTitle();
-
- if (title != null) {
- doc.add(Field.Text("title", title));
- } else {
- doc.add(Field.Text("title", ""));
- }
- */
- doc.add(Field.Text("title", parser.getTitle()));
-
- //System.out.println("HTMLDocument.getLuceneDocument(): title field added: " + title);
- // Add the tag-stripped contents as a Reader-valued Text field so it will get tokenized and indexed.
+ * String title = htmlDoc.getTitle();
+ *
+ * if (title != null) { doc.add(Field.Text("title", title)); } else {
+ * doc.add(Field.Text("title", "")); }
+ */
+ // doc.add(Field.Text("title", parser.getTitle()));
+ doc.add(new Field("title", parser.getTitle(), Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.YES));
+ // System.out.println("HTMLDocument.getLuceneDocument(): title field
+ // added: " + title);
+ // Add the tag-stripped contents as a Reader-valued Text field so it
+ // will get tokenized and indexed.
/*
- String body = htmlDoc.getBody();
- String contents = "";
-
- if ((body != null) && (title != null)) {
- contents = title + " " + body;
- doc.add(Field.Text("contents", title + body));
- }
-
- doc.add(Field.Text("contents", contents));
- */
- doc.add(Field.Text("contents", parser.getReader()));
-
+ * String body = htmlDoc.getBody(); String contents = "";
+ *
+ * if ((body != null) && (title != null)) { contents = title + " " +
+ * body; doc.add(Field.Text("contents", title + body)); }
+ *
+ * doc.add(Field.Text("contents", contents));
+ */
+ // doc.add(Field.Text("contents", parser.getReader()));
+ doc.add(new Field("contents", parser.getReader()));
return doc;
}
}
Modified: lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/ReTokenizeFile.java
URL: http://svn.apache.org/viewvc/lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/ReTokenizeFile.java?rev=574702&r1=574701&r2=574702&view=diff
==============================================================================
--- lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/ReTokenizeFile.java (original)
+++ lenya/branches/revolution/1.3.x/src/java/org/apache/lenya/lucene/ReTokenizeFile.java Tue Sep 11 14:39:37 2007
@@ -14,9 +14,7 @@
* limitations under the License.
*
*/
-
/* $Id$ */
-
package org.apache.lenya.lucene;
import java.io.BufferedReader;
@@ -28,203 +26,164 @@
import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;
import java.util.StringTokenizer;
-
import org.apache.lenya.lucene.html.HTMLParser;
import org.apache.log4j.Category;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
-
/**
* DOCUMENT ME!
*/
public class ReTokenizeFile {
private static final Category log = Category.getInstance(ReTokenizeFile.class);
-
private int offset = 100;
-
/**
* DOCUMENT ME!
- *
- * @param args DOCUMENT ME!
+ *
+ * @param args
+ * DOCUMENT ME!
*/
public static void main(String[] args) {
if (args.length < 2) {
System.err.println("Usage: ReTokenizeFile filename word1 word2 ...");
-
return;
}
-
try {
- String[] words = new String[args.length - 1]; //{"Cocoon","Lenya"};
-
+ String[] words = new String[args.length - 1]; // {"Cocoon","Lenya"};
for (int i = 1; i < args.length; i++) {
words[i - 1] = args[i];
}
-
String s = null;
-
s = new ReTokenizeFile().getExcerpt(new File(args[0]), words);
System.err.println(".main(): Excerpt: " + s);
} catch (Exception e) {
System.err.println(".main(): " + e);
}
}
-
/**
* DOCUMENT ME!
- *
- * @param file DOCUMENT ME!
- *
+ *
+ * @param file
+ * DOCUMENT ME!
+ *
* @return DOCUMENT ME!
- *
- * @throws Exception DOCUMENT ME!
+ *
+ * @throws Exception
+ * DOCUMENT ME!
*/
public String reTokenize(File file) throws Exception {
- TokenStream ts = new StandardAnalyzer().tokenStream(new HTMLParser(file).getReader());
-
+ TokenStream ts = new StandardAnalyzer().tokenStream("", new HTMLParser(file).getReader());
Token token = null;
-
while ((token = ts.next()) != null) {
- System.out.println("ReTokenizeFile.reTokenize(File): " + token.termText() + " " +
- token.startOffset() + " " + token.endOffset() + " " + token.type());
+ System.out.println("ReTokenizeFile.reTokenize(File): " + token.termText() + " " + token.startOffset() + " " + token.endOffset() + " " + token.type());
}
-
return file.getAbsolutePath();
}
-
/**
- *
+ *
*/
- public String getExcerpt(File file, String[] words)
- throws FileNotFoundException, IOException {
+ public String getExcerpt(File file, String[] words) throws FileNotFoundException, IOException {
if (file.getName().substring(file.getName().length() - 4).equals(".pdf")) {
file = new File(file.getAbsolutePath() + ".txt");
}
-
String content = readFileWithEncoding(file);
-
- //log.debug(content);
-
- content = removeTags(content);
-
- //log.debug(content);
-
-
- /*java.io.Reader reader = new HTMLParser(file).getReader();
- char[] chars = new char[1024];
- int chars_read;
- java.io.Writer writer = new java.io.StringWriter();
-
- while ((chars_read = reader.read(chars)) > 0) {
- writer.write(chars, 0, chars_read);
- }*/
-
- //String html = writer.toString();
- //html = writer.toString();
-
-
+ // log.debug(content);
+ content = removeTags(content);
+ // log.debug(content);
+ /*
+ * java.io.Reader reader = new HTMLParser(file).getReader(); char[]
+ * chars = new char[1024]; int chars_read; java.io.Writer writer = new
+ * java.io.StringWriter();
+ *
+ * while ((chars_read = reader.read(chars)) > 0) { writer.write(chars,
+ * 0, chars_read); }
+ */
+ // String html = writer.toString();
+ // html = writer.toString();
int index = -1;
-
for (int i = 0; i < words.length; i++) {
index = content.toLowerCase().indexOf(words[i].toLowerCase());
-
if (index >= 0) {
int start = index - offset;
-
if (start < 0) {
start = 0;
}
-
int end = index + words[i].length() + offset;
-
if (end >= content.length()) {
end = content.length() - 1;
}
-
return content.substring(start, end);
}
}
-
return null;
}
-
/**
* Remove tags
- *
- * @param string Content with tags
- *
+ *
+ * @param string
+ * Content with tags
+ *
* @return Content without tags
*/
public String removeTags(String string) {
StringBuffer sb = new StringBuffer("");
-
boolean tag = false;
-
for (int i = 0; i < string.length(); i++) {
char ch = string.charAt(i);
- if (ch == '<') {
+ if (ch == '<') {
tag = true;
} else if (ch == '>') {
tag = false;
} else {
- if (!tag) sb.append(string.charAt(i));
+ if (!tag)
+ sb.append(string.charAt(i));
}
}
-
return sb.toString();
}
-
/**
* Is being used by search-and-results.xsp. Is this really still necessary?
- *
- * @param string content
- *
+ *
+ * @param string
+ * content
+ *
* @return content without <>&
*/
public String tidy(String string) {
StringTokenizer st = new StringTokenizer(string, "<>&");
-
StringBuffer sb = new StringBuffer("");
-
while (st.hasMoreElements()) {
sb.append(st.nextToken());
}
-
return sb.toString();
}
-
/**
- * Encloses all words in <code>words</code> that appear in <code>string</code> in
- * <word> tags. The whole string is enclosed in <excerpt> tags.
- *
- * @param string The string to process.
- * @param words The words to emphasize.
- *
+ * Encloses all words in <code>words</code> that appear in
+ * <code>string</code> in <word> tags. The whole string is enclosed
+ * in <excerpt> tags.
+ *
+ * @param string
+ * The string to process.
+ * @param words
+ * The words to emphasize.
+ *
* @return DOCUMENT ME!
*/
public String emphasizeAsXML(String string, String[] words) {
String emphasizedString = "... Hello <word>World</word>! ...";
-
String lowerCaseString = string.toLowerCase();
-
for (int i = 0; i < words.length; i++) {
String word = words[i].toLowerCase();
-
// use uppercase tags so that they are not replaced
lowerCaseString = lowerCaseString.replaceAll(word, "<WORD>" + word + "</WORD>");
}
-
lowerCaseString = lowerCaseString.toLowerCase();
-
- //if (true) return "<excerpt>" + lowerCaseString + "</excerpt>";
+ // if (true) return "<excerpt>" + lowerCaseString + "</excerpt>";
String result = "";
-
int sourceIndex = 0;
int index = 0;
String[] tags = { "<word>", "</word>" };
-
while (lowerCaseString.indexOf(tags[0], index) != -1) {
for (int tag = 0; tag < 2; tag++) {
int subStringLength = lowerCaseString.indexOf(tags[tag], index) - index;
@@ -234,41 +193,38 @@
index += (subStringLength + tags[tag].length());
}
}
-
result += includeInCDATA(string.substring(sourceIndex));
-
return "<excerpt>" + result + "</excerpt>";
}
-
/**
* Includes a string in CDATA delimiters.
*/
protected String includeInCDATA(String string) {
return "<![CDATA[" + string + "]]>";
}
-
/**
* reads a file and if the file is an xml file, determine its encoding
- * @param file the file to read.
- * (if the file is an xml file with an specified encoding, this will be overwritten)
+ *
+ * @param file
+ * the file to read. (if the file is an xml file with an
+ * specified encoding, this will be overwritten)
* @return the contents of the file.
*/
protected String readFileWithEncoding(File file) throws FileNotFoundException, IOException {
String content = readHtmlFile(file);
// test if the file contains xml data and extract the encoding
int endOfFirstTag = content.indexOf(">");
- if(endOfFirstTag > 0 && content.charAt(endOfFirstTag-1) == '?') {
+ if (endOfFirstTag > 0 && content.charAt(endOfFirstTag - 1) == '?') {
String upperLine = content.substring(0, endOfFirstTag).toUpperCase();
- int encStart = upperLine.indexOf("ENCODING=")+10;
+ int encStart = upperLine.indexOf("ENCODING=") + 10;
int encEnd = -1;
-
if (encStart > 0) {
encEnd = upperLine.indexOf("\"", encStart);
if (encEnd == -1) {
encEnd = upperLine.indexOf("\'", encStart);
}
}
- if(encStart > 0 && encEnd > 0) {
+ if (encStart > 0 && encEnd > 0) {
String xmlCharset = upperLine.substring(encStart, encEnd);
try {
if (Charset.isSupported(xmlCharset)) {
@@ -281,39 +237,44 @@
}
return content;
}
-
-
/**
* read a html file.
- * @param file the file to read
+ *
+ * @param file
+ * the file to read
* @return the content of the file.
- * @throws FileNotFoundException if the file does not exists.
- * @throws IOException if something else went wrong.
+ * @throws FileNotFoundException
+ * if the file does not exists.
+ * @throws IOException
+ * if something else went wrong.
*/
protected String readHtmlFile(File file) throws FileNotFoundException, IOException {
java.io.Reader reader = new HTMLParser(file).getReader();
char[] chars = new char[1024];
int chars_read;
java.io.Writer writer = new java.io.StringWriter();
-
while ((chars_read = reader.read(chars)) > 0) {
writer.write(chars, 0, chars_read);
}
return writer.toString();
}
-
/**
* reads a file in the specified encoding.
- * @param file the file to read.
- * @param encoding the file encoding
+ *
+ * @param file
+ * the file to read.
+ * @param encoding
+ * the file encoding
* @return the content of the file.
- * @throws FileNotFoundException if the file does not exists.
- * @throws IOException if something else went wrong.
+ * @throws FileNotFoundException
+ * if the file does not exists.
+ * @throws IOException
+ * if something else went wrong.
*/
protected String readFile(File file, Charset charset) throws FileNotFoundException, IOException {
FileInputStream inputFile = new FileInputStream(file);
InputStreamReader inputStream;
- if(charset != null) {
+ if (charset != null) {
inputStream = new InputStreamReader(inputFile, charset);
} else {
inputStream = new InputStreamReader(inputFile);
@@ -330,7 +291,6 @@
inputFile.close();
return buffer.toString();
}
-
/**
* Set offset
*/
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.