forked from geodmms/xdgnjobs

?? ?
2008-05-07 a7d401595583d49df460b6377d8f97dccf8e038a
update for EOFM-76
4 files modified
175 ■■■■■ changed files
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateSymbolStrategy.java 143 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java 2 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/resources/com/ximple/eofms/filter/ElementDispatcherRules.xml 15 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/test/resources/com/ximple/eofms/filter/test-data/testRules.xml 15 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateSymbolStrategy.java
@@ -1,5 +1,146 @@
package com.ximple.eofms.filter;
public class CreateSymbolStrategy
import java.util.List;
import org.geotools.feature.FeatureTypeBuilder;
import org.geotools.feature.FeatureType;
import org.geotools.feature.SchemaException;
import org.geotools.feature.AttributeTypeFactory;
import org.geotools.feature.Feature;
import org.geotools.feature.IllegalAttributeException;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Geometry;
import com.ximple.eofms.jobs.TWD97GeometryConverterDecorator;
import com.ximple.eofms.util.DefaultColorTable;
import com.ximple.io.dgn7.FrammeAttributeData;
import com.ximple.io.dgn7.Element;
import com.ximple.io.dgn7.UserAttributeData;
import com.ximple.io.dgn7.TextElement;
import com.ximple.io.dgn7.TextNodeElement;
public class CreateSymbolStrategy implements CreateFeatureTypeStrategy
{
    GeometryFactory geometryFactory = new GeometryFactory();
    FeatureTypeBuilder typeBuilder = null;
    TWD97GeometryConverterDecorator convertDecorator = new TWD97GeometryConverterDecorator();
    public CreateSymbolStrategy()
{
}
    protected FrammeAttributeData getFeatureLinkage(Element element)
    {
        if (!element.hasUserAttributeData())
            return null;
        List<UserAttributeData> usrDatas = element.getUserAttributeData();
        for (UserAttributeData anUsrData : usrDatas)
        {
            if (anUsrData instanceof FrammeAttributeData)
            {
                return (FrammeAttributeData) anUsrData;
            }
        }
        return null;
    }
    public FeatureType createFeatureElement(String featureName) throws SchemaException
    {
        if (typeBuilder == null)
        {
            typeBuilder = FeatureTypeBuilder.newInstance(featureName);
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("GEOM", Geometry.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("TID", Integer.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("OID", Long.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("CID", Integer.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("LID", Integer.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("LEVEL", Integer.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", String.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMWEIGHT", Integer.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMSTYLE", Integer.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("JUST", Integer.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("HEIGHT", Double.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("WIDTH", Double.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("ANGLE", Double.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMBOL", String.class));
        }
        return typeBuilder.getFeatureType();
    }
    public Feature createFeature(FeatureType featureType, Element element) throws IllegalAttributeException
    {
        DefaultColorTable colorTable = (DefaultColorTable) DefaultColorTable.getInstance();
        FrammeAttributeData fLinkage = getFeatureLinkage(element);
        if (fLinkage == null) return null;
        if (element instanceof TextElement)
        {
            TextElement txtElement = (TextElement) element;
            double angle = txtElement.getRotationAngle();
            angle += 180.0;
            angle = ((angle > 360.0)? (angle - 360.0) : (angle));
            StringBuilder sb = new StringBuilder();
            sb.append(txtElement.getFontIndex());
            sb.append('-');
            char id = txtElement.getText().toCharArray()[0];
            sb.append(Integer.toOctalString((int) id));
            convertDecorator.setConverter(txtElement);
            Feature feature = featureType.create(new Object[]{
                    convertDecorator.toGeometry(geometryFactory),
                    (int) fLinkage.getFsc(),
                    (long) fLinkage.getUfid(),
                    (int) fLinkage.getComponentID(),
                    0,
                    txtElement.getLevelIndex(),
                    colorTable.getColorCode(txtElement.getColorIndex()),
                    txtElement.getWeight(),
                    txtElement.getLineStyle(),
                    txtElement.getJustification(),
                    txtElement.getTextHeight(),
                    txtElement.getTextWidth(),
                    angle,
                    sb.toString()
            });
            return feature;
        } else if (element instanceof TextNodeElement)
        {
            TextNodeElement nodeElement = (TextNodeElement) element;
            convertDecorator.setConverter(nodeElement);
            String[] texts = nodeElement.getTextArray();
            StringBuffer sb = new StringBuffer();
            for (String text : texts)
            {
                if (sb.length() != 0)
                sb.append("\n");
                sb.append(text);
            }
            double angle = nodeElement.getRotationAngle();
            angle += 180.0;
            angle = ((angle > 360.0)? (angle - 360.0) : (angle));
            Feature feature = featureType.create(new Object[]{
                    convertDecorator.toGeometry(geometryFactory),
                    (int) fLinkage.getFsc(),
                    (long) fLinkage.getUfid(),
                    (int) fLinkage.getComponentID(),
                    0,
                    nodeElement.getLevelIndex(),
                    colorTable.getColorCode(nodeElement.getColorIndex()),
                    nodeElement.getWeight(),
                    nodeElement.getLineStyle(),
                    nodeElement.getFontIndex(),
                    nodeElement.getJustification(),
                    nodeElement.getTextNodeHeight(),
                    nodeElement.getTextNodeLength(),
                    angle,
                    sb.toString()
            });
            return feature;
        }
        return null;
    }
}
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/filter/CreateTextStrategy.java
@@ -60,7 +60,6 @@
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMCOLOR", String.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMWEIGHT", Integer.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("SYMSTYLE", Integer.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("FONT", Integer.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("JUST", Integer.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("HEIGHT", Double.class));
            typeBuilder.addType(AttributeTypeFactory.newAttributeType("WIDTH", Double.class));
@@ -92,7 +91,6 @@
                    colorTable.getColorCode(txtElement.getColorIndex()),
                    txtElement.getWeight(),
                    txtElement.getLineStyle(),
                    txtElement.getFontIndex(),
                    txtElement.getJustification(),
                    txtElement.getTextHeight(),
                    txtElement.getTextWidth(),
xdgnjobs/ximple-spatialjob/src/main/resources/com/ximple/eofms/filter/ElementDispatcherRules.xml
@@ -22,6 +22,11 @@
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
        <set-properties-rule/>
      </pattern>
      <pattern value="SymbolCreateStrategy">
        <object-create-rule classname="com.ximple.eofms.filter.CreateSymbolStrategy"/>
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
        <set-properties-rule/>
      </pattern>
      <pattern value="LineTextCreateStrategy">
        <object-create-rule classname="com.ximple.eofms.filter.CreateLineTextStrategy"/>
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
@@ -50,6 +55,11 @@
      </pattern>
      <pattern value="TextCreateStrategy">
        <object-create-rule classname="com.ximple.eofms.filter.CreateTextStrategy"/>
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
        <set-properties-rule/>
      </pattern>
      <pattern value="SymbolCreateStrategy">
        <object-create-rule classname="com.ximple.eofms.filter.CreateSymbolStrategy"/>
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
        <set-properties-rule/>
      </pattern>
@@ -91,6 +101,11 @@
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
        <set-properties-rule/>
      </pattern>
      <pattern value="SymbolCreateStrategy">
        <object-create-rule classname="com.ximple.eofms.filter.CreateSymbolStrategy"/>
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
        <set-properties-rule/>
      </pattern>
      <pattern value="LineTextCreateStrategy">
        <object-create-rule classname="com.ximple.eofms.filter.CreateLineTextStrategy"/>
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
xdgnjobs/ximple-spatialjob/src/test/resources/com/ximple/eofms/filter/test-data/testRules.xml
@@ -22,6 +22,11 @@
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
        <set-properties-rule/>
      </pattern>
      <pattern value="SymbolCreateStrategy">
        <object-create-rule classname="com.ximple.eofms.filter.CreateSymbolStrategy"/>
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
        <set-properties-rule/>
      </pattern>
      <pattern value="LineTextCreateStrategy">
        <object-create-rule classname="com.ximple.eofms.filter.CreateLineTextStrategy"/>
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
@@ -50,6 +55,11 @@
      </pattern>
      <pattern value="TextCreateStrategy">
        <object-create-rule classname="com.ximple.eofms.filter.CreateTextStrategy"/>
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
        <set-properties-rule/>
      </pattern>
      <pattern value="SymbolCreateStrategy">
        <object-create-rule classname="com.ximple.eofms.filter.CreateSymbolStrategy"/>
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
        <set-properties-rule/>
      </pattern>
@@ -91,6 +101,11 @@
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
        <set-properties-rule/>
      </pattern>
      <pattern value="SymbolCreateStrategy">
        <object-create-rule classname="com.ximple.eofms.filter.CreateSymbolStrategy"/>
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>
        <set-properties-rule/>
      </pattern>
      <pattern value="LineTextCreateStrategy">
        <object-create-rule classname="com.ximple.eofms.filter.CreateLineTextStrategy"/>
        <set-next-rule methodname="setCreateStrategy" paramtype="com.ximple.eofms.filter.CreateFeatureTypeStrategy"/>