Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Migrate gatein-api to gatein-4 #616

Open
wants to merge 2 commits into
base: 4.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions component/api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2012, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<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>
<groupId>org.gatein.portal</groupId>
<artifactId>component</artifactId>
<version>4.0.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>component.application-api</artifactId>
<name>GateIn Portal Component API Implementation</name>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.gatein.api</groupId>
<artifactId>gatein-api</artifactId>
</dependency>
<dependency>
<groupId>org.gatein.common</groupId>
<artifactId>common-common</artifactId>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>component.common</artifactId>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>component.portal</artifactId>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>component.web.oauth-common</artifactId>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>component.resources</artifactId>
</dependency>
<!-- For mgmt (rest) of api -->
<dependency>
<groupId>org.gatein.management</groupId>
<artifactId>gatein-management-spi</artifactId>
</dependency>
<!-- For testing -->
<dependency>
<groupId>org.chromattic</groupId>
<artifactId>chromattic.core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>component.test.core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>component.test.jcr</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>component.portal</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>component.identity</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>component.resources</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gatein.portal</groupId>
<artifactId>component.web.oauth-common</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkMode>always</forkMode>
</configuration>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
106 changes: 106 additions & 0 deletions component/api/src/main/java/org/gatein/api/BasicPortalRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.gatein.api;

import org.gatein.api.common.URIResolver;
import org.gatein.api.navigation.NodePath;
import org.gatein.api.security.User;
import org.gatein.api.site.SiteId;

import java.util.Locale;

/**
* A basic portal request supplying all the information needed in the constructor.
*
* @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
*/
public class BasicPortalRequest extends PortalRequest {
private final User user;
private final SiteId siteId;
private final NodePath nodePath;
private final Locale locale;
private final Portal portal;
private final URIResolver uriResolver;

public BasicPortalRequest(User user, SiteId siteId, NodePath nodePath, Locale locale, Portal portal, URIResolver uriResolver) {
this.user = user;
this.siteId = siteId;
this.nodePath = nodePath;
this.locale = locale;
this.portal = portal;
this.uriResolver = uriResolver;
}

@Override
public User getUser() {
return user;
}

@Override
public SiteId getSiteId() {
return siteId;
}

@Override
public NodePath getNodePath() {
return nodePath;
}

@Override
public Locale getLocale() {
return locale;
}

@Override
public Portal getPortal() {
return portal;
}

@Override
public URIResolver getURIResolver() {
return uriResolver;
}

public static void setInstance(BasicPortalRequest request) {
PortalRequest.setInstance(request);
}

public static class BasicURIResolver implements URIResolver {

private String portalURI;

public BasicURIResolver(String portalURI) {
this.portalURI = portalURI;
}

@Override
public String resolveURI(SiteId siteId) {
String name = siteId.getName();
if (name.charAt(0) == '/') {
return portalURI + name;
} else {
return portalURI + "/" + name;
}
}
}
}
89 changes: 89 additions & 0 deletions component/api/src/main/java/org/gatein/api/Comparators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.gatein.api;

import java.util.Comparator;

import org.gatein.api.common.Sorting;
import org.gatein.api.page.Page;
import org.gatein.api.site.Site;

/**
* @author <a href="mailto:nscavell@redhat.com">Nick Scavelli</a>
*/
class Comparators {
public static Comparator<Site> site(final Sorting<Site> sorting) {
if (sorting == null) {
return null;
} else if (sorting.getComparator() == null) {
return new Comparator<Site>() {
@Override
public int compare(Site o1, Site o2) {
if (sorting.getOrder() == Sorting.Order.descending) {
Site tmp = o1;
o1 = o2;
o2 = tmp;
}

return o1.compareTo(o2);
}
};
} else {
return new ComparatorWrapper<Site>(sorting.getComparator());
}
}

public static Comparator<Page> page(final Sorting<Page> sorting) {
if (sorting == null) {
return null;
} else if (sorting.getComparator() == null) {
return new Comparator<Page>() {
@Override
public int compare(Page page, Page other) {
if (sorting.getOrder() == Sorting.Order.descending) {
Page tmp = page;
page = other;
other = tmp;
}

return page.compareTo(other);
}
};
} else {
return sorting.getComparator();
}
}

private static class ComparatorWrapper<T> implements Comparator<T> {
private final Comparator<T> comparator;

public ComparatorWrapper(Comparator<T> comparator) {
this.comparator = comparator;
}

@Override
public int compare(T o1, T o2) {
return comparator.compare(o1, o2);
}
}
}
Loading