Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper2/files
In directory sc8-pr-cvs1:/tmp/cvs-serv3016/src/java/core/org/krysalis/ruper2/files
Modified Files:
ResourceFilenameAnalyzer.java
Added Files:
ResourceGroupFilenameAnalyzer.java
DefaultResourceGroupFilenameAnalyzer.java
Log Message:
Repository.listGroups works better now.
Note: This does not work on flat repos.
--- NEW FILE: ResourceGroupFilenameAnalyzer.java ---
/*
* Created on Sep 3, 2003
*/
package org.krysalis.ruper2.files;
import java.util.List;
import org.krysalis.ruper2.RuperException;
import org.krysalis.ruper2.resource.ResourceGroup;
/**
* @author arb_jack
*/
public interface ResourceGroupFilenameAnalyzer {
List determineGroups(List entityList) throws RuperException;
ResourceGroup determineGroup(Object entity) throws RuperException;
}
--- NEW FILE: DefaultResourceGroupFilenameAnalyzer.java ---
/*
* Created on Sep 3, 2003
*/
package org.krysalis.ruper2.files;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.krysalis.ruper2.RuperException;
import org.krysalis.ruper2.log.Logger;
import org.krysalis.ruper2.protocols.VirtualResourceLocator;
import org.krysalis.ruper2.resource.ResourceGroup;
import org.krysalis.ruper2.util.text.MessageConstants;
import org.krysalis.ruper2.util.text.Messages;
/**
* @author arb_jack
*/
public class DefaultResourceGroupFilenameAnalyzer
implements ResourceGroupFilenameAnalyzer {
private VirtualResourceLocator m_base = null;
public DefaultResourceGroupFilenameAnalyzer(VirtualResourceLocator base) {
m_base = base;
}
public List determineGroups(List entityList) throws RuperException {
List store = new ArrayList();
for (Iterator i = entityList.iterator(); i.hasNext();) {
Object entity = i.next();
try {
//
// Understood objects
//
if (entity instanceof String)
processString(
(String) entity,
new VirtualResourceLocator(m_base, (String) entity),
store);
else if (entity instanceof VirtualResourceLocator)
processVRL((VirtualResourceLocator) entity, store);
else if (entity instanceof File)
processFile((File) entity, store);
//
// Hmm VFS? How utilize yet be separate? Maybe String...
//
else {
Logger.getLog().error(
Messages.getString(
MessageConstants.WRONG_TYPE,
entity));
}
}
catch (RuperException re) {
//:TODO: log/context/listeners...
}
}
return store;
}
public ResourceGroup determineGroup(Object entity) throws RuperException {
List store = new ArrayList();
try {
//
// Understood objects
//
if (entity instanceof String)
processString(
(String) entity,
new VirtualResourceLocator(m_base, (String) entity),
store);
else if (entity instanceof VirtualResourceLocator)
processVRL((VirtualResourceLocator) entity, store);
else if (entity instanceof File)
processFile((File) entity, store);
//
// Hmm VFS? How utilize yet be separate? Maybe String...
//
else {
Logger.getLog().error(
Messages.getString(MessageConstants.WRONG_TYPE, entity));
}
}
catch (RuperException re) {
Logger.getLog().error(
Messages.getString(
MessageConstants.GENERAL_EXCEPTION2,
new Object[] { entity, re.getLocalizedMessage()}),
re);
}
// Check for empty and through ???
return (ResourceGroup) store.get(0);
}
void processVRL(VirtualResourceLocator groupVRL, List store)
throws RuperException {
String name = groupVRL.toExternalForm();
int sepPosn = name.lastIndexOf('/');
String baseName = (-1 == sepPosn) ? name : name.substring(sepPosn + 1);
//
// :TODO: How do we skip non-directories
// 1) Efficiently
// 2) Since VFS doesn't deam any URL a 'directory'
//
processString(baseName, groupVRL, store);
}
void processFile(File group, List store) throws RuperException {
String name = group.getName().toString();
int sepPosn = name.lastIndexOf(File.pathSeparator);
String baseName = (-1 == sepPosn) ? name : name.substring(sepPosn + 1);
//
// Skip non-directories.
//
if (!group.isDirectory())
return;
processString(baseName, new VirtualResourceLocator(group), store);
}
//
// HACK HACK HACK -- to get us started. Will evolve into a
// whole configurable parsing sub-system
//
void processString(
String groupName,
VirtualResourceLocator location,
List store)
throws RuperException {
Logger.getLog().debug(
Messages.getString(
MessageConstants.PROCESS,
new Object[] { groupName, location }));
//
// Ignore files starting with a .
//
boolean ignore =
(null == groupName)
|| (0 == groupName.length())
|| (groupName.startsWith("."));
if (!ignore) {
ResourceGroup group = new ResourceGroup(groupName);
// Store it...
store.add(group);
}
else
Logger.getLog().debug(
Messages.getString(MessageConstants.IGNORE, groupName));
}
}
Index: ResourceFilenameAnalyzer.java
===================================================================
RCS file: /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper2/files/ResourceFilenameAnalyzer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** ResourceFilenameAnalyzer.java 29 Sep 2003 18:09:16 -0000 1.1
--- ResourceFilenameAnalyzer.java 3 Oct 2003 15:07:16 -0000 1.2
***************
*** 13,17 ****
*/
public interface ResourceFilenameAnalyzer {
-
List determineResources(List entityList) throws RuperException;
Resource determineResource(Object entity) throws RuperException;
--- 13,16 ----
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.