mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Moving to root below branch label
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.example.webservice.sample;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.security.auth.callback.Callback;
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
import javax.security.auth.callback.UnsupportedCallbackException;
|
||||
import javax.xml.rpc.ServiceException;
|
||||
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationResult;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationServiceLocator;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.repository.RepositoryServiceLocator;
|
||||
import org.alfresco.example.webservice.repository.RepositoryServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.types.Store;
|
||||
import org.apache.axis.EngineConfiguration;
|
||||
import org.apache.axis.configuration.FileProvider;
|
||||
import org.apache.ws.security.WSPasswordCallback;
|
||||
|
||||
/**
|
||||
* Web service sample 1.
|
||||
* <p>
|
||||
* Connect to the reposity and get a list of all the stores available in the repository.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class WebServiceSample1 implements CallbackHandler
|
||||
{
|
||||
/** Admin user name and password used to connect to the repository */
|
||||
public static final String USERNAME = "admin";
|
||||
public static final String PASSWORD = "admin";
|
||||
|
||||
/** The current ticket */
|
||||
public static String currentTicket;
|
||||
|
||||
/** WS security information */
|
||||
public static final String WS_SECURITY_INFO =
|
||||
"<deployment xmlns='http://xml.apache.org/axis/wsdd/' xmlns:java='http://xml.apache.org/axis/wsdd/providers/java'>" +
|
||||
" <transport name='http' pivot='java:org.apache.axis.transport.http.HTTPSender'/>" +
|
||||
" <globalConfiguration >" +
|
||||
" <requestFlow >" +
|
||||
" <handler type='java:org.apache.ws.axis.security.WSDoAllSender' >" +
|
||||
" <parameter name='action' value='UsernameToken'/>" +
|
||||
" <parameter name='user' value='ticket'/>" +
|
||||
" <parameter name='passwordCallbackClass' value='org.alfresco.example.webservice.sample.WebServiceSample1'/>" +
|
||||
" <parameter name='passwordType' value='PasswordText'/>" +
|
||||
" </handler>" +
|
||||
" </requestFlow >" +
|
||||
" </globalConfiguration>" +
|
||||
"</deployment>";
|
||||
|
||||
/**
|
||||
* Connect to the respository and print out the names of the available
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
throws Exception
|
||||
{
|
||||
AuthenticationServiceSoapBindingStub authenticationService = (AuthenticationServiceSoapBindingStub)new AuthenticationServiceLocator().getAuthenticationService();
|
||||
|
||||
// Start the session
|
||||
AuthenticationResult result = authenticationService.startSession(WebServiceSample1.USERNAME, WebServiceSample1.PASSWORD);
|
||||
WebServiceSample1.currentTicket = result.getTicket();
|
||||
|
||||
// Get a reference to the respository web service
|
||||
RepositoryServiceSoapBindingStub repositoryService = getRepositoryWebService();
|
||||
|
||||
// Get array of stores available in the repository
|
||||
Store[] stores = repositoryService.getStores();
|
||||
if (stores == null)
|
||||
{
|
||||
// NOTE: empty array are returned as a null object, this is a issue with the generated web service code.
|
||||
System.out.println("There are no stores avilable in the repository.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Output the names of all the stores available in the repository
|
||||
System.out.println("The following stores are available in the repository:");
|
||||
for (Store store : stores)
|
||||
{
|
||||
System.out.println(store.getAddress());
|
||||
}
|
||||
}
|
||||
|
||||
// End the session
|
||||
authenticationService.endSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the respository web service.
|
||||
*
|
||||
* @return the respository web service
|
||||
* @throws ServiceException Service Exception
|
||||
*/
|
||||
public static RepositoryServiceSoapBindingStub getRepositoryWebService() throws ServiceException
|
||||
{
|
||||
// Create the respository service, adding the WS security header information
|
||||
EngineConfiguration config = new FileProvider(new ByteArrayInputStream(WebServiceSample1.WS_SECURITY_INFO.getBytes()));
|
||||
RepositoryServiceLocator repositoryServiceLocator = new RepositoryServiceLocator(config);
|
||||
RepositoryServiceSoapBindingStub repositoryService = (RepositoryServiceSoapBindingStub)repositoryServiceLocator.getRepositoryService();
|
||||
return repositoryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* The implementation of the passwrod call back used by the WS Security
|
||||
*
|
||||
* @see javax.security.auth.callback.CallbackHandler#handle(javax.security.auth.callback.Callback[])
|
||||
*/
|
||||
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
|
||||
{
|
||||
for (int i = 0; i < callbacks.length; i++)
|
||||
{
|
||||
if (callbacks[i] instanceof WSPasswordCallback)
|
||||
{
|
||||
WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];
|
||||
pc.setPassword(currentTicket);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.example.webservice.sample;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
import javax.xml.rpc.ServiceException;
|
||||
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationResult;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationServiceLocator;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.repository.QueryResult;
|
||||
import org.alfresco.example.webservice.repository.RepositoryFault;
|
||||
import org.alfresco.example.webservice.repository.RepositoryServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.types.NamedValue;
|
||||
import org.alfresco.example.webservice.types.Query;
|
||||
import org.alfresco.example.webservice.types.QueryLanguageEnum;
|
||||
import org.alfresco.example.webservice.types.Reference;
|
||||
import org.alfresco.example.webservice.types.ResultSet;
|
||||
import org.alfresco.example.webservice.types.ResultSetRow;
|
||||
import org.alfresco.example.webservice.types.Store;
|
||||
import org.alfresco.example.webservice.types.StoreEnum;
|
||||
|
||||
/**
|
||||
* Web service sample 2
|
||||
* <p>
|
||||
* This sample shows how to execute a search using the repository web service and how to
|
||||
* query for a nodes parents.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class WebServiceSample2
|
||||
{
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
throws Exception
|
||||
{
|
||||
// Get the authentication service
|
||||
AuthenticationServiceSoapBindingStub authenticationService = (AuthenticationServiceSoapBindingStub)new AuthenticationServiceLocator().getAuthenticationService();
|
||||
|
||||
// Start the session
|
||||
AuthenticationResult result = authenticationService.startSession(WebServiceSample1.USERNAME, WebServiceSample1.PASSWORD);
|
||||
WebServiceSample1.currentTicket = result.getTicket();
|
||||
|
||||
// Execute the search sample
|
||||
executeSearch();
|
||||
|
||||
// End the session
|
||||
authenticationService.endSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a sample query and provides an example of using a parent query.
|
||||
*
|
||||
* @return returns a reference to a folder that is the parent of the search results
|
||||
* ( used in further samples)
|
||||
* @throws ServiceException Service exception
|
||||
* @throws RemoteException Remove exception
|
||||
* @throws RepositoryFault Repository fault
|
||||
*/
|
||||
public static Reference executeSearch() throws ServiceException, RemoteException, RepositoryFault
|
||||
{
|
||||
Reference parentReference = null;
|
||||
|
||||
// Get a reference to the respository web service
|
||||
RepositoryServiceSoapBindingStub repositoryService = WebServiceSample1.getRepositoryWebService();
|
||||
|
||||
// Create a store object referencing the main spaced store
|
||||
Store store = new Store(StoreEnum.workspace, "SpacesStore");
|
||||
|
||||
// Create a query object, looking for all items with alfresco in the name of text
|
||||
Query query = new Query(QueryLanguageEnum.lucene, "( +@\\{http\\://www.alfresco.org/1.0\\}name:alfresco*) OR TEXT:alfresco*");
|
||||
|
||||
// Execute the query
|
||||
QueryResult queryResult = repositoryService.query(store, query, false);
|
||||
|
||||
// Display the results
|
||||
ResultSet resultSet = queryResult.getResultSet();
|
||||
ResultSetRow[] rows = resultSet.getRows();
|
||||
if (rows == null)
|
||||
{
|
||||
System.out.println("No query results found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Results from query:");
|
||||
outputResultSet(rows);
|
||||
|
||||
// Get the id of the first result
|
||||
String firstResultId = rows[0].getNode().getId();
|
||||
Reference reference = new Reference(store, firstResultId, null);
|
||||
|
||||
// Get the parent(s) of the first result
|
||||
QueryResult parentQueryResult = repositoryService.queryParents(reference);
|
||||
|
||||
// Get the parent of the first result
|
||||
ResultSet parentResultSet = parentQueryResult.getResultSet();
|
||||
ResultSetRow[] parentRows = parentResultSet.getRows();
|
||||
if (parentRows == null)
|
||||
{
|
||||
System.out.println("No query results found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Results from parent query:");
|
||||
outputResultSet(parentRows);
|
||||
|
||||
// Return the first parent (we can use in other samples)
|
||||
String firstParentId = parentRows[0].getNode().getId();
|
||||
parentReference = new Reference(store, firstParentId, null);
|
||||
}
|
||||
}
|
||||
|
||||
return parentReference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to output the rows contained within a result set
|
||||
*
|
||||
* @param rows an array of rows
|
||||
*/
|
||||
public static void outputResultSet(ResultSetRow[] rows)
|
||||
{
|
||||
for (int x = 0; x < rows.length; x++)
|
||||
{
|
||||
ResultSetRow row = rows[x];
|
||||
|
||||
NamedValue[] columns = row.getColumns();
|
||||
for (int y = 0; y < columns.length; y++)
|
||||
{
|
||||
System.out.println("row " + x + ": "
|
||||
+ row.getColumns(y).getName() + " = "
|
||||
+ row.getColumns(y).getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.example.webservice.sample;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import javax.xml.rpc.ServiceException;
|
||||
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationResult;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationServiceLocator;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.content.Content;
|
||||
import org.alfresco.example.webservice.content.ContentServiceLocator;
|
||||
import org.alfresco.example.webservice.content.ContentServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.repository.UpdateResult;
|
||||
import org.alfresco.example.webservice.types.CML;
|
||||
import org.alfresco.example.webservice.types.CMLCreate;
|
||||
import org.alfresco.example.webservice.types.ContentFormat;
|
||||
import org.alfresco.example.webservice.types.NamedValue;
|
||||
import org.alfresco.example.webservice.types.ParentReference;
|
||||
import org.alfresco.example.webservice.types.Predicate;
|
||||
import org.alfresco.example.webservice.types.Reference;
|
||||
import org.alfresco.example.webservice.types.Store;
|
||||
import org.alfresco.example.webservice.types.StoreEnum;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.apache.axis.EngineConfiguration;
|
||||
import org.apache.axis.configuration.FileProvider;
|
||||
|
||||
/**
|
||||
* Web service sample 3
|
||||
* <p>
|
||||
* This web service sample shows how new content can be added to the repository and how content
|
||||
* can be read and updated via the web service API.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class WebServiceSample3
|
||||
{
|
||||
/** Content strings used in the sample */
|
||||
private static final String INITIAL_CONTENT = "This is some new content that I am adding to the repository";
|
||||
private static final String UPDATED_CONTENT = "This is the updated content";
|
||||
|
||||
/** The type of the association we are creating to the new content */
|
||||
private static final String ASSOC_CONTAINS = "{http://www.alfresco.org/model/content/1.0}contains";
|
||||
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
AuthenticationServiceSoapBindingStub authenticationService = (AuthenticationServiceSoapBindingStub)new AuthenticationServiceLocator().getAuthenticationService();
|
||||
|
||||
// Start the session
|
||||
AuthenticationResult result = authenticationService.startSession(WebServiceSample1.USERNAME, WebServiceSample1.PASSWORD);
|
||||
WebServiceSample1.currentTicket = result.getTicket();
|
||||
|
||||
// Get the content service
|
||||
ContentServiceSoapBindingStub contentService = getContentWebService();
|
||||
|
||||
// Create new content in the respository
|
||||
Reference newContentReference = createNewContent(contentService, "sampleThreeFileOne.txt", INITIAL_CONTENT);
|
||||
|
||||
// Read the newly added content from the respository
|
||||
Store store = new Store(StoreEnum.workspace, "SpacesStore");
|
||||
Content[] readResult = contentService.read(
|
||||
new Predicate(new Reference[]{newContentReference}, store, null),
|
||||
ContentModel.PROP_CONTENT.toString());
|
||||
Content content = readResult[0];
|
||||
|
||||
// Get the content from the download servlet using the URL and display it
|
||||
System.out.println("The newly added content is:");
|
||||
System.out.println(getContentAsString(WebServiceSample1.currentTicket, content.getUrl()));
|
||||
|
||||
// Update the content with something new
|
||||
contentService.write(newContentReference, ContentModel.PROP_CONTENT.toString(), UPDATED_CONTENT.getBytes(), null);
|
||||
|
||||
// Now output the updated content
|
||||
Content[] readResult2 = contentService.read(
|
||||
new Predicate(new Reference[]{newContentReference}, store, null),
|
||||
ContentModel.PROP_CONTENT.toString());
|
||||
Content content2 = readResult2[0];
|
||||
System.out.println("The updated content is:");
|
||||
System.out.println(getContentAsString(WebServiceSample1.currentTicket, content2.getUrl()));
|
||||
|
||||
// End the session
|
||||
authenticationService.endSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the content web service
|
||||
*
|
||||
* @return content web service
|
||||
* @throws ServiceException
|
||||
*/
|
||||
public static ContentServiceSoapBindingStub getContentWebService() throws ServiceException
|
||||
{
|
||||
// Create the content service, adding the WS security header information
|
||||
EngineConfiguration config = new FileProvider(new ByteArrayInputStream(WebServiceSample1.WS_SECURITY_INFO.getBytes()));
|
||||
ContentServiceLocator contentServiceLocator = new ContentServiceLocator(config);
|
||||
ContentServiceSoapBindingStub contentService = (ContentServiceSoapBindingStub)contentServiceLocator.getContentService();
|
||||
return contentService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to create new content.
|
||||
*
|
||||
* @param contentService the content web service
|
||||
* @param content the content itself
|
||||
* @return a reference to the created content node
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Reference createNewContent(ContentServiceSoapBindingStub contentService, String name, String contentString)
|
||||
throws Exception
|
||||
{
|
||||
// First we'll use the previous sample to get hold of a reference to a space that we can create the content within
|
||||
Reference reference = WebServiceSample2.executeSearch();
|
||||
|
||||
// Create a parent reference, this contains information about the association we are createing to the new content and the
|
||||
// parent of the new content (the space retrived from the search)
|
||||
ParentReference parentReference = new ParentReference(ASSOC_CONTAINS, ASSOC_CONTAINS);
|
||||
parentReference.setStore(reference.getStore());
|
||||
parentReference.setUuid(reference.getUuid());
|
||||
|
||||
// Define the content format for the content we are adding
|
||||
ContentFormat contentFormat = new ContentFormat("text/plain", "UTF-8");
|
||||
|
||||
NamedValue[] properties = new NamedValue[]{new NamedValue(ContentModel.PROP_NAME.toString(), name)};
|
||||
CMLCreate create = new CMLCreate("1", parentReference, ContentModel.TYPE_CONTENT.toString(), properties);
|
||||
CML cml = new CML();
|
||||
cml.setCreate(new CMLCreate[]{create});
|
||||
UpdateResult[] result = WebServiceSample1.getRepositoryWebService().update(cml);
|
||||
|
||||
Reference newContentNode = result[0].getDestination();
|
||||
Content content = contentService.write(newContentNode, ContentModel.PROP_CONTENT.toString(), contentString.getBytes(), contentFormat);
|
||||
|
||||
// Get a reference to the newly created content
|
||||
return content.getNode();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets the content from the download servlet for a given URL and returns it as a string.
|
||||
*
|
||||
* @param ticket the current ticket
|
||||
* @param strUrl the content URL
|
||||
* @return the content as a string
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String getContentAsString(String ticket, String strUrl) throws Exception
|
||||
{
|
||||
// Add the ticket to the url
|
||||
strUrl += "?ticket=" + ticket;
|
||||
|
||||
// Connect to donwload servlet
|
||||
StringBuilder readContent = new StringBuilder();
|
||||
URL url = new URL(strUrl);
|
||||
URLConnection conn = url.openConnection();
|
||||
InputStream is = conn.getInputStream();
|
||||
int read = is.read();
|
||||
while (read != -1)
|
||||
{
|
||||
readContent.append((char)read);
|
||||
read = is.read();
|
||||
}
|
||||
|
||||
// return content as a string
|
||||
return readContent.toString();
|
||||
}
|
||||
}
|
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.example.webservice.sample;
|
||||
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationResult;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationServiceLocator;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.repository.RepositoryServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.repository.UpdateResult;
|
||||
import org.alfresco.example.webservice.types.CML;
|
||||
import org.alfresco.example.webservice.types.CMLAddAspect;
|
||||
import org.alfresco.example.webservice.types.CMLCreate;
|
||||
import org.alfresco.example.webservice.types.Node;
|
||||
import org.alfresco.example.webservice.types.ParentReference;
|
||||
import org.alfresco.example.webservice.types.Predicate;
|
||||
import org.alfresco.example.webservice.types.Reference;
|
||||
import org.alfresco.example.webservice.types.Store;
|
||||
import org.alfresco.example.webservice.types.StoreEnum;
|
||||
import org.alfresco.model.ContentModel;
|
||||
|
||||
/**
|
||||
* Web service sample 4
|
||||
* <p>
|
||||
* This sample shows how to construct and execute CML queries using the respository web service.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class WebServiceSample4
|
||||
{
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
throws Exception
|
||||
{
|
||||
// Start the session
|
||||
AuthenticationServiceSoapBindingStub authenticationService = (AuthenticationServiceSoapBindingStub)new AuthenticationServiceLocator().getAuthenticationService();
|
||||
AuthenticationResult result = authenticationService.startSession(WebServiceSample1.USERNAME, WebServiceSample1.PASSWORD);
|
||||
WebServiceSample1.currentTicket = result.getTicket();
|
||||
|
||||
// Create a store object referencing the main spaced store
|
||||
Store store = new Store(StoreEnum.workspace, "SpacesStore");
|
||||
|
||||
// Get the repository
|
||||
RepositoryServiceSoapBindingStub repositoryService = WebServiceSample1.getRepositoryWebService();
|
||||
Reference folder = getTutorialFolder(store, repositoryService);
|
||||
|
||||
// Create the CML structure
|
||||
// When executed this cml update query will create a new content node beneth the tutorial folder and the add the
|
||||
// versionable aspect to the newly created node
|
||||
ParentReference parentReference = new ParentReference(ContentModel.ASSOC_CONTAINS.toString(), ContentModel.ASSOC_CONTAINS.toString());
|
||||
parentReference.setStore(store);
|
||||
parentReference.setUuid(folder.getUuid());
|
||||
CMLCreate create = new CMLCreate("id1", parentReference, ContentModel.TYPE_CONTENT.toString(), null);
|
||||
CMLAddAspect addAspect = new CMLAddAspect(ContentModel.ASPECT_VERSIONABLE.toString(), null, null, "id1");
|
||||
CML cml = new CML();
|
||||
cml.setCreate(new CMLCreate[]{create});
|
||||
cml.setAddAspect(new CMLAddAspect[]{addAspect});
|
||||
|
||||
// Execute the update
|
||||
UpdateResult[] updateResults = repositoryService.update(cml);
|
||||
|
||||
for (UpdateResult updateResult : updateResults)
|
||||
{
|
||||
String sourceId = "none";
|
||||
Reference source = updateResult.getSource();
|
||||
if (source != null)
|
||||
{
|
||||
sourceId = source.getUuid();
|
||||
}
|
||||
|
||||
String destinationId = "none";
|
||||
Reference destination = updateResult.getDestination();
|
||||
if (destination != null)
|
||||
{
|
||||
destinationId = destination.getUuid();
|
||||
}
|
||||
|
||||
System.out.println(
|
||||
"Command = " + updateResult.getStatement() +
|
||||
"; Source = " + sourceId +
|
||||
"; Destination = " + destinationId);
|
||||
}
|
||||
|
||||
// End the session
|
||||
authenticationService.endSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the space immediatly beneth company home call "Alfresco Tutorial"
|
||||
*
|
||||
* @param store
|
||||
* @param repositoryService
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static Reference getTutorialFolder(Store store, RepositoryServiceSoapBindingStub repositoryService)
|
||||
throws Exception
|
||||
{
|
||||
Reference reference = new Reference(store, null, "/app:company_home/*[@cm:name=\"Alfresco Tutorial\"]");
|
||||
Predicate predicate = new Predicate(new Reference[]{reference}, null, null);
|
||||
Node[] nodes = repositoryService.get(predicate);
|
||||
return nodes[0].getReference();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.example.webservice.sample;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import javax.xml.rpc.ServiceException;
|
||||
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationResult;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationServiceLocator;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.authoring.AuthoringServiceLocator;
|
||||
import org.alfresco.example.webservice.authoring.AuthoringServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.authoring.CheckoutResult;
|
||||
import org.alfresco.example.webservice.content.Content;
|
||||
import org.alfresco.example.webservice.content.ContentServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.repository.RepositoryServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.types.CML;
|
||||
import org.alfresco.example.webservice.types.CMLAddAspect;
|
||||
import org.alfresco.example.webservice.types.ContentFormat;
|
||||
import org.alfresco.example.webservice.types.NamedValue;
|
||||
import org.alfresco.example.webservice.types.Predicate;
|
||||
import org.alfresco.example.webservice.types.Reference;
|
||||
import org.alfresco.example.webservice.types.Store;
|
||||
import org.alfresco.example.webservice.types.StoreEnum;
|
||||
import org.alfresco.example.webservice.types.Version;
|
||||
import org.alfresco.example.webservice.types.VersionHistory;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.apache.axis.EngineConfiguration;
|
||||
import org.apache.axis.configuration.FileProvider;
|
||||
|
||||
/**
|
||||
* Web service sample 5
|
||||
* <p>
|
||||
* This sample shows how to check documents out, check them back in and then view the
|
||||
* version history.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class WebServiceSample5
|
||||
{
|
||||
private final static String INITIAL_CONTENT = "This is the content pror to checkout";
|
||||
private final static String UPDATED_CONTENT = "This is the updated content";
|
||||
|
||||
private final static String VERSIONABLE_ASPECT = "{http://www.alfresco.org/model/content/1.0}versionable";
|
||||
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
throws Exception
|
||||
{
|
||||
// Start the session
|
||||
AuthenticationServiceSoapBindingStub authenticationService = (AuthenticationServiceSoapBindingStub)new AuthenticationServiceLocator().getAuthenticationService();
|
||||
AuthenticationResult result = authenticationService.startSession(WebServiceSample1.USERNAME, WebServiceSample1.PASSWORD);
|
||||
WebServiceSample1.currentTicket = result.getTicket();
|
||||
|
||||
// Get the content and authoring service
|
||||
RepositoryServiceSoapBindingStub repositoryService = WebServiceSample1.getRepositoryWebService();
|
||||
ContentServiceSoapBindingStub contentService = WebServiceSample3.getContentWebService();
|
||||
AuthoringServiceSoapBindingStub authoringService = WebServiceSample5.getAuthoringWebService();
|
||||
|
||||
// Get a reference to a newly created content
|
||||
Reference contentReference = WebServiceSample3.createNewContent(contentService, "SampleFiveFileOne.txt", INITIAL_CONTENT);
|
||||
|
||||
// Add the versionable aspect to the newly created content. This will allows the content to be versioned
|
||||
makeVersionable(repositoryService, contentReference);
|
||||
|
||||
// Checkout the newly created content, placing the working document in the same folder
|
||||
Predicate itemsToCheckOut = new Predicate(new Reference[]{contentReference}, null, null);
|
||||
CheckoutResult checkOutResult = authoringService.checkout(itemsToCheckOut, null);
|
||||
|
||||
// Get a reference to the working copy
|
||||
Reference workingCopyReference = checkOutResult.getWorkingCopies()[0];
|
||||
|
||||
// Update the content of the working copy
|
||||
ContentFormat format = new ContentFormat(MimetypeMap.MIMETYPE_TEXT_PLAIN, "UTF-8");
|
||||
contentService.write(workingCopyReference, ContentModel.PROP_CONTENT.toString(), UPDATED_CONTENT.getBytes(), format);
|
||||
|
||||
// Now check the working copy in with a description of the change made that will be recorded in the version history
|
||||
Predicate predicate = new Predicate(new Reference[]{workingCopyReference}, null, null);
|
||||
NamedValue[] comments = new NamedValue[]{new NamedValue("description", "The content has been updated")};
|
||||
authoringService.checkin(predicate, comments, false);
|
||||
|
||||
// Output the updated content
|
||||
Store store = new Store(StoreEnum.workspace, "SpacesStore");
|
||||
Content[] readResult = contentService.read(
|
||||
new Predicate(new Reference[]{contentReference}, store, null),
|
||||
ContentModel.PROP_CONTENT.toString());
|
||||
Content content = readResult[0];
|
||||
System.out.println("This is the checked-in content:");
|
||||
System.out.println(WebServiceSample3.getContentAsString(WebServiceSample1.currentTicket, content.getUrl()));
|
||||
|
||||
// Get the version history
|
||||
System.out.println("The version history:");
|
||||
VersionHistory versionHistory = authoringService.getVersionHistory(contentReference);
|
||||
for (Version version : versionHistory.getVersions())
|
||||
{
|
||||
// Output the version details
|
||||
outputVersion(version);
|
||||
}
|
||||
|
||||
// End the session
|
||||
authenticationService.endSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a reference to the authoring web service
|
||||
*
|
||||
* @return the authoring web service
|
||||
* @throws ServiceException
|
||||
*/
|
||||
public static AuthoringServiceSoapBindingStub getAuthoringWebService() throws ServiceException
|
||||
{
|
||||
// Create the content service, adding the WS security header information
|
||||
EngineConfiguration config = new FileProvider(new ByteArrayInputStream(WebServiceSample1.WS_SECURITY_INFO.getBytes()));
|
||||
AuthoringServiceLocator authoringServiceLocator = new AuthoringServiceLocator(config);
|
||||
AuthoringServiceSoapBindingStub authoringService = (AuthoringServiceSoapBindingStub)authoringServiceLocator.getAuthoringService();
|
||||
return authoringService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to make apply the versionable aspect to a given reference
|
||||
* <p>
|
||||
* See sample 4 for more CML examples
|
||||
*
|
||||
* @param respositoryService the respository service
|
||||
* @param reference the reference
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void makeVersionable(RepositoryServiceSoapBindingStub respositoryService, Reference reference)
|
||||
throws Exception
|
||||
{
|
||||
// Create the add aspect query object
|
||||
Predicate predicate = new Predicate(new Reference[]{reference}, null, null);
|
||||
CMLAddAspect addAspect = new CMLAddAspect(VERSIONABLE_ASPECT, null, predicate, null);
|
||||
|
||||
// Create the content management language query
|
||||
CML cml = new CML();
|
||||
cml.setAddAspect(new CMLAddAspect[]{addAspect});
|
||||
|
||||
// Execute the query, which will add the versionable aspect to the node is question
|
||||
respositoryService.update(cml);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to output the version details
|
||||
*
|
||||
* @param version the version
|
||||
*/
|
||||
private static void outputVersion(Version version)
|
||||
{
|
||||
System.out.println("Version label = " + version.getLabel() + "; Version description = " + version.getCommentaries()[0].getValue());
|
||||
}
|
||||
}
|
@@ -0,0 +1,139 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* 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.alfresco.example.webservice.sample;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationResult;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationServiceLocator;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.classification.ClassificationServiceLocator;
|
||||
import org.alfresco.example.webservice.classification.ClassificationServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.repository.QueryResult;
|
||||
import org.alfresco.example.webservice.repository.RepositoryServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.types.Category;
|
||||
import org.alfresco.example.webservice.types.Classification;
|
||||
import org.alfresco.example.webservice.types.Query;
|
||||
import org.alfresco.example.webservice.types.QueryLanguageEnum;
|
||||
import org.alfresco.example.webservice.types.Store;
|
||||
import org.alfresco.example.webservice.types.StoreEnum;
|
||||
import org.alfresco.repo.search.ISO9075;
|
||||
import org.apache.axis.EngineConfiguration;
|
||||
import org.apache.axis.configuration.FileProvider;
|
||||
|
||||
/**
|
||||
* Web service sample 6
|
||||
* <p>
|
||||
* Example showing how content can be queried for using categories
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
*/
|
||||
public class WebServiceSample6
|
||||
{
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
throws Exception
|
||||
{
|
||||
// Start the session
|
||||
AuthenticationServiceSoapBindingStub authenticationService = (AuthenticationServiceSoapBindingStub)new AuthenticationServiceLocator().getAuthenticationService();
|
||||
AuthenticationResult result = authenticationService.startSession(WebServiceSample1.USERNAME, WebServiceSample1.PASSWORD);
|
||||
WebServiceSample1.currentTicket = result.getTicket();
|
||||
|
||||
// Get the content and authoring service
|
||||
RepositoryServiceSoapBindingStub repositoryService = WebServiceSample1.getRepositoryWebService();
|
||||
|
||||
// Get the classification service
|
||||
EngineConfiguration config = new FileProvider(new ByteArrayInputStream(WebServiceSample1.WS_SECURITY_INFO.getBytes()));
|
||||
ClassificationServiceSoapBindingStub classificationService = (ClassificationServiceSoapBindingStub) new ClassificationServiceLocator(config).getClassificationService();
|
||||
|
||||
// Create the store reference
|
||||
Store store = new Store(StoreEnum.workspace, "SpacesStore");
|
||||
|
||||
// Get all the classifications
|
||||
Classification[] classifications = classificationService.getClassifications(store);
|
||||
|
||||
// Output some details
|
||||
System.out.println("All classifications:");
|
||||
for (Classification classification : classifications)
|
||||
{
|
||||
System.out.println(classification.getClassification());
|
||||
System.out.println("Classification = " + classification.getTitle() + "; Root category = " + classification.getRootCategory().getTitle());
|
||||
}
|
||||
|
||||
// Get the class definition for the classification we are interested in
|
||||
Classification classification = classifications[0];
|
||||
|
||||
// Get the child categories
|
||||
Category[] categories = null;
|
||||
if (classifications.length > 0)
|
||||
{
|
||||
categories = classificationService.getChildCategories(classifications[0].getRootCategory().getId());
|
||||
if (categories != null)
|
||||
{
|
||||
// Output some details
|
||||
System.out.println("The child categories of classification '" + classifications[0].getTitle() + "':");
|
||||
for (Category category : categories)
|
||||
{
|
||||
System.out.println("Title = " + category.getTitle());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("No child categories found.");
|
||||
}
|
||||
}
|
||||
|
||||
// Now build a path query
|
||||
StringBuilder pathQuery = new StringBuilder(128);
|
||||
|
||||
//pathQuery.append("PATH:\"cm:generalclassifiable/cm:MyTestCategory/cm:One/member\"");
|
||||
|
||||
// Encode the root category name
|
||||
String encodedRoot = ISO9075.encode(classification.getRootCategory().getTitle());
|
||||
|
||||
// Build up the search path
|
||||
if (categories != null && categories.length != 0)
|
||||
{
|
||||
for (int i=0; i<categories.length; i++)
|
||||
{
|
||||
if (pathQuery.length() != 0)
|
||||
{
|
||||
pathQuery.append("OR");
|
||||
}
|
||||
|
||||
String encoded = ISO9075.encode(categories[i].getTitle());
|
||||
pathQuery.append(" PATH:\"cm:generalclassifiable/cm:" + encodedRoot + "/cm:" + encoded + "/member\" ");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Query path: " + pathQuery.toString());
|
||||
|
||||
// Call the repository service to do search based on category
|
||||
Query query = new Query(QueryLanguageEnum.lucene, pathQuery.toString());
|
||||
|
||||
// Execute the query
|
||||
QueryResult queryResult = repositoryService.query(store, query, true);
|
||||
|
||||
System.out.println("Category query results:");
|
||||
WebServiceSample2.outputResultSet(queryResult.getResultSet().getRows());
|
||||
|
||||
// End the session
|
||||
authenticationService.endSession();
|
||||
}
|
||||
}
|
@@ -0,0 +1,263 @@
|
||||
// NOTE: if you change the package location of this class you will need to update the WS_SEURITY_INFO XML as for this example this class
|
||||
// doubles as the passwordCAllbackClass
|
||||
package org.alfresco.example.webservice.sample;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.security.auth.callback.Callback;
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
import javax.security.auth.callback.UnsupportedCallbackException;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationResult;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationServiceLocator;
|
||||
import org.alfresco.example.webservice.authentication.AuthenticationServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.repository.QueryResult;
|
||||
import org.alfresco.example.webservice.repository.RepositoryServiceLocator;
|
||||
import org.alfresco.example.webservice.repository.RepositoryServiceSoapBindingStub;
|
||||
import org.alfresco.example.webservice.types.NamedValue;
|
||||
import org.alfresco.example.webservice.types.Node;
|
||||
import org.alfresco.example.webservice.types.Predicate;
|
||||
import org.alfresco.example.webservice.types.Query;
|
||||
import org.alfresco.example.webservice.types.QueryLanguageEnum;
|
||||
import org.alfresco.example.webservice.types.Reference;
|
||||
import org.alfresco.example.webservice.types.ResultSet;
|
||||
import org.alfresco.example.webservice.types.ResultSetRow;
|
||||
import org.alfresco.example.webservice.types.Store;
|
||||
import org.alfresco.example.webservice.types.StoreEnum;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.apache.axis.EngineConfiguration;
|
||||
import org.apache.axis.configuration.FileProvider;
|
||||
import org.apache.ws.security.WSPasswordCallback;
|
||||
|
||||
public class WebServiceSampleGetRankedContent implements CallbackHandler
|
||||
{
|
||||
/** Admin user name and password used to connect to the repository */
|
||||
public static final String USERNAME = "admin";
|
||||
public static final String PASSWORD = "admin";
|
||||
|
||||
/** The current ticket */
|
||||
public static String currentTicket;
|
||||
|
||||
/** WS security information */
|
||||
public static final String WS_SECURITY_INFO =
|
||||
"<deployment xmlns='http://xml.apache.org/axis/wsdd/' xmlns:java='http://xml.apache.org/axis/wsdd/providers/java'>" +
|
||||
" <transport name='http' pivot='java:org.apache.axis.transport.http.HTTPSender'/>" +
|
||||
" <globalConfiguration >" +
|
||||
" <requestFlow >" +
|
||||
" <handler type='java:org.apache.ws.axis.security.WSDoAllSender' >" +
|
||||
" <parameter name='action' value='UsernameToken'/>" +
|
||||
" <parameter name='user' value='ticket'/>" +
|
||||
" <parameter name='passwordCallbackClass' value='org.alfresco.example.webservice.sample.WebServiceSampleGetRankedContent'/>" +
|
||||
" <parameter name='passwordType' value='PasswordText'/>" +
|
||||
" </handler>" +
|
||||
" </requestFlow >" +
|
||||
" </globalConfiguration>" +
|
||||
"</deployment>";
|
||||
|
||||
/**
|
||||
* Main method
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
WebServiceSampleGetRankedContent sample = new WebServiceSampleGetRankedContent();
|
||||
List<ContentResult> results = sample.getRankedContent("Alfresco Tutorial", "alfresco*");
|
||||
|
||||
// Output the results for visual inspection
|
||||
int iCount = 1;
|
||||
for (ContentResult result : results)
|
||||
{
|
||||
System.out.println("Result " + iCount + ": " + result.toString());
|
||||
iCount ++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of ordered results of documents in the space specified matching the search
|
||||
* text provided.
|
||||
*
|
||||
* @param spaceName the name of the space (immediatly beneth the company home space) to search
|
||||
* @param searchValue the FTS search value
|
||||
* @return list of results
|
||||
*/
|
||||
public List<ContentResult> getRankedContent(String spaceName, String searchValue)
|
||||
{
|
||||
List<ContentResult> results = new ArrayList<ContentResult>();
|
||||
|
||||
try
|
||||
{
|
||||
// Get the authentication service
|
||||
AuthenticationServiceSoapBindingStub authenticationService = (AuthenticationServiceSoapBindingStub)new AuthenticationServiceLocator().getAuthenticationService();
|
||||
|
||||
// Start the session
|
||||
AuthenticationResult authenticationResult = authenticationService.startSession(WebServiceSample1.USERNAME, WebServiceSample1.PASSWORD);
|
||||
WebServiceSampleGetRankedContent.currentTicket = authenticationResult.getTicket();
|
||||
|
||||
// Create the respository service, adding the WS security header information
|
||||
EngineConfiguration config = new FileProvider(new ByteArrayInputStream(WebServiceSampleGetRankedContent.WS_SECURITY_INFO.getBytes()));
|
||||
RepositoryServiceLocator repositoryServiceLocator = new RepositoryServiceLocator(config);
|
||||
RepositoryServiceSoapBindingStub repositoryService = (RepositoryServiceSoapBindingStub)repositoryServiceLocator.getRepositoryService();
|
||||
|
||||
// Create a store object referencing the main spaced store
|
||||
Store store = new Store(StoreEnum.workspace, "SpacesStore");
|
||||
|
||||
// Get a reference to the space we have named
|
||||
Reference reference = new Reference(store, null, "/app:company_home/*[@cm:name=\"" + spaceName + "\"]");
|
||||
Predicate predicate = new Predicate(new Reference[]{reference}, null, null);
|
||||
Node[] nodes = repositoryService.get(predicate);
|
||||
|
||||
// Create a query object, looking for all items with alfresco in the name of text
|
||||
Query query = new Query(
|
||||
QueryLanguageEnum.lucene,
|
||||
"+PARENT:\"workspace://SpacesStore/"+ nodes[0].getReference().getUuid() + "\" +TEXT:\"" + searchValue + "\"");
|
||||
|
||||
// Execute the query
|
||||
QueryResult queryResult = repositoryService.query(store, query, false);
|
||||
|
||||
// Display the results
|
||||
ResultSet resultSet = queryResult.getResultSet();
|
||||
ResultSetRow[] rows = resultSet.getRows();
|
||||
|
||||
if (rows != null)
|
||||
{
|
||||
// Get the infomation from the result set
|
||||
for(ResultSetRow row : rows)
|
||||
{
|
||||
String nodeId = row.getNode().getId();
|
||||
ContentResult contentResult = new ContentResult(nodeId);
|
||||
|
||||
for (NamedValue namedValue : row.getColumns())
|
||||
{
|
||||
if (namedValue.getName().endsWith(ContentModel.PROP_CREATED.toString()) == true)
|
||||
{
|
||||
contentResult.setCreateDate(namedValue.getValue());
|
||||
}
|
||||
else if (namedValue.getName().endsWith(ContentModel.PROP_NAME.toString()) == true)
|
||||
{
|
||||
contentResult.setName(namedValue.getValue());
|
||||
}
|
||||
else if (namedValue.getName().endsWith(ContentModel.PROP_DESCRIPTION.toString()) == true)
|
||||
{
|
||||
contentResult.setDescription(namedValue.getValue());
|
||||
}
|
||||
else if (namedValue.getName().endsWith(ContentModel.PROP_CONTENT.toString()) == true)
|
||||
{
|
||||
// We could go to the content service and ask for the content to get the URL but to save time we
|
||||
// might as well dig the content URL out of the results.
|
||||
String contentString = namedValue.getValue();
|
||||
String[] values = contentString.split("[|=]");
|
||||
contentResult.setUrl(values[1]);
|
||||
}
|
||||
}
|
||||
|
||||
results.add(contentResult);
|
||||
}
|
||||
}
|
||||
|
||||
// End the session
|
||||
authenticationService.endSession();
|
||||
}
|
||||
catch (Exception serviceException)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Unable to perform search.", serviceException);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Security callback handler
|
||||
*/
|
||||
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
|
||||
{
|
||||
for (int i = 0; i < callbacks.length; i++)
|
||||
{
|
||||
if (callbacks[i] instanceof WSPasswordCallback)
|
||||
{
|
||||
WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];
|
||||
pc.setPassword(WebServiceSampleGetRankedContent.currentTicket);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new UnsupportedCallbackException(callbacks[i], "Unrecognized Callback");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to contain the information about the result from the query
|
||||
*/
|
||||
public class ContentResult
|
||||
{
|
||||
private String id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String url;
|
||||
private String createDate;
|
||||
|
||||
public ContentResult(String id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getCreateDate()
|
||||
{
|
||||
return createDate;
|
||||
}
|
||||
|
||||
public void setCreateDate(String createDate)
|
||||
{
|
||||
this.createDate = createDate;
|
||||
}
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description)
|
||||
{
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUrl()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url)
|
||||
{
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "id=" + this.id +
|
||||
"; name=" + this.name +
|
||||
"; description=" + this.description +
|
||||
"; created=" + this.createDate +
|
||||
"; url=" + this.url;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user