From: erik Date: Tue, 14 Mar 2006 20:39:25 +0000 (+0000) Subject: (no commit message) X-Git-Tag: BEFORE_MAVEN_MIGRATION~236 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=843fadabbebb32b83f4db1d27a1c60e3354b8c19;p=utils --- diff --git a/build.xml b/build.xml index d4aef7ef..149a1150 100644 --- a/build.xml +++ b/build.xml @@ -11,7 +11,7 @@ &header; - + &delegator; diff --git a/build/header.xml b/build/header.xml index 260d482b..ff7ce1be 100644 --- a/build/header.xml +++ b/build/header.xml @@ -9,6 +9,9 @@ + + + @@ -126,6 +129,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -222,9 +271,7 @@ - - - + diff --git a/build/trailer.xml b/build/trailer.xml index 106b4d6e..95ba839c 100644 --- a/build/trailer.xml +++ b/build/trailer.xml @@ -199,7 +199,7 @@ - + @@ -214,7 +214,7 @@ - + diff --git a/support/src/org/wamblee/conditions/Condition.java b/support/src/org/wamblee/conditions/Condition.java new file mode 100644 index 00000000..98da09ee --- /dev/null +++ b/support/src/org/wamblee/conditions/Condition.java @@ -0,0 +1,31 @@ +/* + * Copyright 2005 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wamblee.conditions; + + +/** + * Determines if an object matches. + */ +public interface Condition { + + /** + * Determines if a program matches. + * @param aProgram Program to match. + * @return True iff the program matches. + */ + boolean matches(T aObject); +} diff --git a/support/src/org/wamblee/conditions/OrCondition.java b/support/src/org/wamblee/conditions/OrCondition.java new file mode 100644 index 00000000..14bd24ad --- /dev/null +++ b/support/src/org/wamblee/conditions/OrCondition.java @@ -0,0 +1,52 @@ +/* + * Copyright 2005 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.wamblee.conditions; + +import java.util.ArrayList; +import java.util.List; + + +/** + * + */ +public class OrCondition implements Condition { + + private List> _conditions; + + public OrCondition(Condition aCondition1, Condition aCondition2) { + _conditions = new ArrayList>(); + _conditions.add(aCondition1); + _conditions.add(aCondition2); + } + + public OrCondition(List> aConditions) { + _conditions = aConditions; + } + + /* (non-Javadoc) + * @see org.wamblee.crawler.kiss.ProgramMatcher#matches(org.wamblee.crawler.kiss.Program) + */ + public boolean matches(T aObject) { + for (Condition condition: _conditions) { + if ( condition.matches(aObject)) { + return true; + } + } + return false; + } + +} diff --git a/support/src/org/wamblee/Pair.java b/support/src/org/wamblee/general/Pair.java similarity index 97% rename from support/src/org/wamblee/Pair.java rename to support/src/org/wamblee/general/Pair.java index e06e8e1e..f7a3d972 100644 --- a/support/src/org/wamblee/Pair.java +++ b/support/src/org/wamblee/general/Pair.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.wamblee.utils; +package org.wamblee.general; /** * Represents a pair of objects. This is inspired on the C++ Standard Template Library diff --git a/support/src/org/wamblee/xml/XSLT.java b/support/src/org/wamblee/xml/XSLT.java new file mode 100644 index 00000000..14789e86 --- /dev/null +++ b/support/src/org/wamblee/xml/XSLT.java @@ -0,0 +1,87 @@ +/* + * Copyright 2005 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package org.wamblee.xml; + +import java.io.ByteArrayInputStream; +import java.io.File; + +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamSource; + +import org.w3c.dom.Document; + +/** + * XSLT utilities. + */ +public class XSLT { + + /** + * Transforms a DOM document into another DOM document using a given XSLT + * transformation. + * + * @param aDocument + * Document to transform. + * @param aXslt + * XSLT to use. + * @return Transformed document. + */ + public static Document transform( Document aDocument, File aXslt ) { + Source source = new DOMSource( aDocument ); + DOMResult result = new DOMResult( ); + transform( source, result, aXslt ); + return (Document) result.getNode( ); + } + + public static Document transform(byte[] aDocument, File aXslt ) { + Source source = new StreamSource( new ByteArrayInputStream(aDocument) ); + DOMResult result = new DOMResult( ); + transform( source, result, aXslt ); + return (Document) result.getNode( ); + } + + /** + * Transforms a DOM document into another DOM document using a given XSLT + * transformation. + * + * @param aDocument + * Document to transform. + * @param aXslt + * XSLT to use. + * @return Transformed document. + */ + public static void transform( Source aSource, Result aResult, + File aXslt ) { + try { + Source xslt = new StreamSource( aXslt ); + Transformer transformer = TransformerFactory.newInstance( ) + .newTransformer( xslt ); + transformer.transform( aSource, aResult ); + } catch ( TransformerConfigurationException e ) { + throw new RuntimeException( + "Configuration problem of XSLT transformation", e ); + } catch ( TransformerException e ) { + throw new RuntimeException( "Error transforming document", e ); + } + } +}