You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2009/02/10 23:33:49 UTC
svn commit: r743139 - in
/lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata:
MetaDataRegistryImpl.java impl/ impl/ConfigurableElementSet.java
impl/ElementImpl.java impl/MetaDataRegistryImpl.java
Author: andreas
Date: Tue Feb 10 22:33:48 2009
New Revision: 743139
URL: http://svn.apache.org/viewvc?rev=743139&view=rev
Log:
Continuing making the tests work, added declarations for some resource types (to be continued).
Added:
lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/
lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/ConfigurableElementSet.java
lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/ElementImpl.java
lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/MetaDataRegistryImpl.java
Removed:
lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/MetaDataRegistryImpl.java
Added: lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/ConfigurableElementSet.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/ConfigurableElementSet.java?rev=743139&view=auto
==============================================================================
--- lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/ConfigurableElementSet.java (added)
+++ lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/ConfigurableElementSet.java Tue Feb 10 22:33:48 2009
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.repository.metadata.impl;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.excalibur.source.Source;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.repository.metadata.Element;
+import org.apache.lenya.cms.repository.metadata.ElementSet;
+import org.apache.lenya.cms.repository.metadata.MetaDataException;
+import org.apache.lenya.cms.repository.metadata.MetaDataRegistry;
+
+/**
+ * Avalon-based element set.
+ */
+public class ConfigurableElementSet implements ElementSet {
+
+ private static final Log logger = LogFactory.getLog(ConfigurableElementSet.class);
+
+ private String namespaceUri;
+ private Map<String, Element> elements = new HashMap<String, Element>();
+ private SourceResolver sourceResolver;
+ private boolean loaded = false;
+
+ private MetaDataRegistry registry;
+
+ private String configUri;
+
+ public void loadConfiguration() throws Exception {
+
+ if (this.loaded) {
+ return;
+ }
+ this.loaded = true; // fail only once
+
+ Configuration config;
+ Source source = null;
+ try {
+ source = this.sourceResolver.resolveURI(configUri);
+ DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
+ config = builder.build(source.getInputStream());
+ } finally {
+ if (source != null) {
+ this.sourceResolver.release(source);
+ }
+ }
+
+ this.namespaceUri = config.getAttribute("namespace");
+
+ Configuration[] attributeConfigs = config.getChildren("element");
+ for (int i = 0; i < attributeConfigs.length; i++) {
+ String name = attributeConfigs[i].getAttribute("name");
+ boolean isMultiple = attributeConfigs[i].getAttributeAsBoolean("multiple", false);
+ boolean isEditable = attributeConfigs[i].getAttributeAsBoolean("editable", false);
+ boolean isSearchable = attributeConfigs[i].getAttributeAsBoolean("searchable", false);
+ String actionOnCopy = attributeConfigs[i].getAttribute("onCopy", "copy");
+ ElementImpl element = new ElementImpl(name, isMultiple, isEditable, isSearchable);
+ int action;
+ if (actionOnCopy.equalsIgnoreCase("copy")) {
+ action = Element.ONCOPY_COPY;
+ } else if (actionOnCopy.equalsIgnoreCase("ignore")) {
+ action = Element.ONCOPY_IGNORE;
+ } else if (actionOnCopy.equalsIgnoreCase("delete")) {
+ action = Element.ONCOPY_DELETE;
+ } else {
+ throw new ConfigurationException("The action [" + actionOnCopy
+ + "] is not supported.");
+ }
+ try {
+ element.setActionOnCopy(action);
+ } catch (MetaDataException e) {
+ throw new RuntimeException(e);
+ }
+ this.elements.put(name, element);
+ }
+
+ }
+
+ public Element[] getElements() {
+ Collection<Element> values = this.elements.values();
+ return (Element[]) values.toArray(new Element[values.size()]);
+ }
+
+ public Element getElement(String name) {
+ return (Element) this.elements.get(name);
+ }
+
+ public String getNamespaceUri() {
+ return this.namespaceUri;
+ }
+
+ public boolean containsElement(String name) {
+ return this.elements.keySet().contains(name);
+ }
+
+ public void register() throws Exception {
+ loadConfiguration();
+ this.registry.register(getNamespaceUri(), this);
+ }
+
+ public void setRegistry(MetaDataRegistry registry) throws MetaDataException {
+ this.registry = registry;
+ }
+
+ public void setConfigUri(String configUri) throws Exception {
+ this.configUri = configUri;
+ }
+
+ public void setSourceResolver(SourceResolver sourceResolver) {
+ this.sourceResolver = sourceResolver;
+ }
+
+}
Added: lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/ElementImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/ElementImpl.java?rev=743139&view=auto
==============================================================================
--- lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/ElementImpl.java (added)
+++ lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/ElementImpl.java Tue Feb 10 22:33:48 2009
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.repository.metadata.impl;
+
+import org.apache.lenya.cms.repository.metadata.Element;
+import org.apache.lenya.cms.repository.metadata.MetaDataException;
+
+/**
+ * Element implementation.
+ */
+public class ElementImpl implements Element {
+
+ private String name;
+ private boolean multiple;
+ private String description = "";
+ private boolean editable;
+ private int actionOnCopy;
+ private boolean searchable;
+
+ /**
+ * Ctor.
+ * @param name The name.
+ * @param isMultiple if the element can have multiple values.
+ * @param isEditable if the element can be edited.
+ * @param isSearchable if the element is searchable.
+ */
+ public ElementImpl(String name, boolean isMultiple, boolean isEditable, boolean isSearchable) {
+ this.name = name;
+ this.multiple = isMultiple;
+ this.editable = isEditable;
+ this.searchable = isSearchable;
+ }
+
+ /**
+ * Ctor.
+ * @param name The name.
+ * @param isMultiple if the element can have multiple values.
+ * @param isEditable if the element can be edited.
+ * @param isSearchable if the element is searchable.
+ * @param description The description of the element.
+ */
+ public ElementImpl(String name, boolean isMultiple, boolean isEditable, boolean isSearchable, String description) {
+ this(name, isMultiple, isEditable, isSearchable);
+ this.description = description;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public boolean isMultiple() {
+ return this.multiple;
+ }
+
+ public String getDescription() {
+ return this.description;
+ }
+
+ public boolean isEditable() {
+ return this.editable;
+ }
+
+ public int getActionOnCopy() {
+ return this.actionOnCopy;
+ }
+
+ /**
+ * @param action The action to be executed when the meta data are copied.
+ * @throws MetaDataException if the action is not supported.
+ */
+ public void setActionOnCopy(int action) throws MetaDataException {
+ this.actionOnCopy = action;
+ }
+
+ public boolean isSearchable() {
+ return this.searchable;
+ }
+
+}
Added: lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/MetaDataRegistryImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/MetaDataRegistryImpl.java?rev=743139&view=auto
==============================================================================
--- lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/MetaDataRegistryImpl.java (added)
+++ lenya/trunk/org.apache.lenya.core.repository/src/main/java/org/apache/lenya/cms/repository/metadata/impl/MetaDataRegistryImpl.java Tue Feb 10 22:33:48 2009
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.lenya.cms.repository.metadata.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.lenya.cms.repository.metadata.ElementSet;
+import org.apache.lenya.cms.repository.metadata.MetaDataException;
+import org.apache.lenya.cms.repository.metadata.MetaDataRegistry;
+
+/**
+ * Meta data registry implementation.
+ */
+public class MetaDataRegistryImpl implements MetaDataRegistry {
+
+ public ElementSet getElementSet(String namespaceUri) throws MetaDataException {
+ if (!isRegistered(namespaceUri)) {
+ throw new MetaDataException("The namespace URI [" + namespaceUri
+ + "] is not registered.");
+ }
+ return (ElementSet) this.namespace2set.get(namespaceUri);
+ }
+
+ public boolean isRegistered(String namespaceUri) throws MetaDataException {
+ return this.namespace2set.containsKey(namespaceUri);
+ }
+
+ private Map namespace2set = new HashMap();
+
+ public void register(String namespaceUri, ElementSet elementSet) throws MetaDataException {
+ if (this.namespace2set.containsKey(namespaceUri)) {
+ throw new MetaDataException("The namespace [" + namespaceUri
+ + "] is already registered.");
+ }
+ this.namespace2set.put(namespaceUri, elementSet);
+ }
+
+ public String[] getNamespaceUris() throws MetaDataException {
+ Set keys = this.namespace2set.keySet();
+ return (String[]) keys.toArray(new String[keys.size()]);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org