You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by th...@apache.org on 2006/02/23 18:03:34 UTC
svn commit: r380153 -
/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java
Author: thorsten
Date: Thu Feb 23 09:03:32 2006
New Revision: 380153
URL: http://svn.apache.org/viewcvs?rev=380153&view=rev
Log:
White noise - formating changes
Modified:
lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java
Modified: lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java?rev=380153&r1=380152&r2=380153&view=diff
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java (original)
+++ lenya/trunk/src/java/org/apache/lenya/cms/site/usecases/Create.java Thu Feb 23 09:03:32 2006
@@ -55,319 +55,329 @@
*/
public abstract class Create extends AbstractUsecase {
- protected static final String RESOURCE_TYPES = "resourceTypes";
+ protected static final String RESOURCE_TYPES = "resourceTypes";
- protected static final String LANGUAGE = "language";
+ protected static final String LANGUAGE = "language";
- protected static final String LANGUAGES = "languages";
+ protected static final String LANGUAGES = "languages";
- protected static final String DOCUMENT_ID = "documentId";
+ protected static final String DOCUMENT_ID = "documentId";
- protected static final String VISIBLEINNAV = "visibleInNav";
-
- protected static final String SAMPLE = "sample";
- protected static final String SAMPLES = "samples";
-
- /**
- * Ctor.
- */
- public Create() {
- super();
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
- */
- protected void doCheckPreconditions() throws Exception {
- super.doCheckPreconditions();
-
- if (!getArea().equals(Publication.AUTHORING_AREA)) {
- addErrorMessage("This usecase can only be invoked in the authoring area!");
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
- */
- protected Node[] getNodesToLock() throws UsecaseException {
- try {
- SiteStructure structure = SiteUtil.getSiteStructure(this.manager, getSourceDocument());
- Node[] nodes = { structure.getRepositoryNode() };
- return nodes;
- } catch (SiteException e) {
- throw new UsecaseException(e);
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
- */
- protected void doCheckExecutionConditions() throws Exception {
- String navigationTitle = getParameterAsString(DublinCore.ELEMENT_TITLE);
- if (navigationTitle.equals("")) {
- addErrorMessage("The navigation title is required.");
- }
-
- if (getInitialDocument() == null) {
- List samples = (List) getParameter(SAMPLES);
- String sample = getParameterAsString(SAMPLE);
- if (samples != null && samples.size() > 1 && (sample == null || sample.equals(""))) {
- addErrorMessage("Please select a page layout.");
- }
- }
-
- String doctypeName = getDocumentTypeName();
- if (doctypeName != null) {
- initSampleParameters();
- }
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
- */
- protected void doExecute() throws Exception {
- super.doExecute();
-
- // create new document
- DocumentManager documentManager = null;
- ServiceSelector selector = null;
- ResourceType resourceType = null;
- try {
-
- documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
-
- DocumentIdentityMap map = getDocumentIdentityMap();
- Document document = map.get(getPublication(),
- getArea(),
- getNewDocumentId(),
- getParameterAsString(LANGUAGE));
-
- Document initialDocument = getInitialDocument();
- if (initialDocument == null) {
- selector = (ServiceSelector) this.manager.lookup(ResourceType.ROLE + "Selector");
- resourceType = (ResourceType) selector.select(getDocumentTypeName());
- if (getParameterAsString(SAMPLE) != null
- && getParameterAsString(SAMPLE).length() > 0)
- resourceType.setSampleURI(getParameterAsString(SAMPLE));
- documentManager.add(document,
- resourceType,
- getParameterAsString(DublinCore.ELEMENT_TITLE),
- getVisibleInNav(),
- null);
- resourceType.setSampleURI(""); // reset to default sample
- } else {
- documentManager.add(document,
- initialDocument,
- getParameterAsString(DublinCore.ELEMENT_TITLE),
- getVisibleInNav(),
- null);
- }
-
- setMetaData(document);
-
- // the location to navigate to after completion of usecase
- setTargetURL(document.getCanonicalWebappURL());
-
- } finally {
- if (documentManager != null) {
- this.manager.release(documentManager);
- }
- if (selector != null) {
- if (resourceType != null) {
- selector.release(resourceType);
- }
- this.manager.release(selector);
- }
- }
-
- }
-
- /**
- * @return the name of the document being created in the usecase
- */
- protected abstract String getNewDocumentName();
-
- /**
- * @return the id of the new document being created in the usecase
- */
- protected abstract String getNewDocumentId();
-
- /**
- * If the document created in the usecase shall have initial contents copied from an existing
- * document, construct that document in this method.
- *
- * @return A document.
- */
- protected Document getInitialDocument() {
- return null;
- }
-
- /**
- * @return The type of the created document.
- */
- protected abstract String getDocumentTypeName();
-
- /**
- * Sets the meta data of the created document.
- *
- * @param document The document.
- * @throws DocumentException if an error occurs.
- */
- protected void setMetaData(Document document) throws DocumentException {
-
- if (document == null)
- throw new IllegalArgumentException("parameter document may not be null");
-
- Map dcMetaData = new HashMap();
- dcMetaData.put(DublinCore.ELEMENT_TITLE, getParameterAsString(DublinCore.ELEMENT_TITLE));
- dcMetaData.put(DublinCore.ELEMENT_CREATOR, getParameterAsString(DublinCore.ELEMENT_CREATOR));
- dcMetaData.put(DublinCore.ELEMENT_PUBLISHER,
- getParameterAsString(DublinCore.ELEMENT_PUBLISHER));
- dcMetaData.put(DublinCore.ELEMENT_SUBJECT, getParameterAsString(DublinCore.ELEMENT_SUBJECT));
- dcMetaData.put(DublinCore.ELEMENT_DATE, getParameterAsString(DublinCore.ELEMENT_DATE));
- dcMetaData.put(DublinCore.ELEMENT_RIGHTS, getParameterAsString(DublinCore.ELEMENT_RIGHTS));
- dcMetaData.put(DublinCore.ELEMENT_LANGUAGE, getParameterAsString(LANGUAGE));
-
- document.getMetaDataManager().setDublinCoreMetaData(dcMetaData);
- }
-
- /**
- * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
- */
- protected void initParameters() {
- super.initParameters();
-
- Map objectModel = ContextHelper.getObjectModel(getContext());
- Request request = ObjectModelHelper.getRequest(objectModel);
- Session session = request.getSession(false);
- Identity identity = (Identity) session.getAttribute(Identity.class.getName());
- User user = identity.getUser();
- if (user != null) {
- setParameter(DublinCore.ELEMENT_CREATOR, user.getId());
- } else {
- setParameter(DublinCore.ELEMENT_CREATOR, "");
- }
-
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- setParameter(DublinCore.ELEMENT_DATE, format.format(new GregorianCalendar().getTime()));
-
- String doctypeName = getDocumentTypeName();
- if (doctypeName != null) {
- initSampleParameters();
- setParameter(RESOURCE_TYPES, Collections.EMPTY_LIST);
- }
- else {
- String[] resourceTypes = getPublication().getResourceTypeNames();
- setParameter(RESOURCE_TYPES, Arrays.asList(resourceTypes));
- }
- }
-
- protected void initSampleParameters() {
- ServiceSelector selector = null;
- ResourceType resourceType = null;
- try {
- selector = (ServiceSelector) this.manager.lookup(ResourceType.ROLE + "Selector");
- resourceType = (ResourceType) selector.select(getDocumentTypeName());
- setParameter(SAMPLES, Arrays.asList(resourceType.getSampleNames()));
- } catch (Exception e) {
- throw new RuntimeException(e);
- } finally {
- if (selector != null) {
- if (resourceType != null) {
- selector.release(resourceType);
- }
- this.manager.release(selector);
- }
- }
- }
-
- /**
- * @return The source document or <code>null</code> if the usecase was not invoked on a
- * document.
- */
- protected Document getSourceDocument() {
- Document document = null;
- String url = getSourceURL();
- try {
- if (getDocumentIdentityMap().isDocument(url)) {
- document = getDocumentIdentityMap().getFromURL(url);
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- return document;
- }
-
- /**
- * @return The new document.
- */
- protected Document getNewDocument() {
- Document document = null;
- //get new document
- DocumentManager documentManager = null;
- ServiceSelector selector = null;
- ResourceType resourceType = null;
- try {
- documentManager = (DocumentManager) this.manager.lookup(DocumentManager.ROLE);
-
- DocumentIdentityMap map = getDocumentIdentityMap();
- document = map.get(getPublication(),
- getArea(),
- getNewDocumentId(),
- getParameterAsString(LANGUAGE));
-
- } catch (Exception e) {
- throw new RuntimeException(e);
- } finally {
- if (documentManager != null) {
- this.manager.release(documentManager);
- }
- if (selector != null) {
- if (resourceType != null) {
- selector.release(resourceType);
- }
- this.manager.release(selector);
- }
- }
- return document;
- }
- /**
- * @return The area without the "info-" prefix.
- */
- public String getArea() {
- URLInformation info = new URLInformation(getSourceURL());
- return info.getArea();
- }
-
- private Publication publication;
-
- /**
- * Access to the current publication. Use this when the publication is not yet known in the
- * usecase: e.g. when creating a global asset. When adding a resource or a child to a document,
- * access the publication via that document's interface instead.
- *
- * @return the publication in which the use-case is being executed
- */
- protected Publication getPublication() {
- if (this.publication == null) {
- try {
- this.publication = PublicationUtil.getPublicationFromUrl(this.manager,
- getSourceURL());
- } catch (PublicationException e) {
- throw new RuntimeException(e);
- }
- }
- return this.publication;
- }
-
- /**
- * @return the visibleInNav Attribute of the document being created in the usecase
- */
- protected boolean getVisibleInNav() {
- if (getParameterAsString(VISIBLEINNAV).equals("false")) {
- return false;
- }
- return true;
+ protected static final String VISIBLEINNAV = "visibleInNav";
+
+ protected static final String SAMPLE = "sample";
+
+ protected static final String SAMPLES = "samples";
+
+ /**
+ * Ctor.
+ */
+ public Create() {
+ super();
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckPreconditions()
+ */
+ protected void doCheckPreconditions() throws Exception {
+ super.doCheckPreconditions();
+
+ if (!getArea().equals(Publication.AUTHORING_AREA)) {
+ addErrorMessage("This usecase can only be invoked in the authoring area!");
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#getNodesToLock()
+ */
+ protected Node[] getNodesToLock() throws UsecaseException {
+ try {
+ SiteStructure structure = SiteUtil.getSiteStructure(this.manager,
+ getSourceDocument());
+ Node[] nodes = { structure.getRepositoryNode() };
+ return nodes;
+ } catch (SiteException e) {
+ throw new UsecaseException(e);
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doCheckExecutionConditions()
+ */
+ protected void doCheckExecutionConditions() throws Exception {
+ String navigationTitle = getParameterAsString(DublinCore.ELEMENT_TITLE);
+ if (navigationTitle.equals("")) {
+ addErrorMessage("The navigation title is required.");
+ }
+
+ if (getInitialDocument() == null) {
+ List samples = (List) getParameter(SAMPLES);
+ String sample = getParameterAsString(SAMPLE);
+ if (samples != null && samples.size() > 1
+ && (sample == null || sample.equals(""))) {
+ addErrorMessage("Please select a page layout.");
+ }
+ }
+
+ String doctypeName = getDocumentTypeName();
+ if (doctypeName != null) {
+ initSampleParameters();
+ }
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#doExecute()
+ */
+ protected void doExecute() throws Exception {
+ super.doExecute();
+
+ // create new document
+ DocumentManager documentManager = null;
+ ServiceSelector selector = null;
+ ResourceType resourceType = null;
+ try {
+
+ documentManager = (DocumentManager) this.manager
+ .lookup(DocumentManager.ROLE);
+
+ DocumentIdentityMap map = getDocumentIdentityMap();
+ Document document = map.get(getPublication(), getArea(),
+ getNewDocumentId(), getParameterAsString(LANGUAGE));
+
+ Document initialDocument = getInitialDocument();
+ if (initialDocument == null) {
+ selector = (ServiceSelector) this.manager.lookup(ResourceType.ROLE
+ + "Selector");
+ resourceType = (ResourceType) selector.select(getDocumentTypeName());
+ if (getParameterAsString(SAMPLE) != null
+ && getParameterAsString(SAMPLE).length() > 0)
+ resourceType.setSampleURI(getParameterAsString(SAMPLE));
+ documentManager.add(document, resourceType,
+ getParameterAsString(DublinCore.ELEMENT_TITLE), getVisibleInNav(),
+ null);
+ resourceType.setSampleURI(""); // reset to default sample
+ } else {
+ documentManager.add(document, initialDocument,
+ getParameterAsString(DublinCore.ELEMENT_TITLE), getVisibleInNav(),
+ null);
+ }
+
+ setMetaData(document);
+
+ // the location to navigate to after completion of usecase
+ setTargetURL(document.getCanonicalWebappURL());
+
+ } finally {
+ if (documentManager != null) {
+ this.manager.release(documentManager);
+ }
+ if (selector != null) {
+ if (resourceType != null) {
+ selector.release(resourceType);
+ }
+ this.manager.release(selector);
+ }
+ }
+
+ }
+
+ /**
+ * @return the name of the document being created in the usecase
+ */
+ protected abstract String getNewDocumentName();
+
+ /**
+ * @return the id of the new document being created in the usecase
+ */
+ protected abstract String getNewDocumentId();
+
+ /**
+ * If the document created in the usecase shall have initial contents copied
+ * from an existing document, construct that document in this method.
+ *
+ * @return A document.
+ */
+ protected Document getInitialDocument() {
+ return null;
+ }
+
+ /**
+ * @return The type of the created document.
+ */
+ protected abstract String getDocumentTypeName();
+
+ /**
+ * Sets the meta data of the created document.
+ *
+ * @param document
+ * The document.
+ * @throws DocumentException
+ * if an error occurs.
+ */
+ protected void setMetaData(Document document) throws DocumentException {
+
+ if (document == null)
+ throw new IllegalArgumentException("parameter document may not be null");
+
+ Map dcMetaData = new HashMap();
+ dcMetaData.put(DublinCore.ELEMENT_TITLE,
+ getParameterAsString(DublinCore.ELEMENT_TITLE));
+ dcMetaData.put(DublinCore.ELEMENT_CREATOR,
+ getParameterAsString(DublinCore.ELEMENT_CREATOR));
+ dcMetaData.put(DublinCore.ELEMENT_PUBLISHER,
+ getParameterAsString(DublinCore.ELEMENT_PUBLISHER));
+ dcMetaData.put(DublinCore.ELEMENT_SUBJECT,
+ getParameterAsString(DublinCore.ELEMENT_SUBJECT));
+ dcMetaData.put(DublinCore.ELEMENT_DATE,
+ getParameterAsString(DublinCore.ELEMENT_DATE));
+ dcMetaData.put(DublinCore.ELEMENT_RIGHTS,
+ getParameterAsString(DublinCore.ELEMENT_RIGHTS));
+ dcMetaData.put(DublinCore.ELEMENT_LANGUAGE, getParameterAsString(LANGUAGE));
+
+ document.getMetaDataManager().setDublinCoreMetaData(dcMetaData);
+ }
+
+ /**
+ * @see org.apache.lenya.cms.usecase.AbstractUsecase#initParameters()
+ */
+ protected void initParameters() {
+ super.initParameters();
+
+ Map objectModel = ContextHelper.getObjectModel(getContext());
+ Request request = ObjectModelHelper.getRequest(objectModel);
+ Session session = request.getSession(false);
+ Identity identity = (Identity) session.getAttribute(Identity.class
+ .getName());
+ User user = identity.getUser();
+ if (user != null) {
+ setParameter(DublinCore.ELEMENT_CREATOR, user.getId());
+ } else {
+ setParameter(DublinCore.ELEMENT_CREATOR, "");
+ }
+
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ setParameter(DublinCore.ELEMENT_DATE, format.format(new GregorianCalendar()
+ .getTime()));
+
+ String doctypeName = getDocumentTypeName();
+ if (doctypeName != null) {
+ initSampleParameters();
+ setParameter(RESOURCE_TYPES, Collections.EMPTY_LIST);
+ } else {
+ String[] resourceTypes = getPublication().getResourceTypeNames();
+ setParameter(RESOURCE_TYPES, Arrays.asList(resourceTypes));
+ }
+ }
+
+ protected void initSampleParameters() {
+ ServiceSelector selector = null;
+ ResourceType resourceType = null;
+ try {
+ selector = (ServiceSelector) this.manager.lookup(ResourceType.ROLE
+ + "Selector");
+ resourceType = (ResourceType) selector.select(getDocumentTypeName());
+ setParameter(SAMPLES, Arrays.asList(resourceType.getSampleNames()));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (selector != null) {
+ if (resourceType != null) {
+ selector.release(resourceType);
+ }
+ this.manager.release(selector);
+ }
+ }
+ }
+
+ /**
+ * @return The source document or <code>null</code> if the usecase was not
+ * invoked on a document.
+ */
+ protected Document getSourceDocument() {
+ Document document = null;
+ String url = getSourceURL();
+ try {
+ if (getDocumentIdentityMap().isDocument(url)) {
+ document = getDocumentIdentityMap().getFromURL(url);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return document;
+ }
+
+ /**
+ * @return The new document.
+ */
+ protected Document getNewDocument() {
+ Document document = null;
+ // get new document
+ DocumentManager documentManager = null;
+ ServiceSelector selector = null;
+ ResourceType resourceType = null;
+ try {
+ documentManager = (DocumentManager) this.manager
+ .lookup(DocumentManager.ROLE);
+
+ DocumentIdentityMap map = getDocumentIdentityMap();
+ document = map.get(getPublication(), getArea(), getNewDocumentId(),
+ getParameterAsString(LANGUAGE));
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (documentManager != null) {
+ this.manager.release(documentManager);
+ }
+ if (selector != null) {
+ if (resourceType != null) {
+ selector.release(resourceType);
+ }
+ this.manager.release(selector);
+ }
+ }
+ return document;
+ }
+
+ /**
+ * @return The area without the "info-" prefix.
+ */
+ public String getArea() {
+ URLInformation info = new URLInformation(getSourceURL());
+ return info.getArea();
+ }
+
+ private Publication publication;
+
+ /**
+ * Access to the current publication. Use this when the publication is not yet
+ * known in the usecase: e.g. when creating a global asset. When adding a
+ * resource or a child to a document, access the publication via that
+ * document's interface instead.
+ *
+ * @return the publication in which the use-case is being executed
+ */
+ protected Publication getPublication() {
+ if (this.publication == null) {
+ try {
+ this.publication = PublicationUtil.getPublicationFromUrl(this.manager,
+ getSourceURL());
+ } catch (PublicationException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ return this.publication;
+ }
+
+ /**
+ * @return the visibleInNav Attribute of the document being created in the
+ * usecase
+ */
+ protected boolean getVisibleInNav() {
+ if (getParameterAsString(VISIBLEINNAV).equals("false")) {
+ return false;
}
+ return true;
+ }
-}
\ No newline at end of file
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org