Skip to content

Commit

Permalink
Merge pull request #6 from RaimondKempees/dd4t-compat
Browse files Browse the repository at this point in the history
Dd4t compat
  • Loading branch information
RaimondKempees committed Feb 13, 2015
2 parents b220b25 + acae09e commit d58f872
Show file tree
Hide file tree
Showing 9 changed files with 378 additions and 7 deletions.
16 changes: 9 additions & 7 deletions .gitignore
@@ -1,9 +1,11 @@
*.iml
dd4t-core/target
dd4t-databind/target
dd4t-test/target
dd4t-providers-rs/target
dd4t-providers/target
dd4t-api/target
.classpath
.project
.settings
.metadata
.recommenders
cd_*.xml

target
cd_licenses.xml
META-INF
Servers
26 changes: 26 additions & 0 deletions dd4t-compatibility/pom.xml
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>dd4t-parent</artifactId>
<groupId>org.dd4t</groupId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>dd4t-compability</artifactId>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.dd4t</groupId>
<artifactId>dd4t-core</artifactId>
<version>${version}</version>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,33 @@
/**
* Copyright 2011 Capgemini & SDL
*
* Licensed 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.dd4t.contentmodel.exceptions;

public class ItemNotFoundException extends Exception {

private static final long serialVersionUID = 8243724759254216595L;

public ItemNotFoundException(String message) {
super(message);
}

public ItemNotFoundException(Throwable t) {
super(t);
}

public ItemNotFoundException(String message, Throwable t) {
super(message, t);
}
}
@@ -0,0 +1,21 @@
package org.dd4t.contentmodel.exceptions;

public class NotAuthenticatedException extends Exception {

/**
*
*/
private static final long serialVersionUID = -1393489613071343863L;

public NotAuthenticatedException(String message) {
super(message);
}

public NotAuthenticatedException(Throwable t) {
super(t);
}

public NotAuthenticatedException(String message, Throwable t) {
super(message, t);
}
}
@@ -0,0 +1,33 @@
/**
* Copyright 2011 Capgemini & SDL
*
* Licensed 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.dd4t.contentmodel.exceptions;

public class NotAuthorizedException extends Exception {

private static final long serialVersionUID = 7860070186906683875L;

public NotAuthorizedException(String message) {
super(message);
}

public NotAuthorizedException(Throwable t) {
super(t);
}

public NotAuthorizedException(String message, Throwable t) {
super(message, t);
}
}
@@ -0,0 +1,82 @@
/**
* Copyright 2011 Capgemini & SDL
*
* Licensed 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.dd4t.core.factories;

import org.dd4t.contentmodel.Component;
import org.dd4t.contentmodel.exceptions.ItemNotFoundException;
import org.dd4t.contentmodel.exceptions.NotAuthenticatedException;
import org.dd4t.contentmodel.exceptions.NotAuthorizedException;
import org.dd4t.core.request.RequestContext;

@Deprecated
public interface ComponentFactory extends Factory {
/**
* Get a Component by its uri. No security available; the method will fail if a
* SecurityFilter is configured on the factory.
* @param uri
* @param context
* @return
* @throws ItemNotFoundException
* @throws NotAuthorizedException
* @throws NotAuthenticatedException
*/
public Component getComponent(String uri) throws ItemNotFoundException, NotAuthorizedException, NotAuthenticatedException;

/**
* Get a Component by its uri. The request context is used by the security filter (if there is one).
* @param uri
* @param context
* @return
* @throws ItemNotFoundException
* @throws NotAuthorizedException
* @throws NotAuthenticatedException
*/
public Component getComponent(String uri, RequestContext context) throws ItemNotFoundException, NotAuthorizedException, NotAuthenticatedException;

/**
* Get a component by its uri and component template uri. No security available; the method will fail if a
* SecurityFilter is configured on the factory.
* @param componentUri
* @param componentTemplateUri
* @param context
* @return
* @throws ItemNotFoundException
* @throws NotAuthorizedException
* @throws NotAuthenticatedException
*/
public Component getComponent(String componentUri, String componentTemplateUri) throws ItemNotFoundException, NotAuthorizedException, NotAuthenticatedException;

