You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(233) |
Sep
(199) |
Oct
(206) |
Nov
(185) |
Dec
(270) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(232) |
Feb
(426) |
Mar
(623) |
Apr
(592) |
May
(506) |
Jun
(389) |
Jul
(160) |
Aug
(3) |
Sep
(1) |
Oct
(1) |
Nov
(2) |
Dec
(5) |
2007 |
Jan
(1) |
Feb
(1) |
Mar
(2) |
Apr
(2) |
May
(4) |
Jun
(2) |
Jul
|
Aug
(3) |
Sep
(5) |
Oct
(9) |
Nov
(6) |
Dec
(6) |
2008 |
Jan
(3) |
Feb
|
Mar
(1) |
Apr
(3) |
May
(3) |
Jun
(5) |
Jul
(10) |
Aug
(2) |
Sep
(12) |
Oct
(10) |
Nov
(54) |
Dec
(49) |
2009 |
Jan
(19) |
Feb
(13) |
Mar
(20) |
Apr
(24) |
May
(44) |
Jun
(29) |
Jul
(32) |
Aug
(10) |
Sep
(7) |
Oct
(10) |
Nov
(4) |
Dec
(17) |
2010 |
Jan
(14) |
Feb
(5) |
Mar
(23) |
Apr
(50) |
May
(31) |
Jun
(9) |
Jul
(5) |
Aug
(4) |
Sep
(7) |
Oct
(5) |
Nov
(2) |
Dec
(3) |
2011 |
Jan
(12) |
Feb
(5) |
Mar
(5) |
Apr
(3) |
May
(4) |
Jun
(3) |
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
|
2012 |
Jan
(1) |
Feb
(2) |
Mar
|
Apr
(1) |
May
(1) |
Jun
(2) |
Jul
(4) |
Aug
(1) |
Sep
|
Oct
(1) |
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
2015 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2016 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <jbo...@li...> - 2006-01-25 23:32:33
|
Author: wrzep Date: 2006-01-25 18:32:28 -0500 (Wed, 25 Jan 2006) New Revision: 2205 Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Plugin.java Log: http://jira.jboss.com/jira/browse/JBLAB-595 PAwel Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Plugin.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Plugin.java 2006-01-25 23:27:05 UTC (rev 2204) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Plugin.java 2006-01-25 23:32:28 UTC (rev 2205) @@ -96,7 +96,7 @@ return 0; } - return (int) ((getValue(projectId) / highScore));*/ + return (int) ((getValue(projectId) / highScore)); } /** |
From: <jbo...@li...> - 2006-01-25 23:27:27
|
Author: szimano Date: 2006-01-25 18:27:05 -0500 (Wed, 25 Jan 2006) New Revision: 2204 Added: trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileHistory.java trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileTools.java Modified: trunk/forge/portal-extensions/shotoku/shotoku-files/project.xml trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileDirectory.java trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileNode.java trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FilesContentManager.java Log: further implemenattion to filesystem for shotoku http://jira.jboss.com/jira/browse/JBSHOTOKU-53 Modified: trunk/forge/portal-extensions/shotoku/shotoku-files/project.xml =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-files/project.xml 2006-01-25 23:26:53 UTC (rev 2203) +++ trunk/forge/portal-extensions/shotoku/shotoku-files/project.xml 2006-01-25 23:27:05 UTC (rev 2204) @@ -85,8 +85,17 @@ <version>1.0</version> <jar>activation.jar</jar> </dependency> - </dependencies> + + <dependency> + <groupId>jboss</groupId> + <artifactId>jboss-common</artifactId> + <version>1.0</version> + <jar>jboss-common.jar</jar> + </dependency> + + </dependencies> + <build> <sourceDirectory>src/java</sourceDirectory> <resources> Modified: trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileDirectory.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileDirectory.java 2006-01-25 23:26:53 UTC (rev 2203) +++ trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileDirectory.java 2006-01-25 23:27:05 UTC (rev 2204) @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; +import org.jboss.shotoku.ContentManager; import org.jboss.shotoku.Directory; import org.jboss.shotoku.Node; import org.jboss.shotoku.NodeList; @@ -42,13 +43,17 @@ private File directory; + private FilesContentManager manager; + /** * */ private static final long serialVersionUID = 1L; - public FileDirectory(String directory) throws RepositoryException { + public FileDirectory(String directory, FilesContentManager manager) throws RepositoryException { File dir = new File(directory); + + this.manager = manager; if (!dir.isDirectory()) { throw new RepositoryException(directory + " is not a directory"); @@ -74,7 +79,15 @@ // get all children for (File file : children) { if (file.isFile()) { - list.add(new FileNode(file)); + try { + list.add(new FileNode(this, file.getName(), false, manager)); + } catch (ResourceAlreadyExists e) { + //shouldn't happen + new RepositoryException(e); + } catch (ResourceDoesNotExist e) { + //shouldn't happen + new RepositoryException(e); + } } } @@ -101,10 +114,15 @@ File file = new File(this.directory.getAbsolutePath() + name); if (!file.exists()) { - throw new RepositoryException("File " + file.getAbsolutePath() + throw new ResourceDoesNotExist("File " + file.getAbsolutePath() + " doesn't exists"); } - return new FileNode(name); + try { + return new FileNode(this, name, false, manager); + } catch (ResourceAlreadyExists e) { + // it's not going to happen + return null; + } } public Directory getDirectory(String name) throws RepositoryException, @@ -137,7 +155,12 @@ } } - return new FileNode(file); + try { + return new FileNode(this, name, true, manager); + } catch (ResourceDoesNotExist e) { + // not going to happen + return null; + } } public Directory newDirectory(String name) throws ResourceAlreadyExists, @@ -226,5 +249,9 @@ // TODO Auto-generated method stub return null; } + + public String toString() { + return directory.getAbsolutePath(); + } } Added: trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileHistory.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileHistory.java 2006-01-25 23:26:53 UTC (rev 2203) +++ trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileHistory.java 2006-01-25 23:27:05 UTC (rev 2204) @@ -0,0 +1,107 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt 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.jboss.shotoku.files; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import org.jboss.shotoku.History; +import org.jboss.shotoku.Node; +import org.jboss.shotoku.NodeList; +import org.jboss.shotoku.exceptions.RepositoryException; +import org.jboss.shotoku.exceptions.ResourceDoesNotExist; + +public class FileHistory implements History { + + private FileNode node; + + private FilesContentManager manager; + + public FileHistory(FileNode node, FilesContentManager manager) { + this.node = node; + this.manager = manager; + } + + public int getRevisionsCount() throws RepositoryException { + Properties history = FileTools.getHistoryForNode(node, manager); + + int i = 1; + + while (history.getProperty("ver." + i) != null) { + i++; + } + + return --i; + } + + public Node getNodeAtRevision(int revision) throws ResourceDoesNotExist, + RepositoryException { + + // get copy of this node + Node newNode = node.getDirectory().getNode(node.getName()); + + File revFile = FileTools.getFileAtRevision(node, revision, manager); + + if (!revFile.exists()) { + throw new ResourceDoesNotExist("There is no revision " + revision + + " of node " + node.getFullName()); + } + + //change node's content + try { + InputStream is = new FileInputStream(revFile); + + newNode.setContent(is); + + is.close(); + } catch (FileNotFoundException e) { + throw new RepositoryException(e); + } catch (IOException e) { + throw new RepositoryException(e); + } + + return newNode; + } + + public NodeList getAllRevisions() throws RepositoryException { + List<Node> list = new ArrayList<Node>(); + + int max = getRevisionsCount(); + + for (int i = 0; i < max; i++) { + try { + list.add(getNodeAtRevision(i)); + } catch (ResourceDoesNotExist e) { + throw new RepositoryException(e); + } + } + + return new NodeList(list); + } + +} Modified: trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileNode.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileNode.java 2006-01-25 23:26:53 UTC (rev 2203) +++ trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileNode.java 2006-01-25 23:27:05 UTC (rev 2204) @@ -29,7 +29,9 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Date; +import java.util.HashMap; import java.util.Map; +import java.util.Properties; import org.jboss.shotoku.Directory; import org.jboss.shotoku.History; @@ -38,110 +40,159 @@ import org.jboss.shotoku.exceptions.DeleteException; import org.jboss.shotoku.exceptions.MoveException; import org.jboss.shotoku.exceptions.RepositoryException; +import org.jboss.shotoku.exceptions.ResourceAlreadyExists; +import org.jboss.shotoku.exceptions.ResourceDoesNotExist; import org.jboss.shotoku.exceptions.SaveException; public class FileNode implements Node { private File file; - + + private File tmpFile; + + private FilesContentManager manager; + + private Directory directory; + + private Properties props; + + private boolean propsChanged = false; + + private boolean contentChanged = false; + + private int revision; + + private boolean lastVersion = true; + /** * */ private static final long serialVersionUID = 1L; - public FileNode(String file) throws RepositoryException { - File fil = new File(file); - + public FileNode(Directory directory, String node, boolean newFile, + FilesContentManager manager) throws RepositoryException, + ResourceAlreadyExists, ResourceDoesNotExist { + File fil = new File(directory + File.pathSeparator + node); + + this.manager = manager; + this.directory = directory; + if (!fil.isFile()) { - throw new RepositoryException(file + " is not a file"); + throw new RepositoryException(directory + File.pathSeparator + node + + " is not a file"); } - + + if (!newFile) { + refreshProps(); + } + + if (newFile && fil.exists()) { + throw new ResourceAlreadyExists(directory + File.pathSeparator + + node + " already exists"); + } else if (!newFile && !fil.exists()) { + throw new ResourceDoesNotExist(directory + File.pathSeparator + + node + " doesn't exist"); + } + this.file = fil; - } - - public FileNode(File file) throws RepositoryException { - if (file.isFile()) { - this.file = file; + + try { + tmpFile = File.createTempFile("shotoku-file", node); + } catch (IOException e) { + throw new RepositoryException(e); } - else { - throw new RepositoryException(file.getAbsolutePath()+" is not a file."); - } + + revision = getHistory().getRevisionsCount(); } + /* + * public FileNode(File file) throws RepositoryException { if + * (file.isFile()) { this.file = file; } else { throw new + * RepositoryException(file.getAbsolutePath() + " is not a file."); } } + */ + public String getContent() throws RepositoryException { StringBuffer buffer = new StringBuffer(); - + try { - InputStream is = new FileInputStream(file); - + InputStream is = new FileInputStream( + (contentChanged || lastVersion) ? tmpFile : file); + char chr; - - while ((chr = (char)is.read()) != -1) { + + while ((chr = (char) is.read()) != -1) { buffer.append(chr); } - + is.close(); } catch (FileNotFoundException e) { new RepositoryException(e); } catch (IOException e) { new RepositoryException(e); } - - + return buffer.toString(); } public void setContent(String content) { try { - OutputStream os = new FileOutputStream(file); - + OutputStream os = new FileOutputStream(tmpFile); + for (int i = 0; i < content.length(); i++) { os.write(content.charAt(i)); } - + os.close(); } catch (FileNotFoundException e) { new RepositoryException(e); } catch (IOException e) { new RepositoryException(e); } + + contentChanged = true; } public void setContent(InputStream is) { try { - OutputStream os = new FileOutputStream(file); - + OutputStream os = new FileOutputStream(tmpFile); + int i; - + while ((i = is.read()) != -1) { os.write(i); } - + os.close(); } catch (FileNotFoundException e) { new RepositoryException(e); } catch (IOException e) { new RepositoryException(e); } + + contentChanged = true; } public void setContent(byte[] b) { try { - OutputStream os = new FileOutputStream(file); - + OutputStream os = new FileOutputStream(tmpFile); + os.write(b); - + os.close(); } catch (FileNotFoundException e) { new RepositoryException(e); } catch (IOException e) { new RepositoryException(e); } + + contentChanged = true; } public OutputStream getOutputStream() { try { - return new FileOutputStream(file); + contentChanged = true; + + return new FileOutputStream(tmpFile); } catch (FileNotFoundException e) { e.printStackTrace(); return null; @@ -149,26 +200,33 @@ } public History getHistory() throws RepositoryException { - // TODO Auto-generated method stub - return null; + return new FileHistory(this, manager); } public int getRevisionNumber() throws RepositoryException { - // TODO Auto-generated method stub - return 0; + if (lastVersion) + return getHistory().getRevisionsCount(); + else + return revision; } + public void setRevision(int revision) { + lastVersion = true; + this.revision = revision; + } + public void copyToFile(String fileName) throws RepositoryException { try { OutputStream os = new FileOutputStream(new File(fileName)); InputStream is = getContentInputStream(); - + int b; while ((b = is.read()) != -1) os.write(b); - - os.close(); is.close(); - + + os.close(); + is.close(); + } catch (FileNotFoundException e) { new RepositoryException(e); } catch (IOException e) { @@ -179,7 +237,8 @@ public InputStream getContentInputStream() throws RepositoryException { try { - return new FileInputStream(file); + return new FileInputStream( + (contentChanged || lastVersion) ? tmpFile : file); } catch (FileNotFoundException e) { throw new RepositoryException(e); } @@ -187,14 +246,14 @@ public byte[] getContentByteArray() throws RepositoryException { InputStream is = getContentInputStream(); - - byte[] b = new byte[(int)getLength()]; - + + byte[] b = new byte[(int) getLength()]; + try { is.read(b); - + is.close(); - + return b; } catch (IOException e) { throw new RepositoryException(e); @@ -214,55 +273,109 @@ } public String getMimeType() { - // TODO Auto-generated method stub - return null; + return FileTools.getMimeType(file); } /** - * Copies this resource to the given directory. This can't be called if - * this resource is new and not yet saved. + * Copies this resource to the given directory. This can't be called if this + * resource is new and not yet saved. * * @param dir * Directory to copy this resource to. This can't be a new and * not saved directory. * @param newName - * New name of this resource (in directory dir after copying). + * New name of this resource (in directory dir after copying). * @param logMessage - * Log message associated with this resource copy. + * Log message associated with this resource copy. * @throws CopyException */ - public void copyTo(Directory dir, String newName, - String logMessage) throws CopyException{ - //TODO + public void copyTo(Directory dir, String newName, String logMessage) + throws CopyException { + try { + Node newNode = dir.newNode(newName); + + newNode.setContent(getContentByteArray()); + + newNode.save(logMessage); + } catch (RepositoryException e) { + throw new CopyException(e); + } catch (ResourceAlreadyExists e) { + throw new CopyException(e); + } catch (SaveException e) { + throw new CopyException(e); + } } - + /** - * Moves this resource to the given directory. This can't be called if - * this resource is new and not yet saved. This resource should not be - * used after performing this operation. + * Moves this resource to the given directory. This can't be called if this + * resource is new and not yet saved. This resource should not be used after + * performing this operation. * * @param dir * Directory to move this resource to. This can't be a new and * not saved directory. * @param logMessage - * Log message associated with this resource move. + * Log message associated with this resource move. * @throws MoveException */ - public void moveTo(Directory dir, String logMessage) throws MoveException{ - //TODO + public void moveTo(Directory dir, String logMessage) throws MoveException { + + File toFile = new File(dir + File.pathSeparator + file.getName()); + + try { + // get new node + Node newNode = dir.newNode(file.getName()); + + if (toFile.exists()) { + throw new MoveException("There is " + file.getName() + + " in directory " + dir); + } + + // get history dirs + File oldHisDir = FileTools.getHistoryDir(this, manager); + File newHisDir = FileTools.getHistoryDir((FileNode) newNode, + manager); + + if (newHisDir.exists()) { + throw new MoveException("History for " + newNode.getFullName() + + " already exists"); + } + + // move files + file.renameTo(toFile); + oldHisDir.renameTo(newHisDir); + + file = toFile; + } catch (RepositoryException e) { + new MoveException(e); + } catch (ResourceAlreadyExists e) { + new MoveException(e); + } + } - + /** * Gets a map of all properties associated with this resource. * * @return A map of properties associated with this resource. * @throws RepositoryException */ - public Map<String, String> getProperties() throws RepositoryException{ - //TODO - return null; + public Map<String, String> getProperties() throws RepositoryException { + refreshProps(); + Map<String, String> map = new HashMap<String, String>(); + + for (Object key : props.keySet()) { + map.put((String) key, props.getProperty((String) key)); + } + + return map; } - + + private void refreshProps() { + if (!propsChanged) + props = FileTools.getPropertiesForNode(this, manager); + } + /** * Gets the value of the given property. * @@ -271,11 +384,11 @@ * @return Value of the given property. * @throws RepositoryException */ - public String getProperty(String propertyName) throws RepositoryException{ - //TODO - return null; + public String getProperty(String propertyName) throws RepositoryException { + refreshProps(); + return props.getProperty(propertyName); } - + /** * Deletes the the given property. * @@ -283,23 +396,26 @@ * Name of the property to delete. * @throws RepositoryException */ - public void deleteProperty(String propertyName) throws RepositoryException{ - //TODO + public void deleteProperty(String propertyName) throws RepositoryException { + refreshProps(); + props.remove(propertyName); } /** - * Sets the value of the given property. Only after saving this change will be - * persisted. + * Sets the value of the given property. Only after saving this change will + * be persisted. * * @param propertyName * Name of the property to set. It must begin with a character, - * and cannot contain any special characters (so the regexp to which - * a property name must match would be [a-z][a-z0-9]*). + * and cannot contain any special characters (so the regexp to + * which a property name must match would be [a-z][a-z0-9]*). * @param propertyValue * Value of the property to set. */ - public void setProperty(String propertyName, String propertyValue){ - //TODO + public void setProperty(String propertyName, String propertyValue) { + refreshProps(); + props.setProperty(propertyName, propertyValue); + propsChanged = true; } /** @@ -308,7 +424,7 @@ * @return A directory to which this node/ directory belongs. Null if this * directory is already the root directory. */ - public Directory getParent() throws RepositoryException{ + public Directory getParent() throws RepositoryException { return new FileDirectory(file.getParentFile()); } @@ -317,12 +433,95 @@ * * @param logMessage * Log message for saving this node/ directory. - * @throws SaveException + * @throws SaveException * @throws RepositoryException */ - public void save(String logMessage) throws SaveException, RepositoryException{ - //TODO - + public void save(String logMessage) throws SaveException, + RepositoryException { + Properties history = FileTools.getHistoryForNode(this, manager); + + // get last props version + int i = 1; + + while (history.getProperty("ver." + i) != null) { + i++; + } + + history.setProperty("ver." + i, logMessage); + + // get next history file + File nextVersion = FileTools.getNextHistoryFile(this, manager, i); + + if (nextVersion.exists()) { + throw new SaveException("Conflict in saving: history file exists"); + } + + try { + nextVersion.createNewFile(); + } catch (IOException e) { + throw new RepositoryException(e); + } + + // save prevoius version + copyToFile(file.getAbsolutePath()); + + // save new version + FileOutputStream newFileOS = null; + try { + newFileOS = new FileOutputStream(file); + } catch (FileNotFoundException e2) { + throw new SaveException(e2); + } + + FileInputStream tmpFileIS = null; + try { + tmpFileIS = new FileInputStream(tmpFile); + } catch (FileNotFoundException e2) { + throw new SaveException(e2); + } + + int b; + + try { + while ((b = tmpFileIS.read()) != -1) { + newFileOS.write(b); + } + } catch (IOException e2) { + throw new SaveException(e2); + } + + try { + tmpFileIS.close(); + tmpFileIS.close(); + } catch (IOException e2) { + throw new SaveException(e2); + } + + // save props and history + FileOutputStream fos = null; + FileOutputStream fosPr = null; + try { + fos = new FileOutputStream(FileTools.getHistoryFile(this, manager)); + fosPr = new FileOutputStream(FileTools.getPropsFile(this, manager)); + } catch (FileNotFoundException e) { + throw new SaveException(e); + } + + try { + history.store(fos, FileTools.STORE_TEXT); + props.store(fosPr, FileTools.STORE_TEXT); + } catch (IOException e) { + try { + fos.close(); + fosPr.close(); + } catch (IOException e1) { + throw new RepositoryException(e); + } + throw new RepositoryException(e); + } + + // set bools to false + lastVersion = contentChanged = propsChanged = false; } /** @@ -332,24 +531,34 @@ * the resource is not yet saved or contains modifications. * @throws RepositoryException */ - public String getLogMessage() throws RepositoryException{ - //TODO - return null; - + public String getLogMessage() throws RepositoryException { + + Properties history = FileTools.getHistoryForNode(this, manager); + + int i = 1; + + while (history.getProperty("ver." + i) != null) { + i++; + } + i--; + + return history.getProperty("ver." + i); + } /** * Deletes this node or directory (immediately, no <code>save()</code> is - * needed). This resource should not be used after performing this + * needed). This resource should not be used after performing this * operation. * * @throws DeleteException * @throws RepositoryException */ - public void delete() throws DeleteException, RepositoryException{ + public void delete() throws DeleteException, RepositoryException { try { if (!file.delete()) { - throw new DeleteException("Couldn't delete file "+file.getAbsolutePath()); + throw new DeleteException("Couldn't delete file " + + file.getAbsolutePath()); } } catch (SecurityException e) { throw new RepositoryException(e); @@ -363,19 +572,26 @@ * is the root directory. */ public String getName() { - //TODO - return null; + return file.getName(); } - + /** * Gets the full name of this resource, that is, path to this resource * relative to the content manager this node was read from. * * @return Full name of this resource. */ - public String getFullName(){ - //TODO - return null; + public String getFullName() { + return file.getAbsolutePath().replace( + manager.getPathToRepoCurrent() + File.pathSeparator + + manager.getPrefix(), ""); } + public Directory getDirectory() { + return directory; + } + + public String getNodeName() { + return file.getName(); + } } Added: trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileTools.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileTools.java 2006-01-25 23:26:53 UTC (rev 2203) +++ trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileTools.java 2006-01-25 23:27:05 UTC (rev 2204) @@ -0,0 +1,187 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt 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.jboss.shotoku.files; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Properties; + +import javax.activation.MimetypesFileTypeMap; + +import org.jboss.shotoku.exceptions.RepositoryException; + +public class FileTools { + + private static MimetypesFileTypeMap mimeTypes; + + private final static String HIST_PROPS = "history.properties"; + + private final static String PROPS = "properties.properties"; + + public static final String STORE_TEXT = "Properties saved by Shotoku file-based"; + + public static final String REVISION_SUFFIX = ".version"; + + static { + mimeTypes = new MimetypesFileTypeMap(FileTools.class + .getResourceAsStream("/mime.types.txt")); + } + + public static String getMimeType(File file) { + return mimeTypes.getContentType(file); + } + + public static File getFileAtRevision(FileNode node, int revison, + FilesContentManager manager) { + // delete beggining part of path to get only dir inside repo + String directory = node.getDirectory().toString().replace( + manager.getPathToRepoCurrent(), ""); + + String pathToHistory = manager.getPathToRepoHistory() + + File.pathSeparator + directory + File.pathSeparator + + node.getNodeName() + "-his" + File.pathSeparator + revison + + REVISION_SUFFIX; + + File hisFile = new File(pathToHistory); + + return hisFile; + } + + public static File getHistoryDir(FileNode node, FilesContentManager manager) { + // delete beggining part of path to get only dir inside repo + String directory = node.getDirectory().toString().replace( + manager.getPathToRepoCurrent(), ""); + + String pathToHistory = manager.getPathToRepoHistory() + + File.pathSeparator + directory + File.pathSeparator + + node.getNodeName() + "-his"; + + File hisFile = new File(pathToHistory); + + return hisFile; + } + + public static File getHistoryFile(FileNode node, FilesContentManager manager) { + // delete beggining part of path to get only dir inside repo + String directory = node.getDirectory().toString().replace( + manager.getPathToRepoCurrent(), ""); + + String pathToHistory = manager.getPathToRepoHistory() + + File.pathSeparator + directory + File.pathSeparator + + node.getNodeName() + "-his"; + + createHistoryStructure(pathToHistory); + + File hisFile = new File(pathToHistory + File.pathSeparator + HIST_PROPS); + + return hisFile; + } + + public static File getPropsFile(FileNode node, FilesContentManager manager) { + // delete beggining part of path to get only dir inside repo + String directory = node.getDirectory().toString().replace( + manager.getPathToRepoCurrent(), ""); + + String pathToProps = manager.getPathToRepoHistory() + + File.pathSeparator + directory + File.pathSeparator + + node.getNodeName() + "-his"; + + createHistoryStructure(pathToProps); + + File propsFile = new File(pathToProps + File.pathSeparator + PROPS); + + return propsFile; + } + + public static Properties getHistoryForNode(FileNode node, + FilesContentManager manager) throws RepositoryException { + + File hisFile = getHistoryFile(node, manager); + + Properties hisProps = new Properties(); + + try { + hisProps.load(new FileInputStream(hisFile)); + } catch (FileNotFoundException e) { + throw new RepositoryException(e); + } catch (IOException e) { + throw new RepositoryException(e); + } + + return hisProps; + } + + public static Properties getPropertiesForNode(FileNode node, + FilesContentManager manager) throws RepositoryException { + + File propsFile = getPropsFile(node, manager); + + Properties props = new Properties(); + + try { + props.load(new FileInputStream(propsFile)); + } catch (FileNotFoundException e) { + throw new RepositoryException(e); + } catch (IOException e) { + throw new RepositoryException(e); + } + + return props; + } + + private static void createHistoryStructure(String hisDirStr) + throws RepositoryException { + File hisDir = new File(hisDirStr); + if (!hisDir.exists()) { + // create structure + hisDir.mkdirs(); + try { + (new File(hisDirStr + File.pathSeparator + HIST_PROPS)) + .createNewFile(); + (new File(hisDirStr + File.pathSeparator + PROPS)) + .createNewFile(); + } catch (IOException e) { + throw new RepositoryException(e); + } + } + } + + public static File getNextHistoryFile(FileNode node, + FilesContentManager manager, int version) { + // delete beggining part of path to get only dir inside repo + String directory = node.getDirectory().toString().replace( + manager.getPathToRepoCurrent(), ""); + + String pathToHistory = manager.getPathToRepoHistory() + + File.pathSeparator + directory + File.pathSeparator + + node.getNodeName() + "-his"; + + createHistoryStructure(pathToHistory); + + File hisFile = new File(pathToHistory + File.pathSeparator + version + + REVISION_SUFFIX); + + return hisFile; + } +} Modified: trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FilesContentManager.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FilesContentManager.java 2006-01-25 23:26:53 UTC (rev 2203) +++ trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FilesContentManager.java 2006-01-25 23:27:05 UTC (rev 2204) @@ -21,8 +21,10 @@ */ package org.jboss.shotoku.files; +import java.io.File; import java.util.Collection; +import org.jboss.logging.Logger; import org.jboss.shotoku.ContentManager; import org.jboss.shotoku.Directory; import org.jboss.shotoku.Node; @@ -34,43 +36,108 @@ public class FilesContentManager extends ContentManager { - public FilesContentManager(String arg0, String arg1) throws RepositoryException { - super(arg0, arg1); - // TODO Auto-generated constructor stub + private String pathToRepo; + + private String pathToRepoCurrent; + + private String pathToRepoHistory; + + private final static String CURRENT = "CURRENT"; + + private final static String HISTORY = "HISTORY"; + + private Logger log = Logger.getLogger(FilesContentManager.class); + + public FilesContentManager(String id, String prefix) throws RepositoryException { + super(id, prefix); + + // add separator at the end and at the begginig + if (!prefix.startsWith("/")) { + prefix = "/" + prefix; + } + + if (!prefix.endsWith("/")) { + prefix += "/"; + } + + pathToRepo = getProperty("shotoku.default.localpath"); + + if (pathToRepo == null) { + throw new RepositoryException("shotoku.default.localpath is not set in properties"); + } + else if (!(new File(pathToRepo)).exists() || !(new File(pathToRepo)).isDirectory()){ + throw new RepositoryException(pathToRepo+" doesn't exist or isn't a directory"); + } + + // create paths + + pathToRepoCurrent = pathToRepo + File.pathSeparator + CURRENT; + pathToRepoHistory = pathToRepo + File.pathSeparator + HISTORY; + + // check for current and history existance + File fileCur = new File(pathToRepoCurrent); + File fileHis = new File(pathToRepoHistory); + + // create CURRENT folder if it doesn't exist + if (!fileCur.exists()) { + fileCur.mkdirs(); + log.info("Added CURRENT folder"); + } + + // create HISTORY folder if it doesn't exist + if (!fileHis.exists()) { + fileHis.mkdirs(); + log.info("Added HISTORY folder"); + } } @Override public Directory getRootDirectory() throws RepositoryException { - // TODO Auto-generated method stub - return null; + return new FileDirectory(getPathToRepoCurrent(), this); } @Override - public Node getNode(String arg0) throws ResourceDoesNotExist, + public Node getNode(String nodeName) throws ResourceDoesNotExist, RepositoryException { - // TODO Auto-generated method stub - return null; + return getRootDirectory().getNode(nodeName); } @Override - public Directory getDirectory(String arg0) throws ResourceDoesNotExist, + public Directory getDirectory(String dirName) throws ResourceDoesNotExist, RepositoryException { - // TODO Auto-generated method stub - return null; + return getRootDirectory().getDirectory(dirName); } @Override - public void save(Collection<Resource> arg0, String arg1) + public void save(Collection<Resource> resources, String message) throws SaveException, RepositoryException { - // TODO Auto-generated method stub - + for (Resource resource : resources) { + resource.save(message); + } } @Override - public void delete(Collection<Resource> arg0) throws DeleteException, + public void delete(Collection<Resource> resources) throws DeleteException, RepositoryException { - // TODO Auto-generated method stub + for (Resource resource : resources) { + resource.delete(); + } + } + public String getPathToRepo() { + return pathToRepo; } + public String getPathToRepoCurrent() { + return pathToRepoCurrent + prefix; + } + + public String getPathToRepoHistory() { + return pathToRepoHistory + prefix; + } + + public String getPrefix() { + return prefix; + } + } |
From: <jbo...@li...> - 2006-01-25 23:27:05
|
Author: wrzep Date: 2006-01-25 18:26:53 -0500 (Wed, 25 Jan 2006) New Revision: 2203 Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Plugins.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/KosmosStatusPlugin.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Plugin.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/ScorePlugin.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/StatusPlugin.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/WeightedScorePlugin.java Log: computing project rate (score / high score) http://jira.jboss.com/jira/browse/JBLAB-595 Pawel Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java 2006-01-25 21:26:10 UTC (rev 2202) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java 2006-01-25 23:26:53 UTC (rev 2203) @@ -82,9 +82,11 @@ try { Long value = plugin.getValue(projectId); + Integer rate = plugin.getRate(projectId); if (value != null) { entryContext.put("value", Long.toString(value)); + entryContext.put("rate", Integer.toString(rate)); entryContext.put("special-link", plugin.getLink(projectId)); } } catch (Exception e) { Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Plugins.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Plugins.java 2006-01-25 21:26:10 UTC (rev 2202) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Plugins.java 2006-01-25 23:26:53 UTC (rev 2203) @@ -121,7 +121,7 @@ plugin = (Plugin) pluginClass.newInstance(); if (scorePlugin) { - ((ScorePlugin) plugin).init(pluginId, statusPlugins, pluginProperties); + ((ScorePlugin) plugin).init(pluginId, statusPlugins, projects, pluginProperties); } else { /* status plugin */ ((StatusPlugin) plugin).init(pluginId, portalName, projects, pluginProperties); } Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/KosmosStatusPlugin.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/KosmosStatusPlugin.java 2006-01-25 21:26:10 UTC (rev 2202) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/KosmosStatusPlugin.java 2006-01-25 23:26:53 UTC (rev 2203) @@ -64,7 +64,7 @@ @Override public void init(String id, String portalName, Projects projects, Properties properties) throws InvalidPluginPropertiesException { - super.init(id, portalName, projects,properties); + super.init(id, portalName, projects, properties); getServiceProperty(properties); } Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Plugin.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Plugin.java 2006-01-25 21:26:10 UTC (rev 2202) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Plugin.java 2006-01-25 23:26:53 UTC (rev 2203) @@ -23,7 +23,11 @@ package org.jboss.forge.status.plugins; import java.util.Properties; +import java.util.Set; +import org.jboss.forge.common.projects.Projects; +import org.jboss.forge.common.projects.permissions.NullPermissionsChecker; + /** * @author Pawel Wrzeszcz * Superclass for Status Matrix Plugins. @@ -37,6 +41,11 @@ /** Plugin id */ protected String id; + /** Projects present in the Status Matrix. */ + protected Projects projects; + + private long highScore; + /** * @param id Plugin id * @param properties plugin specyfic properties @@ -45,10 +54,16 @@ * Thrown when properties passed in <code>propertiesNode</code> * are incorrect or missing. */ - public void init(String id, Properties properties) + public void init(String id, Projects projects, Properties properties) throws InvalidPluginPropertiesException { + this.properties = properties; + this.projects = projects; this.id = id; + + System.out.println("Plugin::init properites = " + properties); + + highScore = getHighScore(); } /** @@ -68,7 +83,39 @@ } /** + * For the given project returns it's rate. + * Rate is computed as project's score share in the higest score. + * + * @param projectId project id + * @return rate computed by plugin for the project + * with the given <code>projectId</code>. + */ + public int getRate(String projectId) { + + if (highScore == 0) { + return 0; + } + + return (int) ((getValue(projectId) / highScore));*/ + } + + /** * @return plugin id */ public String getId() { return id; }; + + private long getHighScore() { + + Set<String> projectIds = projects.getProjectIds( + new NullPermissionsChecker(), null); + + long hs = Long.MIN_VALUE; + + for (String projectId : projectIds) { + hs = Math.max(getValue(projectId), hs); + } + + return hs; + } + } Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/ScorePlugin.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/ScorePlugin.java 2006-01-25 21:26:10 UTC (rev 2202) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/ScorePlugin.java 2006-01-25 23:26:53 UTC (rev 2203) @@ -25,6 +25,8 @@ import java.util.Map; import java.util.Properties; +import org.jboss.forge.common.projects.Projects; + /** * @author Pawel Wrzeszcz * @@ -46,10 +48,10 @@ * are incorrect or missing. */ public void init(String id, Map<String, Plugin> plugins, - Properties properties) + Projects projects, Properties properties) throws InvalidPluginPropertiesException { this.plugins = plugins; - init(id, properties); + init(id, projects, properties); } } Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/StatusPlugin.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/StatusPlugin.java 2006-01-25 21:26:10 UTC (rev 2202) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/StatusPlugin.java 2006-01-25 23:26:53 UTC (rev 2203) @@ -33,9 +33,6 @@ public abstract class StatusPlugin extends Plugin { - /** Projects present in the Status Matrix. */ - protected Projects projects; - protected String portalName; /** @@ -49,8 +46,8 @@ public void init(String id, String portalName, Projects projects, Properties properties) throws InvalidPluginPropertiesException { - this.projects = projects; + this.portalName = portalName; - init(id, properties); + init(id, projects, properties); } } Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/WeightedScorePlugin.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/WeightedScorePlugin.java 2006-01-25 21:26:10 UTC (rev 2202) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/WeightedScorePlugin.java 2006-01-25 23:26:53 UTC (rev 2203) @@ -27,6 +27,7 @@ import java.util.Map; import java.util.Properties; +import org.jboss.forge.common.projects.Projects; import org.jboss.logging.Logger; @@ -51,8 +52,8 @@ @Override - public void init(String id, Properties props) throws InvalidPluginPropertiesException { - super.init(id, props); + public void init(String id, Projects projects, Properties props) throws InvalidPluginPropertiesException { + super.init(id, projects, props); properties = new Hashtable<String,Float>(props.size()); |
From: <jbo...@li...> - 2006-01-25 21:26:14
|
Author: wrzep Date: 2006-01-25 16:26:10 -0500 (Wed, 25 Jan 2006) New Revision: 2202 Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java Log: metric page: projects shown now by score (desc) http://jira.jboss.com/jira/browse/JBLAB-595 Pawel Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java 2006-01-25 21:00:11 UTC (rev 2201) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java 2006-01-25 21:26:10 UTC (rev 2202) @@ -22,6 +22,8 @@ package org.jboss.forge.status; +import java.util.Arrays; +import java.util.Comparator; import java.util.Set; import org.jboss.forge.common.projects.Projects; @@ -100,8 +102,8 @@ fillHeaderInfo(columnContext); - Set<String> projectIds = projects.getProjectIds( - new NullPermissionsChecker(), null); + String[] projectIds = getProjectIdsSorted(projects); + for (String projectId : projectIds) { DelegateContext projectContext = columnContext.next("project"); @@ -114,6 +116,18 @@ } } + private String[] getProjectIdsSorted(Projects projects) { + + Set<String> projectIdsSet = projects.getProjectIds(new NullPermissionsChecker(), null); + String[] ids = new String[projectIdsSet.size()]; + projectIdsSet.toArray(ids); + + Comparator<String> projectsComparator = new ProjectsByScoreComparator(plugin); + Arrays.sort(ids, projectsComparator); + + return ids; + } + /** * @return Column plugin id */ |
From: <jbo...@li...> - 2006-01-25 21:00:19
|
Author: wrzep Date: 2006-01-25 16:00:11 -0500 (Wed, 25 Jan 2006) New Revision: 2201 Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/cc/CcStatusPlugin.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/jira/JiraStatusPlugin.java trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/svn/SvnStatusPlugin.java Log: kosmos plugins: simple list size check in case kosmos returns empty list http://jira.jboss.com/jira/browse/JBLAB-595 Pawel Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/cc/CcStatusPlugin.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/cc/CcStatusPlugin.java 2006-01-25 19:00:21 UTC (rev 2200) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/cc/CcStatusPlugin.java 2006-01-25 21:00:11 UTC (rev 2201) @@ -65,7 +65,7 @@ return null; } - Map CcMap = null; + Map ccMap = null; // Connect to the kosmos service HessianProxyFactory factory = new HessianProxyFactory(); @@ -87,9 +87,11 @@ return null; } - CcMap = (Map) repositories.get(0); + if ((repositories != null) && (repositories.size() > 0)) { + ccMap = (Map) repositories.get(0); + } - return CcMap; + return ccMap; } Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/jira/JiraStatusPlugin.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/jira/JiraStatusPlugin.java 2006-01-25 19:00:21 UTC (rev 2200) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/jira/JiraStatusPlugin.java 2006-01-25 21:00:11 UTC (rev 2201) @@ -77,16 +77,18 @@ } // Get map with jira statistics - List repositories = null; + List projects = null; try { - repositories = service.getProjects(jiraURL); + projects = service.getProjects(jiraURL); } catch (Exception e) { log.error("Can not analyze jira: " + jiraURL, e); return null; } - jiraMap = (Map) repositories.get(0); - + if ((projects != null) && (projects.size() > 0)) { + jiraMap = (Map) projects.get(0); + } + return jiraMap; } Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/svn/SvnStatusPlugin.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/svn/SvnStatusPlugin.java 2006-01-25 19:00:21 UTC (rev 2200) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/svn/SvnStatusPlugin.java 2006-01-25 21:00:11 UTC (rev 2201) @@ -86,7 +86,9 @@ return null; } - repositoryMap = (Map) repositories.get(0); + if ((repositories != null) && (repositories.size() > 0)) { + repositoryMap = (Map) repositories.get(0); + } return repositoryMap; } |
From: <jbo...@li...> - 2006-01-25 19:00:40
|
Author: aron.gombas Date: 2006-01-25 14:00:21 -0500 (Wed, 25 Jan 2006) New Revision: 2200 Added: trunk/labs/kosmos/conf-portlet/jboss-portal/kosmos-object.xml Modified: trunk/labs/kosmos/conf-portlet/jboss-portal/kosmos-pages.xml trunk/labs/kosmos/conf-portlet/jboss-portal/portlet-instances.xml Log: Config for JBP 2.2 Added: trunk/labs/kosmos/conf-portlet/jboss-portal/kosmos-object.xml =================================================================== --- trunk/labs/kosmos/conf-portlet/jboss-portal/kosmos-object.xml 2006-01-25 18:59:44 UTC (rev 2199) +++ trunk/labs/kosmos/conf-portlet/jboss-portal/kosmos-object.xml 2006-01-25 19:00:21 UTC (rev 2200) @@ -0,0 +1,148 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Configuration for JBoss Portal 2.2 --> +<deployments> + <deployment> + <if-exists>overwrite</if-exists> + <parent-ref>default</parent-ref> + <properties/> + <page> + <page-name>Kosmos</page-name> + <properties/> + + <window> + <window-name>GmfCcMonitoringPortlet</window-name> + <instance-ref>GmfCcMonitoringPortletInstance</instance-ref> + <region>center</region> + <height>0</height> + </window> + + <window> + <window-name>GridsphereCcMonitoringPortlet</window-name> + <instance-ref>GridsphereCcMonitoringPortletInstance</instance-ref> + <region>center</region> + <height>0</height> + </window> + + <window> + <window-name>JavadesktopCcMonitoringPortlet</window-name> + <instance-ref>JavadesktopCcMonitoringPortletInstance</instance-ref> + <region>center</region> + <height>0</height> + </window> + + <window> + <window-name>JBossCcMonitoring</window-name> + <instance-ref>JBossCcMonitoringPortletInstance</instance-ref> + <region>center</region> + <height>0</height> + </window> + + <window> + <window-name>AtlassianJiraMonitoring</window-name> + <instance-ref>AtlassianJiraMonitoringPortletInstance</instance-ref> + <region>center</region> + <height>1</height> + </window> + + <window> + <window-name>CodehausJiraMonitoring</window-name> + <instance-ref>CodehausJiraMonitoringPortletInstance</instance-ref> + <region>center</region> + <height>2</height> + </window> + + <window> + <window-name>JBossJiraMonitoring</window-name> + <instance-ref>JBossJiraMonitoringPortletInstance</instance-ref> + <region>center</region> + <height>3</height> + </window> + + <window> + <window-name>KosmosDependenciesSfMonitoring</window-name> + <instance-ref>KosmosDependenciesSfMonitoringPortletInstance</instance-ref> + <region>left</region> + <height>0</height> + </window> + + <window> + <window-name>KosmosToolsSfMonitoring</window-name> + <instance-ref>KosmosToolsSfMonitoringPortletInstance</instance-ref> + <region>left</region> + <height>1</height> + </window> + + <window> + <window-name>JBossProductsSfMonitoring</window-name> + <instance-ref>JBossProductsSfMonitoringPortletInstance</instance-ref> + <region>left</region> + <height>2</height> + </window> + + <window> + <window-name>ApacheSvnMonitoringPortlet</window-name> + <instance-ref>ApacheSvnMonitoringPortletInstance</instance-ref> + <region>left</region> + <height>3</height> + </window> + + <window> + <window-name>JBossSvnMonitoringPortlet</window-name> + <instance-ref>JBossSvnMonitoringPortletInstance</instance-ref> + <region>left</region> + <height>4</height> + </window> + + </page> + + <instance> + <instance-name>GmfCcMonitoringPortletInstance</instance-name> + <component-ref>kosmos-portal.GmfCcMonitoringPortlet</component-ref> + </instance> + <instance> + <instance-name>GridsphereCcMonitoringPortletInstance</instance-name> + <component-ref>kosmos-portal.GridsphereCcMonitoringPortlet</component-ref> + </instance> + <instance> + <instance-name>JavadesktopCcMonitoringPortletInstance</instance-name> + <component-ref>kosmos-portal.JavadesktopCcMonitoringPortlet</component-ref> + </instance> + <instance> + <instance-name>JBossCcMonitoringPortletInstance</instance-name> + <component-ref>kosmos-portal.JBossCcMonitoringPortlet</component-ref> + </instance> + <instance> + <instance-name>AtlassianJiraMonitoringPortletInstance</instance-name> + <component-ref>kosmos-portal.AtlassianJiraMonitoringPortlet</component-ref> + </instance> + <instance> + <instance-name>CodehausJiraMonitoringPortletInstance</instance-name> + <component-ref>kosmos-portal.CodehausJiraMonitoringPortlet</component-ref> + </instance> + <instance> + <instance-name>JBossJiraMonitoringPortletInstance</instance-name> + <component-ref>kosmos-portal.JBossJiraMonitoringPortlet</component-ref> + </instance> + <instance> + <instance-name>KosmosDependenciesSfMonitoringPortletInstance</instance-name> + <component-ref>kosmos-portal.KosmosDependenciesSfMonitoringPortlet</component-ref> + </instance> + <instance> + <instance-name>KosmosToolsSfMonitoringPortletInstance</instance-name> + <component-ref>kosmos-portal.KosmosToolsSfMonitoringPortlet</component-ref> + </instance> + <instance> + <instance-name>JBossProductsSfMonitoringPortletInstance</instance-name> + <component-ref>kosmos-portal.JBossProductsSfMonitoringPortlet</component-ref> + </instance> + <instance> + <instance-name>ApacheSvnMonitoringPortletInstance</instance-name> + <component-ref>kosmos-portal.ApacheSvnMonitoringPortlet</component-ref> + </instance> + <instance> + <instance-name>JBossSvnMonitoringPortletInstance</instance-name> + <component-ref>kosmos-portal.JBossSvnMonitoringPortlet</component-ref> + </instance> + + </deployment> +</deployments> Modified: trunk/labs/kosmos/conf-portlet/jboss-portal/kosmos-pages.xml =================================================================== --- trunk/labs/kosmos/conf-portlet/jboss-portal/kosmos-pages.xml 2006-01-25 18:59:44 UTC (rev 2199) +++ trunk/labs/kosmos/conf-portlet/jboss-portal/kosmos-pages.xml 2006-01-25 19:00:21 UTC (rev 2200) @@ -1,3 +1,4 @@ +<!-- Configuration for JBoss Portal 2.0 --> <pages> <portal-name>default</portal-name> <page> Modified: trunk/labs/kosmos/conf-portlet/jboss-portal/portlet-instances.xml =================================================================== --- trunk/labs/kosmos/conf-portlet/jboss-portal/portlet-instances.xml 2006-01-25 18:59:44 UTC (rev 2199) +++ trunk/labs/kosmos/conf-portlet/jboss-portal/portlet-instances.xml 2006-01-25 19:00:21 UTC (rev 2200) @@ -1,4 +1,5 @@ <?xml version="1.0" standalone="yes"?> +<!-- Configuration for JBoss Portal 2.0 --> <instances> <instance> <instance-name>GmfCcMonitoringPortletInstance</instance-name> |
From: <jbo...@li...> - 2006-01-25 18:59:51
|
Author: aron.gombas Date: 2006-01-25 13:59:44 -0500 (Wed, 25 Jan 2006) New Revision: 2199 Modified: trunk/labs/kosmos/build/kosmos-project.properties Log: Verno incremented Modified: trunk/labs/kosmos/build/kosmos-project.properties =================================================================== --- trunk/labs/kosmos/build/kosmos-project.properties 2006-01-25 18:36:26 UTC (rev 2198) +++ trunk/labs/kosmos/build/kosmos-project.properties 2006-01-25 18:59:44 UTC (rev 2199) @@ -1,3 +1,3 @@ project.name=Kosmos project.name.short=kosmos -project.version=0.1.7 +project.version=0.1.8 |
From: <jbo...@li...> - 2006-01-25 18:36:37
|
Author: wrzep Date: 2006-01-25 13:36:26 -0500 (Wed, 25 Jan 2006) New Revision: 2198 Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java Log: fixed overlapping context 'link' entries http://jira.jboss.com/jira/browse/JBLAB-595 Pawel Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java 2006-01-25 17:57:43 UTC (rev 2197) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/Column.java 2006-01-25 18:36:26 UTC (rev 2198) @@ -83,7 +83,7 @@ if (value != null) { entryContext.put("value", Long.toString(value)); - entryContext.put("link", plugin.getLink(projectId)); + entryContext.put("special-link", plugin.getLink(projectId)); } } catch (Exception e) { log.error("Could not get value for plugin: " + plugin.getId(), e); |
From: <jbo...@li...> - 2006-01-25 17:57:50
|
Author: wrzep Date: 2006-01-25 12:57:43 -0500 (Wed, 25 Jan 2006) New Revision: 2197 Added: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/ trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_backbar.gif trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_colorbar.jpg trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_colorbar2.jpg trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_colorbar3.jpg trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_marker.gif Modified: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/graphs.css Log: eventually forced images from css to appear http://jira.jboss.com/jira/browse/JBLAB-595 Pawel Modified: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/graphs.css =================================================================== --- trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/graphs.css 2006-01-25 17:38:25 UTC (rev 2196) +++ trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/graphs.css 2006-01-25 17:57:43 UTC (rev 2197) @@ -45,13 +45,13 @@ width: 197px; height: 20px; margin: 0 0 15px; - background: url("g_colorbar.jpg"); + background: url("/jbossForge/images/graphs/g_colorbar.jpg"); } * html dd { float: none; } /* IE is dumb; Quick IE hack, apply favorite filter methods for wider browser compatibility */ dd div { position: relative; - background: url("g_colorbar2.jpg"); + background: url("/jbossForge/images/graphs/g_colorbar2.jpg"); height: 20px; width: 75%; text-align:right; @@ -61,7 +61,7 @@ right: -5px; top: -2px; display: block; - background: url("g_marker.gif"); + background: url("/jbossForge/images/graphs/g_marker.gif"); height: 24px; width: 9px; text-align: left; @@ -76,7 +76,7 @@ width: 378px; height: 207px; position: relative; - background: url("g_backbar.gif") no-repeat; + background: url("/jbossForge/images/graphs/g_backbar.gif") no-repeat; } #vertgraph ul { width: 378px; @@ -91,7 +91,7 @@ bottom: 34px; padding: 0 !important; margin: 0 !important; - background: url("g_colorbar3.jpg") no-repeat !important; + background: url("jbossForge/images/graphs/g_colorbar3.jpg") no-repeat !important; text-align: center; font-weight: bold; color: white; Added: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_backbar.gif =================================================================== (Binary files differ) Property changes on: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_backbar.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_colorbar.jpg =================================================================== (Binary files differ) Property changes on: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_colorbar.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_colorbar2.jpg =================================================================== (Binary files differ) Property changes on: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_colorbar2.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_colorbar3.jpg =================================================================== (Binary files differ) Property changes on: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_colorbar3.jpg ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_marker.gif =================================================================== (Binary files differ) Property changes on: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/images/graphs/g_marker.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream |
From: <jbo...@li...> - 2006-01-25 17:38:31
|
Author: unibrew Date: 2006-01-25 12:38:25 -0500 (Wed, 25 Jan 2006) New Revision: 2196 Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java Log: [DownloadCounters] Removing massive commit bug. Modified: trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java =================================================================== --- trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java 2006-01-25 16:50:22 UTC (rev 2195) +++ trunk/forge/portal-extensions/forge-common/src/java/org/jboss/forge/common/projects/DownloadCountersDescriptor.java 2006-01-25 17:38:25 UTC (rev 2196) @@ -466,7 +466,7 @@ org.jboss.shotoku.Node xmlFile = contentManager.getNode(pathToCountersXml); xmlFile.setContent(xmlString); xmlFile.save ("[DownlaodCounter] Main xml descriptor file update."); - + changeStatus=false; } catch (Exception e) { e.printStackTrace(); } |
Author: wrzep Date: 2006-01-25 11:50:22 -0500 (Wed, 25 Jan 2006) New Revision: 2195 Added: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/graphs.css Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Plugin.java trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/layouts/jbossForge.jsp Log: added css for bar graphs http://jira.jboss.com/jira/browse/JBLAB-595 Pawel Modified: trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Plugin.java =================================================================== --- trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Plugin.java 2006-01-25 11:29:25 UTC (rev 2194) +++ trunk/forge/portal-extensions/forge-status/src/java/org/jboss/forge/status/plugins/Plugin.java 2006-01-25 16:50:22 UTC (rev 2195) @@ -49,8 +49,6 @@ throws InvalidPluginPropertiesException { this.properties = properties; this.id = id; - - System.out.println("Plugin (" + id + ")"); } /** Added: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/graphs.css =================================================================== --- trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/graphs.css 2006-01-25 11:29:25 UTC (rev 2194) +++ trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/graphs.css 2006-01-25 16:50:22 UTC (rev 2195) @@ -0,0 +1,109 @@ +/* General */ + #content h3 { margin: 2em 0 .5em 0; } + + /* Basic Bar Graph */ + .graph { + position: relative; /* IE is dumb */ + width: 200px; + border: 1px solid #B1D632; + padding: 2px; + margin-bottom: .5em; + } + .graph .bar { + display: block; + position: relative; + background: #B1D632; + text-align: center; + color: #333; + height: 2em; + line-height: 2em; + } + .graph .bar span { position: absolute; left: 1em; } /* This extra markup is necessary because IE doesn't want to follow the rules for overflow: visible */ + + + /* Complex Bar Graph */ + dl { + margin: 0; + padding: 0; + } + dt { + position: relative; /* IE is dumb */ + clear: both; + display: block; + float: left; + width: 104px; + height: 20px; + line-height: 20px; + margin-right: 17px; + font-size: .75em; + text-align: right; + } + dd { + position: relative; /* IE is dumb */ + display: block; + float: left; + width: 197px; + height: 20px; + margin: 0 0 15px; + background: url("g_colorbar.jpg"); + } + * html dd { float: none; } /* IE is dumb; Quick IE hack, apply favorite filter methods for wider browser compatibility */ + + dd div { + position: relative; + background: url("g_colorbar2.jpg"); + height: 20px; + width: 75%; + text-align:right; + } + dd div strong { + position: absolute; + right: -5px; + top: -2px; + display: block; + background: url("g_marker.gif"); + height: 24px; + width: 9px; + text-align: left; + text-indent: -9999px; + overflow: hidden; + } + + + + /* Vertical Bar Graph */ + #vertgraph { + width: 378px; + height: 207px; + position: relative; + background: url("g_backbar.gif") no-repeat; + } + #vertgraph ul { + width: 378px; + height: 207px; + margin: 0; + padding: 0; + } + #vertgraph ul li { + position: absolute; + width: 28px; + height: 160px; + bottom: 34px; + padding: 0 !important; + margin: 0 !important; + background: url("g_colorbar3.jpg") no-repeat !important; + text-align: center; + font-weight: bold; + color: white; + line-height: 2.5em; + } + + #vertgraph li.critical { left: 24px; background-position: 0px bottom !important; } + #vertgraph li.high { left: 101px; background-position: -28px bottom !important; } + #vertgraph li.medium { left: 176px; background-position: -56px bottom !important; } + #vertgraph li.low { left: 251px; background-position: -84px bottom !important; } + #vertgraph li.info { left: 327px; background-position: -112px bottom !important; } + + /* + Note: The use of !important is to over write my site stlyesheets for these examples + */ Modified: trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/layouts/jbossForge.jsp =================================================================== --- trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/layouts/jbossForge.jsp 2006-01-25 11:29:25 UTC (rev 2194) +++ trunk/forge/portal-extensions/forge-theme/jbossForgeLayout.war/layouts/jbossForge.jsp 2006-01-25 16:50:22 UTC (rev 2195) @@ -20,6 +20,7 @@ <link rel="stylesheet" href="/jbossForge/jboss-forge.css" type="text/css" media="all"> <link rel="stylesheet" href="/jbossForge/jboss-forge-forums.css" type="text/css" media="all"> <link rel="stylesheet" href="/jbossForge/portlet.css" type="text/css" media="all"> +<link rel="stylesheet" href="/jbossForge/graphs.css" type="text/css" media="all"> <!-- insert the dynamically determined theme elements here, or use the 'simple-sample' theme by default --> <!-- <p:theme themeName='jboss-forge' /> --> |
Author: mic...@jb... Date: 2006-01-25 06:29:25 -0500 (Wed, 25 Jan 2006) New Revision: 2194 Added: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/LocalStore.java trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/LocalStoreTest.java Removed: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/LocalPersistTest.java Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryException.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryFactory.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManager.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManagerImpl.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetAttachment.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/ISaveHistory.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepoProxyHandler.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/StoreEventListener.java trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetDef.hbm.xml trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/IntegrationTest.java trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java Log: fixed up cascade saves, locking etc Added: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/LocalStore.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/LocalStore.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/LocalStore.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -0,0 +1,91 @@ +package org.drools.repository; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; + +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.io.xml.DomDriver; + + +/** + * This utility provides local persistence for rules. + * <p/> + * Rules can be saved to a single file for later synchronization with the repository. + * + * This uses XStream, as well as (optionally) object serialization. + * @author <a href="mailto:mic...@gm..."> Michael Neale</a> + */ +public class LocalStore { + + public static final int MODE_XSTREAM = 1; + public static final int MODE_OBJECT_SER = 2; + + private int mode = MODE_XSTREAM; + + /** Default instance. */ + public LocalStore() { + } + + /** Can use XStream for XML storage, or object serialization if required */ + public LocalStore(int mode) { + this.mode = mode; + } + + /** Saves the asset locally. Applies to the whole object graph */ + public void save(Asset ruleAsset, OutputStream out) { + if (mode == MODE_XSTREAM) { + OutputStreamWriter writer = new OutputStreamWriter(out); + getXStream().toXML(ruleAsset, writer); + } else if (mode == MODE_OBJECT_SER) { + try { + ObjectOutputStream objOut = new ObjectOutputStream(out); + objOut.writeObject(ruleAsset); + objOut.flush(); + } + catch ( IOException e ) { + throw new RepositoryException("Unable to store asset locally.", e); + } + } else { + throw new IllegalArgumentException("Unknown local persistence mode."); + } + } + + + /** Loads up the whole object graph. */ + public Asset load(InputStream input) { + if (mode == MODE_XSTREAM) { + InputStreamReader reader = new InputStreamReader(input); + Asset asset = (Asset) getXStream().fromXML(reader); + return asset; + } else if (mode == MODE_OBJECT_SER) { + try { + + ObjectInputStream objIn = new ObjectInputStream(input); + Asset asset = (Asset) objIn.readObject(); + return asset; + + } + catch ( Exception e ) { + throw new RepositoryException("Unable to store asset locally.", e); + } + } else { + throw new IllegalArgumentException("Unknown local persistence mode."); + } + + } + + private XStream getXStream() { + XStream xstream = new XStream(new DomDriver()); + return xstream; + } + + + + + +} Property changes on: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/LocalStore.java ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryException.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryException.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryException.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -21,4 +21,8 @@ super(message); } + public RepositoryException(String message, Throwable cause) { + super(message, cause); + } + } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryFactory.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryFactory.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryFactory.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -42,6 +42,17 @@ public static RepositoryManager getRepository(Principal currentUser, boolean stateful) { return getRepo(currentUser, stateful); } + + /** + * User this factory if you want to have audited, controlled access to the repository. + * + * @param currentUser the user accessing the repository. + */ + public static RepositoryManager getRepository(Principal currentUser) { + return getRepo(currentUser, false); + } + + private static RepositoryManager getProxy(RepoProxyHandler handler) { RepositoryManager manager = (RepositoryManager) Proxy.newProxyInstance(RepositoryFactory.class.getClassLoader(), Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManager.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManager.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManager.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -143,15 +143,15 @@ * * The properties should be (key, value) where value is the appropriate type of the field to query on. * The key maps to a " :key" item in your query string. - * + * <p/> * For instance, <code>query = "from RuleDef where versionNumber > :max and name = :name";</code> - * will have a map: + * will have a map:<p/> * <code> * map.put("max", new Long(42)); * map.put("name", "This is a String"); * //note the appropriate type to match the properties you want to search ! * </code> - * + * <p/> * @param query HQL query. Can be of the format "from ClassName where propertyName = :variableInMap" * You can also do "select name from RuleSetDef where ..." and so on. It will then return a list * of strings. If you do "select name, Id from RuleDef .." it will return a list of Object[] "tuples". Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManagerImpl.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManagerImpl.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RepositoryManagerImpl.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -9,6 +9,7 @@ import org.drools.repository.db.ISaveHistory; +import org.drools.repository.db.IVersionable; import org.hibernate.Query; import org.hibernate.Session; @@ -37,8 +38,6 @@ this.session = session; } - - /* (non-Javadoc) * @see org.drools.repository.db.RepositoryManager#loadRule(java.lang.String, long) */ @@ -83,9 +82,21 @@ return result; } + /** We will "manually" cascade changes to the ruleset */ public void save(Asset asset) { + if (asset instanceof RuleSetDef) { + cascadeChanges( (RuleSetDef) asset); + } session.saveOrUpdate( asset ); } + + public void cascadeChanges(RuleSetDef ruleSet) { + for ( Iterator iter = ruleSet.getModified().iterator(); iter.hasNext(); ) { + Asset asset = (Asset) iter.next(); + session.saveOrUpdate(asset); + iter.remove(); + } + } /* (non-Javadoc) * @see org.drools.repository.db.RepositoryManager#loadRuleSet(java.lang.String, long) @@ -219,6 +230,18 @@ session.update(attachment); } + + public List query(String query, + Map parameters) { + Query q = session.createQuery(query); + + for ( Iterator iter = parameters.keySet().iterator(); iter.hasNext(); ) { + String key = (String) iter.next(); + q.setParameter(key, parameters.get(key)); + } + + return q.list(); + } public void close() { /*implemented by the proxy */} @@ -245,21 +268,6 @@ session.disableFilter( "workingVersionFilter" ); } - - - public List query(String query, - Map parameters) { - Query q = session.createQuery(query); - - for ( Iterator iter = parameters.keySet().iterator(); iter.hasNext(); ) { - String key = (String) iter.next(); - q.setParameter(key, parameters.get(key)); - } - - return q.list(); - } - - /** Sets the current user principal for auditing, and access control purposes */ public void setCurrentUser(Principal user) { this.currentUser = user; Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -240,21 +240,6 @@ this.historicalRecord = historicalRecord; } - public boolean isStateChanged(ISaveHistory oldObject) { - RuleDef old = (RuleDef) oldObject; - if (diffStr(this.getContent(), old.getContent())) { - return true; - } else { - return false; - } - } - - - /** return true if different */ - private boolean diffStr(String left, String right) { - return !left.equals(right); - } - private int getLockingVersion() { return lockingVersion; } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetAttachment.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetAttachment.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetAttachment.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -194,11 +194,6 @@ public void setHistoricalRecord(boolean historicalRecord) { this.historicalRecord = historicalRecord; } - - public boolean isStateChanged(ISaveHistory oldObject) { - return true; - } - } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -1,7 +1,5 @@ package org.drools.repository; -import java.util.List; -import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.Set; @@ -44,7 +42,11 @@ private Set imports; private Set applicationData; private Set functions; + + private Set modifiedAssets = new HashSet(); + + public RuleSetDef(String name, MetaData meta) { this.name = name; @@ -57,6 +59,7 @@ this.applicationData = new HashSet(); this.imports = new HashSet(); this.workingVersionNumber = 1; + addNewVersionHistory("new"); } @@ -148,26 +151,32 @@ * The repository API has a delete(RuleDef rule) method * */ - public void removeRule(RuleDef rule) { - rule.setVersionNumber(IVersionable.NO_VERSION); + public void removeRule(RuleDef rule) { + rule.setOwningRuleSetName(null); + removeAsset(rule); } public void removeFunction(FunctionDef function) { - function.setVersionNumber(IVersionable.NO_VERSION); + removeAsset(function); } public void removeApplicationData(ApplicationDataDef appData) { - appData.setVersionNumber(IVersionable.NO_VERSION); + removeAsset(appData); } public void removeImport(ImportDef imp) { - imp.setVersionNumber(IVersionable.NO_VERSION); + removeAsset(imp); } public void removeAttachment(RuleSetAttachment attachment) { - attachment.setVersionNumber(IVersionable.NO_VERSION); + removeAsset(attachment); } + private void removeAsset(IVersionable asset) { + asset.setVersionNumber(IVersionable.NO_VERSION); + modifiedAssets.add(asset); + } + /** * @return a rule that is associated with this ruleset by the rules name. * If its not found, then it will return null. @@ -202,8 +211,26 @@ asset.setVersionComment( "new" ); } set.add( asset ); + + //don't forget this for cascasing ! + this.modifiedAssets.add( asset ); return this; } + + /** + * Call this so the repository knows what assets to save + * when the time comes to sync with the repository. + * + * This is only needed if you change the content of a rule for instance. + * Adding and removing things is automatic. + * + * This can be done so the ruleset temporarily remembers changes, + * or you can save the changes one by one yourself. + * @param A versionable asset (like a RuleDef, Function etc). + */ + public void modify(IVersionable asset) { + this.modifiedAssets.add( asset ); + } public MetaData getMetaData() { return metaData; @@ -289,7 +316,7 @@ * (think of that versioning as "minor" versions, and this sort of ruleset * versions as major versions). * - * Ideally once a new version is created, the RuleSet should be stored and + * IMPORTANT: once a new version is created, the RuleSet should be saved and * then loaded fresh, which will hide the non working versions of the rules. */ public void createNewVersion(String comment) { @@ -350,6 +377,7 @@ } } assets.addAll( newVersions ); + modifiedAssets.addAll( newVersions ); } public String toString() { @@ -397,6 +425,8 @@ this.imports = imports; } + Set getModified() { + return this.modifiedAssets; + } - } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/ISaveHistory.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/ISaveHistory.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/ISaveHistory.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -19,11 +19,6 @@ boolean isHistoricalRecord(); void setHistoricalRecord(boolean b); - /** - * - * @param oldObject Previous version of the object of this type. - * @return - */ - boolean isStateChanged(ISaveHistory oldObject); + } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepoProxyHandler.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepoProxyHandler.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepoProxyHandler.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -8,7 +8,6 @@ import org.drools.repository.RepositoryException; import org.drools.repository.RepositoryManagerImpl; import org.hibernate.Session; -import org.hibernate.StaleObjectStateException; import org.hibernate.Transaction; /** @@ -20,10 +19,10 @@ * This is the glue between the actual implementation and the interface. * * It also provides the stateful and stateless behaviour. - * Stateful simple means that a session instance is created the first time, and + * Stateful simple means that a new session instance is created the first time, and * kept around (long running sessions). + * Stateless uses getCurrentSession functionality in hibernate 3. * - * * It can also be extended to provide user context to the implementation class * (for auditing, access control and locking for instance). * @@ -109,7 +108,7 @@ InvocationTargetException e) { if (! (e.getTargetException() instanceof RepositoryException)) { try { - repoImpl.injectSession(null); + repoImpl.injectSession(null); //not really needed... but anyway session.close(); } catch (Exception e2) { /*ignore*/ } } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/StoreEventListener.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/StoreEventListener.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/StoreEventListener.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -49,15 +49,14 @@ ISaveHistory prev = (ISaveHistory) session.load( entity.getClass(), versionable.getId(), LockMode.NONE ); - if ( versionable.isStateChanged( prev ) ) { - ISaveHistory copy = (ISaveHistory) prev.copy(); - copy.setHistoricalId( versionable.getId() ); - copy.setHistoricalRecord( true ); - session.save( copy ); - session.flush(); - session.close(); - } - + ISaveHistory copy = (ISaveHistory) prev.copy(); + copy.setHistoricalId( versionable.getId() ); + copy.setHistoricalRecord( true ); + //session.beginTransaction(); + session.save( copy ); + //session.getTransaction().commit(); + session.flush(); + session.close(); } /** Modified: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetDef.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetDef.hbm.xml 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetDef.hbm.xml 2006-01-25 11:29:25 UTC (rev 2194) @@ -42,32 +42,39 @@ <one-to-many class="org.drools.repository.RuleSetVersionInfo"/> </set> - <!-- now come the versioned assets --> - <set name="rules" lazy="false" table="RULESET_RULES" cascade="all" optimistic-lock="false"> + <!-- now come the versioned assets + IMPORTANT: Note that cascading is done in the "save" method, not by hibernate + This is due to stop accidental version updates + + Note: the versioned asset sets are really "views" into the latest versions + of the assets. Hence no auto cascading. + + --> + <set name="rules" lazy="false" table="RULESET_RULES" cascade="none" optimistic-lock="false"> <key column="OWNING_RULESET_ID" /> <one-to-many class="org.drools.repository.RuleDef"/> <filter name="workingVersionFilter" condition=":filteredVersionNumber = VERSION_NUMBER" /> </set> - <set name="attachments" lazy="false" table="RULESET_ATTACHMENTS" cascade="all" optimistic-lock="false"> + <set name="attachments" lazy="false" table="RULESET_ATTACHMENTS" cascade="none" optimistic-lock="false"> <key column="RULESET_ID"/> <one-to-many class="org.drools.repository.RuleSetAttachment"/> <filter name="workingVersionFilter" condition=":filteredVersionNumber = versionNumber" /> </set> - <set name="imports" lazy="false" table="RULESET_IMPORTS" cascade="all" optimistic-lock="false"> + <set name="imports" lazy="false" table="RULESET_IMPORTS" cascade="none" optimistic-lock="false"> <key column="RULESET_ID"/> <one-to-many class="org.drools.repository.ImportDef"/> <filter name="workingVersionFilter" condition=":filteredVersionNumber = VERSION_NUMBER" /> </set> - <set name="functions" lazy="false" table="RULESET_FUNCTIONS" cascade="all" optimistic-lock="false"> + <set name="functions" lazy="false" table="RULESET_FUNCTIONS" cascade="none" optimistic-lock="false"> <key column="RULESET_ID"/> <one-to-many class="org.drools.repository.FunctionDef"/> <filter name="workingVersionFilter" condition=":filteredVersionNumber = VERSION_NUMBER" /> </set> - <set name="applicationData" table="RULESET_APP_DATA" lazy="false" cascade="all" optimistic-lock="false"> + <set name="applicationData" table="RULESET_APP_DATA" lazy="false" cascade="none" optimistic-lock="false"> <key column="RULESET_ID"/> <one-to-many class="org.drools.repository.ApplicationDataDef"/> <filter name="workingVersionFilter" condition=":filteredVersionNumber = VERSION_NUMBER" /> Modified: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/IntegrationTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/IntegrationTest.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/IntegrationTest.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -1,5 +1,7 @@ package org.drools.repository; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.security.Principal; import java.util.HashMap; import java.util.Iterator; @@ -32,17 +34,69 @@ * Any failure will cause the test to stop, but this is not a unit test, * so that is acceptable. */ - public void testBootstrap() { + public void testBootstrap() throws Exception { runVersioningTests(); runAttachmentTests(); - + runLocalOfflineTests(); runConcurrentTests(); -// runLocalPersistTests(); } /** + * Test local store features, simulating 2 users running offline. + */ + private void runLocalOfflineTests() throws Exception { + + RuleSetDef setA = new RuleSetDef("offline1", null); + setA.addRule(new RuleDef("offline1", "blah")); + setA.addRule(new RuleDef("offline2", "blah")); + + RepositoryManager repo = RepositoryFactory.getStatefulRepository(); + repo.save(setA); + repo.close(); + + repo = RepositoryFactory.getStatefulRepository(); + //load up copy A + setA = repo.loadRuleSet("offline1", 1); + repo.close(); + + //now load up copy B + repo = RepositoryFactory.getStatefulRepository(); + RuleSetDef setB = repo.loadRuleSet("offline1", 1); + repo.close(); + + //now store them locally + LocalStore store = new LocalStore(); + ByteArrayOutputStream outA = new ByteArrayOutputStream(); + ByteArrayOutputStream outB = new ByteArrayOutputStream(); + store.save(setA, outA); + store.save(setB, outB); + + + setA = (RuleSetDef) store.load(new ByteArrayInputStream(outA.toByteArray())); + setB = (RuleSetDef) store.load(new ByteArrayInputStream(outB.toByteArray())); + //setA.addRule(new RuleDef("yeah", "boo")); + //setB.addRule(new RuleDef("goo", "ya")); + RuleDef rule1 = setA.findRuleByName("offline1"); + RuleDef rule2 = setB.findRuleByName("offline2"); + rule1.setContent("something"); + //setA.addApplicationData(new ApplicationDataDef("dsadsa", "dfsads")); + //setB.setMetaData(new MetaData()); + + //no problems expected, as they were editing different rules + repo = RepositoryFactory.getStatefulRepository(); + repo.save(setA); + repo.close(); + + repo = RepositoryFactory.getStatefulRepository(); + repo.save(setB); + repo.close(); + + } + + + /** * The purpose of this test is to simulate 2 different users editing rules * in different session. Detached and all. */ @@ -285,6 +339,7 @@ for ( Iterator iter = ruleSet.getRules().iterator(); iter.hasNext(); ) { RuleDef myRule = (RuleDef) iter.next(); myRule.setContent("CHANGED RULE TEXT"); + ruleSet.modify(myRule); //this should cause us to have some rule history saved. //this has nothing to do with ruleset versioning. } Deleted: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/LocalPersistTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/LocalPersistTest.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/LocalPersistTest.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -1,34 +0,0 @@ -package org.drools.repository; - -import org.drools.repository.db.PersistentCase; - -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.io.xml.DomDriver; - -public class LocalPersistTest extends PersistentCase { - - public void testXStream() { - RuleSetDef def = new RuleSetDef("xstream1", new MetaData()); - def.addRule(new RuleDef("rulex1", "ndklsanlkdsan")); - XStream xstream = new XStream(new DomDriver()); - String xml = xstream.toXML(def); - //System.out.println(xml); - - def = (RuleSetDef) xstream.fromXML(xml); - - RepositoryManager repo = getRepo(); - repo.save(def); - - def = repo.loadRuleSet("xstream1", 1); - xml = xstream.toXML(def); - //System.out.println(xml); - - def = (RuleSetDef) xstream.fromXML(xml); - def.addRule( new RuleDef("xstream2", "xxxx")); - repo.save(def); - - assertNotNull(def); - - } - -} Added: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/LocalStoreTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/LocalStoreTest.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/LocalStoreTest.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -0,0 +1,117 @@ +package org.drools.repository; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStream; + +import org.drools.repository.db.PersistentCase; + +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.io.xml.DomDriver; + +/** + * @author <a href="mailto:mic...@gm..."> Michael Neale</a> + */ +public class LocalStoreTest extends PersistentCase { + + public void testXStream() { + RuleSetDef def = getRuleSet(); + XStream xstream = new XStream(new DomDriver()); + String xml = xstream.toXML(def); + //System.out.println(xml); + + def = (RuleSetDef) xstream.fromXML(xml); + + RepositoryManager repo = getRepo(); + repo.save(def); + + def = repo.loadRuleSet("xstream1", 1); + xml = xstream.toXML(def); + //System.out.println(xml); + + def = (RuleSetDef) xstream.fromXML(xml); + def.addRule( new RuleDef("xstream2", "xxxx")); + repo.save(def); + + assertNotNull(def); + + } + + /** + * The aim of this is to create a ruledef in one session, persist and then load + * edit and save in a different session. + */ + public void testMultiSession() { + RuleSetDef def1 = new RuleSetDef("multiSess", new MetaData()); + def1.addApplicationData(new ApplicationDataDef("xx", "abc")); + def1.addRule(new RuleDef("multis1", "abc")); + + RepositoryManager repo = RepositoryFactory.getStatefulRepository(); + repo.save(def1); + repo.close(); + + LocalStore store = new LocalStore(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + store.save(def1, out); + + def1 = (RuleSetDef) store.load(new ByteArrayInputStream(out.toByteArray())); + def1.addRule(new RuleDef("multi12", "njkfdkj")); + def1.addAttachment(new RuleSetAttachment("dsl", "nothing", "yeah".getBytes(), "nil")); + def1.createNewVersion("new version"); + out = new ByteArrayOutputStream(); + store.save(def1, out); + + def1 = (RuleSetDef) store.load(new ByteArrayInputStream(out.toByteArray())); + + repo = RepositoryFactory.getStatefulRepository(); + repo.save(def1); + repo.close(); + + repo = RepositoryFactory.getStatefulRepository(); + RuleSetDef def2 = repo.loadRuleSet("multiSess", 2); + assertEquals(1, def2.getAttachments().size()); + assertEquals(2, def2.getWorkingVersionNumber()); + repo.close(); + + + } + + + public void testLocalStoreXstream() { + runSaveLoad(new LocalStore()); + } + + public void testLocalStoreObjectSerialization() { + runSaveLoad(new LocalStore(LocalStore.MODE_OBJECT_SER)); + } + + + + private void runSaveLoad(LocalStore local) { + + RuleSetDef set = getRuleSet(); + + ByteArrayOutputStream out = new ByteArrayOutputStream(); + local.save(set, out); + + InputStream in = new ByteArrayInputStream(out.toByteArray()); + Asset result = local.load(in); + assertNotNull(result); + + RuleSetDef loaded = (RuleSetDef) result; + assertEquals(set.getName(), loaded.getName()); + assertEquals(set.getRules().size(), loaded.getRules().size()); + assertTrue(System.identityHashCode(set) != System.identityHashCode(loaded)); + } + + + private RuleSetDef getRuleSet() { + RuleSetDef def = new RuleSetDef("xstream1", new MetaData()); + def.addRule(new RuleDef("rulex1", "ndklsanlkdsan")); + return def; + } + + + +} Property changes on: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/LocalStoreTest.java ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -119,6 +119,7 @@ rs = repo.loadRuleSet("rule history", 1); RuleDef firstLoaded = rs.findRuleByName("rh1"); firstLoaded.setContent("new again"); + rs.modify(firstLoaded); repo.save(rs); rs = repo.loadRuleSet("rule history", 1); Modified: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java 2006-01-24 22:55:11 UTC (rev 2193) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java 2006-01-25 11:29:25 UTC (rev 2194) @@ -33,6 +33,8 @@ //now modify the content of a rule, ensure it is saved RuleDef rule = (RuleDef) def2.getRules().iterator().next(); rule.setContent("Something new"); + def2.modify(rule); + repo.save(def2); def2 = repo.loadRuleSet("my ruleset", 1); @@ -129,6 +131,7 @@ def = repo.loadRuleSet("addRemove", 2); RuleDef onlyRule = (RuleDef) def.getRules().iterator().next(); def.removeRule(onlyRule); + assertEquals(null, onlyRule.getOwningRuleSetName()); //assertEquals(0, def.getRules().size()); repo.save(def); @@ -278,6 +281,7 @@ repo.save(old); assertEquals(0, repo.listSaveHistory(newRule).size()); newRule.setContent("CHANGED CONTENT"); + old.modify(newRule); repo.save(old); assertEquals(1, repo.listSaveHistory(newRule).size()); @@ -296,6 +300,7 @@ //just make sure it preserves content, and same ID (now new versions). func.setFunctionContent("xyz"); + def.modify(func); Long id = func.getId(); repo.save(def); def = repo.loadRuleSet("with functions", 1); |
From: <jbo...@li...> - 2006-01-24 22:55:20
|
Author: szimano Date: 2006-01-24 17:55:11 -0500 (Tue, 24 Jan 2006) New Revision: 2193 Added: trunk/forge/portal-extensions/shotoku/shotoku-files/ trunk/forge/portal-extensions/shotoku/shotoku-files/maven.xml trunk/forge/portal-extensions/shotoku/shotoku-files/project.properties trunk/forge/portal-extensions/shotoku/shotoku-files/project.xml trunk/forge/portal-extensions/shotoku/shotoku-files/src/ trunk/forge/portal-extensions/shotoku/shotoku-files/src/app/ trunk/forge/portal-extensions/shotoku/shotoku-files/src/app/META-INF/ trunk/forge/portal-extensions/shotoku/shotoku-files/src/app/META-INF/application.xml trunk/forge/portal-extensions/shotoku/shotoku-files/src/etc/ trunk/forge/portal-extensions/shotoku/shotoku-files/src/etc/mime-types.txt trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/ trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/ trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/ trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/ trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/ trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileDirectory.java trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileNode.java trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FilesContentManager.java Log: Begining of FileContentManager for shotoku http://jira.jboss.com/jira/browse/JBSHOTOKU-53 Added: trunk/forge/portal-extensions/shotoku/shotoku-files/maven.xml =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-files/maven.xml 2006-01-24 22:18:44 UTC (rev 2192) +++ trunk/forge/portal-extensions/shotoku/shotoku-files/maven.xml 2006-01-24 22:55:11 UTC (rev 2193) @@ -0,0 +1,54 @@ +<!-- + JBoss, the OpenSource J2EE webOS + Distributable under LGPL license. + See terms of license at gnu.org. + --> +<project xmlns:j="jelly:core" xmlns:ant="jelly:ant" xmlns:u="jelly:util"> + <goal name="clean"> + <attainGoal name="prj-clean" /> + </goal> + + <goal name="build"> + <attainGoal name="ejb" /> + </goal> + + <goal name="deploy"> + <!-- Constructing the ear. --> + <ant:copy overwrite="true" + tofile="target/${shotoku.ear.dir}/shotoku-svn.ejb3" + file="target/shotoku-svn-1.0.jar" /> + <ant:copy + todir="target/${shotoku.ear.dir}" overwrite="true" + file="${maven.repo.local}/shotoku/jars/shotoku-base.jar" /> + <ant:copy + todir="target/${shotoku.ear.dir}" overwrite="true" + file="${maven.repo.local}/commons-configuration/jars/commons-configuration-1.1.jar" /> + <ant:copy + todir="target/${shotoku.ear.dir}" overwrite="true" + file="${maven.repo.local}/commons-lang/jars/commons-lang-2.1.jar" /> + <ant:copy + todir="target/${shotoku.ear.dir}" overwrite="true" + file="${maven.repo.local}/commons-collections/jars/commons-collections-3.1.jar" /> + <ant:copy + todir="target/${shotoku.ear.dir}" overwrite="true" + file="${maven.repo.local}/tmate/jars/javasvn.jar" /> + <ant:copy + todir="target/${shotoku.ear.dir}" overwrite="true"> + <ant:fileset dir="${maven.repo.local}/velocity/jars"> + <ant:filename name="velocity*-1.4.jar" /> + </ant:fileset> + </ant:copy> + <ant:copy todir="target/${shotoku.ear.dir}"> + <ant:fileset dir="src/app" flatten="true" overwrite="true"> + <ant:filename name="**" /> + </ant:fileset> + </ant:copy> + + <!-- Copying the ear to the deploy directory. --> + <ant:copy todir="${local.deploy.dir}"> + <ant:fileset dir="target" flatten="true" overwrite="true"> + <ant:filename name="${shotoku.ear.dir}/**" /> + </ant:fileset> + </ant:copy> + </goal> +</project> Added: trunk/forge/portal-extensions/shotoku/shotoku-files/project.properties =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-files/project.properties 2006-01-24 22:18:44 UTC (rev 2192) +++ trunk/forge/portal-extensions/shotoku/shotoku-files/project.properties 2006-01-24 22:55:11 UTC (rev 2193) @@ -0,0 +1,7 @@ +maven.repo.remote=http://repository.atlassian.com,http://www.ibiblio.org/maven,http://dist.codehaus.org/ +maven.junit.fork=yes +maven.war.src=${basedir}/src/web +maven.ejb.excludes=**/*Listener*,**/listener +maven.war.classes.excludes=**/*Bean* + +shotoku.ear.dir=00shotoku.ear \ No newline at end of file Added: trunk/forge/portal-extensions/shotoku/shotoku-files/project.xml =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-files/project.xml 2006-01-24 22:18:44 UTC (rev 2192) +++ trunk/forge/portal-extensions/shotoku/shotoku-files/project.xml 2006-01-24 22:55:11 UTC (rev 2193) @@ -0,0 +1,99 @@ +<?xml version='1.0' encoding='ISO-8859-1'?> +<!-- + JBoss, the OpenSource J2EE webOS + Distributable under LGPL license. + See terms of license at gnu.org. + --> +<project> + <pomVersion>3</pomVersion> + <extend>../project.xml</extend> + <id>shotoku-svn</id> + <name>Shotoku svn</name> + <currentVersion>1.0</currentVersion> + <organization> + <name>Adam Warski</name> + <url>http://mamut.net.pl</url> + </organization> + <description></description> + + <dependencies> + + <dependency> + <groupId>shotoku</groupId> + <artifactId>shotoku-base</artifactId> + <jar>shotoku-base.jar</jar> + <properties> + <ejb.manifest.classpath>true</ejb.manifest.classpath> + </properties> + </dependency> + + <dependency> + <groupId>velocity</groupId> + <artifactId>velocity</artifactId> + <version>1.4</version> + <properties> + <ejb.manifest.classpath>true</ejb.manifest.classpath> + </properties> + </dependency> + <dependency> + <groupId>velocity</groupId> + <artifactId>velocity-dep</artifactId> + <version>1.4</version> + <properties> + <ejb.manifest.classpath>true</ejb.manifest.classpath> + </properties> + </dependency> + + <dependency> + <groupId>jboss</groupId> + <artifactId>jboss-ejb3</artifactId> + <version>1.0</version> + <jar>jboss-ejb3.jar</jar> + </dependency> + + <dependency> + <groupId>jboss</groupId> + <artifactId>jboss-ejb3x</artifactId> + <version>1.0</version> + <jar>jboss-ejb3x.jar</jar> + </dependency> + + <dependency> + <groupId>jboss</groupId> + <artifactId>jboss-annotations-ejb3</artifactId> + <version>1.0</version> + <jar>jboss-annotations-ejb3.jar</jar> + </dependency> + + <dependency> + <groupId>jboss</groupId> + <artifactId>jboss-jmx</artifactId> + <version>1.0</version> + <jar>jboss-jmx.jar</jar> + </dependency> + + <dependency> + <groupId>jboss</groupId> + <artifactId>jboss-j2ee</artifactId> + <version>1.0</version> + <jar>jboss-j2ee.jar</jar> + </dependency> + + <dependency> + <groupId>jboss</groupId> + <artifactId>activation</artifactId> + <version>1.0</version> + <jar>activation.jar</jar> + </dependency> + </dependencies> + + <build> + <sourceDirectory>src/java</sourceDirectory> + <resources> + <resource> + <directory>src/etc/</directory> + <include>**/*.xml</include> + </resource> + </resources> + </build> +</project> Added: trunk/forge/portal-extensions/shotoku/shotoku-files/src/app/META-INF/application.xml =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-files/src/app/META-INF/application.xml 2006-01-24 22:18:44 UTC (rev 2192) +++ trunk/forge/portal-extensions/shotoku/shotoku-files/src/app/META-INF/application.xml 2006-01-24 22:55:11 UTC (rev 2193) @@ -0,0 +1,6 @@ +<application> + <display-name>Shotoku service</display-name> + <module> + <ejb>shotoku-svn.ejb3</ejb> + </module> +</application> Added: trunk/forge/portal-extensions/shotoku/shotoku-files/src/etc/mime-types.txt =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-files/src/etc/mime-types.txt 2006-01-24 22:18:44 UTC (rev 2192) +++ trunk/forge/portal-extensions/shotoku/shotoku-files/src/etc/mime-types.txt 2006-01-24 22:55:11 UTC (rev 2193) @@ -0,0 +1,714 @@ +############################################################################### +# +# MIME-TYPES and the extensions that represent them +# +# This file is part of the "mime-support" package. Please send email (not a +# bug report) to mim...@pa... if you would like new types +# and/or extensions to be added. +# +# Users can add their own types if they wish by creating a ".mime.types" +# file in their home directory. Definitions included there will take +# precedence over those listed here. +# +# Note: Compression schemes like "gzip", "bzip", and "compress" are not +# actually "mime-types". They are "encodings" and hence must _not_ have +# entries in this file to map their extensions. The "mime-type" of an +# encoded file refers to the type of data that has been encoded, not the +# type of the encoding. +# +############################################################################### + + +application/activemessage +application/andrew-inset ez +application/applefile +application/atomicmail +application/batch-SMTP +application/beep+xml +application/cals-1840 +application/commonground +application/cu-seeme cu +application/cybercash +application/dca-rft +application/dec-dx +application/docbook+xml +application/dsptype tsp +application/dvcs +application/edi-consent +application/edi-x12 +application/edifact +application/eshop +application/font-tdpfr +application/futuresplash spl +application/ghostview +application/hta hta +application/http +application/hyperstudio +application/iges +application/index +application/index.cmd +application/index.obj +application/index.response +application/index.vnd +application/iotp +application/ipp +application/isup +application/mac-binhex40 hqx +application/mac-compactpro cpt +application/macwriteii +application/marc +application/mathematica nb +application/mathematica-old +application/msaccess mdb +application/msword doc dot +application/news-message-id +application/news-transmission +application/ocsp-request +application/ocsp-response +application/octet-stream bin +application/oda oda +application/ogg ogg +application/parityfec +application/pdf pdf +application/pgp-encrypted +application/pgp-keys key +application/pgp-signature pgp +application/pics-rules prf +application/pkcs10 +application/pkcs7-mime +application/pkcs7-signature +application/pkix-cert +application/pkix-crl +application/pkixcmp +application/postscript ps ai eps +application/prs.alvestrand.titrax-sheet +application/prs.cww +application/prs.nprend +application/qsig +application/rar rar +application/rdf+xml rdf +application/remote-printing +application/riscos +application/rss+xml rss +application/rtf +application/sdp +application/set-payment +application/set-payment-initiation +application/set-registration +application/set-registration-initiation +application/sgml +application/sgml-open-catalog +application/sieve +application/slate +application/smil smi smil +application/timestamp-query +application/timestamp-reply +application/vemmi +application/whoispp-query +application/whoispp-response +application/wita +application/wordperfect5.1 wp5 +application/x400-bp +application/xhtml+xml xhtml xht +application/xml xml xsl +application/xml-dtd +application/xml-external-parsed-entity +application/zip zip +application/vnd.3M.Post-it-Notes +application/vnd.accpac.simply.aso +application/vnd.accpac.simply.imp +application/vnd.acucobol +application/vnd.aether.imp +application/vnd.anser-web-certificate-issue-initiation +application/vnd.anser-web-funds-transfer-initiation +application/vnd.audiograph +application/vnd.bmi +application/vnd.businessobjects +application/vnd.canon-cpdl +application/vnd.canon-lips +application/vnd.cinderella cdy +application/vnd.claymore +application/vnd.commerce-battelle +application/vnd.commonspace +application/vnd.comsocaller +application/vnd.contact.cmsg +application/vnd.cosmocaller +application/vnd.ctc-posml +application/vnd.cups-postscript +application/vnd.cups-raster +application/vnd.cups-raw +application/vnd.cybank +application/vnd.dna +application/vnd.dpgraph +application/vnd.dxr +application/vnd.ecdis-update +application/vnd.ecowin.chart +application/vnd.ecowin.filerequest +application/vnd.ecowin.fileupdate +application/vnd.ecowin.series +application/vnd.ecowin.seriesrequest +application/vnd.ecowin.seriesupdate +application/vnd.enliven +application/vnd.epson.esf +application/vnd.epson.msf +application/vnd.epson.quickanime +application/vnd.epson.salt +application/vnd.epson.ssf +application/vnd.ericsson.quickcall +application/vnd.eudora.data +application/vnd.fdf +application/vnd.ffsns +application/vnd.flographit +application/vnd.framemaker +application/vnd.fsc.weblaunch +application/vnd.fujitsu.oasys +application/vnd.fujitsu.oasys2 +application/vnd.fujitsu.oasys3 +application/vnd.fujitsu.oasysgp +application/vnd.fujitsu.oasysprs +application/vnd.fujixerox.ddd +application/vnd.fujixerox.docuworks +application/vnd.fujixerox.docuworks.binder +application/vnd.fut-misnet +application/vnd.grafeq +application/vnd.groove-account +application/vnd.groove-identity-message +application/vnd.groove-injector +application/vnd.groove-tool-message +application/vnd.groove-tool-template +application/vnd.groove-vcard +application/vnd.hhe.lesson-player +application/vnd.hp-HPGL +application/vnd.hp-PCL +application/vnd.hp-PCLXL +application/vnd.hp-hpid +application/vnd.hp-hps +application/vnd.httphone +application/vnd.hzn-3d-crossword +application/vnd.ibm.MiniPay +application/vnd.ibm.afplinedata +application/vnd.ibm.modcap +application/vnd.informix-visionary +application/vnd.intercon.formnet +application/vnd.intertrust.digibox +application/vnd.intertrust.nncp +application/vnd.intu.qbo +application/vnd.intu.qfx +application/vnd.irepository.package+xml +application/vnd.is-xpr +application/vnd.japannet-directory-service +application/vnd.japannet-jpnstore-wakeup +application/vnd.japannet-payment-wakeup +application/vnd.japannet-registration +application/vnd.japannet-registration-wakeup +application/vnd.japannet-setstore-wakeup +application/vnd.japannet-verification +application/vnd.japannet-verification-wakeup +application/vnd.koan +application/vnd.lotus-1-2-3 +application/vnd.lotus-approach +application/vnd.lotus-freelance +application/vnd.lotus-notes +application/vnd.lotus-organizer +application/vnd.lotus-screencam +application/vnd.lotus-wordpro +application/vnd.mcd +application/vnd.mediastation.cdkey +application/vnd.meridian-slingshot +application/vnd.mif +application/vnd.minisoft-hp3000-save +application/vnd.mitsubishi.misty-guard.trustweb +application/vnd.mobius.daf +application/vnd.mobius.dis +application/vnd.mobius.msl +application/vnd.mobius.plc +application/vnd.mobius.txf +application/vnd.motorola.flexsuite +application/vnd.motorola.flexsuite.adsi +application/vnd.motorola.flexsuite.fis +application/vnd.motorola.flexsuite.gotap +application/vnd.motorola.flexsuite.kmr +application/vnd.motorola.flexsuite.ttc +application/vnd.motorola.flexsuite.wem +application/vnd.mozilla.xul+xml xul +application/vnd.ms-artgalry +application/vnd.ms-asf +application/vnd.ms-excel xls xlb xlt +application/vnd.ms-lrm +application/vnd.ms-pki.seccat cat +application/vnd.ms-pki.stl stl +application/vnd.ms-powerpoint ppt pps +application/vnd.ms-project +application/vnd.ms-tnef +application/vnd.ms-works +application/vnd.mseq +application/vnd.msign +application/vnd.music-niff +application/vnd.musician +application/vnd.netfpx +application/vnd.noblenet-directory +application/vnd.noblenet-sealer +application/vnd.noblenet-web +application/vnd.novadigm.EDM +application/vnd.novadigm.EDX +application/vnd.novadigm.EXT +application/vnd.oasis.opendocument.chart odc +application/vnd.oasis.opendocument.database odb +application/vnd.oasis.opendocument.formula odf +application/vnd.oasis.opendocument.graphics odg +application/vnd.oasis.opendocument.graphics-template otg +application/vnd.oasis.opendocument.image odi +application/vnd.oasis.opendocument.presentation odp +application/vnd.oasis.opendocument.presentation-template otp +application/vnd.oasis.opendocument.spreadsheet ods +application/vnd.oasis.opendocument.spreadsheet-template ots +application/vnd.oasis.opendocument.text odt +application/vnd.oasis.opendocument.text-master odm +application/vnd.oasis.opendocument.text-template ott +application/vnd.oasis.opendocument.text-web oth +application/vnd.osa.netdeploy +application/vnd.palm +application/vnd.pg.format +application/vnd.pg.osasli +application/vnd.powerbuilder6 +application/vnd.powerbuilder6-s +application/vnd.powerbuilder7 +application/vnd.powerbuilder7-s +application/vnd.powerbuilder75 +application/vnd.powerbuilder75-s +application/vnd.previewsystems.box +application/vnd.publishare-delta-tree +application/vnd.pvi.ptid1 +application/vnd.pwg-xhtml-print+xml +application/vnd.rapid +application/vnd.rim.cod cod +application/vnd.s3sms +application/vnd.seemail +application/vnd.shana.informed.formdata +application/vnd.shana.informed.formtemplate +application/vnd.shana.informed.interchange +application/vnd.shana.informed.package +application/vnd.smaf mmf +application/vnd.sss-cod +application/vnd.sss-dtf +application/vnd.sss-ntf +application/vnd.stardivision.calc sdc +application/vnd.stardivision.draw sda +application/vnd.stardivision.impress sdd sdp +application/vnd.stardivision.math smf +application/vnd.stardivision.writer sdw vor +application/vnd.stardivision.writer-global sgl +application/vnd.street-stream +application/vnd.sun.xml.calc sxc +application/vnd.sun.xml.calc.template stc +application/vnd.sun.xml.draw sxd +application/vnd.sun.xml.draw.template std +application/vnd.sun.xml.impress sxi +application/vnd.sun.xml.impress.template sti +application/vnd.sun.xml.math sxm +application/vnd.sun.xml.writer sxw +application/vnd.sun.xml.writer.global sxg +application/vnd.sun.xml.writer.template stw +application/vnd.svd +application/vnd.swiftview-ics +application/vnd.symbian.install sis +application/vnd.triscape.mxs +application/vnd.trueapp +application/vnd.truedoc +application/vnd.tve-trigger +application/vnd.ufdl +application/vnd.uplanet.alert +application/vnd.uplanet.alert-wbxml +application/vnd.uplanet.bearer-choice +application/vnd.uplanet.bearer-choice-wbxml +application/vnd.uplanet.cacheop +application/vnd.uplanet.cacheop-wbxml +application/vnd.uplanet.channel +application/vnd.uplanet.channel-wbxml +application/vnd.uplanet.list +application/vnd.uplanet.list-wbxml +application/vnd.uplanet.listcmd +application/vnd.uplanet.listcmd-wbxml +application/vnd.uplanet.signal +application/vnd.vcx +application/vnd.vectorworks +application/vnd.vidsoft.vidconference +application/vnd.visio vsd +application/vnd.vividence.scriptfile +application/vnd.wap.sic +application/vnd.wap.slc +application/vnd.wap.wbxml wbxml +application/vnd.wap.wmlc wmlc +application/vnd.wap.wmlscriptc wmlsc +application/vnd.webturbo +application/vnd.wrq-hp3000-labelled +application/vnd.wt.stf +application/vnd.xara +application/vnd.xfdl +application/vnd.yellowriver-custom-menu +application/x-123 wk +application/x-apple-diskimage dmg +application/x-bcpio bcpio +application/x-bittorrent torrent +application/x-cdf cdf +application/x-cdlink vcd +application/x-chess-pgn pgn +application/x-core +application/x-cpio cpio +application/x-csh csh +application/x-debian-package deb +application/x-director dcr dir dxr +application/x-dms dms +application/x-doom wad +application/x-dvi dvi +application/x-executable +application/x-flac flac +application/x-font pfa pfb gsf pcf pcf.Z +application/x-futuresplash spl +application/x-gnumeric gnumeric +application/x-go-sgf sgf +application/x-graphing-calculator gcf +application/x-gtar gtar tgz taz +application/x-hdf hdf +application/x-httpd-php phtml pht php +application/x-httpd-php-source phps +application/x-httpd-php3 php3 +application/x-httpd-php3-preprocessed php3p +application/x-httpd-php4 php4 +application/x-ica ica +application/x-internet-signup ins isp +application/x-iphone iii +application/x-iso9660-image iso +application/x-java-applet +application/x-java-archive jar +application/x-java-bean +application/x-java-jnlp-file jnlp +application/x-java-serialized-object ser +application/x-java-vm class +application/x-javascript js +application/x-jmol jmz +application/x-kchart chrt +application/x-kdelnk +application/x-killustrator kil +application/x-koan skp skd skt skm +application/x-kpresenter kpr kpt +application/x-kspread ksp +application/x-kword kwd kwt +application/x-latex latex +application/x-lha lha +application/x-lzh lzh +application/x-lzx lzx +application/x-maker frm maker frame fm fb book fbdoc +application/x-mif mif +application/x-ms-wmd wmd +application/x-ms-wmz wmz +application/x-msdos-program com exe bat dll +application/x-msi msi +application/x-netcdf nc +application/x-ns-proxy-autoconfig pac +application/x-nwc nwc +application/x-object o +application/x-oz-application oza +application/x-pkcs7-certreqresp p7r +application/x-pkcs7-crl crl +application/x-python-code pyc pyo +application/x-quicktimeplayer qtl +application/x-redhat-package-manager rpm +application/x-rx +application/x-sh sh +application/x-shar shar +application/x-shellscript +application/x-shockwave-flash swf swfl +application/x-stuffit sit +application/x-sv4cpio sv4cpio +application/x-sv4crc sv4crc +application/x-tar tar +application/x-tcl tcl +application/x-tex-gf gf +application/x-tex-pk pk +application/x-texinfo texinfo texi +application/x-trash ~ % bak old sik +application/x-troff t tr roff +application/x-troff-man man +application/x-troff-me me +application/x-troff-ms ms +application/x-ustar ustar +application/x-videolan +application/x-wais-source src +application/x-wingz wz +application/x-x509-ca-cert crt +application/x-xcf xcf +application/x-xfig fig + +audio/32kadpcm +audio/basic au snd +audio/g.722.1 +audio/l16 +audio/midi mid midi kar +audio/mp4a-latm +audio/mpa-robust +audio/mpeg mpga mpega mp2 mp3 m4a +audio/mpegurl m3u +audio/parityfec +audio/prs.sid sid +audio/telephone-event +audio/tone +audio/vnd.cisco.nse +audio/vnd.cns.anp1 +audio/vnd.cns.inf1 +audio/vnd.digital-winds +audio/vnd.everad.plj +audio/vnd.lucent.voice +audio/vnd.nortel.vbk +audio/vnd.nuera.ecelp4800 +audio/vnd.nuera.ecelp7470 +audio/vnd.nuera.ecelp9600 +audio/vnd.octel.sbc +audio/vnd.qcelp +audio/vnd.rhetorex.32kadpcm +audio/vnd.vmx.cvsd +audio/x-aiff aif aiff aifc +audio/x-gsm gsm +audio/x-mpegurl m3u +audio/x-ms-wma wma +audio/x-ms-wax wax +audio/x-pn-realaudio-plugin +audio/x-pn-realaudio ra rm ram +audio/x-realaudio ra +audio/x-scpls pls +audio/x-sd2 sd2 +audio/x-wav wav + +chemical/x-alchemy alc +chemical/x-cache cac cache +chemical/x-cache-csf csf +chemical/x-cactvs-binary cbin cascii ctab +chemical/x-cdx cdx +chemical/x-cerius cer +chemical/x-chem3d c3d +chemical/x-chemdraw chm +chemical/x-cif cif +chemical/x-cmdf cmdf +chemical/x-cml cml +chemical/x-compass cpa +chemical/x-crossfire bsd +chemical/x-csml csml csm +chemical/x-ctx ctx +chemical/x-cxf cxf cef +#chemical/x-daylight-smiles smi +chemical/x-embl-dl-nucleotide emb embl +chemical/x-galactic-spc spc +chemical/x-gamess-input inp gam gamin +chemical/x-gaussian-checkpoint fch fchk +chemical/x-gaussian-cube cub +chemical/x-gaussian-input gau gjc gjf +chemical/x-gaussian-log gal +chemical/x-gcg8-sequence gcg +chemical/x-genbank gen +chemical/x-hin hin +chemical/x-isostar istr ist +chemical/x-jcamp-dx jdx dx +chemical/x-kinemage kin +chemical/x-macmolecule mcm +chemical/x-macromodel-input mmd mmod +chemical/x-mdl-molfile mol +chemical/x-mdl-rdfile rd +chemical/x-mdl-rxnfile rxn +chemical/x-mdl-sdfile sd sdf +chemical/x-mdl-tgf tgf +#chemical/x-mif mif +chemical/x-mmcif mcif +chemical/x-mol2 mol2 +chemical/x-molconn-Z b +chemical/x-mopac-graph gpt +chemical/x-mopac-input mop mopcrt mpc dat zmt +chemical/x-mopac-out moo +chemical/x-mopac-vib mvb +chemical/x-ncbi-asn1 asn +chemical/x-ncbi-asn1-ascii prt ent +chemical/x-ncbi-asn1-binary val aso +chemical/x-ncbi-asn1-spec asn +chemical/x-pdb pdb ent +chemical/x-rosdal ros +chemical/x-swissprot sw +chemical/x-vamas-iso14976 vms +chemical/x-vmd vmd +chemical/x-xtel xtel +chemical/x-xyz xyz + +image/cgm +image/g3fax +image/gif gif +image/ief ief +image/jpeg jpeg jpg jpe +image/naplps +image/pcx pcx +image/png png +image/prs.btif +image/prs.pti +image/svg+xml svg svgz +image/tiff tiff tif +image/vnd.cns.inf2 +image/vnd.djvu djvu djv +image/vnd.dwg +image/vnd.dxf +image/vnd.fastbidsheet +image/vnd.fpx +image/vnd.fst +image/vnd.fujixerox.edmics-mmr +image/vnd.fujixerox.edmics-rlc +image/vnd.mix +image/vnd.net-fpx +image/vnd.svf +image/vnd.wap.wbmp wbmp +image/vnd.xiff +image/x-cmu-raster ras +image/x-coreldraw cdr +image/x-coreldrawpattern pat +image/x-coreldrawtemplate cdt +image/x-corelphotopaint cpt +image/x-icon ico +image/x-jg art +image/x-jng jng +image/x-ms-bmp bmp +image/x-photoshop psd +image/x-portable-anymap pnm +image/x-portable-bitmap pbm +image/x-portable-graymap pgm +image/x-portable-pixmap ppm +image/x-rgb rgb +image/x-xbitmap xbm +image/x-xpixmap xpm +image/x-xwindowdump xwd + +inode/chardevice +inode/blockdevice +inode/directory-locked +inode/directory +inode/fifo +inode/socket + +message/delivery-status +message/disposition-notification +message/external-body +message/http +message/s-http +message/news +message/partial +message/rfc822 + +model/iges igs iges +model/mesh msh mesh silo +model/vnd.dwf +model/vnd.flatland.3dml +model/vnd.gdl +model/vnd.gs-gdl +model/vnd.gtw +model/vnd.mts +model/vnd.vtu +model/vrml wrl vrml + +multipart/alternative +multipart/appledouble +multipart/byteranges +multipart/digest +multipart/encrypted +multipart/form-data +multipart/header-set +multipart/mixed +multipart/parallel +multipart/related +multipart/report +multipart/signed +multipart/voice-message + +text/calendar ics icz +text/comma-separated-values csv +text/css css +text/directory +text/english +text/enriched +text/h323 323 +text/html html htm shtml +text/iuls uls +text/mathml mml +text/parityfec +text/plain asc txt text diff pot +text/prs.lines.tag +text/rfc822-headers +text/richtext rtx +text/rtf rtf +text/scriptlet sct wsc +text/t140 +text/texmacs tm ts +text/tab-separated-values tsv +text/uri-list +text/vnd.abc +text/vnd.curl +text/vnd.DMClientScript +text/vnd.flatland.3dml +text/vnd.fly +text/vnd.fmi.flexstor +text/vnd.in3d.3dml +text/vnd.in3d.spot +text/vnd.IPTC.NewsML +text/vnd.IPTC.NITF +text/vnd.latex-z +text/vnd.motorola.reflex +text/vnd.ms-mediapackage +text/vnd.sun.j2me.app-descriptor jad +text/vnd.wap.si +text/vnd.wap.sl +text/vnd.wap.wml wml +text/vnd.wap.wmlscript wmls +text/x-c++hdr h++ hpp hxx hh +text/x-c++src c++ cpp cxx cc +text/x-chdr h +text/x-crontab +text/x-csh csh +text/x-csrc c +text/x-java java +text/x-makefile +text/x-moc moc +text/x-pascal p pas +text/x-pcs-gcd gcd +text/x-perl pl pm +text/x-python py +text/x-server-parsed-html +text/x-setext etx +text/x-sh sh +text/x-tcl tcl tk +text/x-tex tex ltx sty cls +text/x-vcalendar vcs +text/x-vcard vcf + +video/dl dl +video/fli fli +video/gl gl +video/mpeg mpeg mpg mpe m4v +video/mp4 mp4 +video/quicktime qt mov +video/mp4v-es +video/parityfec +video/pointer +video/vnd.fvt +video/vnd.motorola.video +video/vnd.motorola.videop +video/vnd.mpegurl mxu +video/vnd.mts +video/vnd.nokia.interleaved-multimedia +video/vnd.vivo +video/x-dv dif dv +video/x-la-asf lsf lsx +video/x-mng mng +video/x-ms-asf asf asx +video/x-ms-wm wm +video/x-ms-wmv wmv +video/x-ms-wmx wmx +video/x-ms-wvx wvx +video/x-msvideo avi +video/x-sgi-movie movie + +x-conference/x-cooltalk ice + +x-world/x-vrml vrm vrml wrl Added: trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileDirectory.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileDirectory.java 2006-01-24 22:18:44 UTC (rev 2192) +++ trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileDirectory.java 2006-01-24 22:55:11 UTC (rev 2193) @@ -0,0 +1,230 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt 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.jboss.shotoku.files; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.jboss.shotoku.Directory; +import org.jboss.shotoku.Node; +import org.jboss.shotoku.NodeList; +import org.jboss.shotoku.exceptions.CopyException; +import org.jboss.shotoku.exceptions.DeleteException; +import org.jboss.shotoku.exceptions.MoveException; +import org.jboss.shotoku.exceptions.RepositoryException; +import org.jboss.shotoku.exceptions.ResourceAlreadyExists; +import org.jboss.shotoku.exceptions.ResourceDoesNotExist; +import org.jboss.shotoku.exceptions.SaveException; + +public class FileDirectory implements Directory { + + private File directory; + + /** + * + */ + private static final long serialVersionUID = 1L; + + public FileDirectory(String directory) throws RepositoryException { + File dir = new File(directory); + + if (!dir.isDirectory()) { + throw new RepositoryException(directory + " is not a directory"); + } + + this.directory = dir; + } + + public FileDirectory(File directory) throws RepositoryException { + if (directory.isDirectory()) { + this.directory = directory; + } else { + throw new RepositoryException(directory.getAbsolutePath() + + " is not a directory."); + } + } + + public NodeList getNodes() throws RepositoryException { + List<Node> list = new ArrayList<Node>(); + + File[] children = directory.listFiles(); + + // get all children + for (File file : children) { + if (file.isFile()) { + list.add(new FileNode(file)); + } + } + + return new NodeList(list); + } + + public List<Directory> getDirectories() throws RepositoryException { + List<Directory> list = new ArrayList<Directory>(); + + File[] children = directory.listFiles(); + + // get all children + for (File directory : children) { + if (directory.isDirectory()) { + list.add(new FileDirectory(directory)); + } + } + + return list; + } + + public Node getNode(String name) throws RepositoryException, + ResourceDoesNotExist { + File file = new File(this.directory.getAbsolutePath() + name); + + if (!file.exists()) { + throw new RepositoryException("File " + file.getAbsolutePath() + + " doesn't exists"); + } + return new FileNode(name); + } + + public Directory getDirectory(String name) throws RepositoryException, + ResourceDoesNotExist { + File dir = new File(this.directory.getAbsolutePath() + name); + + if (!dir.exists()) { + throw new RepositoryException("Directory " + dir.getAbsolutePath() + + " doesn't exists"); + } + + return new FileDirectory(dir); + } + + public Node newNode(String name) throws ResourceAlreadyExists, + RepositoryException { + File file = new File(this.directory.getAbsolutePath() + name); + + if (file.exists()) { + throw new ResourceAlreadyExists("File " + file.getAbsolutePath() + + " already exists"); + } else { + try { + if (!file.createNewFile()) { + throw new RepositoryException("Couldn't create new file: " + + file.getAbsolutePath()); + } + } catch (IOException e) { + throw new RepositoryException(e); + } + } + + return new FileNode(file); + } + + public Directory newDirectory(String name) throws ResourceAlreadyExists, + RepositoryException { + File dir = new File(this.directory.getAbsolutePath() + name); + + if (dir.exists()) { + throw new ResourceAlreadyExists("Directory " + + dir.getAbsolutePath() + " already exists"); + } else { + if (!dir.mkdirs()) { + throw new RepositoryException("Couldn't create new directory: " + + dir.getAbsolutePath()); + } + } + + return new FileDirectory(dir); + } + + public boolean hasIndex(String arg0) throws RepositoryException { + // TODO Auto-generated method stub + return false; + } + + public void setIndex(String arg0, boolean arg1) throws RepositoryException { + // TODO Auto-generated method stub + + } + + public void copyTo(Directory arg0, String arg1, String arg2) + throws CopyException { + // TODO Auto-generated method stub + + } + + public void moveTo(Directory arg0, String arg1) throws MoveException { + // TODO Auto-generated method stub + + } + + public Map<String, String> getProperties() throws RepositoryException { + // TODO Auto-generated method stub + return null; + } + + public String getProperty(String arg0) throws RepositoryException { + // TODO Auto-generated method stub + return null; + } + + public void deleteProperty(String arg0) throws RepositoryException { + // TODO Auto-generated method stub + + } + + public void setProperty(String arg0, String arg1) { + // TODO Auto-generated method stub + + } + + public void save(String arg0) throws SaveException, RepositoryException { + // TODO Auto-generated method stub + + } + + public String getLogMessage() throws RepositoryException { + // TODO Auto-generated method stub + return null; + } + + public String getFullName() { + // TODO Auto-generated method stub + return null; + } + + public Directory getParent() throws RepositoryException { + return new FileDirectory(directory.getParentFile()); + } + + public void delete() throws DeleteException, RepositoryException { + // TODO Auto-generated method stub + + } + + public String getName() { + // TODO Auto-generated method stub + return null; + } + +} Added: trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileNode.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileNode.java 2006-01-24 22:18:44 UTC (rev 2192) +++ trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FileNode.java 2006-01-24 22:55:11 UTC (rev 2193) @@ -0,0 +1,381 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt 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.jboss.shotoku.files; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Date; +import java.util.Map; + +import org.jboss.shotoku.Directory; +import org.jboss.shotoku.History; +import org.jboss.shotoku.Node; +import org.jboss.shotoku.exceptions.CopyException; +import org.jboss.shotoku.exceptions.DeleteException; +import org.jboss.shotoku.exceptions.MoveException; +import org.jboss.shotoku.exceptions.RepositoryException; +import org.jboss.shotoku.exceptions.SaveException; + +public class FileNode implements Node { + + private File file; + + /** + * + */ + private static final long serialVersionUID = 1L; + + public FileNode(String file) throws RepositoryException { + File fil = new File(file); + + if (!fil.isFile()) { + throw new RepositoryException(file + " is not a file"); + } + + this.file = fil; + } + + public FileNode(File file) throws RepositoryException { + if (file.isFile()) { + this.file = file; + } + else { + throw new RepositoryException(file.getAbsolutePath()+" is not a file."); + } + } + + public String getContent() throws RepositoryException { + StringBuffer buffer = new StringBuffer(); + + try { + InputStream is = new FileInputStream(file); + + char chr; + + while ((chr = (char)is.read()) != -1) { + buffer.append(chr); + } + + is.close(); + } catch (FileNotFoundException e) { + new RepositoryException(e); + } catch (IOException e) { + new RepositoryException(e); + } + + + return buffer.toString(); + } + + public void setContent(String content) { + try { + OutputStream os = new FileOutputStream(file); + + for (int i = 0; i < content.length(); i++) { + os.write(content.charAt(i)); + } + + os.close(); + } catch (FileNotFoundException e) { + new RepositoryException(e); + } catch (IOException e) { + new RepositoryException(e); + } + } + + public void setContent(InputStream is) { + try { + OutputStream os = new FileOutputStream(file); + + int i; + + while ((i = is.read()) != -1) { + os.write(i); + } + + os.close(); + } catch (FileNotFoundException e) { + new RepositoryException(e); + } catch (IOException e) { + new RepositoryException(e); + } + } + + public void setContent(byte[] b) { + try { + OutputStream os = new FileOutputStream(file); + + os.write(b); + + os.close(); + } catch (FileNotFoundException e) { + new RepositoryException(e); + } catch (IOException e) { + new RepositoryException(e); + } + } + + public OutputStream getOutputStream() { + try { + return new FileOutputStream(file); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return null; + } + } + + public History getHistory() throws RepositoryException { + // TODO Auto-generated method stub + return null; + } + + public int getRevisionNumber() throws RepositoryException { + // TODO Auto-generated method stub + return 0; + } + + public void copyToFile(String fileName) throws RepositoryException { + try { + OutputStream os = new FileOutputStream(new File(fileName)); + InputStream is = getContentInputStream(); + + int b; + while ((b = is.read()) != -1) + os.write(b); + + os.close(); is.close(); + + } catch (FileNotFoundException e) { + new RepositoryException(e); + } catch (IOException e) { + new RepositoryException(e); + } + + } + + public InputStream getContentInputStream() throws RepositoryException { + try { + return new FileInputStream(file); + } catch (FileNotFoundException e) { + throw new RepositoryException(e); + } + } + + public byte[] getContentByteArray() throws RepositoryException { + InputStream is = getContentInputStream(); + + byte[] b = new byte[(int)getLength()]; + + try { + is.read(b); + + is.close(); + + return b; + } catch (IOException e) { + throw new RepositoryException(e); + } + } + + public long getLength() throws RepositoryException { + return file.length(); + } + + public long getLastModification() throws RepositoryException { + return file.lastModified(); + } + + public Date getLastModificationDate() throws RepositoryException { + return new Date(getLastModification()); + } + + public String getMimeType() { + // TODO Auto-generated method stub + return null; + } + + /** + * Copies this resource to the given directory. This can't be called if + * this resource is new and not yet saved. + * + * @param dir + * Directory to copy this resource to. This can't be a new and + * not saved directory. + * @param newName + * New name of this resource (in directory dir after copying). + * @param logMessage + * Log message associated with this resource copy. + * @throws CopyException + */ + public void copyTo(Directory dir, String newName, + String logMessage) throws CopyException{ + //TODO + } + + /** + * Moves this resource to the given directory. This can't be called if + * this resource is new and not yet saved. This resource should not be + * used after performing this operation. + * + * @param dir + * Directory to move this resource to. This can't be a new and + * not saved directory. + * @param logMessage + * Log message associated with this resource move. + * @throws MoveException + */ + public void moveTo(Directory dir, String logMessage) throws MoveException{ + //TODO + } + + /** + * Gets a map of all properties associated with this resource. + * + * @return A map of properties associated with this resource. + * @throws RepositoryException + */ + public Map<String, String> getProperties() throws RepositoryException{ + //TODO + return null; + } + + /** + * Gets the value of the given property. + * + * @param propertyName + * Name of the property to get. + * @return Value of the given property. + * @throws RepositoryException + */ + public String getProperty(String propertyName) throws RepositoryException{ + //TODO + return null; + } + + /** + * Deletes the the given property. + * + * @param propertyName + * Name of the property to delete. + * @throws RepositoryException + */ + public void deleteProperty(String propertyName) throws RepositoryException{ + //TODO + } + + /** + * Sets the value of the given property. Only after saving this change will be + * persisted. + * + * @param propertyName + * Name of the property to set. It must begin with a character, + * and cannot contain any special characters (so the regexp to which + * a property name must match would be [a-z][a-z0-9]*). + * @param propertyValue + * Value of the property to set. + */ + public void setProperty(String propertyName, String propertyValue){ + //TODO + } + + /** + * Gets a directory to which this node/ directory belongs. + * + * @return A directory to which this node/ directory belongs. Null if this + * directory is already the root directory. + */ + public Directory getParent() throws RepositoryException{ + return new FileDirectory(file.getParentFile()); + } + + /** + * Saves modified properties and possibly content (in case of nodes). + * + * @param logMessage + * Log message for saving this node/ directory. + * @throws SaveException + * @throws RepositoryException + */ + public void save(String logMessage) throws SaveException, RepositoryException{ + //TODO + + } + + /** + * Gets a log message with which this node/ directory was saved. + * + * @return Log message with which this node/ directory was saved. Null, if + * the resource is not yet saved or contains modifications. + * @throws RepositoryException + */ + public String getLogMessage() throws RepositoryException{ + //TODO + return null; + + } + + /** + * Deletes this node or directory (immediately, no <code>save()</code> is + * needed). This resource should not be used after performing this + * operation. + * + * @throws DeleteException + * @throws RepositoryException + */ + public void delete() throws DeleteException, RepositoryException{ + try { + if (!file.delete()) { + throw new DeleteException("Couldn't delete file "+file.getAbsolutePath()); + } + } catch (SecurityException e) { + throw new RepositoryException(e); + } + } + + /** + * Gets the name of this resource (node/ directory). + * + * @return Name of this resource (node/ directory). An empty string, if this + * is the root directory. + */ + public String getName() { + //TODO + return null; + } + + /** + * Gets the full name of this resource, that is, path to this resource + * relative to the content manager this node was read from. + * + * @return Full name of this resource. + */ + public String getFullName(){ + //TODO + return null; + } + +} Added: trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FilesContentManager.java =================================================================== --- trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FilesContentManager.java 2006-01-24 22:18:44 UTC (rev 2192) +++ trunk/forge/portal-extensions/shotoku/shotoku-files/src/java/org/jboss/shotoku/files/FilesContentManager.java 2006-01-24 22:55:11 UTC (rev 2193) @@ -0,0 +1,76 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2005, JBoss Inc., and individual contributors as indicated + * by the @authors tag. See the copyright.txt 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.jboss.shotoku.files; + +import java.util.Collection; + +import org.jboss.shotoku.ContentManager; +import org.jboss.shotoku.Directory; +import org.jboss.shotoku.Node; +import org.jboss.shotoku.Resource; +import org.jboss.shotoku.exceptions.DeleteException; +import org.jboss.shotoku.exceptions.RepositoryException; +import org.jboss.shotoku.exceptions.ResourceDoesNotExist; +import org.jboss.shotoku.exceptions.SaveException; + +public class FilesContentManager extends ContentManager { + + public FilesContentManager(String arg0, String arg1) throws RepositoryException { + super(arg0, arg1); + // TODO Auto-generated constructor stub + } + + @Override + public Directory getRootDirectory() throws RepositoryException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Node getNode(String arg0) throws ResourceDoesNotExist, + RepositoryException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Directory getDirectory(String arg0) throws ResourceDoesNotExist, + RepositoryException { + // TODO Auto-generated method stub + return null; + } + + @Override + public void save(Collection<Resource> arg0, String arg1) + throws SaveException, RepositoryException { + // TODO Auto-generated method stub + + } + + @Override + public void delete(Collection<Resource> arg0) throws DeleteException, + RepositoryException { + // TODO Auto-generated method stub + + } + +} |
From: <jbo...@li...> - 2006-01-24 22:19:08
|
Author: mnasato Date: 2006-01-24 17:18:44 -0500 (Tue, 24 Jan 2006) New Revision: 2192 Modified: trunk/labs/davcache/README.txt Log: fixed tomcat instructions Modified: trunk/labs/davcache/README.txt =================================================================== --- trunk/labs/davcache/README.txt 2006-01-24 13:52:33 UTC (rev 2191) +++ trunk/labs/davcache/README.txt 2006-01-24 22:18:44 UTC (rev 2192) @@ -20,19 +20,21 @@ For JBoss (tested with 4.0.3SP1) - 1. start JBoss (tested with 4.0.3SP1) with the 'all' configuration - 2. deploy 'davcache.sar' - 3. optionally start another JBoss instance to test replication + 1. download the JBoss service (SAR) version + 2. explode and copy to JBOSS_HOME/server/all/deploy/ + 3. start JBoss in the all configuration + 4. optionally start another JBoss instance to test replication For standalone Tomcat (tested with 5.5.12) or any other servlet container - 1. start JBoss (tested with 4.0.3SP1) with the 'all' configuration - 2. deploy 'davcache.sar' - 3. optionally start another JBoss instance to test replication + 1. download the Webapp (WAR) version + 2. explode and copy to TOMCAT_HOME/webapps/ + 3. start Tomcat + 4. optionally deploy to another Tomcat server for replication finally - 4. point your Webdav client to 'http://localhost:8080/davcache' (no auth needed) + 5. point your Webdav client to 'http://localhost:8080/davcache' (no auth needed) Enjoy, |
From: <jbo...@li...> - 2006-01-24 13:53:08
|
Author: mic...@jb... Date: 2006-01-24 08:52:33 -0500 (Tue, 24 Jan 2006) New Revision: 2191 Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/DefaultExpander.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/Chunk.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLExpressionCompiler.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLGrammar.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLMappingItem.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/TemplateContext.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/TemplateFactory.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ExpanderContextTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/cheese-rules.drl trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/cheese.dsl.properties trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/NLExpressionCompilerTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/NLGrammarTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/TemplateContextTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/TemplateFactoryTest.java Removed: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/rule-with-expansion.drl Modified: trunk/labs/jbossrules/drools-core/pom.xml trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/ExpanderContext.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java Log: first cut of expander with natural rules Modified: trunk/labs/jbossrules/drools-core/pom.xml =================================================================== --- trunk/labs/jbossrules/drools-core/pom.xml 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/pom.xml 2006-01-24 13:52:33 UTC (rev 2191) @@ -34,7 +34,17 @@ <groupId>jparsec</groupId> <artifactId>jparsec</artifactId> <version>0.01</version> - </dependency> + </dependency> + + <!-- only needed for the default expander in lang.. remove when it is refactored. --> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.1</version> + </dependency> + </dependencies> + + </project> \ No newline at end of file Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/ExpanderContext.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/ExpanderContext.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/ExpanderContext.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -1,5 +1,6 @@ package org.drools.lang; +import java.io.IOException; import java.io.InputStream; import java.io.Serializable; import java.net.URL; @@ -67,7 +68,7 @@ registerExpander(expander, expanderName); return expander; - } catch (Exception e) { + } catch (IOException e) { throw new IllegalArgumentException("Unable to load expander with name: " + expanderName); } } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -303,11 +303,12 @@ if ( line == null ) { throw new ParseException( "end expected", lineNumber ); } - if ( line.trim().equals( "end" ) ) { + String trimLine = line.trim(); + if ( trimLine.equals( "end" ) ) { break; } consumeDiscard(); - line = maybeExpand( line ); + line = maybeExpand( trimLine ); consequence.append( line + "\n" ); } System.err.println( "begin consequence"); Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/DefaultExpander.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/DefaultExpander.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/DefaultExpander.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -0,0 +1,40 @@ +package org.drools.lang.dsl; + +import java.util.Properties; + +import org.drools.lang.Expander; +import org.drools.lang.Parser; +import org.drools.lang.dsl.template.NLExpressionCompiler; +import org.drools.lang.dsl.template.NLGrammar; + +/** + * The default expander uses String templates to provide pseudo natural language, + * as well as general DSLs. + * + * For most people, this should do the job just fine. + * TODO: refactor out the template stuff into the natural module. + */ +public class DefaultExpander + implements + Expander { + + private NLExpressionCompiler compiler; + + public String expand(String pattern, + Parser context) { + return compiler.compile(pattern); + } + + /** + * Properties contain the mapping between the language expressions, and the target expressions. + * Use {0} style notation to place "holes" where data will be parsed from the natural text input. + * + * @see org.drools.lang.dsl.template.NLExpressionCompiler for details. + */ + public DefaultExpander(Properties props) { + NLGrammar grammar = new NLGrammar(); + grammar.loadFromProperties(props); + compiler = new NLExpressionCompiler(grammar); + } + +} Property changes on: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/DefaultExpander.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/Chunk.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/Chunk.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/Chunk.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -0,0 +1,112 @@ +package org.drools.lang.dsl.template; + +import java.util.Map; + +import org.apache.commons.lang.StringUtils; + +/** + * This holds a linked list of chunks of natural language. + * A chunk is basically some text, which is delimited by "holes" in the template. + * + * eg: "this is {0} an {1} expression" + * Would have 5 chunks: "this is", "{0}", "an", "{1}" and "expression". + * + * Chunks also know how to parse themselves to work out the value. + * + * This is used by TemplateContext. + * This class is very recursive, to be prepated to be confused. + * + * @author <a href="mailto:mic...@gm..."> Michael Neale</a> + */ +class Chunk { + + //the chunk of text from the dicitonary + final String text; + final boolean isHole; + + Chunk next; + + //for building the substitution string, remember how the {0} was spaced with the rest of the string + //for example: date of '{0}' ---- this needs to be handled as well as: date of ' {0} ' + String padL = ""; + String padR = ""; + + //value parsed out if it is a hole, starts out as null. + String value; + + Chunk(String text) { + this.text = text; + if (text.startsWith("{")) { + isHole = true; + } else { + isHole = false; + } + } + + /** + * This will build up a key to use to substitute the original string with. + * Can then swap it with the target text. + */ + void buildSubtitutionKey(StringBuffer buffer) { + if (isHole) { + buffer.append(padL + value + padR); + } else { + buffer.append(text); + } + if (next != null) { + next.buildSubtitutionKey(buffer); + } + } + + void process(String expression) { + if (isHole) { + //value = text until next next.text is found + if (next == null || next.text == null) { + storeSpacePadding( expression ); + value = expression.trim(); + } else { + String val = StringUtils.substringBefore(expression, next.text); + storeSpacePadding( val ); + value = val.trim(); + } + + } else { + value = text; + } + if (next != null) { + next.process(StringUtils.substringAfter(expression, value)); + } + } + + private void storeSpacePadding(String val) { + if (val.startsWith(" ")) padL = " "; + if (val.endsWith(" ")) padR = " "; + } + + void buildValueMap(Map map) { + if (isHole) { + map.put(text, value); + } + if (next != null) { + next.buildValueMap(map); + } + } + + void addToEnd(Chunk chunk) { + if (next == null) { + next = chunk; + } else { + next.addToEnd(chunk); + } + } + + + /** recursively reset the values */ + public void clearValues() { + this.value = null; + if (this.next != null) { + next.clearValues(); + } + } + +} Property changes on: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/Chunk.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLExpressionCompiler.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLExpressionCompiler.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLExpressionCompiler.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -0,0 +1,63 @@ +package org.drools.lang.dsl.template; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + * This is the utility class for compiling pseudo natural/DSL expression into the target + * language, via the supplied mappings. + * + * This version works off "string templates" rather then infix operators. + * + * Note that this is not particularly efficient for large grammars - IN THEORY ! + * However, I have tested it with grammars of 200 000 terms, and it took less then a second per expression, + * so its no slouch. This could be a problem for bulk compiling of large rulesets with thousands of conditions. + * + * In general, grammars of < 1000 items should be fine. The cost is a parse time cost for Drools, which can be done + * incrementally in a suitable environment ideally anyway. + * + * It will go through each item in the grammar, trying to apply it regardless of if it is needed. + * This may be improved by some early regex scanning, but most likely this will not really save much. + * + * @author <a href="mailto:mic...@gm..."> Michael Neale</a> + */ +public class NLExpressionCompiler { + + //a map of templates to the template contexts (template contexts are used to populate populate + //the target mappings with data from a real expression. + private Map templateCache; + + + public NLExpressionCompiler(NLGrammar grammar) { + Collection grammarItems = grammar.getMappings(); + this.templateCache = new HashMap(); + + //build up a map of templates + TemplateFactory factory = new TemplateFactory(); + for ( Iterator iter = grammarItems.iterator(); iter.hasNext(); ) { + NLMappingItem mapping = (NLMappingItem) iter.next(); + TemplateContext ctx = factory.getContext(mapping.getNaturalTemplate()); + templateCache.put(mapping, ctx); + } + } + + /** + * This will iterate through the grammar, trying to match any grammar templates with the expression. + * When it can, it will pull the values out of the expression, put them in the target string, and then swap it out with + * the original, and then move on to the next item from the grammar/dictionary. + */ + public String compile(String expression) { + String nl = expression; + for ( Iterator iter = templateCache.entrySet().iterator(); iter.hasNext(); ) { + Map.Entry entry = (Map.Entry) iter.next(); + NLMappingItem mapping = (NLMappingItem) entry.getKey(); + TemplateContext ctx = (TemplateContext) entry.getValue(); + nl = ctx.processAllInstances(nl, mapping.getGrammarTemplate()); + } + return nl; + } + + +} Property changes on: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLExpressionCompiler.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLGrammar.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLGrammar.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLGrammar.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -0,0 +1,51 @@ +package org.drools.lang.dsl.template; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; + +/** This represents a simple grammar mapping. */ +public class NLGrammar + implements + Serializable { + + + private static final long serialVersionUID = 1L; + private List mappings = new ArrayList(); + + public NLGrammar() { + } + + + /** + * When loading from properties, the order in which they appear in the props file + * is the priority. (TODO: order means nothing to properties it seems). + * + * Which makes sense intuitively, the order you read them it the order in which they will be applied. + */ + public void loadFromProperties(Properties props) { + int i = props.size(); + for ( Iterator iter = props.keySet().iterator(); iter.hasNext(); ) { + String key = (String) iter.next(); + String property = props.getProperty(key); + NLMappingItem item = new NLMappingItem(i, key, property); + addNLItem(item); + i--; + } + } + + public void addNLItem(NLMappingItem item) { + this.mappings.add(item); + } + + public Collection getMappings() { + Collections.sort(mappings); + return Collections.unmodifiableCollection(mappings); + } + + +} Property changes on: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLGrammar.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLMappingItem.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLMappingItem.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLMappingItem.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -0,0 +1,58 @@ +package org.drools.lang.dsl.template; + +import java.io.Serializable; + +/** + * This contains a single mapping from psuedo NL to a grammarTemplate. + * + * @author <a href="mailto:mic...@gm..."> Michael Neale</a> + * + */ +public class NLMappingItem + implements + Comparable, Serializable { + + + private static final long serialVersionUID = 7185580607729787497L; + + private int priority = 0; + + private String naturalTemplate; + private String grammarTemplate; + + public NLMappingItem(int priority, + String naturalTemplate, + String grammarTemplate) { + this.priority = priority; + this.naturalTemplate = naturalTemplate; + this.grammarTemplate = grammarTemplate; + } + + public String getNaturalTemplate() { + return naturalTemplate; + } + + public String getGrammarTemplate() { + return grammarTemplate; + } + + public int compareTo(Object arg) { + if ( arg instanceof NLMappingItem ) { + NLMappingItem item = (NLMappingItem) arg; + if ( item.priority == this.priority ) return 0; + if ( item.priority > this.priority ) return -1; + if ( item.priority < this.priority ) return 1; + return 0; + } + else { + return 0; + } + } + + int getPriority() { + return this.priority; + } + + + +} Property changes on: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/NLMappingItem.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/TemplateContext.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/TemplateContext.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/TemplateContext.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -0,0 +1,130 @@ +package org.drools.lang.dsl.template; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.apache.commons.lang.StringUtils; + + +/** + * This class takes a linked list of Chunk objects, and will replace what the chunks represent + * in an nl string with a interpolated grammar template. + * The values are obtained by matching the chunks with the nl. + * + * @author <a href="mailto:mic...@gm..."> Michael Neale</a> + * This is an alternative approach to the infix parser. + */ +class TemplateContext { + + //the start of the linked list. + Chunk start; + + /** + * Ad a chunk from the dictionary expression. + * A chunk is a piece of nl, or a hole. + * nl & holes must not be mixed. + */ + TemplateContext addChunk(String chunkText) { + Chunk chunk = new Chunk(chunkText); + if (start == null) { + start = chunk; + } else { + start.addToEnd(chunk); + } + return this; + } + + /** + * This will parse the input nl expression, and build a map of values for the "holes" + * in the grammar expression. + * It does this by getting the Chunks of the grammar to parse themselves. + */ + void processNL(String nl, Map map) { + start.clearValues(); + start.process(nl); + start.buildValueMap(map); + } + + /** + * This builds a fragment of the nl expression which can be used + * to swap out a piece of the original with the target expression. + * + * The target expression is the "right hand side" of the grammar map. + */ + String getSubstitutionKey() { + StringBuffer buffer = new StringBuffer(); + start.buildSubtitutionKey(buffer); + return buffer.toString().trim(); //trim so we don't get any erroneous spaces to stop replacing. + } + + /** + * This will build the target string that you can use to substitute the original with. + * @param map The map of values to hole keys. + * @param grammar_r The grammar item which will have the values plugged into the "holes". + * @return The final expression ready for substitution. + */ + String populateTargetString(Map map, + String grammar_r) { + for ( Iterator iter = map.keySet().iterator(); iter.hasNext(); ) { + String key = (String) iter.next(); + grammar_r = StringUtils.replace(grammar_r, key, (String) map.get(key)); + } + return grammar_r; + } + + /** + * @param nl The natural language expression. + * @param subKey The part of the nl expression to be swapped out. + * @param target The chunk to be swapped in to the nl + * @return The nl with the chunk replaced with the target. + */ + String interpolate(String nl, String subKey, String target) { + return StringUtils.replace(nl, subKey, target); + } + + /** + * This does it all as one call. Requires that chunks have been setup. + * @param nl The nl expression to process. + * @param grammarTemplate The grammar expression that will be interpolated (with the values from the original chunks), + * and then inserted in to the nl. + * @return the NL with the populated grammarRHS replacing the original pattern (from the chunks). + */ + public String process(String nl, String grammarTemplate) { + Map values = new HashMap(); + this.processNL(nl, values); + String subKey = this.getSubstitutionKey(); + String target = this.populateTargetString(values, grammarTemplate); + return this.interpolate(nl, subKey, target); + } + + + /** + * Similar to process, but processes iteratively until there is + * no change in the output. This allows for stuff to be repeated in an NL expression. + */ + public String processAllInstances(String nl, String grammarTemplate) { + String result = nl; + + //put an upper limit + int i = 0; + while (i < 10) { + String newResult = process(result, grammarTemplate); + if (newResult.equals(result)) { + break; + } + result = newResult; + + i++; + if (i == 10) { + throw new IllegalArgumentException("To many iterations in processing the expression: [" + + nl + + "] with target template: [" + + grammarTemplate + "]"); + } + } + return result; + } + + +} Property changes on: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/TemplateContext.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/TemplateFactory.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/TemplateFactory.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/TemplateFactory.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -0,0 +1,95 @@ +package org.drools.lang.dsl.template; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +/** + * This takes a grammar template (the left hand side of a grammar mapping table) + * and builds a TemplateContext for it. + * + * Uses a built in lexer. + * + * @author <a href="mailto:mic...@gm..."> Michael Neale</a> + */ +class TemplateFactory { + + /** + * This will lex the template string into chunks. + * @param template From the grammar. eg "{0} likes cheese" is a template. + * @return A template context ready to apply to a nl expression. + */ + public TemplateContext getContext(String template) { + + TemplateContext ctx = new TemplateContext(); + + List chunkList = lexChunks(template); + for ( Iterator iter = chunkList.iterator(); iter.hasNext(); ) { + ctx.addChunk((String) iter.next()); + + } + return ctx; + } + + + List lexChunks(String grammarTemplate) { + ChunkLexer lexer = new ChunkLexer(); + return lexer.lex(grammarTemplate); + } + + + /** + * Lex out chunks. + * @author <a href="mailto:mic...@gm..."> Michael Neale</a> + */ + static class ChunkLexer { + + private List chunks = new ArrayList(); + + private StringBuffer buffer = new StringBuffer(); + + public List lex(String grammarTemplate) { + + char[] chars = grammarTemplate.toCharArray(); + + for ( int i = 0; i < chars.length; i++ ) { + switch ( chars[i] ) { + case '{' : + startHole(); + break; + case '}' : + endHole(); + break; + default : + buffer.append(chars[i]); + break; + } + } + String buf = this.buffer.toString(); + if (!buf.equals("")) addChunk( buf ); + return this.chunks; + + } + + private boolean addChunk(String buf) { + return this.chunks.add( buf.trim() ); + } + + private void endHole() { + String buf = this.buffer.toString(); + chunks.add("{" + buf + "}"); + this.buffer = new StringBuffer(); + } + + private void startHole() { + String buf = this.buffer.toString(); + if (!buf.equals("")) { + addChunk( buf ); + } + this.buffer = new StringBuffer(); + } + + + } + +} Property changes on: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/dsl/template/TemplateFactory.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ExpanderContextTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ExpanderContextTest.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ExpanderContextTest.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -0,0 +1,36 @@ +package org.drools.lang; + +import junit.framework.TestCase; + +public class ExpanderContextTest extends TestCase { + + public void testExpander() { + ExpanderContext ctx = ExpanderContext.getInstance(); + ctx.registerExpander(new MockExpander("mock1"), "mock1"); + MockExpander exp = (MockExpander) ctx.getExpander("mock1"); + assertEquals("mock1", exp.returnVal); + + //test re-register + ctx.registerExpander(new MockExpander("mock2"), "mock1"); + exp = (MockExpander) ctx.getExpander("mock1"); + assertEquals("mock2", exp.returnVal); + + } + + static class MockExpander implements Expander { + + String returnVal; + + MockExpander(String val) { + returnVal = val; + } + + public String expand(String pattern, + Parser context) { + + return null; + } + + } + +} Property changes on: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ExpanderContextTest.java ___________________________________________________________________ Name: svn:eol-style + native Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -53,8 +53,10 @@ } public void test_with_expander() throws Exception { - Parser parser = parser( "rule-with-expansion.drl" ); + Parser parser = parser( "cheese-rules.drl" ); parser.parse(); + assertEquals("cheese_rules", ((Rule)parser.getRules().get(0)).getName() ); + } protected Parser parser(String name) { Added: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/cheese-rules.drl =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/cheese-rules.drl 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/cheese-rules.drl 2006-01-24 13:52:33 UTC (rev 2191) @@ -0,0 +1,22 @@ +# Example DRL with expansion +# (ie "domain specific language") + +# declare expanders for domain specific and natural language extensions +use expander cheese.dsl.properties +#this one is just a simple properties file + + +rule cheese_rules + when + Bob is in atlanta + Bob likes cheese + #There exists a Guest with name of "Michael" and sex of "Male" + >Guest( name == seatingRightGuestName, rightGuestSex:sex, rightGuestHobby:hobby ) + >Guest( leftGuestName:name , sex != rightGuestSex, hobby == rightGuestHobby ) + + #count => Count() can be replaced by + bind count to Count + then + Send notification to Mark with message "hello" + >System.out.println("and this is code") +end \ No newline at end of file Property changes on: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/cheese-rules.drl ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/cheese.dsl.properties =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/cheese.dsl.properties 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/cheese.dsl.properties 2006-01-24 13:52:33 UTC (rev 2191) @@ -0,0 +1,6 @@ +#this is an little dsl + +Bob\ is\ in\ {0}=Bob(location={0}) +{Person}\ likes\ cheese={Person}(cheeseFan==true) +bind\ {var}\ to\ {object}={var} => {object}() +Send\ notification\ to\ {Person}\ with\ message\ {message}=EmailUtil.sendEmail("{Person}", {message}) \ No newline at end of file Property changes on: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/cheese.dsl.properties ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/NLExpressionCompilerTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/NLExpressionCompilerTest.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/NLExpressionCompilerTest.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -0,0 +1,103 @@ +package org.drools.lang.dsl.template; + +import java.util.Properties; + +import junit.framework.TestCase; + +public class NLExpressionCompilerTest extends TestCase { + + public void testIntegration() { + NLGrammar grammar = new NLGrammar(); + grammar.addNLItem(new NLMappingItem(0, "{0} likes cheese", "likesCheese({0})")); + + NLExpressionCompiler compiler = new NLExpressionCompiler(grammar); + String result = compiler.compile("bob likes cheese"); + + assertEquals("likesCheese(bob)", result); + + //now lets use a properties + Properties props = new Properties(); + props.setProperty("{0} likes cheese", "likesCheese({0})"); + props.setProperty("the date between {0} and {1}", "dateCompare({0}, {1})"); + props.setProperty("bind", "=>"); + + grammar = new NLGrammar(); + grammar.loadFromProperties(props); + compiler = new NLExpressionCompiler(grammar); + result = compiler.compile("bob likes cheese"); + + assertEquals("likesCheese(bob)", result); + + result = compiler.compile("the date between bob and michael"); + assertEquals("dateCompare(bob, michael)", result); + + result = compiler.compile("bind"); + assertEquals("=>", result); + + } + + public void testLargeGrammar() { + Properties props = new Properties(); + + for (int i = 0; i < 1000; i++ ) { + props.put("some {0} grammar" + i, "some mapping{0}"); + if (i == 42) { + props.put("{0} likes cheese", "{0}.likesCheese()"); + props.put("{0} is happy", "{0}.isHappy()"); + } + } + + + + NLGrammar grammar = new NLGrammar(); + grammar.loadFromProperties(props); + + NLExpressionCompiler compiler = new NLExpressionCompiler(grammar); + + long start = System.currentTimeMillis(); + String result = compiler.compile("michael likes cheese and michael is happy"); + long runtime = System.currentTimeMillis() - start; + System.out.println("Runtime for compile with dictionary of 1000: " + runtime + "ms"); + assertEquals("michael.likesCheese() and michael.isHappy()", result); + + } + + + public void testNestingAndOrderOfExpressions() { + NLGrammar grammar = new NLGrammar(); + + grammar.addNLItem(new NLMappingItem(0, "{0} likes cheese", "{0}.likesCheese()" )); + grammar.addNLItem(new NLMappingItem(1, "print out cheese fan status {0}", "print({0})" )); + + + NLExpressionCompiler compiler = new NLExpressionCompiler(grammar); + String nl = "print out cheese fan status bob likes cheese"; + String expected = "print(bob.likesCheese())"; + + String result = compiler.compile(nl); + + assertEquals(expected, result); + + + grammar = new NLGrammar(); + + grammar.addNLItem(new NLMappingItem(1, "date of '{0}'", "dateOf({0})")); + grammar.addNLItem(new NLMappingItem(2, "age of [ {0} ]", "{0}.getAge()")); + grammar.addNLItem(new NLMappingItem(3, "Today", "new java.util.Date()")); + grammar.addNLItem(new NLMappingItem(4, "{0} is before {1}", "({0}).compareTo({1}) > 0")); + + nl = "date of '10-jul-2006' is before Today"; + + compiler = new NLExpressionCompiler(grammar); + expected = "(dateOf(10-jul-2006)).compareTo(new java.util.Date()) > 0"; + assertEquals(expected, compiler.compile(nl)); + + nl = "age of [ bob ] < age of [ michael ]"; + expected = "bob.getAge() < michael.getAge()"; + assertEquals(expected, compiler.compile(nl)); + + + + } + +} Property changes on: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/NLExpressionCompilerTest.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/NLGrammarTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/NLGrammarTest.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/NLGrammarTest.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -0,0 +1,63 @@ +package org.drools.lang.dsl.template; + +import java.io.ByteArrayInputStream; +import java.util.Collection; +import java.util.Properties; + +import junit.framework.TestCase; + +public class NLGrammarTest extends TestCase { + + /** Check that it sets up priorities correctly */ + public void testLoadFromProperties() throws Exception { + NLGrammar grammar = new NLGrammar(); + + + String data = "number\\ 1=number 1\n" + + "number\\ 2=number 2"; + + Properties props = new Properties(); + + ByteArrayInputStream stream = new ByteArrayInputStream(data.getBytes("UTF-8")); + + props.load(stream); + + grammar.loadFromProperties(props); + + Collection list = grammar.getMappings(); + Object[] items = list.toArray(); + + NLMappingItem item = (NLMappingItem) items[0]; + assertEquals("number 1", item.getNaturalTemplate()); + assertEquals(1, item.getPriority()); + + item = (NLMappingItem) items[1]; + assertEquals("number 2", item.getNaturalTemplate()); + assertEquals(2, item.getPriority()); + + props = new Properties(); + props.setProperty("znumber 1", "number 1"); + props.setProperty("bnumber 2", "number 2"); + props.setProperty("anumber 3", "number 3"); + + grammar = new NLGrammar(); + grammar.loadFromProperties(props); + + list = grammar.getMappings(); + items = list.toArray(); + + item = (NLMappingItem) items[0]; + assertEquals("znumber 1", item.getNaturalTemplate()); + assertEquals(1, item.getPriority()); + + item = (NLMappingItem) items[1]; + assertEquals("bnumber 2", item.getNaturalTemplate()); + assertEquals(2, item.getPriority()); + + item = (NLMappingItem) items[2]; + assertEquals("anumber 3", item.getNaturalTemplate()); + assertEquals(3, item.getPriority()); + + } + +} Property changes on: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/NLGrammarTest.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/TemplateContextTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/TemplateContextTest.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/TemplateContextTest.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -0,0 +1,192 @@ +package org.drools.lang.dsl.template; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.apache.commons.lang.StringUtils; + +import junit.framework.TestCase; + +public class TemplateContextTest extends TestCase { + + + public void testAllInOne() { + TemplateContext ctx = new TemplateContext(); + //chunks represent a lexed grammar "left hand side" + ctx.addChunk("baby on board") + .addChunk("{0}") + .addChunk("and") + .addChunk("{1}") + .addChunk("burt ward"); + String result = ctx.process("yeah this is an expression baby on board exp1 and exp2 burt ward end.", "something({0}, {1})"); + assertEquals("yeah this is an expression something(exp1, exp2) end.", result); + + + //and check that the iterative one is OK. + result = ctx.process("yeah this is an expression baby on board exp1 and exp2 burt ward end.", "something({0}, {1})"); + assertEquals("yeah this is an expression something(exp1, exp2) end.", result); + } + + public void testBuildStrings() { + + TemplateContext ctx = new TemplateContext(); + + //chunks represent a lexed grammar "left hand side" + ctx.addChunk("baby on board") + .addChunk("{0}") + .addChunk("and") + .addChunk("{1}") + .addChunk("burt ward"); + + //and this is the right hand side grammar mapping (no lexing required, simple hole filling !). + String grammar_r = "something({0}, {1})"; + + //and this is the full expression + String nl = "yeah this is an expression baby on board exp1 and exp2 burt ward end."; + + //match the pattern in nl, put the values in the map + HashMap map = new HashMap(); + ctx.processNL(nl, map); + + //now get the chunk of nl that will be replaced with the target later. + String subKey = ctx.getSubstitutionKey(); + assertEquals("baby on board exp1 and exp2 burt ward", subKey); + + String target = ctx.populateTargetString( map, grammar_r ); + assertEquals("something(exp1, exp2)", target); + + String result = ctx.interpolate(nl, subKey, target); + + assertEquals("yeah this is an expression something(exp1, exp2) end.", result); + + + + } + + + public void testMultipleReplacement() { + + TemplateContext ctx = new TemplateContext(); + + //chunks represent a lexed grammar "left hand side" + ctx.addChunk("{0}") + .addChunk("likes cheese"); + + String nl = "bob likes cheese and michael likes cheese conan likes cheese"; + String grammarTemplate = "{0}.likesCheese()"; + String expected = "bob.likesCheese() and michael.likesCheese() conan.likesCheese()"; + + + String result = ctx.processAllInstances(nl, grammarTemplate); + assertEquals(expected, result); + } + + + + + + public void testBasicExpression() { + + Chunk chunk1 = new Chunk("baby on board"); + Chunk chunk2 = new Chunk("{0}"); + Chunk chunk3 = new Chunk("and"); + Chunk chunk4 = new Chunk("{1}"); + Chunk chunk5 = new Chunk("burt ward"); + + chunk1.next = chunk2; + chunk2.next = chunk3; + chunk3.next = chunk4; + chunk4.next = chunk5; + + String nl = "yeah this is an expression baby on board exp1 and exp2 burt ward"; + chunk1.process(nl); + + HashMap map = new HashMap(); + chunk1.buildValueMap(map); + + assertEquals("exp1", map.get("{0}")); + assertEquals("exp2", map.get("{1}")); + + } + + public void testStartWith() { + + Chunk chunk1 = new Chunk("{0}"); + Chunk chunk2 = new Chunk("a thing"); + Chunk chunk3 = new Chunk("and"); + Chunk chunk4 = new Chunk("{1}"); + Chunk chunk5 = new Chunk("one more"); + + chunk1.next = chunk2; + chunk2.next = chunk3; + chunk3.next = chunk4; + chunk4.next = chunk5; + + String nl = "exp1 a thing and exp2 one more"; + chunk1.process(nl); + + HashMap map = new HashMap(); + chunk1.buildValueMap(map); + + assertEquals("exp1", map.get("{0}")); + assertEquals("exp2", map.get("{1}")); + + } + + + public void testEndWith() { + + Chunk chunk1 = new Chunk("blah blah blah"); + Chunk chunk2 = new Chunk("{1}"); + + chunk1.next = chunk2; + + String nl = "blah blah blah exp1"; + chunk1.process(nl); + + HashMap map = new HashMap(); + chunk1.buildValueMap(map); + + assertEquals("exp1", map.get("{1}")); + assertEquals(1, map.size()); + } + + public void testOneInTheMiddle() { + Chunk chunk1 = new Chunk("yeah "); + Chunk chunk2 = new Chunk("{abc}"); + Chunk chunk3 = new Chunk("one more"); + + chunk1.next = chunk2; + chunk2.next = chunk3; + + String nl = "yeah exp1 one more "; + chunk1.process(nl); + + HashMap map = new HashMap(); + chunk1.buildValueMap(map); + + assertEquals("exp1", map.get("{abc}")); + + } + + public void testNoTokens() { + Chunk chunk1 = new Chunk("yeah "); + + String nl = "yeah exp1 one more "; + chunk1.process(nl); + + HashMap map = new HashMap(); + chunk1.buildValueMap(map); + + assertEquals(0, map.size()); + } + + + + + + +} + + Property changes on: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/TemplateContextTest.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/TemplateFactoryTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/TemplateFactoryTest.java 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/TemplateFactoryTest.java 2006-01-24 13:52:33 UTC (rev 2191) @@ -0,0 +1,41 @@ +package org.drools.lang.dsl.template; + +import java.util.List; + +import junit.framework.TestCase; + +public class TemplateFactoryTest extends TestCase { + + public void testMake() { + TemplateFactory factory = new TemplateFactory(); + TemplateContext ctx = factory.getContext("something {0} going {1} on."); + assertNotNull(ctx); + } + + public void testLex() { + TemplateFactory factory = new TemplateFactory(); + List list = factory.lexChunks("one chunk"); + assertEquals(1, list.size()); + assertEquals("one chunk", list.get(0)); + + + list = factory.lexChunks("three {0} chunks"); + assertEquals(3, list.size()); + + assertEquals("three", list.get(0)); + assertEquals("{0}", list.get(1)); + assertEquals("chunks", list.get(2)); + + + list = factory.lexChunks("{42} more '{0}' chunks"); + assertEquals(4, list.size()); + + assertEquals("{42}", list.get(0)); + assertEquals("more '", list.get(1)); + assertEquals("{0}", list.get(2)); + assertEquals("' chunks", list.get(3)); + + + } + +} Property changes on: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/dsl/template/TemplateFactoryTest.java ___________________________________________________________________ Name: svn:eol-style + native Deleted: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/rule-with-expansion.drl =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/rule-with-expansion.drl 2006-01-24 12:46:23 UTC (rev 2190) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/rule-with-expansion.drl 2006-01-24 13:52:33 UTC (rev 2191) @@ -1,19 +0,0 @@ -# Example DRL with expansion -# (ie "domain specific language") -# use expanders for domain specific and natural language extensions -use expander cheese.dsl - - -rule find_seating - when - #Bob is in atlanta - #Bob likes cheese - #There exists a Guest with name of "Michael" and sex of "Male" - >Guest( name == seatingRightGuestName, rightGuestSex:sex, rightGuestHobby:hobby ) - >Guest( leftGuestName:name , sex != rightGuestSex, hobby == rightGuestHobby ) - >count => Count() - #bind count to Count - then - #Send notification to Mark with message "hello" - >System.out.println("and this is code") -end \ No newline at end of file |
From: <jbo...@li...> - 2006-01-24 12:46:44
|
Author: mic...@jb... Date: 2006-01-24 07:46:23 -0500 (Tue, 24 Jan 2006) New Revision: 2190 Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl Log: allow spaces in rule name Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java 2006-01-24 12:06:36 UTC (rev 2189) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java 2006-01-24 12:46:23 UTC (rev 2190) @@ -24,7 +24,7 @@ private static Pattern PACKAGE_DECL = Pattern.compile( "\\s*package\\s*([^;]+);?\\s*" ); private static Pattern IMPORT_STATEMENT = Pattern.compile( "\\s*import\\s*([^;]+);?\\s*" ); - private static Pattern RULE_DECL = Pattern.compile( "\\s*rule\\s*([^\\s]+)\\s*" ); + private static Pattern RULE_DECL = Pattern.compile( "\\s*rule\\s*(.*[^\\s]+)\\s*" ); private static Pattern EXPANDER_STATEMENT = Pattern.compile("\\s*use\\s*expander\\s([^;]+);?\\s*"); Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java 2006-01-24 12:06:36 UTC (rev 2189) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java 2006-01-24 12:46:23 UTC (rev 2190) @@ -47,7 +47,7 @@ assertEquals( "java.util.ArrayList", parser.getImports().get( 1 ) ); assertEquals( 1, parser.getRules().size() ); - assertEquals( "find_seating", ((Rule)parser.getRules().get(0)).getName() ); + assertEquals( "find seating", ((Rule)parser.getRules().get(0)).getName() ); assertEquals(null, parser.getExpander()); } Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl 2006-01-24 12:06:36 UTC (rev 2189) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl 2006-01-24 12:46:23 UTC (rev 2190) @@ -14,7 +14,7 @@ # use expander foo; -rule find_seating +rule find seating when context => Context( state == Context.ASSIGN_SEATS ) Seating( seatingId:id, seatingPid:pid, pathDone == true, seatingRightSeat:rightSeat, seatingRightGuestName:rightGuestName ) |
From: <jbo...@li...> - 2006-01-24 12:06:58
|
Author: mic...@jb... Date: 2006-01-24 07:06:36 -0500 (Tue, 24 Jan 2006) New Revision: 2189 Added: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/rule-with-expansion.drl Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Expander.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/ExpanderContext.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java Log: first cut of expanders. Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Expander.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Expander.java 2006-01-24 11:09:13 UTC (rev 2188) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Expander.java 2006-01-24 12:06:36 UTC (rev 2189) @@ -1,8 +1,17 @@ package org.drools.lang; /** - * Expanders provide just in time expansion for expressions in DRL. + * Expanders are extension points for expanding + * expressions in DRL at parse time. + * This is just-in-time translation, or macro expansion, or + * whatever you want. * + * The important thing is that it happens at the last possible moment, + * so any errors in expansion are included in the parsers errors. + * + * Just-in-time expansions may include complex pre-compilers, + * or just macros, and everything in between. + * * Expanders should ideally not make presumptions on any embedded semantic * language. For instance, java aware pre processing should be done in * drools-java semantic module, not in the parser itself. Expanders should @@ -13,4 +22,24 @@ */ public interface Expander { + /** + * The parser should call this on an expression/line that potentially needs expanding + * BEFORE it parses that line (as the line may change radically as the result of expansion). + * + * Expands the expression Just-In-Time for the parser. + * If the expression is not meant to be expanded, or if no + * appropriate expander is found, it will echo back the same + * expression. + * + * @param expression The "line" or expression to be expanded/pre-compiled. + * @param context The context of the current state of parsing. This can help + * the expander know if it needs to expand, what to do etc. + * + * If <code>isEnabled()</code> is false then it is not required to + * call this method. + */ + public String expand(String pattern, Parser context); + + + } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/ExpanderContext.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/ExpanderContext.java 2006-01-24 11:09:13 UTC (rev 2188) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/ExpanderContext.java 2006-01-24 12:06:36 UTC (rev 2189) @@ -1,77 +1,79 @@ package org.drools.lang; +import java.io.InputStream; import java.io.Serializable; -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import org.drools.lang.dsl.DefaultExpander; + /** - * Expanders are extension points for expanding - * expressions in DRL at parse time. - * This is just-in-time translation, or macro expansion, or - * whatever you want. + * Create instances of appropriate expanders based on name, and prior configuration of expanders. * - * The important thing is that it happens at the last possible moment, - * so any errors in expansion are included in the parsers errors. + * Expanders can be added to this programmatically, or they can be loaded from the classpath. * - * Just-in-time expansions may include complex pre-compilers, - * or just macros, and everything in between. - * * @author <a href="mailto:mic...@gm..."> Michael Neale</a> - * */ public class ExpanderContext implements Serializable { private static final long serialVersionUID = 1806461802987228880L; - private boolean enabled = true; + private Map expanders; + + private static final ExpanderContext INSTANCE = new ExpanderContext(); + + public static ExpanderContext getInstance() { + return INSTANCE; + } + + private ExpanderContext() { + expanders = new HashMap(); + } + + /** + * This registers an expander against a name for DRL files to use when compiling. + * The name appears as "use expander name" in DRL source. + * + * This can be called again to "refresh" an expander. + */ + public void registerExpander(Expander expander, String name) { + if (expanders.containsKey(name)) { + expanders.remove(name); + } + expanders.put(name, expander); + } + + /** + * This will load up the appropriate expander. + * The default expander is configured via a properties file. + */ + public Expander getExpander(String expanderName) { + + if (expanders.containsKey(expanderName)) return (Expander) expanders.get(expanderName); + + try { + InputStream stream = this.getClass().getResourceAsStream(expanderName); + if (stream == null) { + URL url = new URL(expanderName); + stream = url.openStream(); + } + + Properties props = new Properties(); + props.load(stream); + stream.close(); + + DefaultExpander expander = new DefaultExpander(props); + registerExpander(expander, expanderName); + return expander; + + } catch (Exception e) { + throw new IllegalArgumentException("Unable to load expander with name: " + expanderName); + } + } - private final Set expanders; - /** - * This indicates that at least one expander has been configured for - * this parser configuration. - */ - public boolean isEnabled() { - return enabled; - } - public void disable() { - this.enabled = false; - } - public ExpanderContext(Collection initialExpanders) { - this.expanders = new HashSet(initialExpanders); - } - public ExpanderContext() { - this.expanders = new HashSet(); - } - - public ExpanderContext addExpander(Expander exp) { - expanders.add(exp); - return this; - } - - /** - * The parser should call this on an expression/line that potentially needs expanding - * BEFORE it parses that line (as the line may change radically as the result of expansion). - * - * Expands the expression Just-In-Time for the parser. - * If the expression is not meant to be expanded, or if no - * appropriate expander is found, it will echo back the same - * expression. - * - * @param expression The "line" or expression to be expanded/pre-compiled. - * @param context The context of the current state of parsing. This can help - * the expander know if it needs to expand, what to do etc. - * - * If <code>isEnabled()</code> is false then it is not required to - * call this method. - */ - public CharSequence expand(CharSequence expression, Parser context) { - return expression; - } - - - } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java 2006-01-24 11:09:13 UTC (rev 2188) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java 2006-01-24 12:06:36 UTC (rev 2189) @@ -39,7 +39,7 @@ private String packageDeclaration; private List imports; - private String expanderName; + private Expander expander; private List rules; @@ -50,7 +50,7 @@ this.reader = new BufferedReader( reader ); this.imports = new ArrayList(); this.rules = new ArrayList(); - this.expanderName = null; + this.expander = null; this.lineNumber = 0; } @@ -66,8 +66,8 @@ return rules; } - String getExpanderName() { - return expanderName; + Expander getExpander() { + return expander; } public void parse() throws IOException, RuleConstructionException { @@ -126,7 +126,8 @@ if ( matcher.matches() ) { consumeDiscard(); - expanderName = matcher.group( 1 ); + String expanderName = matcher.group( 1 ); + expander = ExpanderContext.getInstance().getExpander(expanderName); return true; } @@ -244,12 +245,11 @@ } protected String expand(String pattern) { - //MN hook in here. Will only be called if it is honest to God expanding. - return pattern; + return expander.expand(pattern, this); } protected boolean expanding() { - return this.expanderName != null; + return this.expander != null; } protected void pattern(String pattern) { Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java 2006-01-24 11:09:13 UTC (rev 2188) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java 2006-01-24 12:06:36 UTC (rev 2189) @@ -49,8 +49,13 @@ assertEquals( 1, parser.getRules().size() ); assertEquals( "find_seating", ((Rule)parser.getRules().get(0)).getName() ); - assertEquals(null, parser.getExpanderName()); + assertEquals(null, parser.getExpander()); } + + public void test_with_expander() throws Exception { + Parser parser = parser( "rule-with-expansion.drl" ); + parser.parse(); + } protected Parser parser(String name) { InputStream in = getClass().getResourceAsStream( name ); Added: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/rule-with-expansion.drl =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/rule-with-expansion.drl 2006-01-24 11:09:13 UTC (rev 2188) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/rule-with-expansion.drl 2006-01-24 12:06:36 UTC (rev 2189) @@ -0,0 +1,19 @@ +# Example DRL with expansion +# (ie "domain specific language") +# use expanders for domain specific and natural language extensions +use expander cheese.dsl + + +rule find_seating + when + #Bob is in atlanta + #Bob likes cheese + #There exists a Guest with name of "Michael" and sex of "Male" + >Guest( name == seatingRightGuestName, rightGuestSex:sex, rightGuestHobby:hobby ) + >Guest( leftGuestName:name , sex != rightGuestSex, hobby == rightGuestHobby ) + >count => Count() + #bind count to Count + then + #Send notification to Mark with message "hello" + >System.out.println("and this is code") +end \ No newline at end of file Property changes on: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/rule-with-expansion.drl ___________________________________________________________________ Name: svn:eol-style + native |
Author: mic...@jb... Date: 2006-01-24 06:09:13 -0500 (Tue, 24 Jan 2006) New Revision: 2188 Modified: trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/Chunk.java trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/NLExpressionCompiler.java trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/NLMappingItem.java trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/TemplateContext.java trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/TemplateFactory.java trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/NaturalLanguageCompilerTest.java trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/template/NLExpressionCompilerTest.java trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/template/TemplateFactoryTest.java Log: small improvements in efficiency Modified: trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/Chunk.java =================================================================== --- trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/Chunk.java 2006-01-24 09:01:07 UTC (rev 2187) +++ trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/Chunk.java 2006-01-24 11:09:13 UTC (rev 2188) @@ -13,7 +13,7 @@ * * Chunks also know how to parse themselves to work out the value. * - * This is used by TemplatePopulateContext. + * This is used by TemplateContext. * This class is very recursive, to be prepated to be confused. * * @author <a href="mailto:mic...@gm..."> Michael Neale</a> @@ -21,7 +21,8 @@ class Chunk { //the chunk of text from the dicitonary - String text; + final String text; + final boolean isHole; Chunk next; @@ -35,6 +36,11 @@ Chunk(String text) { this.text = text; + if (text.startsWith("{")) { + isHole = true; + } else { + isHole = false; + } } /** @@ -42,7 +48,7 @@ * Can then swap it with the target text. */ void buildSubtitutionKey(StringBuffer buffer) { - if (isHole()) { + if (isHole) { buffer.append(padL + value + padR); } else { buffer.append(text); @@ -52,12 +58,8 @@ } } - boolean isHole() { - return text.startsWith("{"); - } - void process(String expression) { - if (isHole()) { + if (isHole) { //value = text until next next.text is found if (next == null || next.text == null) { storeSpacePadding( expression ); @@ -82,7 +84,7 @@ } void buildValueMap(Map map) { - if (this.isHole()) { + if (isHole) { map.put(text, value); } if (next != null) { Modified: trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/NLExpressionCompiler.java =================================================================== --- trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/NLExpressionCompiler.java 2006-01-24 09:01:07 UTC (rev 2187) +++ trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/NLExpressionCompiler.java 2006-01-24 11:09:13 UTC (rev 2188) @@ -1,7 +1,9 @@ package org.drools.natural.template; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map; /** * This is the utility class for compiling pseudo natural/DSL expression into the target @@ -23,19 +25,33 @@ */ public class NLExpressionCompiler { - private TemplateFactory factory; - private Collection grammar; + //a map of templates to the template contexts (template contexts are used to populate populate + //the target mappings with data from a real expression. + private Map templateCache; + public NLExpressionCompiler(NLGrammar grammar) { - this.grammar = grammar.getMappings(); - this.factory = new TemplateFactory(); + Collection grammarItems = grammar.getMappings(); + this.templateCache = new HashMap(); + + //build up a map of templates + TemplateFactory factory = new TemplateFactory(); + for ( Iterator iter = grammarItems.iterator(); iter.hasNext(); ) { + NLMappingItem mapping = (NLMappingItem) iter.next(); + TemplateContext ctx = factory.getContext(mapping.getNaturalTemplate()); + templateCache.put(mapping, ctx); + } } + /** + * + */ public String compile(String expression) { String nl = expression; - for ( Iterator iter = grammar.iterator(); iter.hasNext(); ) { - NLMappingItem mapping = (NLMappingItem) iter.next(); - TemplateContext ctx = factory.buildContext(mapping.getNaturalTemplate()); + for ( Iterator iter = templateCache.entrySet().iterator(); iter.hasNext(); ) { + Map.Entry entry = (Map.Entry) iter.next(); + NLMappingItem mapping = (NLMappingItem) entry.getKey(); + TemplateContext ctx = (TemplateContext) entry.getValue(); nl = ctx.processAllInstances(nl, mapping.getGrammarTemplate()); } return nl; Modified: trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/NLMappingItem.java =================================================================== --- trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/NLMappingItem.java 2006-01-24 09:01:07 UTC (rev 2187) +++ trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/NLMappingItem.java 2006-01-24 11:09:13 UTC (rev 2188) @@ -52,5 +52,7 @@ int getPriority() { return this.priority; } + + } Modified: trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/TemplateContext.java =================================================================== --- trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/TemplateContext.java 2006-01-24 09:01:07 UTC (rev 2187) +++ trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/TemplateContext.java 2006-01-24 11:09:13 UTC (rev 2188) @@ -23,7 +23,7 @@ /** * Ad a chunk from the dictionary expression. * A chunk is a piece of nl, or a hole. - * nl & holes should not be mixed. + * nl & holes must not be mixed. */ TemplateContext addChunk(String chunkText) { Chunk chunk = new Chunk(chunkText); Modified: trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/TemplateFactory.java =================================================================== --- trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/TemplateFactory.java 2006-01-24 09:01:07 UTC (rev 2187) +++ trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/TemplateFactory.java 2006-01-24 11:09:13 UTC (rev 2188) @@ -19,7 +19,7 @@ * @param template From the grammar. eg "{0} likes cheese" is a template. * @return A template context ready to apply to a nl expression. */ - public TemplateContext buildContext(String template) { + public TemplateContext getContext(String template) { TemplateContext ctx = new TemplateContext(); Modified: trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/NaturalLanguageCompilerTest.java =================================================================== --- trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/NaturalLanguageCompilerTest.java 2006-01-24 09:01:07 UTC (rev 2187) +++ trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/NaturalLanguageCompilerTest.java 2006-01-24 11:09:13 UTC (rev 2188) @@ -83,7 +83,6 @@ String snippet = "that bob likes cheese"; assertEquals("bob.likesCheese()", parser.compileNaturalExpression(snippet)); } - } Modified: trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/template/NLExpressionCompilerTest.java =================================================================== --- trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/template/NLExpressionCompilerTest.java 2006-01-24 09:01:07 UTC (rev 2187) +++ trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/template/NLExpressionCompilerTest.java 2006-01-24 11:09:13 UTC (rev 2188) @@ -36,7 +36,6 @@ } - /** This is surprisingly fast. I didn't build it for speed. */ public void testLargeGrammar() { Properties props = new Properties(); Modified: trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/template/TemplateFactoryTest.java =================================================================== --- trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/template/TemplateFactoryTest.java 2006-01-24 09:01:07 UTC (rev 2187) +++ trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/template/TemplateFactoryTest.java 2006-01-24 11:09:13 UTC (rev 2188) @@ -8,7 +8,7 @@ public void testMake() { TemplateFactory factory = new TemplateFactory(); - TemplateContext ctx = factory.buildContext("something {0} going {1} on."); + TemplateContext ctx = factory.getContext("something {0} going {1} on."); assertNotNull(ctx); } |
From: <jbo...@li...> - 2006-01-24 09:01:10
|
Author: rem...@jb... Date: 2006-01-24 04:01:07 -0500 (Tue, 24 Jan 2006) New Revision: 2187 Modified: trunk/labs/jbossweb/src/share/classes/org/apache/catalina/connector/InputBuffer.java Log: - Fix bug causing input problems triggered by usage of readLine (through mark/reset functionality). Modified: trunk/labs/jbossweb/src/share/classes/org/apache/catalina/connector/InputBuffer.java =================================================================== --- trunk/labs/jbossweb/src/share/classes/org/apache/catalina/connector/InputBuffer.java 2006-01-24 08:55:45 UTC (rev 2186) +++ trunk/labs/jbossweb/src/share/classes/org/apache/catalina/connector/InputBuffer.java 2006-01-24 09:01:07 UTC (rev 2187) @@ -216,6 +216,7 @@ if (cb.getChars().length > size) { cb = new CharChunk(size); cb.setLimit(size); + cb.setOptimizedWrite(false); cb.setCharInputChannel(this); cb.setCharOutputChannel(this); } else { @@ -337,6 +338,10 @@ cb.setEnd(0); } + int limit = bb.getLength()+cb.getStart(); + if (cb.getLimit() < limit) { + cb.setLimit(limit); + } conv.convert(bb, cb); bb.setOffset(bb.getEnd()); state = CHAR_STATE; |
From: <jbo...@li...> - 2006-01-24 08:55:50
|
Author: rem...@jb... Date: 2006-01-24 03:55:45 -0500 (Tue, 24 Jan 2006) New Revision: 2186 Modified: trunk/labs/jbossweb/src/share/classes/org/apache/catalina/connector/Response.java Log: - Remove useless charset. Modified: trunk/labs/jbossweb/src/share/classes/org/apache/catalina/connector/Response.java =================================================================== --- trunk/labs/jbossweb/src/share/classes/org/apache/catalina/connector/Response.java 2006-01-24 08:31:09 UTC (rev 2185) +++ trunk/labs/jbossweb/src/share/classes/org/apache/catalina/connector/Response.java 2006-01-24 08:55:45 UTC (rev 2186) @@ -606,20 +606,6 @@ throw new IllegalStateException (sm.getString("coyoteResponse.getWriter.ise")); - /* - * If the response's character encoding has not been specified as - * described in <code>getCharacterEncoding</code> (i.e., the method - * just returns the default value <code>ISO-8859-1</code>), - * <code>getWriter</code> updates it to <code>ISO-8859-1</code> - * (with the effect that a subsequent call to getContentType() will - * include a charset=ISO-8859-1 component which will also be - * reflected in the Content-Type response header, thereby satisfying - * the Servlet spec requirement that containers must communicate the - * character encoding used for the servlet response's writer to the - * client). - */ - setCharacterEncoding(getCharacterEncoding()); - usingWriter = true; outputBuffer.checkConverter(); if (writer == null) { |
From: <jbo...@li...> - 2006-01-24 08:31:18
|
Author: mic...@jb... Date: 2006-01-24 03:31:09 -0500 (Tue, 24 Jan 2006) New Revision: 2185 Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl Log: silly idea. Undid it mostly. Don't want people to do inline comments anyway. Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java 2006-01-24 08:19:56 UTC (rev 2184) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java 2006-01-24 08:31:09 UTC (rev 2185) @@ -335,7 +335,7 @@ return null; } - String trimLine = line.trim(); + String trimLine = line.trim(); if ( trimLine.length() == 0 || trimLine.startsWith( COMMENT_1 ) || trimLine.startsWith( COMMENT_2 ) ) { line = null; @@ -343,7 +343,7 @@ } reader.reset(); - return stripTrailingComments(line); + return line; } protected String consume() throws IOException { @@ -370,19 +370,7 @@ } } - return stripTrailingComments(line); + return line; } - - /** - * Removes "inline" comments from string. - */ - protected String stripTrailingComments(final String line) { - //BOB: is this more efficient with a single regex? - //Then can have a single definition of a comment? - int pos = line.lastIndexOf(COMMENT_1); - if (pos > 0) return line.substring(0, pos); - pos = line.lastIndexOf(COMMENT_2); - if (pos > 0) return line.substring(0, pos); - return line; - } + } Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl 2006-01-24 08:19:56 UTC (rev 2184) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl 2006-01-24 08:31:09 UTC (rev 2185) @@ -3,11 +3,11 @@ // yes, you can use silly java comments -package org.drools.lang; +package org.drools.lang; # semi colons are optional, we're line-centric -import java.util.List//trailing comment +import java.util.List import java.util.ArrayList; # use expanders for domain specific and pseudo natural language extensions @@ -15,7 +15,7 @@ rule find_seating - when #trailing comment + when context => Context( state == Context.ASSIGN_SEATS ) Seating( seatingId:id, seatingPid:pid, pathDone == true, seatingRightSeat:rightSeat, seatingRightGuestName:rightGuestName ) |
From: <jbo...@li...> - 2006-01-24 08:20:08
|
Author: mic...@jb... Date: 2006-01-24 03:19:56 -0500 (Tue, 24 Jan 2006) New Revision: 2184 Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl Log: trailing comments allowed Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java 2006-01-24 07:02:40 UTC (rev 2183) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java 2006-01-24 08:19:56 UTC (rev 2184) @@ -22,7 +22,7 @@ */ public class Parser { - private static Pattern PACKAGE_DECL = Pattern.compile( "\\s*package\\s*([^;]+);?\\s*" ); + private static Pattern PACKAGE_DECL = Pattern.compile( "\\s*package\\s*([^;]+);?\\s*" ); private static Pattern IMPORT_STATEMENT = Pattern.compile( "\\s*import\\s*([^;]+);?\\s*" ); private static Pattern RULE_DECL = Pattern.compile( "\\s*rule\\s*([^\\s]+)\\s*" ); @@ -30,7 +30,11 @@ private static Pattern FACT_BINDING = Pattern.compile( "\\s*(\\w+)\\s*=>\\s*(.*)" ); private static Pattern FIELD_BINDING = Pattern.compile( "\\s*(\\w+):(\\w+)\\s*" ); - + + private static String COMMENT_2 = "//"; + private static String COMMENT_1 = "#"; + + private BufferedReader reader; private String packageDeclaration; @@ -165,7 +169,7 @@ line = laDiscard(); if ( ! line.trim().equals( "end" ) ) { - throw new ParseException( "end expected.", lineNumber); + throw new ParseException( "[end] expected. But instead got: [" + line.trim() + "]", lineNumber); } consumeDiscard(); @@ -263,7 +267,7 @@ String guts = pattern.substring( leftParen+1, rightParen ).trim(); - // TODO: Michael, should be also expand the guts? + // TODO: Michael, should be also expand the guts? Nope. Don't really think so. StringTokenizer tokens = new StringTokenizer( guts, "," ); @@ -281,7 +285,7 @@ String field = matcher.group( 2 ); System.err.println( "bind [" + bindTo + "] to field [" + field + "]" ); } else { - // TODO: Michael, want to jack in here also? + // TODO: Michael, want to jack in here also? Nope, not really... System.err.println( "further work required for [" + constraint + "]" ); } } @@ -333,13 +337,13 @@ String trimLine = line.trim(); - if ( trimLine.length() == 0 || trimLine.startsWith( "#" ) || trimLine.startsWith( "//" ) ) { + if ( trimLine.length() == 0 || trimLine.startsWith( COMMENT_1 ) || trimLine.startsWith( COMMENT_2 ) ) { line = null; } } reader.reset(); - return line; + return stripTrailingComments(line); } protected String consume() throws IOException { @@ -361,11 +365,24 @@ String trimLine = line.trim(); - if ( trimLine.length() == 0 || trimLine.startsWith( "#" ) || trimLine.startsWith( "//" ) ) { + if ( trimLine.length() == 0 || trimLine.startsWith( COMMENT_1 ) || trimLine.startsWith( COMMENT_2 ) ) { line = null; } } - return line; + return stripTrailingComments(line); } + + /** + * Removes "inline" comments from string. + */ + protected String stripTrailingComments(final String line) { + //BOB: is this more efficient with a single regex? + //Then can have a single definition of a comment? + int pos = line.lastIndexOf(COMMENT_1); + if (pos > 0) return line.substring(0, pos); + pos = line.lastIndexOf(COMMENT_2); + if (pos > 0) return line.substring(0, pos); + return line; + } } Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl 2006-01-24 07:02:40 UTC (rev 2183) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl 2006-01-24 08:19:56 UTC (rev 2184) @@ -7,7 +7,7 @@ # semi colons are optional, we're line-centric -import java.util.List +import java.util.List//trailing comment import java.util.ArrayList; # use expanders for domain specific and pseudo natural language extensions @@ -15,7 +15,7 @@ rule find_seating - when + when #trailing comment context => Context( state == Context.ASSIGN_SEATS ) Seating( seatingId:id, seatingPid:pid, pathDone == true, seatingRightSeat:rightSeat, seatingRightGuestName:rightGuestName ) |
From: <jbo...@li...> - 2006-01-24 07:02:50
|
Author: mic...@jb... Date: 2006-01-24 02:02:40 -0500 (Tue, 24 Jan 2006) New Revision: 2183 Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/ParseException.java trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl Log: line numbers in parse errors, tweaks for expanders Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/ParseException.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/ParseException.java 2006-01-24 04:36:35 UTC (rev 2182) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/ParseException.java 2006-01-24 07:02:40 UTC (rev 2183) @@ -4,8 +4,33 @@ public class ParseException extends DroolsRuntimeException { - public ParseException(String message) { - super( message ); - } + private static final long serialVersionUID = -7500818890340701977L; + + private int lineNumber; + + /** + * Thrown if there is an exception related to parsing a line in a drl file. + * For more generic exception, a different exception class will be used. + */ + public ParseException(String message, int lineNumber) { + super(message); + this.lineNumber = lineNumber; + } + + /** + * The line number on which the error occurred. + */ + public int getLineNumber() { + return this.lineNumber; + } + + public String getMessage() { + return super.getMessage() + " Line number: " + lineNumber; + } + + public String toString() { + return getMessage(); + } + } Modified: trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java 2006-01-24 04:36:35 UTC (rev 2182) +++ trunk/labs/jbossrules/drools-core/src/main/java/org/drools/lang/Parser.java 2006-01-24 07:02:40 UTC (rev 2183) @@ -14,11 +14,19 @@ import org.drools.rule.Rule; import org.drools.rule.RuleConstructionException; +/** + * The one, the only DRL parser. + * + * @master Bob McWirther + * @apprentice Michael Neale + */ public class Parser { private static Pattern PACKAGE_DECL = Pattern.compile( "\\s*package\\s*([^;]+);?\\s*" ); private static Pattern IMPORT_STATEMENT = Pattern.compile( "\\s*import\\s*([^;]+);?\\s*" ); private static Pattern RULE_DECL = Pattern.compile( "\\s*rule\\s*([^\\s]+)\\s*" ); + + private static Pattern EXPANDER_STATEMENT = Pattern.compile("\\s*use\\s*expander\\s([^;]+);?\\s*"); private static Pattern FACT_BINDING = Pattern.compile( "\\s*(\\w+)\\s*=>\\s*(.*)" ); private static Pattern FIELD_BINDING = Pattern.compile( "\\s*(\\w+):(\\w+)\\s*" ); @@ -27,12 +35,19 @@ private String packageDeclaration; private List imports; + private String expanderName; private List rules; + + + private int lineNumber; + public Parser(Reader reader) { this.reader = new BufferedReader( reader ); this.imports = new ArrayList(); this.rules = new ArrayList(); + this.expanderName = null; + this.lineNumber = 0; } public String getPackageDeclaration() { @@ -46,6 +61,10 @@ public List getRules() { return rules; } + + String getExpanderName() { + return expanderName; + } public void parse() throws IOException, RuleConstructionException { prolog(); @@ -55,6 +74,7 @@ protected void prolog() throws IOException { packageDeclaration(); importStatements(); + expanderStatement(); functions(); } @@ -76,7 +96,7 @@ // just do it again } } - + protected boolean importStatement() throws IOException { String line = laDiscard(); @@ -92,6 +112,22 @@ return false; } + + protected boolean expanderStatement() throws IOException { + String line = laDiscard(); + + if ( line == null ) { return false; } + + Matcher matcher = EXPANDER_STATEMENT.matcher( line ); + + if ( matcher.matches() ) { + consumeDiscard(); + expanderName = matcher.group( 1 ); + return true; + } + + return false; + } protected void functions() { @@ -129,7 +165,7 @@ line = laDiscard(); if ( ! line.trim().equals( "end" ) ) { - throw new ParseException( "end expected" ); + throw new ParseException( "end expected.", lineNumber); } consumeDiscard(); @@ -181,31 +217,48 @@ pattern = line; } - if ( pattern.startsWith( ":" ) ) { - pattern = expand( pattern ); - } + + pattern = maybeExpand( pattern ); pattern( pattern ); return true; } + + /** + * Only want to expand if we are using an expander, and if the pattern isn't escaped. + */ + protected String maybeExpand(final String pattern) { + if ( expanding() ) { + if (pattern.startsWith( ">" )) { + return pattern.substring(1); + } else { + return expand( pattern ); + } + } + return pattern; + } protected String expand(String pattern) { - // TODO: Michael, here goes the expansion bits - return pattern; + //MN hook in here. Will only be called if it is honest to God expanding. + return pattern; } + + protected boolean expanding() { + return this.expanderName != null; + } protected void pattern(String pattern) { int leftParen = pattern.indexOf( "(" ); if ( leftParen < 0 ) { - throw new ParseException( "invalid pattern: " + pattern ); + throw new ParseException( "invalid pattern: " + pattern, lineNumber ); } int rightParen = pattern.lastIndexOf( ")" ); if ( rightParen < 0 ) { - throw new ParseException( "invalid pattern: " + pattern ); + throw new ParseException( "invalid pattern: " + pattern, lineNumber ); } String guts = pattern.substring( leftParen+1, rightParen ).trim(); @@ -244,12 +297,13 @@ while ( true ) { line = laDiscard(); if ( line == null ) { - throw new ParseException( "end expected" ); + throw new ParseException( "end expected", lineNumber ); } if ( line.trim().equals( "end" ) ) { break; } consumeDiscard(); + line = maybeExpand( line ); consequence.append( line + "\n" ); } System.err.println( "begin consequence"); @@ -289,6 +343,7 @@ } protected String consume() throws IOException { + lineNumber++; return reader.readLine(); } @@ -302,7 +357,8 @@ reader.reset(); return null; } - + lineNumber++; + String trimLine = line.trim(); if ( trimLine.length() == 0 || trimLine.startsWith( "#" ) || trimLine.startsWith( "//" ) ) { Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java 2006-01-24 04:36:35 UTC (rev 2182) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/ParserTest.java 2006-01-24 07:02:40 UTC (rev 2183) @@ -48,6 +48,8 @@ assertEquals( 1, parser.getRules().size() ); assertEquals( "find_seating", ((Rule)parser.getRules().get(0)).getName() ); + + assertEquals(null, parser.getExpanderName()); } protected Parser parser(String name) { Modified: trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl =================================================================== --- trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl 2006-01-24 04:36:35 UTC (rev 2182) +++ trunk/labs/jbossrules/drools-core/src/test/java/org/drools/lang/one-rule.drl 2006-01-24 07:02:40 UTC (rev 2183) @@ -10,13 +10,15 @@ import java.util.List import java.util.ArrayList; +# use expanders for domain specific and pseudo natural language extensions +# use expander foo; + + rule find_seating when - context => Context( state == Context.ASSIGN_SEATS ) + context => Context( state == Context.ASSIGN_SEATS ) Seating( seatingId:id, seatingPid:pid, pathDone == true, seatingRightSeat:rightSeat, seatingRightGuestName:rightGuestName ) - #:bob is in atlanta - Guest( name == seatingRightGuestName, rightGuestSex:sex, rightGuestHobby:hobby ) Guest( leftGuestName:name , sex != rightGuestSex, hobby == rightGuestHobby ) count => Count() |
From: <jbo...@li...> - 2006-01-24 04:36:44
|
Author: mic...@jb... Date: 2006-01-23 23:36:35 -0500 (Mon, 23 Jan 2006) New Revision: 2182 Modified: trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/NLGrammar.java Log: Modified: trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/NLGrammar.java =================================================================== --- trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/NLGrammar.java 2006-01-24 03:22:52 UTC (rev 2181) +++ trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/NLGrammar.java 2006-01-24 04:36:35 UTC (rev 2182) @@ -22,7 +22,7 @@ /** - * When loading from properties, the order in which they apprear in the props file + * When loading from properties, the order in which they appear in the props file * is the priority. (TODO: order means nothing to properties it seems). * * Which makes sense intuitively, the order you read them it the order in which they will be applied. |
From: <jbo...@li...> - 2006-01-24 03:23:02
|
Author: mic...@jb... Date: 2006-01-23 22:22:52 -0500 (Mon, 23 Jan 2006) New Revision: 2181 Modified: trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/Chunk.java trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/template/NLExpressionCompilerTest.java Log: better space handling Modified: trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/Chunk.java =================================================================== --- trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/Chunk.java 2006-01-24 03:12:21 UTC (rev 2180) +++ trunk/labs/jbossrules/drools-natural-dsl/src/main/java/org/drools/natural/template/Chunk.java 2006-01-24 03:22:52 UTC (rev 2181) @@ -20,26 +20,30 @@ */ class Chunk { + //the chunk of text from the dicitonary String text; + Chunk next; - //value if it is a hole, starts out as null. + //for building the substitution string, remember how the {0} was spaced with the rest of the string + //for example: date of '{0}' ---- this needs to be handled as well as: date of ' {0} ' + String padL = ""; + String padR = ""; + + //value parsed out if it is a hole, starts out as null. String value; - Chunk(String text) { this.text = text; } - - /** * This will build up a key to use to substitute the original string with. * Can then swap it with the target text. */ void buildSubtitutionKey(StringBuffer buffer) { if (isHole()) { - buffer.append(" " + value + " "); + buffer.append(padL + value + padR); } else { buffer.append(text); } @@ -56,9 +60,12 @@ if (isHole()) { //value = text until next next.text is found if (next == null || next.text == null) { + storeSpacePadding( expression ); value = expression.trim(); } else { - value = StringUtils.substringBefore(expression, next.text).trim(); + String val = StringUtils.substringBefore(expression, next.text); + storeSpacePadding( val ); + value = val.trim(); } } else { @@ -68,6 +75,11 @@ next.process(StringUtils.substringAfter(expression, value)); } } + + private void storeSpacePadding(String val) { + if (val.startsWith(" ")) padL = " "; + if (val.endsWith(" ")) padR = " "; + } void buildValueMap(Map map) { if (this.isHole()) { Modified: trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/template/NLExpressionCompilerTest.java =================================================================== --- trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/template/NLExpressionCompilerTest.java 2006-01-24 03:12:21 UTC (rev 2180) +++ trunk/labs/jbossrules/drools-natural-dsl/src/test/java/org/drools/natural/template/NLExpressionCompilerTest.java 2006-01-24 03:22:52 UTC (rev 2181) @@ -82,14 +82,13 @@ grammar = new NLGrammar(); - grammar.addNLItem(new NLMappingItem(1, "date of ' {0} '", "dateOf({0})")); + grammar.addNLItem(new NLMappingItem(1, "date of '{0}'", "dateOf({0})")); grammar.addNLItem(new NLMappingItem(2, "age of [ {0} ]", "{0}.getAge()")); grammar.addNLItem(new NLMappingItem(3, "Today", "new java.util.Date()")); grammar.addNLItem(new NLMappingItem(4, "{0} is before {1}", "({0}).compareTo({1}) > 0")); + nl = "date of '10-jul-2006' is before Today"; - nl = "date of ' 10-jul-2006 ' is before Today"; - compiler = new NLExpressionCompiler(grammar); expected = "(dateOf(10-jul-2006)).compareTo(new java.util.Date()) > 0"; assertEquals(expected, compiler.compile(nl)); |