/**
* Get a component by its uri and component template uri. The request context is used by the security filter (if there is one).
* @param componentUri
* @param componentTemplateUri
* @param context
* @return
* @throws ItemNotFoundException
* @throws NotAuthorizedException
* @throws NotAuthenticatedException
*/
public Component getComponent(String componentUri, String componentTemplateUri, RequestContext context) throws ItemNotFoundException, NotAuthorizedException, NotAuthenticatedException;

/**
* Get an embedded (i.e.: stored inside of a DD4T page) component. This method is slightly slower as it has to utilize the componentlinker.
*
* @param tcmUri
* @return
* @throws ItemNotFoundException
*/
public Component getEmbeddedComponent(String uri) throws ItemNotFoundException;
}
@@ -0,0 +1,102 @@
/**
* Copyright 2011 Capgemini & SDL
*
* Licensed 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.dd4t.core.factories.impl;

import org.dd4t.contentmodel.Component;
import org.dd4t.contentmodel.ComponentPresentation;
import org.dd4t.contentmodel.exceptions.ItemNotFoundException;
import org.dd4t.contentmodel.exceptions.NotAuthenticatedException;
import org.dd4t.contentmodel.exceptions.NotAuthorizedException;
import org.dd4t.core.exceptions.FactoryException;
import org.dd4t.core.factories.ComponentFactory;
import org.dd4t.core.request.RequestContext;
import org.dd4t.providers.PayloadCacheProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Backwards compatibility class
* @author Rogier Oudshoorn
*
*/
public class GenericComponentFactory extends BaseFactory implements ComponentFactory {

private static Logger logger = LoggerFactory
.getLogger(GenericComponentFactory.class);

@Override
public void setCacheProvider(PayloadCacheProvider cacheAgent) {
// necessary setter, but don't bother
}

@Override
public Component getComponent(String uri) throws ItemNotFoundException,
NotAuthorizedException, NotAuthenticatedException {
ComponentPresentation cp;
try {
cp = ComponentPresentationFactoryImpl.getInstance().getComponentPresentation(uri, null);
} catch (FactoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();

return null;
}

return cp.getComponent();
}

@Override
public Component getComponent(String uri, RequestContext context)
throws ItemNotFoundException, NotAuthorizedException,
NotAuthenticatedException {
return getComponent(uri);
}

@Override
public Component getComponent(String componentUri,
String componentTemplateUri) throws ItemNotFoundException,
NotAuthorizedException, NotAuthenticatedException {
ComponentPresentation cp;
try {
cp = ComponentPresentationFactoryImpl.getInstance().getComponentPresentation(componentUri, componentTemplateUri);
} catch (FactoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();

return null;
}

return cp.getComponent();
}

@Override
public Component getComponent(String componentUri,
String componentTemplateUri, RequestContext context)
throws ItemNotFoundException, NotAuthorizedException,
NotAuthenticatedException {
return getComponent(componentUri, componentTemplateUri);
}

@Override
public Component getEmbeddedComponent(String uri)
throws ItemNotFoundException {
// Discuss if this is somehting we still should support, we probably do ...

return null;
}


}
@@ -0,0 +1,26 @@
/**
* Copyright 2011 Rogier Oudshoorn
*
* Licensed 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.dd4t.core.factories.impl;

/**
* Backwards compatibility class
* @author Rogier Oudshoorn
*
*/
@Deprecated
public class GenericPageFactory extends PageFactoryImpl {

}
@@ -0,0 +1,46 @@
/**
* Copyright 2011 Capgemini & SDL
*
* Licensed 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.dd4t.core.request.impl;

import javax.servlet.http.HttpServletRequest;

import org.dd4t.core.request.RequestContext;


/**
* Simple implementation of the RequestContext interface.
*
* @author rooudsho
*
*/
@Deprecated
public class BasicRequestContext implements RequestContext {
private HttpServletRequest req;

public BasicRequestContext(HttpServletRequest req){
this.req = req;
}

@Override
public HttpServletRequest getServletRequest() {
return req;
}

@Override
public boolean isUserInRole(String role) {
return req.isUserInRole(role);
}
}

0 comments on commit d58f872

Please sign in to comment.